The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 20 | #pragma clang diagnostic ignored "-Wextra" |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 21 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 22 | //#define LOG_NDEBUG 0 |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 23 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 24 | |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 25 | #include "SurfaceFlinger.h" |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 26 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 27 | #include <aidl/android/hardware/power/Boost.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 28 | #include <android-base/parseint.h> |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 29 | #include <android-base/properties.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 30 | #include <android-base/stringprintf.h> |
| 31 | #include <android-base/strings.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 32 | #include <android/configuration.h> |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 33 | #include <android/gui/IDisplayEventConnection.h> |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 34 | #include <android/gui/StaticDisplayInfo.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 35 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 36 | #include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h> |
| 37 | #include <android/hardware/configstore/1.1/types.h> |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 38 | #include <android/native_window.h> |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 39 | #include <android/os/IInputFlinger.h> |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 40 | #include <binder/IPCThreadState.h> |
| 41 | #include <binder/IServiceManager.h> |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 42 | #include <binder/PermissionCache.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 43 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 44 | #include <compositionengine/CompositionRefreshArgs.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 45 | #include <compositionengine/Display.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 46 | #include <compositionengine/DisplayColorProfile.h> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 47 | #include <compositionengine/DisplayColorProfileCreationArgs.h> |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 48 | #include <compositionengine/DisplayCreationArgs.h> |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 49 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 50 | #include <compositionengine/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 51 | #include <compositionengine/RenderSurface.h> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 52 | #include <compositionengine/impl/DisplayColorProfile.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 53 | #include <compositionengine/impl/OutputCompositionState.h> |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 54 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 55 | #include <configstore/Utils.h> |
| 56 | #include <cutils/compiler.h> |
| 57 | #include <cutils/properties.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 58 | #include <ftl/algorithm.h> |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 59 | #include <ftl/concat.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 60 | #include <ftl/fake_guard.h> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 61 | #include <ftl/future.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 62 | #include <ftl/unit.h> |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 63 | #include <gui/AidlStatusUtil.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 64 | #include <gui/BufferQueue.h> |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 65 | #include <gui/DebugEGLImageTracker.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 66 | #include <gui/IProducerListener.h> |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 67 | #include <gui/LayerDebugInfo.h> |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 68 | #include <gui/LayerMetadata.h> |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 69 | #include <gui/LayerState.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 70 | #include <gui/Surface.h> |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 71 | #include <gui/SurfaceComposerClient.h> |
rnlee | 60f46b5 | 2021-05-21 15:14:07 -0700 | [diff] [blame] | 72 | #include <gui/TraceUtils.h> |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 73 | #include <hidl/ServiceManagement.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 74 | #include <layerproto/LayerProtoParser.h> |
| 75 | #include <log/log.h> |
| 76 | #include <private/android_filesystem_config.h> |
| 77 | #include <private/gui/SyncFeatures.h> |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 78 | #include <processgroup/processgroup.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 79 | #include <renderengine/RenderEngine.h> |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 80 | #include <renderengine/impl/ExternalTexture.h> |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 81 | #include <scheduler/FrameTargeter.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 82 | #include <sys/types.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 83 | #include <ui/ColorSpace.h> |
| 84 | #include <ui/DebugUtils.h> |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 85 | #include <ui/DisplayId.h> |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 86 | #include <ui/DisplayMode.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 87 | #include <ui/DisplayStatInfo.h> |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 88 | #include <ui/DisplayState.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 89 | #include <ui/DynamicDisplayInfo.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 90 | #include <ui/GraphicBufferAllocator.h> |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 91 | #include <ui/HdrRenderTypeUtils.h> |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 92 | #include <ui/LayerStack.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 93 | #include <ui/PixelFormat.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 94 | #include <ui/StaticDisplayInfo.h> |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 95 | #include <unistd.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | #include <utils/StopWatch.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 97 | #include <utils/String16.h> |
| 98 | #include <utils/String8.h> |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 99 | #include <utils/Timers.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 100 | #include <utils/misc.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 101 | #include <algorithm> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 102 | #include <cerrno> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 103 | #include <cinttypes> |
| 104 | #include <cmath> |
| 105 | #include <cstdint> |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 106 | #include <filesystem> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 107 | #include <functional> |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 108 | #include <memory> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 109 | #include <mutex> |
| 110 | #include <optional> |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 111 | #include <string> |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 112 | #include <type_traits> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 113 | #include <unordered_map> |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 114 | #include <vector> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | |
Alec Mouri | 9b133ca | 2023-11-14 19:00:01 +0000 | [diff] [blame] | 116 | #include <common/FlagManager.h> |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 117 | #include <gui/LayerStatePermissions.h> |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 118 | #include <gui/SchedulingPolicy.h> |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 119 | #include <gui/SyncScreenCaptureListener.h> |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 120 | #include <ui/DisplayIdentification.h> |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 121 | #include "BackgroundExecutor.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 122 | #include "Client.h" |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 123 | #include "ClientCache.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 124 | #include "Colorizer.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 125 | #include "DisplayDevice.h" |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 126 | #include "DisplayHardware/ComposerHal.h" |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 127 | #include "DisplayHardware/FramebufferSurface.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 128 | #include "DisplayHardware/HWComposer.h" |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 129 | #include "DisplayHardware/Hal.h" |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 130 | #include "DisplayHardware/PowerAdvisor.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 131 | #include "DisplayHardware/VirtualDisplaySurface.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 132 | #include "DisplayRenderArea.h" |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 133 | #include "Effects/Daltonizer.h" |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 134 | #include "FpsReporter.h" |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 135 | #include "FrameTimeline/FrameTimeline.h" |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 136 | #include "FrameTracer/FrameTracer.h" |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 137 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 138 | #include "FrontEnd/LayerHandle.h" |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 139 | #include "FrontEnd/LayerLifecycleManager.h" |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 140 | #include "FrontEnd/LayerLog.h" |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 141 | #include "FrontEnd/LayerSnapshot.h" |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 142 | #include "HdrLayerInfoReporter.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 143 | #include "Layer.h" |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 144 | #include "LayerProtoHelper.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 145 | #include "LayerRenderArea.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 146 | #include "LayerVector.h" |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 147 | #include "MutexUtils.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 148 | #include "NativeWindowSurface.h" |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 149 | #include "RegionSamplingThread.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 150 | #include "Scheduler/EventThread.h" |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 151 | #include "Scheduler/LayerHistory.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 152 | #include "Scheduler/Scheduler.h" |
Ady Abraham | c581d3c | 2020-08-06 17:34:27 -0700 | [diff] [blame] | 153 | #include "Scheduler/VsyncConfiguration.h" |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 154 | #include "Scheduler/VsyncModulator.h" |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 155 | #include "ScreenCaptureOutput.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 156 | #include "StartPropertySetThread.h" |
| 157 | #include "SurfaceFlingerProperties.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 158 | #include "TimeStats/TimeStats.h" |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 159 | #include "TunnelModeEnabledReporter.h" |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 160 | #include "Utils/Dumper.h" |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 161 | #include "WindowInfosListenerInvoker.h" |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 162 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 163 | #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 164 | #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 165 | #include <aidl/android/hardware/graphics/composer3/RenderIntent.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 166 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 167 | #undef NO_THREAD_SAFETY_ANALYSIS |
| 168 | #define NO_THREAD_SAFETY_ANALYSIS \ |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 169 | _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] | 170 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 171 | // To enable layer borders in the system, change the below flag to true. |
| 172 | #undef DOES_CONTAIN_BORDER |
| 173 | #define DOES_CONTAIN_BORDER false |
| 174 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | namespace android { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 176 | using namespace std::chrono_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 177 | using namespace std::string_literals; |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 178 | using namespace std::string_view_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 179 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 180 | using namespace hardware::configstore; |
| 181 | using namespace hardware::configstore::V1_0; |
| 182 | using namespace sysprop; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 183 | using ftl::Flags; |
| 184 | using namespace ftl::flag_operators; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 185 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 186 | using aidl::android::hardware::graphics::common::DisplayDecorationSupport; |
| 187 | using aidl::android::hardware::graphics::composer3::Capability; |
| 188 | using aidl::android::hardware::graphics::composer3::DisplayCapability; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 189 | using CompositionStrategyPredictionState = android::compositionengine::impl:: |
| 190 | OutputCompositionState::CompositionStrategyPredictionState; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 191 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 192 | using base::StringAppendF; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 193 | using display::PhysicalDisplay; |
| 194 | using display::PhysicalDisplays; |
Vishnu Nair | af6d297 | 2022-11-18 06:26:38 +0000 | [diff] [blame] | 195 | using frontend::TransactionHandler; |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 196 | using gui::DisplayInfo; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 197 | using gui::GameMode; |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 198 | using gui::IDisplayEventConnection; |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 199 | using gui::IWindowInfosListener; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 200 | using gui::LayerMetadata; |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 201 | using gui::WindowInfo; |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 202 | using gui::aidl_utils::binderStatusFromStatusT; |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 203 | using scheduler::VsyncModulator; |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 204 | using ui::Dataspace; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 205 | using ui::DisplayPrimaries; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 206 | using ui::RenderIntent; |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 207 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 208 | using KernelIdleTimerController = scheduler::RefreshRateSelector::KernelIdleTimerController; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 209 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 210 | namespace hal = android::hardware::graphics::composer::hal; |
| 211 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 212 | namespace { |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 213 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 214 | static constexpr int FOUR_K_WIDTH = 3840; |
| 215 | static constexpr int FOUR_K_HEIGHT = 2160; |
| 216 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 217 | // TODO(b/141333600): Consolidate with DisplayMode::Builder::getDefaultDensity. |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 218 | constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 219 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 220 | float getDensityFromProperty(const char* property, bool required) { |
| 221 | char value[PROPERTY_VALUE_MAX]; |
| 222 | const float density = property_get(property, value, nullptr) > 0 ? std::atof(value) : 0.f; |
| 223 | if (!density && required) { |
| 224 | ALOGE("%s must be defined as a build property", property); |
| 225 | return FALLBACK_DENSITY; |
| 226 | } |
| 227 | return density; |
| 228 | } |
| 229 | |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 230 | // Currently we only support V0_SRGB and DISPLAY_P3 as composition preference. |
| 231 | bool validateCompositionDataspace(Dataspace dataspace) { |
| 232 | return dataspace == Dataspace::V0_SRGB || dataspace == Dataspace::DISPLAY_P3; |
| 233 | } |
| 234 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 235 | std::chrono::milliseconds getIdleTimerTimeout(DisplayId displayId) { |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 236 | if (const int32_t displayIdleTimerMs = |
| 237 | base::GetIntProperty("debug.sf.set_idle_timer_ms_"s + |
| 238 | std::to_string(displayId.value), |
| 239 | 0); |
| 240 | displayIdleTimerMs > 0) { |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 241 | return std::chrono::milliseconds(displayIdleTimerMs); |
| 242 | } |
| 243 | |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 244 | 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] | 245 | const int32_t millis = setIdleTimerMs ? setIdleTimerMs : sysprop::set_idle_timer_ms(0); |
| 246 | return std::chrono::milliseconds(millis); |
| 247 | } |
| 248 | |
| 249 | bool getKernelIdleTimerSyspropConfig(DisplayId displayId) { |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 250 | const bool displaySupportKernelIdleTimer = |
| 251 | base::GetBoolProperty("debug.sf.support_kernel_idle_timer_"s + |
| 252 | std::to_string(displayId.value), |
| 253 | false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 254 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 255 | return displaySupportKernelIdleTimer || sysprop::support_kernel_idle_timer(false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 258 | bool isAbove4k30(const ui::DisplayMode& outMode) { |
| 259 | using fps_approx_ops::operator>; |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 260 | Fps refreshRate = Fps::fromValue(outMode.peakRefreshRate); |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 261 | return outMode.resolution.getWidth() >= FOUR_K_WIDTH && |
| 262 | outMode.resolution.getHeight() >= FOUR_K_HEIGHT && refreshRate > 30_Hz; |
| 263 | } |
| 264 | |
| 265 | void excludeDolbyVisionIf4k30Present(const std::vector<ui::Hdr>& displayHdrTypes, |
| 266 | ui::DisplayMode& outMode) { |
| 267 | if (isAbove4k30(outMode) && |
| 268 | std::any_of(displayHdrTypes.begin(), displayHdrTypes.end(), |
| 269 | [](ui::Hdr type) { return type == ui::Hdr::DOLBY_VISION_4K30; })) { |
| 270 | for (ui::Hdr type : displayHdrTypes) { |
| 271 | if (type != ui::Hdr::DOLBY_VISION_4K30 && type != ui::Hdr::DOLBY_VISION) { |
| 272 | outMode.supportedHdrTypes.push_back(type); |
| 273 | } |
| 274 | } |
| 275 | } else { |
| 276 | for (ui::Hdr type : displayHdrTypes) { |
| 277 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 278 | outMode.supportedHdrTypes.push_back(type); |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | HdrCapabilities filterOut4k30(const HdrCapabilities& displayHdrCapabilities) { |
| 285 | std::vector<ui::Hdr> hdrTypes; |
| 286 | for (ui::Hdr type : displayHdrCapabilities.getSupportedHdrTypes()) { |
| 287 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 288 | hdrTypes.push_back(type); |
| 289 | } |
| 290 | } |
| 291 | return {hdrTypes, displayHdrCapabilities.getDesiredMaxLuminance(), |
| 292 | displayHdrCapabilities.getDesiredMaxAverageLuminance(), |
| 293 | displayHdrCapabilities.getDesiredMinLuminance()}; |
| 294 | } |
| 295 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 296 | uint32_t getLayerIdFromSurfaceControl(sp<SurfaceControl> surfaceControl) { |
| 297 | if (!surfaceControl) { |
| 298 | return UNASSIGNED_LAYER_ID; |
| 299 | } |
| 300 | return LayerHandle::getLayerId(surfaceControl->getHandle()); |
| 301 | } |
| 302 | |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 303 | /** |
| 304 | * Returns true if the file at path exists and is newer than duration. |
| 305 | */ |
| 306 | bool fileNewerThan(const std::string& path, std::chrono::minutes duration) { |
| 307 | using Clock = std::filesystem::file_time_type::clock; |
| 308 | std::error_code error; |
| 309 | std::filesystem::file_time_type updateTime = std::filesystem::last_write_time(path, error); |
| 310 | if (error) { |
| 311 | return false; |
| 312 | } |
| 313 | return duration > (Clock::now() - updateTime); |
| 314 | } |
| 315 | |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 316 | bool isFrameIntervalOnCadence(TimePoint expectedPresentTime, TimePoint lastExpectedPresentTimestamp, |
| 317 | Fps lastFrameInterval, Period timeout, Duration threshold) { |
| 318 | if (lastFrameInterval.getPeriodNsecs() == 0) { |
| 319 | return false; |
| 320 | } |
| 321 | |
| 322 | const auto expectedPresentTimeDeltaNs = |
| 323 | expectedPresentTime.ns() - lastExpectedPresentTimestamp.ns(); |
| 324 | |
| 325 | if (expectedPresentTimeDeltaNs > timeout.ns()) { |
| 326 | return false; |
| 327 | } |
| 328 | |
| 329 | const auto expectedPresentPeriods = static_cast<nsecs_t>( |
| 330 | std::round(static_cast<float>(expectedPresentTimeDeltaNs) / |
| 331 | static_cast<float>(lastFrameInterval.getPeriodNsecs()))); |
| 332 | const auto calculatedPeriodsOutNs = lastFrameInterval.getPeriodNsecs() * expectedPresentPeriods; |
| 333 | const auto calculatedExpectedPresentTimeNs = |
| 334 | lastExpectedPresentTimestamp.ns() + calculatedPeriodsOutNs; |
| 335 | const auto presentTimeDelta = |
| 336 | std::abs(expectedPresentTime.ns() - calculatedExpectedPresentTimeNs); |
| 337 | return presentTimeDelta < threshold.ns(); |
| 338 | } |
| 339 | |
| 340 | bool isExpectedPresentWithinTimeout(TimePoint expectedPresentTime, |
| 341 | TimePoint lastExpectedPresentTimestamp, |
| 342 | std::optional<Period> timeoutOpt, Duration threshold) { |
| 343 | if (!timeoutOpt) { |
| 344 | // Always within timeout if timeoutOpt is absent and don't send hint |
| 345 | // for the timeout |
| 346 | return true; |
| 347 | } |
| 348 | |
| 349 | if (timeoutOpt->ns() == 0) { |
| 350 | // Always outside timeout if timeoutOpt is 0 and always send |
| 351 | // the hint for the timeout. |
| 352 | return false; |
| 353 | } |
| 354 | |
| 355 | if (expectedPresentTime.ns() < lastExpectedPresentTimestamp.ns() + timeoutOpt->ns()) { |
| 356 | return true; |
| 357 | } |
| 358 | |
| 359 | // Check if within the threshold as it can be just outside the timeout |
| 360 | return std::abs(expectedPresentTime.ns() - |
| 361 | (lastExpectedPresentTimestamp.ns() + timeoutOpt->ns())) < threshold.ns(); |
| 362 | } |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 363 | } // namespace anonymous |
| 364 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | // --------------------------------------------------------------------------- |
| 366 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 367 | const String16 sHardwareTest("android.permission.HARDWARE_TEST"); |
| 368 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 369 | const String16 sRotateSurfaceFlinger("android.permission.ROTATE_SURFACE_FLINGER"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 370 | const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER"); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 371 | const String16 sControlDisplayBrightness("android.permission.CONTROL_DISPLAY_BRIGHTNESS"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 372 | const String16 sDump("android.permission.DUMP"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 373 | const String16 sCaptureBlackoutContent("android.permission.CAPTURE_BLACKOUT_CONTENT"); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 374 | const String16 sInternalSystemWindow("android.permission.INTERNAL_SYSTEM_WINDOW"); |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 375 | const String16 sWakeupSurfaceFlinger("android.permission.WAKEUP_SURFACE_FLINGER"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 376 | |
Amy Hsu | c8cdfef | 2020-05-07 13:06:25 +0800 | [diff] [blame] | 377 | const char* KERNEL_IDLE_TIMER_PROP = "graphics.display.kernel_idle_timer.enabled"; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 378 | |
| 379 | // --------------------------------------------------------------------------- |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 380 | int64_t SurfaceFlinger::dispSyncPresentTimeOffset; |
| 381 | bool SurfaceFlinger::useHwcForRgbToYuv; |
| 382 | bool SurfaceFlinger::hasSyncFramework; |
| 383 | int64_t SurfaceFlinger::maxFrameBufferAcquiredBuffers; |
| 384 | int64_t SurfaceFlinger::minAcquiredBuffers = 1; |
| 385 | uint32_t SurfaceFlinger::maxGraphicsWidth; |
| 386 | uint32_t SurfaceFlinger::maxGraphicsHeight; |
| 387 | bool SurfaceFlinger::useContextPriority; |
| 388 | Dataspace SurfaceFlinger::defaultCompositionDataspace = Dataspace::V0_SRGB; |
| 389 | ui::PixelFormat SurfaceFlinger::defaultCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
| 390 | Dataspace SurfaceFlinger::wideColorGamutCompositionDataspace = Dataspace::V0_SRGB; |
| 391 | ui::PixelFormat SurfaceFlinger::wideColorGamutCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 392 | LatchUnsignaledConfig SurfaceFlinger::enableLatchUnsignaledConfig; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 393 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 394 | std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) { |
| 395 | switch(displayColorSetting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 396 | case DisplayColorSetting::kManaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 397 | return std::string("Managed"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 398 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 399 | return std::string("Unmanaged"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 400 | case DisplayColorSetting::kEnhanced: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 401 | return std::string("Enhanced"); |
| 402 | default: |
| 403 | return std::string("Unknown ") + |
| 404 | std::to_string(static_cast<int>(displayColorSetting)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 405 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 408 | bool callingThreadHasPermission(const String16& permission) { |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 409 | IPCThreadState* ipc = IPCThreadState::self(); |
| 410 | const int pid = ipc->getCallingPid(); |
| 411 | const int uid = ipc->getCallingUid(); |
| 412 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 413 | PermissionCache::checkPermission(permission, pid, uid); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 414 | } |
| 415 | |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 416 | ui::Transform::RotationFlags SurfaceFlinger::sActiveDisplayRotationFlags = ui::Transform::ROT_0; |
| 417 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 418 | SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag) |
| 419 | : mFactory(factory), |
| 420 | mPid(getpid()), |
Yiwei Zhang | f0229a7 | 2019-09-09 19:28:02 -0700 | [diff] [blame] | 421 | mTimeStats(std::make_shared<impl::TimeStats>()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 422 | mFrameTracer(mFactory.createFrameTracer()), |
| 423 | mFrameTimeline(mFactory.createFrameTimeline(mTimeStats, mPid)), |
| 424 | mCompositionEngine(mFactory.createCompositionEngine()), |
| 425 | mHwcServiceName(base::GetProperty("debug.sf.hwc_service_name"s, "default"s)), |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 426 | mTunnelModeEnabledReporter(sp<TunnelModeEnabledReporter>::make()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 427 | mEmulatedDisplayDensity(getDensityFromProperty("qemu.sf.lcd_density", false)), |
| 428 | mInternalDisplayDensity( |
| 429 | getDensityFromProperty("ro.sf.lcd_density", !mEmulatedDisplayDensity)), |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 430 | mPowerAdvisor(std::make_unique<Hwc2::impl::PowerAdvisor>(*this)), |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 431 | mWindowInfosListenerInvoker(sp<WindowInfosListenerInvoker>::make()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 432 | ALOGI("Using HWComposer service: %s", mHwcServiceName.c_str()); |
| 433 | } |
Fabien Sanglard | 0cc1938 | 2017-03-06 11:54:40 -0800 | [diff] [blame] | 434 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 435 | SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { |
| 436 | ATRACE_CALL(); |
| 437 | ALOGI("SurfaceFlinger is starting"); |
| 438 | |
| 439 | hasSyncFramework = running_without_sync_framework(true); |
| 440 | |
| 441 | dispSyncPresentTimeOffset = present_time_offset_from_vsync_ns(0); |
| 442 | |
| 443 | useHwcForRgbToYuv = force_hwc_copy_for_virtual_displays(false); |
| 444 | |
| 445 | maxFrameBufferAcquiredBuffers = max_frame_buffer_acquired_buffers(2); |
| 446 | minAcquiredBuffers = |
| 447 | SurfaceFlingerProperties::min_acquired_buffers().value_or(minAcquiredBuffers); |
| 448 | |
| 449 | maxGraphicsWidth = std::max(max_graphics_width(0), 0); |
| 450 | maxGraphicsHeight = std::max(max_graphics_height(0), 0); |
| 451 | |
| 452 | mSupportsWideColor = has_wide_color_display(false); |
| 453 | mDefaultCompositionDataspace = |
| 454 | static_cast<ui::Dataspace>(default_composition_dataspace(Dataspace::V0_SRGB)); |
| 455 | mWideColorGamutCompositionDataspace = static_cast<ui::Dataspace>(wcg_composition_dataspace( |
| 456 | mSupportsWideColor ? Dataspace::DISPLAY_P3 : Dataspace::V0_SRGB)); |
| 457 | defaultCompositionDataspace = mDefaultCompositionDataspace; |
| 458 | wideColorGamutCompositionDataspace = mWideColorGamutCompositionDataspace; |
| 459 | defaultCompositionPixelFormat = static_cast<ui::PixelFormat>( |
| 460 | default_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 461 | wideColorGamutCompositionPixelFormat = |
| 462 | static_cast<ui::PixelFormat>(wcg_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 463 | |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 464 | mLayerCachingEnabled = |
| 465 | base::GetBoolProperty("debug.sf.enable_layer_caching"s, |
| 466 | sysprop::SurfaceFlingerProperties::enable_layer_caching() |
| 467 | .value_or(false)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 468 | |
| 469 | useContextPriority = use_context_priority(true); |
| 470 | |
| 471 | mInternalDisplayPrimaries = sysprop::getDisplayNativePrimaries(); |
| 472 | |
| 473 | // debugging stuff... |
| 474 | char value[PROPERTY_VALUE_MAX]; |
| 475 | |
| 476 | property_get("ro.build.type", value, "user"); |
| 477 | mIsUserBuild = strcmp(value, "user") == 0; |
| 478 | |
| 479 | mDebugFlashDelay = base::GetUintProperty("debug.sf.showupdates"s, 0u); |
| 480 | |
| 481 | mBackpressureGpuComposition = base::GetBoolProperty("debug.sf.enable_gl_backpressure"s, true); |
| 482 | ALOGI_IF(mBackpressureGpuComposition, "Enabling backpressure for GPU composition"); |
| 483 | |
| 484 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 485 | bool supportsBlurs = atoi(value); |
| 486 | mSupportsBlur = supportsBlurs; |
| 487 | ALOGI_IF(!mSupportsBlur, "Disabling blur effects, they are not supported."); |
| 488 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 489 | property_get("debug.sf.luma_sampling", value, "1"); |
| 490 | mLumaSampling = atoi(value); |
| 491 | |
| 492 | property_get("debug.sf.disable_client_composition_cache", value, "0"); |
| 493 | mDisableClientCompositionCache = atoi(value); |
| 494 | |
| 495 | property_get("debug.sf.predict_hwc_composition_strategy", value, "1"); |
| 496 | mPredictCompositionStrategy = atoi(value); |
| 497 | |
| 498 | property_get("debug.sf.treat_170m_as_sRGB", value, "0"); |
| 499 | mTreat170mAsSrgb = atoi(value); |
| 500 | |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 501 | property_get("debug.sf.dim_in_gamma_in_enhanced_screenshots", value, 0); |
| 502 | mDimInGammaSpaceForEnhancedScreenshots = atoi(value); |
| 503 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 504 | mIgnoreHwcPhysicalDisplayOrientation = |
| 505 | base::GetBoolProperty("debug.sf.ignore_hwc_physical_display_orientation"s, false); |
| 506 | |
| 507 | // We should be reading 'persist.sys.sf.color_saturation' here |
| 508 | // but since /data may be encrypted, we need to wait until after vold |
| 509 | // comes online to attempt to read the property. The property is |
| 510 | // instead read after the boot animation |
| 511 | |
| 512 | if (base::GetBoolProperty("debug.sf.treble_testing_override"s, false)) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 513 | // Without the override SurfaceFlinger cannot connect to HIDL |
| 514 | // services that are not listed in the manifests. Considered |
| 515 | // deriving the setting from the set service name, but it |
| 516 | // would be brittle if the name that's not 'default' is used |
| 517 | // for production purposes later on. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 518 | ALOGI("Enabling Treble testing override"); |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 519 | android::hardware::details::setTrebleTestingOverride(true); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 520 | } |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 521 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 522 | // TODO (b/270966065) Update the HWC based refresh rate overlay to support spinner |
| 523 | mRefreshRateOverlaySpinner = property_get_bool("debug.sf.show_refresh_rate_overlay_spinner", 0); |
| 524 | mRefreshRateOverlayRenderRate = |
| 525 | property_get_bool("debug.sf.show_refresh_rate_overlay_render_rate", 0); |
| 526 | mRefreshRateOverlayShowInMiddle = |
| 527 | property_get_bool("debug.sf.show_refresh_rate_overlay_in_middle", 0); |
| 528 | |
| 529 | if (!mIsUserBuild && base::GetBoolProperty("debug.sf.enable_transaction_tracing"s, true)) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 530 | mTransactionTracing.emplace(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 531 | mLayerTracing.setTransactionTracing(*mTransactionTracing); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 532 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 533 | |
| 534 | mIgnoreHdrCameraLayers = ignore_hdr_camera_layers(false); |
| 535 | |
| 536 | mLayerLifecycleManagerEnabled = |
Vishnu Nair | f42d9bd | 2023-08-23 21:35:33 +0000 | [diff] [blame] | 537 | base::GetBoolProperty("persist.debug.sf.enable_layer_lifecycle_manager"s, true); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 538 | mLegacyFrontEndEnabled = !mLayerLifecycleManagerEnabled || |
| 539 | base::GetBoolProperty("persist.debug.sf.enable_legacy_frontend"s, false); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 540 | |
| 541 | // These are set by the HWC implementation to indicate that they will use the workarounds. |
| 542 | mIsHotplugErrViaNegVsync = |
| 543 | base::GetBoolProperty("debug.sf.hwc_hotplug_error_via_neg_vsync"s, false); |
| 544 | |
| 545 | mIsHdcpViaNegVsync = base::GetBoolProperty("debug.sf.hwc_hdcp_via_neg_vsync"s, false); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | LatchUnsignaledConfig SurfaceFlinger::getLatchUnsignaledConfig() { |
Ady Abraham | d9e8d1b | 2022-02-25 00:36:10 +0000 | [diff] [blame] | 549 | if (base::GetBoolProperty("debug.sf.auto_latch_unsignaled"s, true)) { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 550 | return LatchUnsignaledConfig::AutoSingleLayer; |
| 551 | } |
| 552 | |
| 553 | return LatchUnsignaledConfig::Disabled; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | } |
| 555 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 556 | SurfaceFlinger::~SurfaceFlinger() = default; |
| 557 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 558 | void SurfaceFlinger::binderDied(const wp<IBinder>&) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 559 | // the window manager died on us. prepare its eulogy. |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 560 | mBootFinished = false; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 561 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 562 | static_cast<void>(mScheduler->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 563 | // Sever the link to inputflinger since it's gone as well. |
| 564 | mInputFlinger.clear(); |
Vishnu Nair | b9df470 | 2021-03-01 11:53:15 -0800 | [diff] [blame] | 565 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 566 | initializeDisplays(); |
| 567 | })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 568 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 569 | startBootAnim(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 570 | } |
| 571 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 572 | void SurfaceFlinger::run() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 573 | mScheduler->run(); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 574 | } |
| 575 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 576 | sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName, bool secure, |
| 577 | float requestedRefreshRate) { |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 578 | // onTransact already checks for some permissions, but adding an additional check here. |
| 579 | // This is to ensure that only system and graphics can request to create a secure |
| 580 | // display. Secure displays can show secure content so we add an additional restriction on it. |
| 581 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 582 | if (secure && uid != AID_GRAPHICS && uid != AID_SYSTEM) { |
| 583 | ALOGE("Only privileged processes can create a secure display"); |
| 584 | return nullptr; |
| 585 | } |
| 586 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 587 | class DisplayToken : public BBinder { |
| 588 | sp<SurfaceFlinger> flinger; |
| 589 | virtual ~DisplayToken() { |
| 590 | // no more references, this display must be terminated |
| 591 | Mutex::Autolock _l(flinger->mStateLock); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 592 | flinger->mCurrentState.displays.removeItem(wp<IBinder>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 593 | flinger->setTransactionFlags(eDisplayTransactionNeeded); |
| 594 | } |
| 595 | public: |
Chih-Hung Hsieh | c406791 | 2016-05-03 14:03:27 -0700 | [diff] [blame] | 596 | explicit DisplayToken(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 597 | : flinger(flinger) { |
| 598 | } |
| 599 | }; |
| 600 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 601 | sp<BBinder> token = sp<DisplayToken>::make(sp<SurfaceFlinger>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 602 | |
| 603 | Mutex::Autolock _l(mStateLock); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 604 | // Display ID is assigned when virtual display is allocated by HWC. |
| 605 | DisplayDeviceState state; |
| 606 | state.isSecure = secure; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 607 | // Set display as protected when marked as secure to ensure no behavior change |
| 608 | // TODO (b/314820005): separate as a different arg when creating the display. |
| 609 | state.isProtected = secure; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 610 | state.displayName = displayName; |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 611 | state.requestedRefreshRate = Fps::fromValue(requestedRefreshRate); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 612 | mCurrentState.displays.add(token, state); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 613 | return token; |
| 614 | } |
| 615 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 616 | void SurfaceFlinger::destroyDisplay(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 617 | Mutex::Autolock lock(mStateLock); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 618 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 619 | const ssize_t index = mCurrentState.displays.indexOfKey(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 620 | if (index < 0) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 621 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 622 | return; |
| 623 | } |
| 624 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 625 | const DisplayDeviceState& state = mCurrentState.displays.valueAt(index); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 626 | if (state.physical) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 627 | ALOGE("%s: Invalid operation on physical display", __func__); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 628 | return; |
| 629 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 630 | mCurrentState.displays.removeItemsAt(index); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 631 | setTransactionFlags(eDisplayTransactionNeeded); |
| 632 | } |
| 633 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 634 | void SurfaceFlinger::enableHalVirtualDisplays(bool enable) { |
| 635 | auto& generator = mVirtualDisplayIdGenerators.hal; |
| 636 | if (!generator && enable) { |
| 637 | ALOGI("Enabling HAL virtual displays"); |
| 638 | generator.emplace(getHwComposer().getMaxVirtualDisplayCount()); |
| 639 | } else if (generator && !enable) { |
| 640 | ALOGW_IF(generator->inUse(), "Disabling HAL virtual displays while in use"); |
| 641 | generator.reset(); |
| 642 | } |
| 643 | } |
| 644 | |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 645 | VirtualDisplayId SurfaceFlinger::acquireVirtualDisplay(ui::Size resolution, |
| 646 | ui::PixelFormat format) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 647 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 648 | if (const auto id = generator->generateId()) { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 649 | if (getHwComposer().allocateVirtualDisplay(*id, resolution, &format)) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 650 | return *id; |
| 651 | } |
| 652 | |
| 653 | generator->releaseId(*id); |
| 654 | } else { |
| 655 | ALOGW("%s: Exhausted HAL virtual displays", __func__); |
| 656 | } |
| 657 | |
| 658 | ALOGW("%s: Falling back to GPU virtual display", __func__); |
| 659 | } |
| 660 | |
| 661 | const auto id = mVirtualDisplayIdGenerators.gpu.generateId(); |
| 662 | LOG_ALWAYS_FATAL_IF(!id, "Failed to generate ID for GPU virtual display"); |
| 663 | return *id; |
| 664 | } |
| 665 | |
| 666 | void SurfaceFlinger::releaseVirtualDisplay(VirtualDisplayId displayId) { |
| 667 | if (const auto id = HalVirtualDisplayId::tryCast(displayId)) { |
| 668 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 669 | generator->releaseId(*id); |
| 670 | } |
| 671 | return; |
| 672 | } |
| 673 | |
| 674 | const auto id = GpuVirtualDisplayId::tryCast(displayId); |
| 675 | LOG_ALWAYS_FATAL_IF(!id); |
| 676 | mVirtualDisplayIdGenerators.gpu.releaseId(*id); |
| 677 | } |
| 678 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 679 | std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdsLocked() const { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 680 | std::vector<PhysicalDisplayId> displayIds; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 681 | displayIds.reserve(mPhysicalDisplays.size()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 682 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 683 | const auto defaultDisplayId = getDefaultDisplayDeviceLocked()->getPhysicalId(); |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 684 | displayIds.push_back(defaultDisplayId); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 685 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 686 | for (const auto& [id, display] : mPhysicalDisplays) { |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 687 | if (id != defaultDisplayId) { |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 688 | displayIds.push_back(id); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 689 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 690 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 691 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 692 | return displayIds; |
| 693 | } |
| 694 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 695 | std::optional<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdLocked( |
| 696 | const sp<display::DisplayToken>& displayToken) const { |
| 697 | return ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 698 | .transform(&ftl::to_key<PhysicalDisplays>); |
| 699 | } |
| 700 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 701 | sp<IBinder> SurfaceFlinger::getPhysicalDisplayToken(PhysicalDisplayId displayId) const { |
| 702 | Mutex::Autolock lock(mStateLock); |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 703 | return getPhysicalDisplayTokenLocked(displayId); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 706 | HWComposer& SurfaceFlinger::getHwComposer() const { |
| 707 | return mCompositionEngine->getHwComposer(); |
| 708 | } |
| 709 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 710 | renderengine::RenderEngine& SurfaceFlinger::getRenderEngine() const { |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 711 | return *mRenderEngine; |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 714 | compositionengine::CompositionEngine& SurfaceFlinger::getCompositionEngine() const { |
| 715 | return *mCompositionEngine.get(); |
| 716 | } |
| 717 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 718 | void SurfaceFlinger::bootFinished() { |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 719 | if (mBootFinished == true) { |
| 720 | ALOGE("Extra call to bootFinished"); |
| 721 | return; |
| 722 | } |
| 723 | mBootFinished = true; |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame] | 724 | FlagManager::getMutableInstance().markBootCompleted(); |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 725 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 726 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 727 | } |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 728 | |
| 729 | if (mRenderEnginePrimeCacheFuture.valid()) { |
| 730 | mRenderEnginePrimeCacheFuture.get(); |
| 731 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 732 | const nsecs_t now = systemTime(); |
| 733 | const nsecs_t duration = now - mBootTime; |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 734 | ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 735 | |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 736 | mFrameTracer->initialize(); |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 737 | mFrameTimeline->onBootFinished(); |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 738 | getRenderEngine().setEnableTracing(FlagManager::getInstance().use_skia_tracing()); |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 739 | |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 740 | // wait patiently for the window manager death |
| 741 | const String16 name("window"); |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 742 | mWindowManager = defaultServiceManager()->waitForService(name); |
Steven Moreland | a904bb9 | 2019-07-02 17:37:23 -0700 | [diff] [blame] | 743 | if (mWindowManager != 0) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 744 | mWindowManager->linkToDeath(sp<IBinder::DeathRecipient>::fromExisting(this)); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | // stop boot animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 748 | // formerly we would just kill the process, but we now ask it to exit so it |
| 749 | // can choose where to stop the animation. |
| 750 | property_set("service.bootanim.exit", "1"); |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 751 | |
| 752 | const int LOGTAG_SF_STOP_BOOTANIM = 60110; |
| 753 | LOG_EVENT_LONG(LOGTAG_SF_STOP_BOOTANIM, |
| 754 | ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 755 | |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 756 | sp<IBinder> input(defaultServiceManager()->waitForService(String16("inputflinger"))); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 757 | |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 758 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 759 | if (input == nullptr) { |
| 760 | ALOGE("Failed to link to input service"); |
| 761 | } else { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 762 | mInputFlinger = interface_cast<os::IInputFlinger>(input); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 763 | } |
| 764 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 765 | readPersistentProperties(); |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 766 | const bool hintSessionEnabled = FlagManager::getInstance().use_adpf_cpu_hint(); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 767 | mPowerAdvisor->enablePowerHintSession(hintSessionEnabled); |
| 768 | const bool hintSessionUsed = mPowerAdvisor->usePowerHintSession(); |
Matt Buckley | 547cc0c | 2023-10-27 22:22:36 +0000 | [diff] [blame] | 769 | // Ordering is important here, as onBootFinished signals to PowerAdvisor that concurrency |
| 770 | // is safe because its variables are initialized. |
| 771 | mPowerAdvisor->onBootFinished(); |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 772 | ALOGD("Power hint is %s", |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 773 | hintSessionUsed ? "supported" : (hintSessionEnabled ? "unsupported" : "disabled")); |
| 774 | if (hintSessionUsed) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 775 | std::optional<pid_t> renderEngineTid = getRenderEngine().getRenderEngineTid(); |
| 776 | std::vector<int32_t> tidList; |
| 777 | tidList.emplace_back(gettid()); |
| 778 | if (renderEngineTid.has_value()) { |
| 779 | tidList.emplace_back(*renderEngineTid); |
| 780 | } |
Matt Buckley | 547cc0c | 2023-10-27 22:22:36 +0000 | [diff] [blame] | 781 | if (!mPowerAdvisor->startPowerHintSession(std::move(tidList))) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 782 | ALOGW("Cannot start power hint session"); |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 783 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 784 | } |
| 785 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 786 | mBootStage = BootStage::FINISHED; |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 787 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 788 | if (base::GetBoolProperty("sf.debug.show_refresh_rate_overlay"s, false)) { |
| 789 | ftl::FakeGuard guard(mStateLock); |
| 790 | enableRefreshRateOverlay(true); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 791 | } |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 792 | })); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 795 | void chooseRenderEngineType(renderengine::RenderEngineCreationArgs::Builder& builder) { |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 796 | char prop[PROPERTY_VALUE_MAX]; |
Leon Scroggins III | f840ae5 | 2024-01-25 15:10:12 -0500 | [diff] [blame] | 797 | property_get(PROPERTY_DEBUG_RENDERENGINE_BACKEND, prop, ""); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 798 | |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 799 | if (strcmp(prop, "skiagl") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 800 | builder.setThreaded(renderengine::RenderEngine::Threaded::NO) |
| 801 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::GL); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 802 | } else if (strcmp(prop, "skiaglthreaded") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 803 | builder.setThreaded(renderengine::RenderEngine::Threaded::YES) |
| 804 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::GL); |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 805 | } else if (strcmp(prop, "skiavk") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 806 | builder.setThreaded(renderengine::RenderEngine::Threaded::NO) |
| 807 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::VK); |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 808 | } else if (strcmp(prop, "skiavkthreaded") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 809 | builder.setThreaded(renderengine::RenderEngine::Threaded::YES) |
| 810 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::VK); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 811 | } else { |
Leon Scroggins III | f3369ed | 2024-02-16 17:52:42 -0500 | [diff] [blame] | 812 | const auto kVulkan = renderengine::RenderEngine::GraphicsApi::VK; |
| 813 | const bool useVulkan = FlagManager::getInstance().vulkan_renderengine() && |
| 814 | renderengine::RenderEngine::canSupport(kVulkan); |
| 815 | builder.setGraphicsApi(useVulkan ? kVulkan : renderengine::RenderEngine::GraphicsApi::GL); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 819 | // Do not call property_set on main thread which will be blocked by init |
| 820 | // Use StartPropertySetThread instead. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 821 | void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) { |
Parth Sane | 343626c | 2023-04-06 16:17:04 +0000 | [diff] [blame] | 822 | ATRACE_CALL(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 823 | ALOGI( "SurfaceFlinger's main thread ready to run. " |
| 824 | "Initializing graphics H/W..."); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 825 | addTransactionReadyFilters(); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 826 | Mutex::Autolock lock(mStateLock); |
Kevin DuBois | 413287f | 2019-02-25 08:46:47 -0800 | [diff] [blame] | 827 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 828 | // Get a RenderEngine for the given display / config (can't fail) |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 829 | // 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] | 830 | // Sending maxFrameBufferAcquiredBuffers as the cache size is tightly tuned to single-display. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 831 | auto builder = renderengine::RenderEngineCreationArgs::Builder() |
| 832 | .setPixelFormat(static_cast<int32_t>(defaultCompositionPixelFormat)) |
| 833 | .setImageCacheSize(maxFrameBufferAcquiredBuffers) |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 834 | .setEnableProtectedContext(enable_protected_contents(false)) |
| 835 | .setPrecacheToneMapperShaderOnly(false) |
| 836 | .setSupportsBackgroundBlur(mSupportsBlur) |
| 837 | .setContextPriority( |
| 838 | useContextPriority |
| 839 | ? renderengine::RenderEngine::ContextPriority::REALTIME |
| 840 | : renderengine::RenderEngine::ContextPriority::MEDIUM); |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 841 | chooseRenderEngineType(builder); |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 842 | mRenderEngine = renderengine::RenderEngine::create(builder.build()); |
| 843 | mCompositionEngine->setRenderEngine(mRenderEngine.get()); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 844 | mMaxRenderTargetSize = |
| 845 | std::min(getRenderEngine().getMaxTextureSize(), getRenderEngine().getMaxViewportDims()); |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 846 | |
| 847 | // Set SF main policy after initializing RenderEngine which has its own policy. |
| 848 | if (!SetTaskProfiles(0, {"SFMainPolicy"})) { |
| 849 | ALOGW("Failed to set main task profile"); |
| 850 | } |
| 851 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 852 | mCompositionEngine->setTimeStats(mTimeStats); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 853 | mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName)); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 854 | mCompositionEngine->getHwComposer().setCallback(*this); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 855 | ClientCache::getInstance().setRenderEngine(&getRenderEngine()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 856 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 857 | enableLatchUnsignaledConfig = getLatchUnsignaledConfig(); |
| 858 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 859 | if (base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false)) { |
| 860 | enableHalVirtualDisplays(true); |
| 861 | } |
| 862 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 863 | // Process hotplug for displays connected at boot. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 864 | LOG_ALWAYS_FATAL_IF(!configureLocked(), |
| 865 | "Initial display configuration failed: HWC did not hotplug"); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 866 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 867 | // Commit primary display. |
| 868 | sp<const DisplayDevice> display; |
| 869 | if (const auto indexOpt = mCurrentState.getDisplayIndex(getPrimaryDisplayIdLocked())) { |
| 870 | const auto& displays = mCurrentState.displays; |
| 871 | |
| 872 | const auto& token = displays.keyAt(*indexOpt); |
| 873 | const auto& state = displays.valueAt(*indexOpt); |
| 874 | |
| 875 | processDisplayAdded(token, state); |
| 876 | mDrawingState.displays.add(token, state); |
| 877 | |
| 878 | display = getDefaultDisplayDeviceLocked(); |
| 879 | } |
| 880 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 881 | LOG_ALWAYS_FATAL_IF(!display, "Failed to configure the primary display"); |
| 882 | LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(display->getPhysicalId()), |
| 883 | "Primary display is disconnected"); |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 884 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 885 | // TODO(b/241285876): The Scheduler needlessly depends on creating the CompositionEngine part of |
| 886 | // the DisplayDevice, hence the above commit of the primary display. Remove that special case by |
| 887 | // initializing the Scheduler after configureLocked, once decoupled from DisplayDevice. |
| 888 | initScheduler(display); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 889 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 890 | mLayerTracing.setTakeLayersSnapshotProtoFunction([&](uint32_t traceFlags) { |
| 891 | auto snapshot = perfetto::protos::LayersSnapshotProto{}; |
| 892 | mScheduler |
| 893 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 894 | snapshot = takeLayersSnapshotProto(traceFlags, TimePoint::now(), |
| 895 | mLastCommittedVsyncId, true); |
| 896 | }) |
| 897 | .wait(); |
| 898 | return snapshot; |
| 899 | }); |
| 900 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 901 | // Commit secondary display(s). |
| 902 | processDisplayChangesLocked(); |
| 903 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 904 | // initialize our drawing state |
| 905 | mDrawingState = mCurrentState; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 906 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 907 | onActiveDisplayChangedLocked(nullptr, *display); |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 908 | |
| 909 | static_cast<void>(mScheduler->schedule( |
| 910 | [this]() FTL_FAKE_GUARD(kMainThreadContext) { initializeDisplays(); })); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 911 | |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 912 | mPowerAdvisor->init(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 913 | |
Bruno BELANYI | fd02878 | 2023-10-13 14:39:53 +0000 | [diff] [blame] | 914 | if (base::GetBoolProperty("service.sf.prime_shader_cache"s, true)) { |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 915 | if (setSchedFifo(false) != NO_ERROR) { |
| 916 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 917 | } |
| 918 | |
Bruno BELANYI | b9b5b70 | 2023-10-13 13:25:11 +0000 | [diff] [blame] | 919 | bool shouldPrimeUltraHDR = |
| 920 | base::GetBoolProperty("ro.surface_flinger.prime_shader_cache.ultrahdr"s, false); |
| 921 | mRenderEnginePrimeCacheFuture = getRenderEngine().primeCache(shouldPrimeUltraHDR); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 922 | |
| 923 | if (setSchedFifo(true) != NO_ERROR) { |
linkai | d696a4f | 2023-11-14 10:13:36 +0800 | [diff] [blame] | 924 | ALOGW("Can't set SCHED_FIFO after primeCache"); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 925 | } |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 926 | } |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 927 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 928 | // Inform native graphics APIs whether the present timestamp is supported: |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 929 | |
| 930 | const bool presentFenceReliable = |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 931 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE); |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 932 | mStartPropertySetThread = getFactory().createStartPropertySetThread(presentFenceReliable); |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 933 | |
| 934 | if (mStartPropertySetThread->Start() != NO_ERROR) { |
| 935 | ALOGE("Run StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 936 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 938 | initTransactionTraceWriter(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 939 | ALOGV("Done initializing"); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 940 | } |
| 941 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 942 | void SurfaceFlinger::initTransactionTraceWriter() { |
| 943 | if (!mTransactionTracing) { |
| 944 | return; |
| 945 | } |
| 946 | TransactionTraceWriter::getInstance().setWriterFunction( |
| 947 | [&](const std::string& filename, bool overwrite) { |
| 948 | auto writeFn = [&]() { |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 949 | if (!overwrite && fileNewerThan(filename, std::chrono::minutes{10})) { |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 950 | ALOGD("TransactionTraceWriter: file=%s already exists", filename.c_str()); |
| 951 | return; |
| 952 | } |
| 953 | mTransactionTracing->flush(); |
| 954 | mTransactionTracing->writeToFile(filename); |
| 955 | }; |
| 956 | if (std::this_thread::get_id() == mMainThreadId) { |
| 957 | writeFn(); |
| 958 | } else { |
| 959 | mScheduler->schedule(writeFn).get(); |
| 960 | } |
| 961 | }); |
| 962 | } |
| 963 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 964 | void SurfaceFlinger::readPersistentProperties() { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 965 | Mutex::Autolock _l(mStateLock); |
| 966 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 967 | char value[PROPERTY_VALUE_MAX]; |
| 968 | |
| 969 | property_get("persist.sys.sf.color_saturation", value, "1.0"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 970 | mGlobalSaturationFactor = atof(value); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 971 | updateColorMatrixLocked(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 972 | ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 973 | |
| 974 | property_get("persist.sys.sf.native_mode", value, "0"); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 975 | mDisplayColorSetting = static_cast<DisplayColorSetting>(atoi(value)); |
Peiyong Lin | a3ea559 | 2019-02-10 14:45:00 -0800 | [diff] [blame] | 976 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 977 | mForceColorMode = |
| 978 | 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] | 979 | } |
| 980 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 981 | void SurfaceFlinger::startBootAnim() { |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 982 | // Start boot animation service by setting a property mailbox |
| 983 | // if property setting thread is already running, Start() will be just a NOP |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 984 | mStartPropertySetThread->Start(); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 985 | // Wait until property was set |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 986 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 987 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 988 | } |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 989 | } |
| 990 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | // ---------------------------------------------------------------------------- |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 992 | |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 993 | status_t SurfaceFlinger::getSupportedFrameTimestamps( |
| 994 | std::vector<FrameEvent>* outSupported) const { |
| 995 | *outSupported = { |
| 996 | FrameEvent::REQUESTED_PRESENT, |
| 997 | FrameEvent::ACQUIRE, |
| 998 | FrameEvent::LATCH, |
| 999 | FrameEvent::FIRST_REFRESH_START, |
| 1000 | FrameEvent::LAST_REFRESH_START, |
| 1001 | FrameEvent::GPU_COMPOSITION_DONE, |
| 1002 | FrameEvent::DEQUEUE_READY, |
| 1003 | FrameEvent::RELEASE, |
| 1004 | }; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1005 | |
| 1006 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 1007 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 1008 | if (!getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 1009 | outSupported->push_back(FrameEvent::DISPLAY_PRESENT); |
| 1010 | } |
| 1011 | return NO_ERROR; |
| 1012 | } |
| 1013 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1014 | status_t SurfaceFlinger::getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState* state) { |
| 1015 | if (!displayToken || !state) { |
| 1016 | return BAD_VALUE; |
| 1017 | } |
| 1018 | |
| 1019 | Mutex::Autolock lock(mStateLock); |
| 1020 | |
| 1021 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1022 | if (!display) { |
| 1023 | return NAME_NOT_FOUND; |
| 1024 | } |
| 1025 | |
| 1026 | state->layerStack = display->getLayerStack(); |
| 1027 | state->orientation = display->getOrientation(); |
| 1028 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 1029 | const Rect layerStackRect = display->getLayerStackSpaceRect(); |
| 1030 | state->layerStackSpaceRect = |
| 1031 | layerStackRect.isValid() ? layerStackRect.getSize() : display->getSize(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1032 | |
| 1033 | return NO_ERROR; |
| 1034 | } |
| 1035 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1036 | status_t SurfaceFlinger::getStaticDisplayInfo(int64_t displayId, ui::StaticDisplayInfo* info) { |
| 1037 | if (!info) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1038 | return BAD_VALUE; |
| 1039 | } |
| 1040 | |
| 1041 | Mutex::Autolock lock(mStateLock); |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1042 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 1043 | const auto displayOpt = mPhysicalDisplays.get(*id).and_then(getDisplayDeviceAndSnapshot()); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1044 | |
| 1045 | if (!displayOpt) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1046 | return NAME_NOT_FOUND; |
| 1047 | } |
| 1048 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1049 | const auto& [display, snapshotRef] = *displayOpt; |
| 1050 | const auto& snapshot = snapshotRef.get(); |
| 1051 | |
| 1052 | info->connectionType = snapshot.connectionType(); |
| 1053 | info->deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1054 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1055 | if (mEmulatedDisplayDensity) { |
| 1056 | info->density = mEmulatedDisplayDensity; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1057 | } else { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1058 | info->density = info->connectionType == ui::DisplayConnectionType::Internal |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1059 | ? mInternalDisplayDensity |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1060 | : FALLBACK_DENSITY; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1061 | } |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 1062 | info->density /= ACONFIGURATION_DENSITY_MEDIUM; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1063 | |
| 1064 | info->secure = display->isSecure(); |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1065 | info->installOrientation = display->getPhysicalOrientation(); |
Vishnu Nair | d0a8965 | 2022-01-13 12:05:54 -0800 | [diff] [blame] | 1066 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1067 | return NO_ERROR; |
| 1068 | } |
| 1069 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1070 | void SurfaceFlinger::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo*& info, |
| 1071 | const sp<DisplayDevice>& display, |
| 1072 | const display::DisplaySnapshot& snapshot) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1073 | const auto& displayModes = snapshot.displayModes(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1074 | info->supportedDisplayModes.clear(); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1075 | info->supportedDisplayModes.reserve(displayModes.size()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1076 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1077 | for (const auto& [id, mode] : displayModes) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1078 | ui::DisplayMode outMode; |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1079 | outMode.id = ftl::to_underlying(id); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1080 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1081 | auto [width, height] = mode->getResolution(); |
| 1082 | auto [xDpi, yDpi] = mode->getDpi(); |
Yiwei Zhang | 27de5df | 2018-08-23 17:04:51 -0700 | [diff] [blame] | 1083 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1084 | if (const auto physicalOrientation = display->getPhysicalOrientation(); |
| 1085 | physicalOrientation == ui::ROTATION_90 || physicalOrientation == ui::ROTATION_270) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1086 | std::swap(width, height); |
| 1087 | std::swap(xDpi, yDpi); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1090 | outMode.resolution = ui::Size(width, height); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1091 | |
Huan Song | f7eeb10 | 2022-03-28 11:02:38 -0700 | [diff] [blame] | 1092 | outMode.xDpi = xDpi; |
| 1093 | outMode.yDpi = yDpi; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1094 | |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1095 | const auto peakFps = mode->getPeakFps(); |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 1096 | outMode.peakRefreshRate = peakFps.getValue(); |
Alec Mouri | d122a1c | 2023-09-30 01:36:33 +0000 | [diff] [blame] | 1097 | outMode.vsyncRate = mode->getVsyncRate().getValue(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1098 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1099 | const auto vsyncConfigSet = mScheduler->getVsyncConfiguration().getConfigsForRefreshRate( |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 1100 | Fps::fromValue(outMode.peakRefreshRate)); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1101 | outMode.appVsyncOffset = vsyncConfigSet.late.appOffset; |
| 1102 | outMode.sfVsyncOffset = vsyncConfigSet.late.sfOffset; |
| 1103 | outMode.group = mode->getGroup(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1104 | |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1105 | // This is how far in advance a buffer must be queued for |
| 1106 | // presentation at a given time. If you want a buffer to appear |
| 1107 | // on the screen at time N, you must submit the buffer before |
| 1108 | // (N - presentationDeadline). |
| 1109 | // |
| 1110 | // Normally it's one full refresh period (to give SF a chance to |
| 1111 | // latch the buffer), but this can be reduced by configuring a |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 1112 | // VsyncController offset. Any additional delays introduced by the hardware |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1113 | // composer or panel must be accounted for here. |
| 1114 | // |
| 1115 | // We add an additional 1ms to allow for processing time and |
| 1116 | // differences between the ideal and actual refresh rate. |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1117 | outMode.presentationDeadline = peakFps.getPeriodNsecs() - outMode.sfVsyncOffset + 1000000; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1118 | excludeDolbyVisionIf4k30Present(display->getHdrCapabilities().getSupportedHdrTypes(), |
| 1119 | outMode); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1120 | info->supportedDisplayModes.push_back(outMode); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1123 | info->supportedColorModes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1124 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1125 | const PhysicalDisplayId displayId = snapshot.displayId(); |
| 1126 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1127 | const auto mode = display->refreshRateSelector().getActiveMode(); |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1128 | info->activeDisplayModeId = ftl::to_underlying(mode.modePtr->getId()); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1129 | info->renderFrameRate = mode.fps.getValue(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1130 | info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1131 | info->hdrCapabilities = filterOut4k30(display->getHdrCapabilities()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1132 | |
Marin Shalamanov | b173f75 | 2021-02-16 19:38:36 +0100 | [diff] [blame] | 1133 | info->autoLowLatencyModeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1134 | getHwComposer().hasDisplayCapability(displayId, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1135 | DisplayCapability::AUTO_LOW_LATENCY_MODE); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1136 | info->gameContentTypeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1137 | getHwComposer().supportsContentType(displayId, hal::ContentType::GAME); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1138 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1139 | info->preferredBootDisplayMode = static_cast<ui::DisplayModeId>(-1); |
Kriti Dang | ac0a74d | 2022-03-16 11:52:35 +0100 | [diff] [blame] | 1140 | |
| 1141 | if (getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG)) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1142 | if (const auto hwcId = getHwComposer().getPreferredBootDisplayMode(displayId)) { |
| 1143 | if (const auto modeId = snapshot.translateModeId(*hwcId)) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1144 | info->preferredBootDisplayMode = ftl::to_underlying(*modeId); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1145 | } |
| 1146 | } |
| 1147 | } |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1148 | } |
Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame] | 1149 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1150 | status_t SurfaceFlinger::getDynamicDisplayInfoFromId(int64_t physicalDisplayId, |
| 1151 | ui::DynamicDisplayInfo* info) { |
| 1152 | if (!info) { |
| 1153 | return BAD_VALUE; |
| 1154 | } |
| 1155 | |
| 1156 | Mutex::Autolock lock(mStateLock); |
| 1157 | |
| 1158 | const auto id_ = |
| 1159 | DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(physicalDisplayId)); |
| 1160 | const auto displayOpt = mPhysicalDisplays.get(*id_).and_then(getDisplayDeviceAndSnapshot()); |
| 1161 | |
| 1162 | if (!displayOpt) { |
| 1163 | return NAME_NOT_FOUND; |
| 1164 | } |
| 1165 | |
| 1166 | const auto& [display, snapshotRef] = *displayOpt; |
| 1167 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
| 1168 | return NO_ERROR; |
| 1169 | } |
| 1170 | |
| 1171 | status_t SurfaceFlinger::getDynamicDisplayInfoFromToken(const sp<IBinder>& displayToken, |
| 1172 | ui::DynamicDisplayInfo* info) { |
| 1173 | if (!displayToken || !info) { |
| 1174 | return BAD_VALUE; |
| 1175 | } |
| 1176 | |
| 1177 | Mutex::Autolock lock(mStateLock); |
| 1178 | |
| 1179 | const auto displayOpt = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1180 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1181 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1182 | |
| 1183 | if (!displayOpt) { |
| 1184 | return NAME_NOT_FOUND; |
| 1185 | } |
| 1186 | |
| 1187 | const auto& [display, snapshotRef] = *displayOpt; |
| 1188 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1189 | return NO_ERROR; |
| 1190 | } |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 1191 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1192 | status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>& displayToken, |
| 1193 | DisplayStatInfo* outStats) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1194 | if (!outStats) { |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1195 | return BAD_VALUE; |
| 1196 | } |
| 1197 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1198 | std::optional<PhysicalDisplayId> displayIdOpt; |
| 1199 | { |
| 1200 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1201 | if (displayToken) { |
| 1202 | displayIdOpt = getPhysicalDisplayIdLocked(displayToken); |
| 1203 | if (!displayIdOpt) { |
| 1204 | ALOGW("%s: Invalid physical display token %p", __func__, displayToken.get()); |
| 1205 | return NAME_NOT_FOUND; |
| 1206 | } |
| 1207 | } else { |
| 1208 | // TODO (b/277364366): Clients should be updated to pass in the display they |
| 1209 | // want, rather than us picking an arbitrary one (the active display, in this |
| 1210 | // case). |
| 1211 | displayIdOpt = mActiveDisplayId; |
| 1212 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1213 | } |
| 1214 | |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1215 | const auto schedule = mScheduler->getVsyncSchedule(displayIdOpt); |
| 1216 | if (!schedule) { |
| 1217 | ALOGE("%s: Missing VSYNC schedule for display %s!", __func__, |
| 1218 | to_string(*displayIdOpt).c_str()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1219 | return NAME_NOT_FOUND; |
| 1220 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1221 | outStats->vsyncTime = schedule->vsyncDeadlineAfter(TimePoint::now()).ns(); |
| 1222 | outStats->vsyncPeriod = schedule->period().ns(); |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1223 | return NO_ERROR; |
| 1224 | } |
| 1225 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1226 | void SurfaceFlinger::setDesiredMode(display::DisplayModeRequest&& desiredMode) { |
| 1227 | const auto mode = desiredMode.mode; |
| 1228 | const auto displayId = mode.modePtr->getPhysicalDisplayId(); |
| 1229 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1230 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
| 1231 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1232 | const auto display = getDisplayDeviceLocked(displayId); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1233 | if (!display) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1234 | ALOGW("%s: display is no longer valid", __func__); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1235 | return; |
| 1236 | } |
| 1237 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1238 | const bool emitEvent = desiredMode.emitEvent; |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 1239 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1240 | switch (display->setDesiredMode(std::move(desiredMode))) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1241 | case DisplayDevice::DesiredModeAction::InitiateDisplayModeSwitch: |
| 1242 | // DisplayDevice::setDesiredMode updated the render rate, so inform Scheduler. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1243 | mScheduler->setRenderRate(displayId, |
| 1244 | display->refreshRateSelector().getActiveMode().fps); |
Ady Abraham | 95a37e2 | 2023-01-18 22:57:28 -0800 | [diff] [blame] | 1245 | |
| 1246 | // Schedule a new frame to initiate the display mode switch. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1247 | scheduleComposite(FrameHint::kNone); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1248 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1249 | // Start receiving vsync samples now, so that we can detect a period |
| 1250 | // switch. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1251 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 1252 | mode.modePtr.get()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1253 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1254 | // As we called to set period, we will call to onRefreshRateChangeCompleted once |
| 1255 | // VsyncController model is locked. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1256 | mScheduler->modulateVsync(displayId, &VsyncModulator::onRefreshRateChangeInitiated); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1257 | |
| 1258 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1259 | mScheduler->updatePhaseConfiguration(mode.fps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1260 | } |
| 1261 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1262 | mScheduler->setModeChangePending(true); |
| 1263 | break; |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1264 | case DisplayDevice::DesiredModeAction::InitiateRenderRateSwitch: |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1265 | mScheduler->setRenderRate(displayId, mode.fps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1266 | |
| 1267 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1268 | mScheduler->updatePhaseConfiguration(mode.fps); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1269 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1270 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1271 | if (emitEvent) { |
| 1272 | dispatchDisplayModeChangeEvent(displayId, mode); |
| 1273 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1274 | break; |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1275 | case DisplayDevice::DesiredModeAction::None: |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1276 | break; |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1277 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1278 | } |
| 1279 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1280 | status_t SurfaceFlinger::setActiveModeFromBackdoor(const sp<display::DisplayToken>& displayToken, |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1281 | DisplayModeId modeId, Fps minFps, Fps maxFps) { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1282 | ATRACE_CALL(); |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1283 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 1284 | if (!displayToken) { |
| 1285 | return BAD_VALUE; |
| 1286 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1287 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1288 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1289 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1290 | const auto displayOpt = |
| 1291 | FTL_FAKE_GUARD(mStateLock, |
| 1292 | ftl::find_if(mPhysicalDisplays, |
| 1293 | PhysicalDisplay::hasToken(displayToken)) |
| 1294 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1295 | .and_then(getDisplayDeviceAndSnapshot())); |
| 1296 | if (!displayOpt) { |
| 1297 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1298 | return NAME_NOT_FOUND; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1299 | } |
| 1300 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1301 | const auto& [display, snapshotRef] = *displayOpt; |
| 1302 | const auto& snapshot = snapshotRef.get(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1303 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1304 | const auto fpsOpt = snapshot.displayModes().get(modeId).transform( |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1305 | [](const DisplayModePtr& mode) { return mode->getPeakFps(); }); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1306 | |
| 1307 | if (!fpsOpt) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1308 | 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] | 1309 | to_string(snapshot.displayId()).c_str()); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1310 | return BAD_VALUE; |
| 1311 | } |
| 1312 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1313 | const Fps fps = *fpsOpt; |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1314 | const FpsRange physical = {fps, fps}; |
| 1315 | const FpsRange render = {minFps.isValid() ? minFps : fps, maxFps.isValid() ? maxFps : fps}; |
| 1316 | const FpsRanges ranges = {physical, render}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1317 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1318 | // Keep the old switching type. |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1319 | const bool allowGroupSwitching = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1320 | display->refreshRateSelector().getCurrentPolicy().allowGroupSwitching; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1321 | |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1322 | const scheduler::RefreshRateSelector::DisplayManagerPolicy policy{modeId, ranges, ranges, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 1323 | allowGroupSwitching}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1324 | |
| 1325 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1326 | }); |
| 1327 | |
| 1328 | return future.get(); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1329 | } |
| 1330 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1331 | void SurfaceFlinger::finalizeDisplayModeChange(DisplayDevice& display) { |
| 1332 | const auto displayId = display.getPhysicalId(); |
| 1333 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1334 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1335 | const auto pendingModeOpt = display.getPendingMode(); |
| 1336 | if (!pendingModeOpt) { |
| 1337 | // There is no pending mode change. This can happen if the active |
| 1338 | // display changed and the mode change happened on a different display. |
| 1339 | return; |
| 1340 | } |
Ady Abraham | faac6da | 2021-07-15 10:04:40 -0700 | [diff] [blame] | 1341 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1342 | const auto& activeMode = pendingModeOpt->mode; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1343 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1344 | if (display.getActiveMode().modePtr->getResolution() != activeMode.modePtr->getResolution()) { |
| 1345 | auto& state = mCurrentState.displays.editValueFor(display.getDisplayToken()); |
| 1346 | // We need to generate new sequenceId in order to recreate the display (and this |
| 1347 | // way the framebuffer). |
| 1348 | state.sequenceId = DisplayDeviceState{}.sequenceId; |
| 1349 | state.physical->activeMode = activeMode.modePtr.get(); |
| 1350 | processDisplayChangesLocked(); |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1351 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1352 | // processDisplayChangesLocked will update all necessary components so we're done here. |
| 1353 | return; |
| 1354 | } |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 1355 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1356 | display.finalizeModeChange(activeMode.modePtr->getId(), activeMode.modePtr->getVsyncRate(), |
| 1357 | activeMode.fps); |
| 1358 | |
| 1359 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1360 | mScheduler->updatePhaseConfiguration(activeMode.fps); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | if (pendingModeOpt->emitEvent) { |
| 1364 | dispatchDisplayModeChangeEvent(displayId, activeMode); |
| 1365 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1366 | } |
| 1367 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1368 | void SurfaceFlinger::dropModeRequest(const sp<DisplayDevice>& display) { |
| 1369 | display->clearDesiredMode(); |
| 1370 | if (display->getPhysicalId() == mActiveDisplayId) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1371 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1372 | mScheduler->setModeChangePending(false); |
| 1373 | } |
Ady Abraham | 53852a5 | 2019-05-28 18:07:44 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1376 | void SurfaceFlinger::applyActiveMode(const sp<DisplayDevice>& display) { |
| 1377 | const auto activeModeOpt = display->getDesiredMode(); |
| 1378 | auto activeModePtr = activeModeOpt->mode.modePtr; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1379 | const auto displayId = activeModePtr->getPhysicalDisplayId(); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1380 | const auto renderFps = activeModeOpt->mode.fps; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1381 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1382 | dropModeRequest(display); |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1383 | |
| 1384 | constexpr bool kAllowToEnable = true; |
| 1385 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, std::move(activeModePtr).take()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1386 | mScheduler->setRenderRate(displayId, renderFps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1387 | |
| 1388 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1389 | mScheduler->updatePhaseConfiguration(renderFps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1390 | } |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1391 | } |
| 1392 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1393 | void SurfaceFlinger::initiateDisplayModeChanges() { |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1394 | ATRACE_CALL(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1395 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1396 | std::optional<PhysicalDisplayId> displayToUpdateImmediately; |
| 1397 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1398 | for (const auto& [id, physical] : mPhysicalDisplays) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1399 | const auto display = getDisplayDeviceLocked(id); |
| 1400 | if (!display) continue; |
| 1401 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1402 | auto desiredModeOpt = display->getDesiredMode(); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1403 | if (!desiredModeOpt) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1404 | continue; |
| 1405 | } |
| 1406 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 1407 | if (!shouldApplyRefreshRateSelectorPolicy(*display)) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1408 | dropModeRequest(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1409 | continue; |
| 1410 | } |
| 1411 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1412 | const auto desiredModeId = desiredModeOpt->mode.modePtr->getId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1413 | const auto displayModePtrOpt = physical.snapshot().displayModes().get(desiredModeId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1414 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1415 | if (!displayModePtrOpt) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1416 | ALOGW("Desired display mode is no longer supported. Mode ID = %d", |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1417 | ftl::to_underlying(desiredModeId)); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1418 | continue; |
| 1419 | } |
| 1420 | |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1421 | ALOGV("%s changing active mode to %d(%s) for display %s", __func__, |
| 1422 | ftl::to_underlying(desiredModeId), |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1423 | to_string(displayModePtrOpt->get()->getVsyncRate()).c_str(), |
| 1424 | to_string(display->getId()).c_str()); |
| 1425 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1426 | if ((!FlagManager::getInstance().connected_display() || !desiredModeOpt->force) && |
| 1427 | display->getActiveMode() == desiredModeOpt->mode) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1428 | applyActiveMode(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1429 | continue; |
| 1430 | } |
| 1431 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1432 | // Desired active mode was set, it is different than the mode currently in use, however |
| 1433 | // allowed modes might have changed by the time we process the refresh. |
| 1434 | // Make sure the desired mode is still allowed |
| 1435 | if (!display->refreshRateSelector().isModeAllowed(desiredModeOpt->mode)) { |
| 1436 | dropModeRequest(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1437 | continue; |
| 1438 | } |
| 1439 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1440 | // TODO(b/142753666) use constrains |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1441 | hal::VsyncPeriodChangeConstraints constraints; |
| 1442 | constraints.desiredTimeNanos = systemTime(); |
| 1443 | constraints.seamlessRequired = false; |
| 1444 | hal::VsyncPeriodChangeTimeline outTimeline; |
| 1445 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1446 | if (!display->initiateModeChange(std::move(*desiredModeOpt), constraints, outTimeline)) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1447 | continue; |
| 1448 | } |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1449 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1450 | display->refreshRateSelector().onModeChangeInitiated(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1451 | mScheduler->onNewVsyncPeriodChangeTimeline(outTimeline); |
| 1452 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1453 | if (outTimeline.refreshRequired) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 1454 | scheduleComposite(FrameHint::kNone); |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1455 | } else { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1456 | // TODO(b/255635711): Remove `displayToUpdateImmediately` to `finalizeDisplayModeChange` |
| 1457 | // for all displays. This was only needed when the loop iterated over `mDisplays` rather |
| 1458 | // than `mPhysicalDisplays`. |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1459 | displayToUpdateImmediately = display->getPhysicalId(); |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | if (displayToUpdateImmediately) { |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1464 | const auto display = getDisplayDeviceLocked(*displayToUpdateImmediately); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1465 | finalizeDisplayModeChange(*display); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1466 | |
| 1467 | const auto desiredModeOpt = display->getDesiredMode(); |
| 1468 | if (desiredModeOpt && display->getActiveMode() == desiredModeOpt->mode) { |
| 1469 | applyActiveMode(display); |
| 1470 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1471 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1472 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1473 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1474 | void SurfaceFlinger::disableExpensiveRendering() { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1475 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1476 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1477 | ATRACE_NAME(whence); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1478 | if (mPowerAdvisor->isUsingExpensiveRendering()) { |
Dominik Laskowski | bc6c860 | 2022-01-11 08:53:24 -0800 | [diff] [blame] | 1479 | for (const auto& [_, display] : mDisplays) { |
| 1480 | constexpr bool kDisable = false; |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1481 | mPowerAdvisor->setExpensiveRenderingExpected(display->getId(), kDisable); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1482 | } |
| 1483 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1484 | }); |
| 1485 | |
| 1486 | future.wait(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1489 | status_t SurfaceFlinger::getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1490 | ui::DisplayPrimaries& primaries) { |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1491 | if (!displayToken) { |
| 1492 | return BAD_VALUE; |
| 1493 | } |
| 1494 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1495 | Mutex::Autolock lock(mStateLock); |
| 1496 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1497 | const auto display = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1498 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>); |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1499 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1500 | return NAME_NOT_FOUND; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1501 | } |
| 1502 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1503 | if (!display.transform(&PhysicalDisplay::isInternal).value()) { |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1504 | return INVALID_OPERATION; |
| 1505 | } |
| 1506 | |
| 1507 | // 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] | 1508 | primaries = mInternalDisplayPrimaries; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1509 | return NO_ERROR; |
| 1510 | } |
| 1511 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1512 | status_t SurfaceFlinger::setActiveColorMode(const sp<IBinder>& displayToken, ui::ColorMode mode) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1513 | if (!displayToken) { |
| 1514 | return BAD_VALUE; |
| 1515 | } |
| 1516 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1517 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1518 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1519 | const auto displayOpt = |
| 1520 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1521 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1522 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1523 | |
| 1524 | if (!displayOpt) { |
| 1525 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1526 | return NAME_NOT_FOUND; |
| 1527 | } |
| 1528 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1529 | const auto& [display, snapshotRef] = *displayOpt; |
| 1530 | const auto& snapshot = snapshotRef.get(); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1531 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1532 | const auto modes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1533 | const bool exists = std::find(modes.begin(), modes.end(), mode) != modes.end(); |
| 1534 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1535 | if (mode < ui::ColorMode::NATIVE || !exists) { |
| 1536 | ALOGE("%s: Invalid color mode %s (%d) for display %s", whence, |
| 1537 | decodeColorMode(mode).c_str(), mode, to_string(snapshot.displayId()).c_str()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1538 | return BAD_VALUE; |
| 1539 | } |
| 1540 | |
| 1541 | display->getCompositionDisplay()->setColorProfile( |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 1542 | {mode, Dataspace::UNKNOWN, RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1543 | |
| 1544 | return NO_ERROR; |
| 1545 | }); |
| 1546 | |
Dominik Laskowski | 0a5f921 | 2021-08-05 17:00:04 -0700 | [diff] [blame] | 1547 | // TODO(b/195698395): Propagate error. |
| 1548 | future.wait(); |
| 1549 | return NO_ERROR; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1550 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1551 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1552 | status_t SurfaceFlinger::getBootDisplayModeSupport(bool* outSupport) const { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1553 | auto future = mScheduler->schedule( |
| 1554 | [this] { return getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG); }); |
| 1555 | |
| 1556 | *outSupport = future.get(); |
| 1557 | return NO_ERROR; |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1558 | } |
| 1559 | |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1560 | status_t SurfaceFlinger::getOverlaySupport(gui::OverlayProperties* outProperties) const { |
| 1561 | const auto& aidlProperties = getHwComposer().getOverlaySupport(); |
| 1562 | // convert aidl OverlayProperties to gui::OverlayProperties |
| 1563 | outProperties->combinations.reserve(aidlProperties.combinations.size()); |
| 1564 | for (const auto& combination : aidlProperties.combinations) { |
| 1565 | std::vector<int32_t> pixelFormats; |
| 1566 | pixelFormats.reserve(combination.pixelFormats.size()); |
| 1567 | std::transform(combination.pixelFormats.cbegin(), combination.pixelFormats.cend(), |
| 1568 | std::back_inserter(pixelFormats), |
| 1569 | [](const auto& val) { return static_cast<int32_t>(val); }); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1570 | std::vector<int32_t> standards; |
| 1571 | standards.reserve(combination.standards.size()); |
| 1572 | std::transform(combination.standards.cbegin(), combination.standards.cend(), |
| 1573 | std::back_inserter(standards), |
| 1574 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1575 | std::vector<int32_t> transfers; |
| 1576 | transfers.reserve(combination.transfers.size()); |
| 1577 | std::transform(combination.transfers.cbegin(), combination.transfers.cend(), |
| 1578 | std::back_inserter(transfers), |
| 1579 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1580 | std::vector<int32_t> ranges; |
| 1581 | ranges.reserve(combination.ranges.size()); |
| 1582 | std::transform(combination.ranges.cbegin(), combination.ranges.cend(), |
| 1583 | std::back_inserter(ranges), |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1584 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1585 | gui::OverlayProperties::SupportedBufferCombinations outCombination; |
| 1586 | outCombination.pixelFormats = std::move(pixelFormats); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1587 | outCombination.standards = std::move(standards); |
| 1588 | outCombination.transfers = std::move(transfers); |
| 1589 | outCombination.ranges = std::move(ranges); |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1590 | outProperties->combinations.emplace_back(outCombination); |
| 1591 | } |
Sally Qi | 8b4cb55 | 2022-12-14 16:24:31 -0800 | [diff] [blame] | 1592 | outProperties->supportMixedColorSpaces = aidlProperties.supportMixedColorSpaces; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 1593 | return NO_ERROR; |
| 1594 | } |
| 1595 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1596 | status_t SurfaceFlinger::setBootDisplayMode(const sp<display::DisplayToken>& displayToken, |
| 1597 | DisplayModeId modeId) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1598 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1599 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1600 | const auto snapshotOpt = |
| 1601 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1602 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1603 | .transform(&PhysicalDisplay::snapshotRef); |
| 1604 | |
| 1605 | if (!snapshotOpt) { |
| 1606 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1607 | return NAME_NOT_FOUND; |
| 1608 | } |
Kriti Dang | f50d677 | 2022-02-18 15:09:12 +0100 | [diff] [blame] | 1609 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1610 | const auto& snapshot = snapshotOpt->get(); |
| 1611 | const auto hwcIdOpt = snapshot.displayModes().get(modeId).transform( |
| 1612 | [](const DisplayModePtr& mode) { return mode->getHwcId(); }); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1613 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1614 | if (!hwcIdOpt) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1615 | 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] | 1616 | to_string(snapshot.displayId()).c_str()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1617 | return BAD_VALUE; |
| 1618 | } |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1619 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1620 | return getHwComposer().setBootDisplayMode(snapshot.displayId(), *hwcIdOpt); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1621 | }); |
| 1622 | return future.get(); |
| 1623 | } |
| 1624 | |
| 1625 | status_t SurfaceFlinger::clearBootDisplayMode(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1626 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1627 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1628 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1629 | return getHwComposer().clearBootDisplayMode(*displayId); |
| 1630 | } else { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1631 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1632 | return BAD_VALUE; |
| 1633 | } |
| 1634 | }); |
| 1635 | return future.get(); |
| 1636 | } |
| 1637 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1638 | status_t SurfaceFlinger::getHdrConversionCapabilities( |
| 1639 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) const { |
| 1640 | bool hdrOutputConversionSupport; |
| 1641 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1642 | if (hdrOutputConversionSupport == false) { |
| 1643 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1644 | return INVALID_OPERATION; |
| 1645 | } |
| 1646 | const auto aidlConversionCapability = getHwComposer().getHdrConversionCapabilities(); |
| 1647 | for (auto capability : aidlConversionCapability) { |
| 1648 | gui::HdrConversionCapability tempCapability; |
Kriti Dang | 3c243dc | 2023-03-07 15:00:13 +0100 | [diff] [blame] | 1649 | tempCapability.sourceType = static_cast<int>(capability.sourceType); |
| 1650 | tempCapability.outputType = static_cast<int>(capability.outputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1651 | tempCapability.addsLatency = capability.addsLatency; |
| 1652 | hdrConversionCapabilities->push_back(tempCapability); |
| 1653 | } |
| 1654 | return NO_ERROR; |
| 1655 | } |
| 1656 | |
| 1657 | status_t SurfaceFlinger::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1658 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 1659 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1660 | bool hdrOutputConversionSupport; |
| 1661 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1662 | if (hdrOutputConversionSupport == false) { |
| 1663 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1664 | return INVALID_OPERATION; |
| 1665 | } |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1666 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) mutable -> status_t { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1667 | using AidlHdrConversionStrategy = |
| 1668 | aidl::android::hardware::graphics::common::HdrConversionStrategy; |
| 1669 | using GuiHdrConversionStrategyTag = gui::HdrConversionStrategy::Tag; |
| 1670 | AidlHdrConversionStrategy aidlConversionStrategy; |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1671 | status_t status; |
| 1672 | aidl::android::hardware::graphics::common::Hdr aidlPreferredHdrOutputType; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1673 | switch (hdrConversionStrategy.getTag()) { |
| 1674 | case GuiHdrConversionStrategyTag::passthrough: { |
| 1675 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::passthrough>( |
| 1676 | hdrConversionStrategy.get<GuiHdrConversionStrategyTag::passthrough>()); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1677 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1678 | &aidlPreferredHdrOutputType); |
| 1679 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1680 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1681 | } |
| 1682 | case GuiHdrConversionStrategyTag::autoAllowedHdrTypes: { |
| 1683 | auto autoHdrTypes = |
| 1684 | hdrConversionStrategy |
| 1685 | .get<GuiHdrConversionStrategyTag::autoAllowedHdrTypes>(); |
| 1686 | std::vector<aidl::android::hardware::graphics::common::Hdr> aidlAutoHdrTypes; |
| 1687 | for (auto type : autoHdrTypes) { |
| 1688 | aidlAutoHdrTypes.push_back( |
| 1689 | static_cast<aidl::android::hardware::graphics::common::Hdr>(type)); |
| 1690 | } |
| 1691 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::autoAllowedHdrTypes>( |
| 1692 | aidlAutoHdrTypes); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1693 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1694 | &aidlPreferredHdrOutputType); |
| 1695 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1696 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1697 | } |
| 1698 | case GuiHdrConversionStrategyTag::forceHdrConversion: { |
| 1699 | auto forceHdrConversion = |
| 1700 | hdrConversionStrategy |
| 1701 | .get<GuiHdrConversionStrategyTag::forceHdrConversion>(); |
| 1702 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::forceHdrConversion>( |
| 1703 | static_cast<aidl::android::hardware::graphics::common::Hdr>( |
| 1704 | forceHdrConversion)); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1705 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1706 | &aidlPreferredHdrOutputType); |
| 1707 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1708 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1709 | } |
| 1710 | } |
| 1711 | }); |
| 1712 | return future.get(); |
| 1713 | } |
| 1714 | |
| 1715 | status_t SurfaceFlinger::getHdrOutputConversionSupport(bool* outSupport) const { |
| 1716 | auto future = mScheduler->schedule([this] { |
| 1717 | return getHwComposer().hasCapability(Capability::HDR_OUTPUT_CONVERSION_CONFIG); |
| 1718 | }); |
| 1719 | |
| 1720 | *outSupport = future.get(); |
| 1721 | return NO_ERROR; |
| 1722 | } |
| 1723 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1724 | void SurfaceFlinger::setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1725 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1726 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1727 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1728 | getHwComposer().setAutoLowLatencyMode(*displayId, on); |
| 1729 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1730 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1731 | } |
| 1732 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1733 | } |
| 1734 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1735 | void SurfaceFlinger::setGameContentType(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1736 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1737 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1738 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1739 | const auto type = on ? hal::ContentType::GAME : hal::ContentType::NONE; |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1740 | getHwComposer().setContentType(*displayId, type); |
| 1741 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1742 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1743 | } |
| 1744 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1745 | } |
| 1746 | |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1747 | status_t SurfaceFlinger::overrideHdrTypes(const sp<IBinder>& displayToken, |
| 1748 | const std::vector<ui::Hdr>& hdrTypes) { |
| 1749 | Mutex::Autolock lock(mStateLock); |
| 1750 | |
| 1751 | auto display = getDisplayDeviceLocked(displayToken); |
| 1752 | if (!display) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1753 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1754 | return NAME_NOT_FOUND; |
| 1755 | } |
| 1756 | |
| 1757 | display->overrideHdrTypes(hdrTypes); |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 1758 | mScheduler->dispatchHotplug(display->getPhysicalId(), scheduler::Scheduler::Hotplug::Connected); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1759 | return NO_ERROR; |
| 1760 | } |
| 1761 | |
Huihong Luo | 30aa437 | 2022-10-03 14:54:12 -0700 | [diff] [blame] | 1762 | status_t SurfaceFlinger::onPullAtom(const int32_t atomId, std::vector<uint8_t>* pulledData, |
| 1763 | bool* success) { |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 1764 | *success = mTimeStats->onPullAtom(atomId, pulledData); |
| 1765 | return NO_ERROR; |
| 1766 | } |
| 1767 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1768 | status_t SurfaceFlinger::getDisplayedContentSamplingAttributes(const sp<IBinder>& displayToken, |
| 1769 | ui::PixelFormat* outFormat, |
| 1770 | ui::Dataspace* outDataspace, |
| 1771 | uint8_t* outComponentMask) const { |
| 1772 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 1773 | return BAD_VALUE; |
| 1774 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1775 | |
| 1776 | Mutex::Autolock lock(mStateLock); |
| 1777 | |
| 1778 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1779 | if (!displayId) { |
| 1780 | return NAME_NOT_FOUND; |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1781 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1782 | |
| 1783 | return getHwComposer().getDisplayedContentSamplingAttributes(*displayId, outFormat, |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1784 | outDataspace, outComponentMask); |
| 1785 | } |
| 1786 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1787 | status_t SurfaceFlinger::setDisplayContentSamplingEnabled(const sp<IBinder>& displayToken, |
| 1788 | bool enable, uint8_t componentMask, |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1789 | uint64_t maxFrames) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1790 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1791 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1792 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1793 | return getHwComposer().setDisplayContentSamplingEnabled(*displayId, enable, |
| 1794 | componentMask, maxFrames); |
| 1795 | } else { |
| 1796 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
| 1797 | return NAME_NOT_FOUND; |
| 1798 | } |
| 1799 | }); |
| 1800 | |
| 1801 | return future.get(); |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1802 | } |
| 1803 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1804 | status_t SurfaceFlinger::getDisplayedContentSample(const sp<IBinder>& displayToken, |
| 1805 | uint64_t maxFrames, uint64_t timestamp, |
| 1806 | DisplayedFrameStats* outStats) const { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1807 | Mutex::Autolock lock(mStateLock); |
| 1808 | |
| 1809 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1810 | if (!displayId) { |
| 1811 | return NAME_NOT_FOUND; |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1814 | return getHwComposer().getDisplayedContentSample(*displayId, maxFrames, timestamp, outStats); |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1815 | } |
| 1816 | |
Peiyong Lin | 3c2791e | 2019-01-14 17:05:18 -0800 | [diff] [blame] | 1817 | status_t SurfaceFlinger::getProtectedContentSupport(bool* outSupported) const { |
| 1818 | if (!outSupported) { |
| 1819 | return BAD_VALUE; |
| 1820 | } |
| 1821 | *outSupported = getRenderEngine().supportsProtectedContent(); |
| 1822 | return NO_ERROR; |
| 1823 | } |
| 1824 | |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1825 | status_t SurfaceFlinger::isWideColorDisplay(const sp<IBinder>& displayToken, |
| 1826 | bool* outIsWideColorDisplay) const { |
| 1827 | if (!displayToken || !outIsWideColorDisplay) { |
| 1828 | return BAD_VALUE; |
| 1829 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1830 | |
| 1831 | Mutex::Autolock lock(mStateLock); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1832 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1833 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1834 | return NAME_NOT_FOUND; |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1835 | } |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 1836 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1837 | *outIsWideColorDisplay = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1838 | display->isPrimary() ? mSupportsWideColor : display->hasWideColorGamut(); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1839 | return NO_ERROR; |
| 1840 | } |
| 1841 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 1842 | status_t SurfaceFlinger::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1843 | outLayers->clear(); |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1844 | auto future = mScheduler->schedule([=, this] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1845 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Vishnu Nair | 43bccf8 | 2020-06-05 10:53:37 -0700 | [diff] [blame] | 1846 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 1847 | outLayers->push_back(layer->getLayerDebugInfo(display.get())); |
| 1848 | }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1849 | }); |
| 1850 | |
| 1851 | future.wait(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1852 | return NO_ERROR; |
| 1853 | } |
| 1854 | |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1855 | status_t SurfaceFlinger::getCompositionPreference( |
| 1856 | Dataspace* outDataspace, ui::PixelFormat* outPixelFormat, |
| 1857 | Dataspace* outWideColorGamutDataspace, |
| 1858 | ui::PixelFormat* outWideColorGamutPixelFormat) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1859 | *outDataspace = mDefaultCompositionDataspace; |
| 1860 | *outPixelFormat = defaultCompositionPixelFormat; |
| 1861 | *outWideColorGamutDataspace = mWideColorGamutCompositionDataspace; |
| 1862 | *outWideColorGamutPixelFormat = wideColorGamutCompositionPixelFormat; |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 1863 | return NO_ERROR; |
| 1864 | } |
| 1865 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1866 | status_t SurfaceFlinger::addRegionSamplingListener(const Rect& samplingArea, |
| 1867 | const sp<IBinder>& stopLayerHandle, |
| 1868 | const sp<IRegionSamplingListener>& listener) { |
Leon Scroggins III | ae16b80 | 2022-01-12 11:42:05 -0500 | [diff] [blame] | 1869 | if (!listener || samplingArea == Rect::INVALID_RECT || samplingArea.isEmpty()) { |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1870 | return BAD_VALUE; |
| 1871 | } |
Alec Mouri | 9a02eda | 2020-04-21 17:39:34 -0700 | [diff] [blame] | 1872 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 1873 | // LayerHandle::getLayer promotes the layer object in a binder thread but we will not destroy |
| 1874 | // 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] | 1875 | const sp<Layer> stopLayer = LayerHandle::getLayer(stopLayerHandle); |
| 1876 | mRegionSamplingThread->addListener(samplingArea, |
| 1877 | stopLayer ? stopLayer->getSequence() : UNASSIGNED_LAYER_ID, |
| 1878 | listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1879 | return NO_ERROR; |
| 1880 | } |
| 1881 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1882 | status_t SurfaceFlinger::removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) { |
tangrobin | af45f01 | 2019-02-26 18:10:10 +0800 | [diff] [blame] | 1883 | if (!listener) { |
| 1884 | return BAD_VALUE; |
| 1885 | } |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1886 | mRegionSamplingThread->removeListener(listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1887 | return NO_ERROR; |
| 1888 | } |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1889 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1890 | status_t SurfaceFlinger::addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) { |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1891 | if (!listener) { |
| 1892 | return BAD_VALUE; |
| 1893 | } |
| 1894 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1895 | mFpsReporter->addListener(listener, taskId); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1896 | return NO_ERROR; |
| 1897 | } |
| 1898 | |
| 1899 | status_t SurfaceFlinger::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 1900 | if (!listener) { |
| 1901 | return BAD_VALUE; |
| 1902 | } |
| 1903 | mFpsReporter->removeListener(listener); |
| 1904 | return NO_ERROR; |
| 1905 | } |
| 1906 | |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 1907 | status_t SurfaceFlinger::addTunnelModeEnabledListener( |
| 1908 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1909 | if (!listener) { |
| 1910 | return BAD_VALUE; |
| 1911 | } |
| 1912 | |
| 1913 | mTunnelModeEnabledReporter->addListener(listener); |
| 1914 | return NO_ERROR; |
| 1915 | } |
| 1916 | |
| 1917 | status_t SurfaceFlinger::removeTunnelModeEnabledListener( |
| 1918 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1919 | if (!listener) { |
| 1920 | return BAD_VALUE; |
| 1921 | } |
| 1922 | |
| 1923 | mTunnelModeEnabledReporter->removeListener(listener); |
| 1924 | return NO_ERROR; |
| 1925 | } |
| 1926 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1927 | status_t SurfaceFlinger::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 1928 | bool* outSupport) const { |
| 1929 | if (!displayToken || !outSupport) { |
| 1930 | return BAD_VALUE; |
| 1931 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1932 | |
| 1933 | Mutex::Autolock lock(mStateLock); |
| 1934 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1935 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1936 | if (!displayId) { |
| 1937 | return NAME_NOT_FOUND; |
| 1938 | } |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1939 | *outSupport = getHwComposer().hasDisplayCapability(*displayId, DisplayCapability::BRIGHTNESS); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1940 | return NO_ERROR; |
| 1941 | } |
| 1942 | |
John Reck | 22be696 | 2021-03-10 12:59:54 -0500 | [diff] [blame] | 1943 | status_t SurfaceFlinger::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 1944 | const gui::DisplayBrightness& brightness) { |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1945 | if (!displayToken) { |
| 1946 | return BAD_VALUE; |
| 1947 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1948 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1949 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1950 | return ftl::Future(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 1951 | // 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] | 1952 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1953 | const bool supportsDisplayBrightnessCommand = |
| 1954 | getHwComposer().getComposer()->isSupported( |
| 1955 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 1956 | // If we support applying display brightness as a command, then we also support |
| 1957 | // dimming SDR layers. |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1958 | if (supportsDisplayBrightnessCommand) { |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1959 | auto compositionDisplay = display->getCompositionDisplay(); |
| 1960 | float currentDimmingRatio = |
| 1961 | compositionDisplay->editState().sdrWhitePointNits / |
| 1962 | compositionDisplay->editState().displayBrightnessNits; |
Sally Qi | 0ea47b5 | 2023-06-22 13:27:20 -0700 | [diff] [blame] | 1963 | static constexpr float kDimmingThreshold = 0.02f; |
| 1964 | if (brightness.sdrWhitePointNits == 0.f || |
| 1965 | abs(brightness.sdrWhitePointNits - brightness.displayBrightnessNits) / |
| 1966 | brightness.sdrWhitePointNits >= |
| 1967 | kDimmingThreshold) { |
| 1968 | // to optimize, skip brightness setter if the brightness difference ratio |
| 1969 | // is lower than threshold |
| 1970 | compositionDisplay |
| 1971 | ->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 1972 | brightness.displayBrightnessNits); |
| 1973 | } else { |
| 1974 | compositionDisplay->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 1975 | brightness.sdrWhitePointNits); |
| 1976 | } |
| 1977 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1978 | FTL_FAKE_GUARD(kMainThreadContext, |
| 1979 | display->stageBrightness(brightness.displayBrightness)); |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 1980 | float currentHdrSdrRatio = |
| 1981 | compositionDisplay->editState().displayBrightnessNits / |
| 1982 | compositionDisplay->editState().sdrWhitePointNits; |
| 1983 | FTL_FAKE_GUARD(kMainThreadContext, |
| 1984 | display->updateHdrSdrRatioOverlayRatio(currentHdrSdrRatio)); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1985 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1986 | if (brightness.sdrWhitePointNits / brightness.displayBrightnessNits != |
| 1987 | currentDimmingRatio) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1988 | scheduleComposite(FrameHint::kNone); |
| 1989 | } else { |
| 1990 | scheduleCommit(FrameHint::kNone); |
| 1991 | } |
| 1992 | return ftl::yield<status_t>(OK); |
| 1993 | } else { |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1994 | return getHwComposer() |
| 1995 | .setDisplayBrightness(display->getPhysicalId(), |
| 1996 | brightness.displayBrightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 1997 | brightness.displayBrightnessNits, |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1998 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 1999 | .applyImmediately = true}); |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 2000 | } |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2001 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2002 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 2003 | return ftl::yield<status_t>(NAME_NOT_FOUND); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2004 | } |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 2005 | })) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 2006 | .then([](ftl::Future<status_t> task) { return task; }) |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2007 | .get(); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2010 | status_t SurfaceFlinger::addHdrLayerInfoListener(const sp<IBinder>& displayToken, |
| 2011 | const sp<gui::IHdrLayerInfoListener>& listener) { |
| 2012 | if (!displayToken) { |
| 2013 | return BAD_VALUE; |
| 2014 | } |
| 2015 | |
| 2016 | Mutex::Autolock lock(mStateLock); |
| 2017 | |
| 2018 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2019 | if (!display) { |
| 2020 | return NAME_NOT_FOUND; |
| 2021 | } |
| 2022 | const auto displayId = display->getId(); |
| 2023 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2024 | if (!hdrInfoReporter) { |
| 2025 | hdrInfoReporter = sp<HdrLayerInfoReporter>::make(); |
| 2026 | } |
| 2027 | hdrInfoReporter->addListener(listener); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2028 | |
| 2029 | |
| 2030 | mAddingHDRLayerInfoListener = true; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2031 | return OK; |
| 2032 | } |
| 2033 | |
| 2034 | status_t SurfaceFlinger::removeHdrLayerInfoListener( |
| 2035 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 2036 | if (!displayToken) { |
| 2037 | return BAD_VALUE; |
| 2038 | } |
| 2039 | |
| 2040 | Mutex::Autolock lock(mStateLock); |
| 2041 | |
| 2042 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2043 | if (!display) { |
| 2044 | return NAME_NOT_FOUND; |
| 2045 | } |
| 2046 | const auto displayId = display->getId(); |
| 2047 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2048 | if (hdrInfoReporter) { |
| 2049 | hdrInfoReporter->removeListener(listener); |
| 2050 | } |
| 2051 | return OK; |
| 2052 | } |
| 2053 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2054 | status_t SurfaceFlinger::notifyPowerBoost(int32_t boostId) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 2055 | using aidl::android::hardware::power::Boost; |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2056 | Boost powerBoost = static_cast<Boost>(boostId); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2057 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2058 | if (powerBoost == Boost::INTERACTION) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2059 | mScheduler->onTouchHint(); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | return NO_ERROR; |
| 2063 | } |
| 2064 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2065 | status_t SurfaceFlinger::getDisplayDecorationSupport( |
| 2066 | const sp<IBinder>& displayToken, |
| 2067 | std::optional<DisplayDecorationSupport>* outSupport) const { |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2068 | if (!displayToken || !outSupport) { |
| 2069 | return BAD_VALUE; |
| 2070 | } |
| 2071 | |
| 2072 | Mutex::Autolock lock(mStateLock); |
| 2073 | |
| 2074 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 2075 | if (!displayId) { |
| 2076 | return NAME_NOT_FOUND; |
| 2077 | } |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2078 | getHwComposer().getDisplayDecorationSupport(*displayId, outSupport); |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2079 | return NO_ERROR; |
| 2080 | } |
| 2081 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 2082 | // ---------------------------------------------------------------------------- |
| 2083 | |
Jorim Jaggi | b1e2f8d | 2017-06-08 15:43:59 -0700 | [diff] [blame] | 2084 | sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection( |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 2085 | gui::ISurfaceComposer::VsyncSource vsyncSource, EventRegistrationFlags eventRegistration, |
| 2086 | const sp<IBinder>& layerHandle) { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 2087 | const auto cycle = vsyncSource == gui::ISurfaceComposer::VsyncSource::eVsyncSourceSurfaceFlinger |
| 2088 | ? scheduler::Cycle::LastComposite |
| 2089 | : scheduler::Cycle::Render; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 2090 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 2091 | return mScheduler->createDisplayEventConnection(cycle, eventRegistration, layerHandle); |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2094 | void SurfaceFlinger::scheduleCommit(FrameHint hint) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2095 | if (hint == FrameHint::kActive) { |
| 2096 | mScheduler->resetIdleTimer(); |
| 2097 | } |
Matt Buckley | 15ecd1c | 2022-11-01 21:57:16 +0000 | [diff] [blame] | 2098 | mPowerAdvisor->notifyDisplayUpdateImminentAndCpuReset(); |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 2099 | mScheduler->scheduleFrame(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2100 | } |
| 2101 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2102 | void SurfaceFlinger::scheduleComposite(FrameHint hint) { |
| 2103 | mMustComposite = true; |
| 2104 | scheduleCommit(hint); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | void SurfaceFlinger::scheduleRepaint() { |
| 2108 | mGeometryDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2109 | scheduleComposite(FrameHint::kActive); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2112 | void SurfaceFlinger::scheduleSample() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2113 | static_cast<void>(mScheduler->schedule([this] { sample(); })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2114 | } |
| 2115 | |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 2116 | nsecs_t SurfaceFlinger::getVsyncPeriodFromHWC() const { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2117 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
| 2118 | return display->getVsyncPeriodFromHWC(); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2119 | } |
| 2120 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2121 | return 0; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2122 | } |
| 2123 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2124 | void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp, |
| 2125 | std::optional<hal::VsyncPeriodNanos> vsyncPeriod) { |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2126 | if (FlagManager::getInstance().connected_display() && timestamp < 0 && |
| 2127 | vsyncPeriod.has_value()) { |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2128 | // 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] | 2129 | if (mIsHotplugErrViaNegVsync && vsyncPeriod.value() == ~0) { |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2130 | const auto errorCode = static_cast<int32_t>(-timestamp); |
| 2131 | ALOGD("%s: Hotplug error %d for display %" PRIu64, __func__, errorCode, hwcDisplayId); |
| 2132 | mScheduler->dispatchHotplugError(errorCode); |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2133 | return; |
| 2134 | } |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2135 | |
| 2136 | if (mIsHdcpViaNegVsync && vsyncPeriod.value() == ~1) { |
| 2137 | const int32_t value = static_cast<int32_t>(-timestamp); |
| 2138 | // one byte is good enough to encode android.hardware.drm.HdcpLevel |
| 2139 | const int32_t maxLevel = (value >> 8) & 0xFF; |
| 2140 | const int32_t connectedLevel = value & 0xFF; |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2141 | 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] | 2142 | connectedLevel, maxLevel, hwcDisplayId); |
| 2143 | updateHdcpLevels(hwcDisplayId, connectedLevel, maxLevel); |
| 2144 | return; |
| 2145 | } |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
Dominik Laskowski | 3d48304 | 2023-02-22 17:58:56 -0500 | [diff] [blame] | 2148 | ATRACE_NAME(vsyncPeriod |
| 2149 | ? ftl::Concat(__func__, ' ', hwcDisplayId, ' ', *vsyncPeriod, "ns").c_str() |
| 2150 | : ftl::Concat(__func__, ' ', hwcDisplayId).c_str()); |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 2151 | |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2152 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2153 | if (const auto displayIdOpt = getHwComposer().onVsync(hwcDisplayId, timestamp)) { |
| 2154 | if (mScheduler->addResyncSample(*displayIdOpt, timestamp, vsyncPeriod)) { |
| 2155 | // period flushed |
| 2156 | mScheduler->modulateVsync(displayIdOpt, &VsyncModulator::onRefreshRateChangeCompleted); |
| 2157 | } |
Alec Mouri | 754c98a | 2019-03-18 18:53:42 -0700 | [diff] [blame] | 2158 | } |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2161 | void SurfaceFlinger::onComposerHalHotplugEvent(hal::HWDisplayId hwcDisplayId, |
| 2162 | DisplayHotplugEvent event) { |
| 2163 | if (event == DisplayHotplugEvent::CONNECTED || event == DisplayHotplugEvent::DISCONNECTED) { |
| 2164 | hal::Connection connection = (event == DisplayHotplugEvent::CONNECTED) |
| 2165 | ? hal::Connection::CONNECTED |
| 2166 | : hal::Connection::DISCONNECTED; |
| 2167 | { |
| 2168 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 2169 | mPendingHotplugEvents.push_back(HotplugEvent{hwcDisplayId, connection}); |
| 2170 | } |
| 2171 | |
| 2172 | if (mScheduler) { |
| 2173 | mScheduler->scheduleConfigure(); |
| 2174 | } |
| 2175 | |
| 2176 | return; |
Jiwen 'Steve' Cai | ccfd682 | 2018-02-21 16:15:58 -0800 | [diff] [blame] | 2177 | } |
| 2178 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2179 | if (FlagManager::getInstance().hotplug2()) { |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2180 | // TODO(b/311403559): use enum type instead of int |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2181 | const auto errorCode = static_cast<int32_t>(event); |
| 2182 | ALOGD("%s: Hotplug error %d for display %" PRIu64, __func__, errorCode, hwcDisplayId); |
| 2183 | mScheduler->dispatchHotplugError(errorCode); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2184 | } |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2187 | void SurfaceFlinger::onComposerHalVsyncPeriodTimingChanged( |
| 2188 | hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline& timeline) { |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2189 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2190 | mScheduler->onNewVsyncPeriodChangeTimeline(timeline); |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2191 | |
| 2192 | if (timeline.refreshRequired) { |
| 2193 | scheduleComposite(FrameHint::kNone); |
| 2194 | } |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 2195 | } |
| 2196 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2197 | void SurfaceFlinger::onComposerHalSeamlessPossible(hal::HWDisplayId) { |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 2198 | // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and |
Ady Abraham | b0433bc | 2020-01-08 17:31:06 -0800 | [diff] [blame] | 2199 | // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE. |
| 2200 | } |
| 2201 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2202 | void SurfaceFlinger::onComposerHalRefresh(hal::HWDisplayId) { |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2203 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2204 | scheduleComposite(FrameHint::kNone); |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2205 | } |
| 2206 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2207 | void SurfaceFlinger::onComposerHalVsyncIdle(hal::HWDisplayId) { |
Ady Abraham | e9befd7 | 2022-02-24 17:24:44 -0800 | [diff] [blame] | 2208 | ATRACE_CALL(); |
| 2209 | mScheduler->forceNextResync(); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2210 | } |
| 2211 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 2212 | void SurfaceFlinger::onRefreshRateChangedDebug(const RefreshRateChangedDebugData& data) { |
| 2213 | ATRACE_CALL(); |
| 2214 | if (const auto displayId = getHwComposer().toPhysicalDisplayId(data.display); displayId) { |
ramindani | 19919ff | 2023-12-07 11:27:06 -0800 | [diff] [blame] | 2215 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 2216 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
ramindani | 19919ff | 2023-12-07 11:27:06 -0800 | [diff] [blame] | 2217 | const Fps fps = Fps::fromPeriodNsecs(getHwComposer().getComposer()->isVrrSupported() |
| 2218 | ? data.refreshPeriodNanos |
| 2219 | : data.vsyncPeriodNanos); |
| 2220 | ATRACE_FORMAT("%s Fps %d", whence, fps.getIntValue()); |
| 2221 | const auto display = getDisplayDeviceLocked(*displayId); |
| 2222 | FTL_FAKE_GUARD(kMainThreadContext, |
| 2223 | display->updateRefreshRateOverlayRate(fps, display->getActiveMode().fps, |
| 2224 | /* setByHwc */ true)); |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 2225 | })); |
| 2226 | } |
ramindani | 12bfe6b | 2023-02-03 13:29:19 -0800 | [diff] [blame] | 2227 | } |
| 2228 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2229 | void SurfaceFlinger::configure() { |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2230 | Mutex::Autolock lock(mStateLock); |
| 2231 | if (configureLocked()) { |
| 2232 | setTransactionFlags(eDisplayTransactionNeeded); |
| 2233 | } |
| 2234 | } |
| 2235 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2236 | bool SurfaceFlinger::updateLayerSnapshotsLegacy(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2237 | bool flushTransactions, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2238 | bool& outTransactionsAreEmpty) { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2239 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2240 | frontend::Update update; |
| 2241 | if (flushTransactions) { |
| 2242 | update = flushLifecycleUpdates(); |
| 2243 | if (mTransactionTracing) { |
| 2244 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2245 | update, mFrontEndDisplayInfos, |
| 2246 | mFrontEndDisplayInfosChanged); |
| 2247 | } |
| 2248 | } |
| 2249 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2250 | bool needsTraversal = false; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2251 | if (flushTransactions) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2252 | needsTraversal |= commitMirrorDisplays(vsyncId); |
| 2253 | needsTraversal |= commitCreatedLayers(vsyncId, update.layerCreatedStates); |
| 2254 | needsTraversal |= applyTransactions(update.transactions, vsyncId); |
| 2255 | } |
| 2256 | outTransactionsAreEmpty = !needsTraversal; |
| 2257 | const bool shouldCommit = (getTransactionFlags() & ~eTransactionFlushNeeded) || needsTraversal; |
| 2258 | if (shouldCommit) { |
| 2259 | commitTransactions(); |
| 2260 | } |
| 2261 | |
| 2262 | bool mustComposite = latchBuffers() || shouldCommit; |
| 2263 | updateLayerGeometry(); |
| 2264 | return mustComposite; |
| 2265 | } |
| 2266 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2267 | void SurfaceFlinger::updateLayerHistory(nsecs_t now) { |
| 2268 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 2269 | using Changes = frontend::RequestedLayerState::Changes; |
| 2270 | if (snapshot->path.isClone()) { |
| 2271 | continue; |
| 2272 | } |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 2273 | |
Jerry Chang | 3667800 | 2023-11-29 16:56:17 +0000 | [diff] [blame] | 2274 | const bool updateSmallDirty = FlagManager::getInstance().enable_small_area_detection() && |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2275 | ((snapshot->clientChanges & layer_state_t::eSurfaceDamageRegionChanged) || |
| 2276 | snapshot->changes.any(Changes::Geometry)); |
| 2277 | |
| 2278 | const bool hasChanges = |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 2279 | snapshot->changes.any(Changes::FrameRate | Changes::Buffer | Changes::Animation | |
| 2280 | Changes::Geometry | Changes::Visibility) || |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2281 | (snapshot->clientChanges & layer_state_t::eDefaultFrameRateCompatibilityChanged) != |
| 2282 | 0; |
| 2283 | |
| 2284 | if (!updateSmallDirty && !hasChanges) { |
| 2285 | continue; |
| 2286 | } |
| 2287 | |
| 2288 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 2289 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 2290 | "Couldn't find layer object for %s", |
| 2291 | snapshot->getDebugString().c_str()); |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2292 | |
| 2293 | if (updateSmallDirty) { |
| 2294 | // Update small dirty flag while surface damage region or geometry changed |
| 2295 | it->second->setIsSmallDirty(snapshot.get()); |
| 2296 | } |
| 2297 | |
| 2298 | if (!hasChanges) { |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2299 | continue; |
| 2300 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2301 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2302 | const auto layerProps = scheduler::LayerProps{ |
| 2303 | .visible = snapshot->isVisible, |
| 2304 | .bounds = snapshot->geomLayerBounds, |
| 2305 | .transform = snapshot->geomLayerTransform, |
| 2306 | .setFrameRateVote = snapshot->frameRate, |
| 2307 | .frameRateSelectionPriority = snapshot->frameRateSelectionPriority, |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2308 | .isSmallDirty = snapshot->isSmallDirty, |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 2309 | .isFrontBuffered = snapshot->isFrontBuffered(), |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2310 | }; |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2311 | |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 2312 | if (snapshot->changes.any(Changes::Geometry | Changes::Visibility)) { |
| 2313 | mScheduler->setLayerProperties(snapshot->sequence, layerProps); |
| 2314 | } |
| 2315 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2316 | if (snapshot->clientChanges & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 2317 | mScheduler->setDefaultFrameRateCompatibility(snapshot->sequence, |
| 2318 | snapshot->defaultFrameRateCompatibility); |
| 2319 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2320 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2321 | if (snapshot->changes.test(Changes::Animation)) { |
| 2322 | it->second->recordLayerHistoryAnimationTx(layerProps, now); |
| 2323 | } |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 2324 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2325 | if (snapshot->changes.test(Changes::FrameRate)) { |
| 2326 | it->second->setFrameRateForLayerTree(snapshot->frameRate, layerProps, now); |
| 2327 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2328 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2329 | if (snapshot->changes.test(Changes::Buffer)) { |
| 2330 | it->second->recordLayerHistoryBufferUpdate(layerProps, now); |
| 2331 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2335 | bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2336 | bool flushTransactions, bool& outTransactionsAreEmpty) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2337 | using Changes = frontend::RequestedLayerState::Changes; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2338 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2339 | frontend::Update update; |
| 2340 | if (flushTransactions) { |
| 2341 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 2342 | // Locking: |
| 2343 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 2344 | // we must keep a copy of the transactions (specifically the composer |
| 2345 | // states) around outside the scope of the lock. |
| 2346 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 2347 | // transactions with layers still in the createdLayer queue, collect the transactions |
| 2348 | // before committing the created layers. |
| 2349 | // 3. Transactions can only be flushed after adding layers, since the layer can be a newly |
| 2350 | // created one |
| 2351 | mTransactionHandler.collectTransactions(); |
| 2352 | { |
| 2353 | // TODO(b/238781169) lockless queue this and keep order. |
| 2354 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 2355 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 2356 | mCreatedLayers.clear(); |
| 2357 | update.newLayers = std::move(mNewLayers); |
| 2358 | mNewLayers.clear(); |
| 2359 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 2360 | mNewLayerArgs.clear(); |
| 2361 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 2362 | mDestroyedHandles.clear(); |
| 2363 | } |
| 2364 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2365 | mLayerLifecycleManager.addLayers(std::move(update.newLayers)); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2366 | update.transactions = mTransactionHandler.flushTransactions(); |
| 2367 | if (mTransactionTracing) { |
| 2368 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2369 | update, mFrontEndDisplayInfos, |
| 2370 | mFrontEndDisplayInfosChanged); |
| 2371 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2372 | mLayerLifecycleManager.applyTransactions(update.transactions); |
| 2373 | mLayerLifecycleManager.onHandlesDestroyed(update.destroyedHandles); |
| 2374 | for (auto& legacyLayer : update.layerCreatedStates) { |
| 2375 | sp<Layer> layer = legacyLayer.layer.promote(); |
| 2376 | if (layer) { |
| 2377 | mLegacyLayers[layer->sequence] = layer; |
| 2378 | } |
| 2379 | } |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 2380 | mLayerHierarchyBuilder.update(mLayerLifecycleManager); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2381 | } |
| 2382 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2383 | bool mustComposite = false; |
| 2384 | mustComposite |= applyAndCommitDisplayTransactionStates(update.transactions); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2385 | |
| 2386 | { |
| 2387 | ATRACE_NAME("LayerSnapshotBuilder:update"); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2388 | frontend::LayerSnapshotBuilder::Args |
| 2389 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 2390 | .layerLifecycleManager = mLayerLifecycleManager, |
| 2391 | .displays = mFrontEndDisplayInfos, |
| 2392 | .displayChanges = mFrontEndDisplayInfosChanged, |
| 2393 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2394 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2395 | .forceFullDamage = mForceFullDamage, |
| 2396 | .supportedLayerGenericMetadata = |
| 2397 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 2398 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 2399 | .skipRoundCornersWhenProtected = |
| 2400 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2401 | mLayerSnapshotBuilder.update(args); |
| 2402 | } |
| 2403 | |
| 2404 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Geometry | Changes::Input | |
Vishnu Nair | 40d0228 | 2023-02-28 21:11:40 +0000 | [diff] [blame] | 2405 | Changes::Hierarchy | Changes::Visibility)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2406 | mUpdateInputInfo = true; |
| 2407 | } |
| 2408 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::VisibleRegion | Changes::Hierarchy | |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2409 | Changes::Visibility | Changes::Geometry)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2410 | mVisibleRegionsDirty = true; |
| 2411 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2412 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Hierarchy | Changes::FrameRate)) { |
| 2413 | // The frame rate of attached choreographers can only change as a result of a |
| 2414 | // FrameRate change (including when Hierarchy changes). |
| 2415 | mUpdateAttachedChoreographer = true; |
| 2416 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2417 | outTransactionsAreEmpty = mLayerLifecycleManager.getGlobalChanges().get() == 0; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2418 | mustComposite |= mLayerLifecycleManager.getGlobalChanges().get() != 0; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2419 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2420 | bool newDataLatched = false; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2421 | if (!mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2422 | ATRACE_NAME("DisplayCallbackAndStatsUpdates"); |
Vishnu Nair | d2a38f9 | 2023-08-23 18:43:01 -0700 | [diff] [blame] | 2423 | mustComposite |= applyTransactions(update.transactions, vsyncId); |
Vishnu Nair | c1d19d7 | 2023-08-10 12:35:11 -0700 | [diff] [blame] | 2424 | traverseLegacyLayers([&](Layer* layer) { layer->commitTransaction(); }); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2425 | const nsecs_t latchTime = systemTime(); |
| 2426 | bool unused = false; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2427 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2428 | for (auto& layer : mLayerLifecycleManager.getLayers()) { |
| 2429 | if (layer->changes.test(frontend::RequestedLayerState::Changes::Created) && |
| 2430 | layer->bgColorLayer) { |
| 2431 | sp<Layer> bgColorLayer = getFactory().createEffectLayer( |
| 2432 | LayerCreationArgs(this, nullptr, layer->name, |
| 2433 | ISurfaceComposerClient::eFXSurfaceEffect, LayerMetadata(), |
Vishnu Nair | e4af095 | 2023-05-01 09:11:33 -0700 | [diff] [blame] | 2434 | std::make_optional(layer->id), true)); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2435 | mLegacyLayers[bgColorLayer->sequence] = bgColorLayer; |
| 2436 | } |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2437 | const bool willReleaseBufferOnLatch = layer->willReleaseBufferOnLatch(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2438 | |
| 2439 | auto it = mLegacyLayers.find(layer->id); |
Vishnu Nair | 1009dbd | 2024-01-17 10:42:29 -0800 | [diff] [blame] | 2440 | if (it == mLegacyLayers.end() && |
| 2441 | layer->changes.test(frontend::RequestedLayerState::Changes::Destroyed)) { |
| 2442 | // Layer handle was created and immediately destroyed. It was destroyed before it |
| 2443 | // was added to the map. |
| 2444 | continue; |
| 2445 | } |
| 2446 | |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 2447 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 2448 | "Couldnt find layer object for %s", |
| 2449 | layer->getDebugString().c_str()); |
Vishnu Nair | f32ff9b | 2023-08-23 14:32:30 -0700 | [diff] [blame] | 2450 | if (!layer->hasReadyFrame() && !willReleaseBufferOnLatch) { |
| 2451 | if (!it->second->hasBuffer()) { |
| 2452 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 2453 | // instead of a missed frame. This is used to identify scenarios where we |
| 2454 | // could not latch a buffer or apply a transaction due to backpressure. |
| 2455 | // We only update the latch time for buffer less layers here, the latch time |
| 2456 | // is updated for buffer layers when the buffer is latched. |
| 2457 | it->second->updateLastLatchTime(latchTime); |
| 2458 | } |
| 2459 | continue; |
| 2460 | } |
| 2461 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2462 | const bool bgColorOnly = |
| 2463 | !layer->externalTexture && (layer->bgColorLayerId != UNASSIGNED_LAYER_ID); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2464 | if (willReleaseBufferOnLatch) { |
| 2465 | mLayersWithBuffersRemoved.emplace(it->second); |
| 2466 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2467 | it->second->latchBufferImpl(unused, latchTime, bgColorOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2468 | newDataLatched = true; |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2469 | |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2470 | mLayersWithQueuedFrames.emplace(it->second); |
| 2471 | mLayersIdsWithQueuedFrames.emplace(it->second->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2472 | } |
| 2473 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2474 | updateLayerHistory(latchTime); |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2475 | mLayerSnapshotBuilder.forEachVisibleSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2476 | if (mLayersIdsWithQueuedFrames.find(snapshot.path.id) == |
| 2477 | mLayersIdsWithQueuedFrames.end()) |
| 2478 | return; |
| 2479 | Region visibleReg; |
| 2480 | visibleReg.set(snapshot.transformedBoundsWithoutTransparentRegion); |
| 2481 | invalidateLayerStack(snapshot.outputFilter, visibleReg); |
| 2482 | }); |
| 2483 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2484 | for (auto& destroyedLayer : mLayerLifecycleManager.getDestroyedLayers()) { |
| 2485 | mLegacyLayers.erase(destroyedLayer->id); |
| 2486 | } |
| 2487 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2488 | { |
| 2489 | ATRACE_NAME("LLM:commitChanges"); |
| 2490 | mLayerLifecycleManager.commitChanges(); |
| 2491 | } |
| 2492 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2493 | // enter boot animation on first buffer latch |
| 2494 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 2495 | ALOGI("Enter boot animation"); |
| 2496 | mBootStage = BootStage::BOOTANIMATION; |
| 2497 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2498 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2499 | mustComposite |= (getTransactionFlags() & ~eTransactionFlushNeeded) || newDataLatched; |
Vishnu Nair | 8134c1a | 2023-10-17 22:55:49 -0700 | [diff] [blame] | 2500 | if (mustComposite && !mLegacyFrontEndEnabled) { |
| 2501 | commitTransactions(); |
| 2502 | } |
| 2503 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2504 | return mustComposite; |
| 2505 | } |
| 2506 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2507 | bool SurfaceFlinger::commit(PhysicalDisplayId pacesetterId, |
| 2508 | const scheduler::FrameTargets& frameTargets) { |
| 2509 | const scheduler::FrameTarget& pacesetterFrameTarget = *frameTargets.get(pacesetterId)->get(); |
| 2510 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2511 | const VsyncId vsyncId = pacesetterFrameTarget.vsyncId(); |
| 2512 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2513 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2514 | if (pacesetterFrameTarget.didMissFrame()) { |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2515 | mTimeStats->incrementMissedFrames(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2516 | } |
| 2517 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2518 | // If a mode set is pending and the fence hasn't fired yet, wait for the next commit. |
| 2519 | if (std::any_of(frameTargets.begin(), frameTargets.end(), |
| 2520 | [this](const auto& pair) FTL_FAKE_GUARD(mStateLock) |
| 2521 | FTL_FAKE_GUARD(kMainThreadContext) { |
| 2522 | if (!pair.second->isFramePending()) return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2523 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2524 | if (const auto display = getDisplayDeviceLocked(pair.first)) { |
| 2525 | return display->isModeSetPending(); |
| 2526 | } |
| 2527 | |
| 2528 | return false; |
| 2529 | })) { |
| 2530 | mScheduler->scheduleFrame(); |
| 2531 | return false; |
| 2532 | } |
| 2533 | |
| 2534 | { |
| 2535 | Mutex::Autolock lock(mStateLock); |
| 2536 | |
| 2537 | for (const auto [id, target] : frameTargets) { |
| 2538 | // TODO(b/241285876): This is `nullptr` when the DisplayDevice is about to be removed in |
| 2539 | // this commit, since the PhysicalDisplay has already been removed. Rather than checking |
| 2540 | // for `nullptr` below, change Scheduler::onFrameSignal to filter out the FrameTarget of |
| 2541 | // the removed display. |
| 2542 | const auto display = getDisplayDeviceLocked(id); |
| 2543 | |
| 2544 | if (display && display->isModeSetPending()) { |
| 2545 | finalizeDisplayModeChange(*display); |
| 2546 | } |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2547 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2548 | } |
| 2549 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2550 | if (pacesetterFrameTarget.isFramePending()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2551 | if (mBackpressureGpuComposition || pacesetterFrameTarget.didMissHwcFrame()) { |
Ady Abraham | e988303 | 2023-11-20 17:54:54 -0800 | [diff] [blame] | 2552 | if (FlagManager::getInstance().vrr_config()) { |
| 2553 | mScheduler->getVsyncSchedule()->getTracker().onFrameMissed( |
| 2554 | pacesetterFrameTarget.expectedPresentTime()); |
| 2555 | } |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2556 | scheduleCommit(FrameHint::kNone); |
| 2557 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2558 | } |
| 2559 | } |
| 2560 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2561 | const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); |
| 2562 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2563 | // Save this once per commit + composite to ensure consistency |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2564 | // TODO (b/240619471): consider removing active display check once AOD is fixed |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 2565 | const auto activeDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(mActiveDisplayId)); |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2566 | mPowerHintSessionEnabled = mPowerAdvisor->usePowerHintSession() && activeDisplay && |
| 2567 | activeDisplay->getPowerMode() == hal::PowerMode::ON; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2568 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2569 | mPowerAdvisor->setCommitStart(pacesetterFrameTarget.frameBeginTime()); |
| 2570 | mPowerAdvisor->setExpectedPresentTime(pacesetterFrameTarget.expectedPresentTime()); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2571 | |
| 2572 | // 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] | 2573 | const Duration idealSfWorkDuration = |
| 2574 | mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2575 | const Duration frameDelay = |
| 2576 | idealSfWorkDuration - pacesetterFrameTarget.expectedFrameDuration(); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2577 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2578 | mPowerAdvisor->setFrameDelay(frameDelay); |
| 2579 | mPowerAdvisor->setTotalFrameTargetWorkDuration(idealSfWorkDuration); |
Matt Buckley | 676e439 | 2023-05-25 22:09:26 +0000 | [diff] [blame] | 2580 | |
| 2581 | const auto& display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get(); |
| 2582 | const Period idealVsyncPeriod = display->getActiveMode().fps.getPeriod(); |
| 2583 | mPowerAdvisor->updateTargetWorkDuration(idealVsyncPeriod); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2584 | } |
| 2585 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2586 | if (mRefreshRateOverlaySpinner || mHdrSdrRatioOverlay) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 2587 | Mutex::Autolock lock(mStateLock); |
| 2588 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2589 | display->animateOverlay(); |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2590 | } |
| 2591 | } |
| 2592 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2593 | // Composite if transactions were committed, or if requested by HWC. |
| 2594 | bool mustComposite = mMustComposite.exchange(false); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2595 | { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2596 | mFrameTimeline->setSfWakeUp(ftl::to_underlying(vsyncId), |
| 2597 | pacesetterFrameTarget.frameBeginTime().ns(), |
Pascal Muetschard | ac7bcd9 | 2023-10-03 15:05:36 +0200 | [diff] [blame] | 2598 | Fps::fromPeriodNsecs(vsyncPeriod.ns()), |
| 2599 | mScheduler->getPacesetterRefreshRate()); |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 2600 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2601 | const bool flushTransactions = clearTransactionFlags(eTransactionFlushNeeded); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2602 | bool transactionsAreEmpty; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2603 | if (mLegacyFrontEndEnabled) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2604 | mustComposite |= |
| 2605 | updateLayerSnapshotsLegacy(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2606 | flushTransactions, transactionsAreEmpty); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2607 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2608 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2609 | mustComposite |= |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2610 | updateLayerSnapshots(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2611 | flushTransactions, transactionsAreEmpty); |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | if (transactionFlushNeeded()) { |
| 2615 | setTransactionFlags(eTransactionFlushNeeded); |
| 2616 | } |
| 2617 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2618 | // This has to be called after latchBuffers because we want to include the layers that have |
| 2619 | // been latched in the commit callback |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2620 | if (transactionsAreEmpty) { |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2621 | // Invoke empty transaction callbacks early. |
| 2622 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 2623 | } else { |
| 2624 | // Invoke OnCommit callbacks. |
| 2625 | mTransactionCallbackInvoker.sendCallbacks(true /* onCommitOnly */); |
| 2626 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | // Layers need to get updated (in the previous line) before we can use them for |
| 2630 | // choosing the refresh rate. |
| 2631 | // Hold mStateLock as chooseRefreshRateForContent promotes wp<Layer> to sp<Layer> |
| 2632 | // and may eventually call to ~Layer() if it holds the last reference |
| 2633 | { |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2634 | bool updateAttachedChoreographer = mUpdateAttachedChoreographer; |
| 2635 | mUpdateAttachedChoreographer = false; |
| 2636 | |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 2637 | Mutex::Autolock lock(mStateLock); |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2638 | mScheduler->chooseRefreshRateForContent(mLayerLifecycleManagerEnabled |
| 2639 | ? &mLayerHierarchyBuilder.getHierarchy() |
| 2640 | : nullptr, |
| 2641 | updateAttachedChoreographer); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2642 | initiateDisplayModeChanges(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2643 | } |
| 2644 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2645 | updateCursorAsync(); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2646 | if (!mustComposite) { |
| 2647 | updateInputFlinger(vsyncId, pacesetterFrameTarget.frameBeginTime()); |
| 2648 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2649 | doActiveLayersTracingIfNeeded(false, mVisibleRegionsDirty, |
| 2650 | pacesetterFrameTarget.frameBeginTime(), vsyncId); |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 2651 | |
Pablo Gamito | 6be8244 | 2022-06-13 11:04:34 +0000 | [diff] [blame] | 2652 | mLastCommittedVsyncId = vsyncId; |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2653 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2654 | persistDisplayBrightness(mustComposite); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2655 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2656 | return mustComposite && CC_LIKELY(mBootStage != BootStage::BOOTLOADER); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2659 | CompositeResultsPerDisplay SurfaceFlinger::composite( |
| 2660 | PhysicalDisplayId pacesetterId, const scheduler::FrameTargeters& frameTargeters) { |
| 2661 | const scheduler::FrameTarget& pacesetterTarget = |
| 2662 | frameTargeters.get(pacesetterId)->get()->target(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2663 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2664 | const VsyncId vsyncId = pacesetterTarget.vsyncId(); |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2665 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2666 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2667 | compositionengine::CompositionRefreshArgs refreshArgs; |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 2668 | refreshArgs.powerCallback = this; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2669 | const auto& displays = FTL_FAKE_GUARD(mStateLock, mDisplays); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2670 | refreshArgs.outputs.reserve(displays.size()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2671 | |
| 2672 | // Add outputs for physical displays. |
| 2673 | for (const auto& [id, targeter] : frameTargeters) { |
| 2674 | ftl::FakeGuard guard(mStateLock); |
| 2675 | |
| 2676 | if (const auto display = getCompositionDisplayLocked(id)) { |
| 2677 | refreshArgs.outputs.push_back(display); |
| 2678 | } |
Leon Scroggins III | 370b8b5 | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 2679 | |
| 2680 | refreshArgs.frameTargets.try_emplace(id, &targeter->target()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2681 | } |
| 2682 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2683 | std::vector<DisplayId> displayIds; |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2684 | for (const auto& [_, display] : displays) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2685 | displayIds.push_back(display->getId()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2686 | display->tracePowerMode(); |
| 2687 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2688 | // Add outputs for virtual displays. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2689 | if (display->isVirtual()) { |
| 2690 | const Fps refreshRate = display->getAdjustedRefreshRate(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2691 | |
| 2692 | if (!refreshRate.isValid() || |
| 2693 | mScheduler->isVsyncInPhase(pacesetterTarget.frameBeginTime(), refreshRate)) { |
| 2694 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2695 | } |
| 2696 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2697 | } |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2698 | mPowerAdvisor->setDisplays(displayIds); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2699 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 2700 | const bool updateTaskMetadata = mCompositionEngine->getFeatureFlags().test( |
| 2701 | compositionengine::Feature::kSnapshotLayerMetadata); |
| 2702 | if (updateTaskMetadata && (mVisibleRegionsDirty || mLayerMetadataSnapshotNeeded)) { |
| 2703 | updateLayerMetadataSnapshot(); |
| 2704 | mLayerMetadataSnapshotNeeded = false; |
| 2705 | } |
| 2706 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2707 | if (DOES_CONTAIN_BORDER) { |
| 2708 | refreshArgs.borderInfoList.clear(); |
| 2709 | mDrawingState.traverse([&refreshArgs](Layer* layer) { |
| 2710 | if (layer->isBorderEnabled()) { |
| 2711 | compositionengine::BorderRenderInfo info; |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 2712 | info.width = layer->getBorderWidth(); |
| 2713 | info.color = layer->getBorderColor(); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2714 | layer->traverse(LayerVector::StateSet::Drawing, [&info](Layer* ilayer) { |
| 2715 | info.layerIds.push_back(ilayer->getSequence()); |
| 2716 | }); |
| 2717 | refreshArgs.borderInfoList.emplace_back(std::move(info)); |
| 2718 | } |
| 2719 | }); |
| 2720 | } |
| 2721 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 2722 | refreshArgs.bufferIdsToUncache = std::move(mBufferIdsToUncache); |
| 2723 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2724 | refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); |
Alec Mouri | 5c9c960 | 2020-09-01 15:10:40 -0700 | [diff] [blame] | 2725 | for (auto layer : mLayersWithQueuedFrames) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 2726 | if (auto layerFE = layer->getCompositionEngineLayerFE()) |
| 2727 | refreshArgs.layersWithQueuedFrames.push_back(layerFE); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2728 | } |
| 2729 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 2730 | refreshArgs.outputColorSetting = mDisplayColorSetting; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 2731 | refreshArgs.forceOutputColorMode = mForceColorMode; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2732 | |
| 2733 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
Vishnu Nair | 995f4cf | 2024-03-07 19:40:03 -0800 | [diff] [blame^] | 2734 | refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || |
| 2735 | mVisibleRegionsDirty || mDrawingState.colorMatrixChanged; |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 2736 | refreshArgs.internalDisplayRotationFlags = getActiveDisplayRotationFlags(); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2737 | |
| 2738 | if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) { |
| 2739 | refreshArgs.colorTransformMatrix = mDrawingState.colorMatrix; |
| 2740 | mDrawingState.colorMatrixChanged = false; |
| 2741 | } |
| 2742 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2743 | refreshArgs.devOptForceClientComposition = mDebugDisableHWC; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2744 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2745 | if (mDebugFlashDelay != 0) { |
| 2746 | refreshArgs.devOptForceClientComposition = true; |
| 2747 | refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay); |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 2748 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2749 | |
ramindani | 0491e64 | 2023-11-16 17:42:14 -0800 | [diff] [blame] | 2750 | // TODO(b/255601557) Update frameInterval per display |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 2751 | refreshArgs.frameInterval = |
| 2752 | mScheduler->getNextFrameInterval(pacesetterId, pacesetterTarget.expectedPresentTime()); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 2753 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 2754 | const auto scheduledFrameTimeOpt = scheduledFrameResultOpt |
| 2755 | ? std::optional{scheduledFrameResultOpt->callbackTime} |
| 2756 | : std::nullopt; |
| 2757 | refreshArgs.scheduledFrameTime = scheduledFrameTimeOpt; |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 2758 | refreshArgs.hasTrustedPresentationListener = mNumTrustedPresentationListeners > 0; |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2759 | // Store the present time just before calling to the composition engine so we could notify |
| 2760 | // the scheduler. |
| 2761 | const auto presentTime = systemTime(); |
| 2762 | |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2763 | constexpr bool kCursorOnly = false; |
| 2764 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
| 2765 | |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2766 | if (mLayerLifecycleManagerEnabled && !mVisibleRegionsDirty) { |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2767 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 2768 | auto compositionDisplay = display->getCompositionDisplay(); |
| 2769 | if (!compositionDisplay->getState().isEnabled) continue; |
| 2770 | for (auto outputLayer : compositionDisplay->getOutputLayersOrderedByZ()) { |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2771 | if (outputLayer->getLayerFE().getCompositionState() == nullptr) { |
| 2772 | // This is unexpected but instead of crashing, capture traces to disk |
| 2773 | // and recover gracefully by forcing CE to rebuild layer stack. |
| 2774 | ALOGE("Output layer %s for display %s %" PRIu64 " has a null " |
| 2775 | "snapshot. Forcing mVisibleRegionsDirty", |
| 2776 | outputLayer->getLayerFE().getDebugName(), |
| 2777 | compositionDisplay->getName().c_str(), compositionDisplay->getId().value); |
| 2778 | |
| 2779 | TransactionTraceWriter::getInstance().invoke(__func__, /* overwrite= */ false); |
| 2780 | mVisibleRegionsDirty = true; |
| 2781 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
| 2782 | refreshArgs.updatingGeometryThisFrame = mVisibleRegionsDirty; |
| 2783 | } |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2784 | } |
| 2785 | } |
| 2786 | } |
| 2787 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2788 | mCompositionEngine->present(refreshArgs); |
| 2789 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2790 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2791 | for (auto [layer, layerFE] : layers) { |
| 2792 | CompositionResult compositionResult{layerFE->stealCompositionResult()}; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2793 | layer->onPreComposition(compositionResult.refreshStartTime); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2794 | for (auto& [releaseFence, layerStack] : compositionResult.releaseFences) { |
Vishnu Nair | 332e6ba | 2023-01-25 17:16:19 -0800 | [diff] [blame] | 2795 | Layer* clonedFrom = layer->getClonedFrom().get(); |
| 2796 | auto owningLayer = clonedFrom ? clonedFrom : layer; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2797 | owningLayer->onLayerDisplayed(std::move(releaseFence), layerStack); |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2798 | } |
| 2799 | if (compositionResult.lastClientCompositionFence) { |
| 2800 | layer->setWasClientComposed(compositionResult.lastClientCompositionFence); |
| 2801 | } |
| 2802 | } |
| 2803 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2804 | mTimeStats->recordFrameDuration(pacesetterTarget.frameBeginTime().ns(), systemTime()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2805 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2806 | // Send a power hint after presentation is finished. |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2807 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2808 | // Now that the current frame has been presented above, PowerAdvisor needs the present time |
| 2809 | // of the previous frame (whose fence is signaled by now) to determine how long the HWC had |
| 2810 | // waited on that fence to retire before presenting. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2811 | const auto& previousPresentFence = pacesetterTarget.presentFenceForPreviousFrame(); |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2812 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2813 | mPowerAdvisor->setSfPresentTiming(TimePoint::fromNs(previousPresentFence->getSignalTime()), |
| 2814 | TimePoint::now()); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 2815 | mPowerAdvisor->reportActualWorkDuration(); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2816 | } |
| 2817 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2818 | if (mScheduler->onCompositionPresented(presentTime)) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2819 | scheduleComposite(FrameHint::kNone); |
| 2820 | } |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2821 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 2822 | mNotifyExpectedPresentMap[pacesetterId].hintStatus = NotifyExpectedPresentHintStatus::Start; |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2823 | onCompositionPresented(pacesetterId, frameTargeters, presentTime); |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 2824 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2825 | const bool hadGpuComposited = |
| 2826 | multiDisplayUnion(mCompositionCoverage).test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2827 | mCompositionCoverage.clear(); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2828 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2829 | TimeStats::ClientCompositionRecord clientCompositionRecord; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2830 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2831 | for (const auto& [_, display] : displays) { |
| 2832 | const auto& state = display->getCompositionDisplay()->getState(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2833 | CompositionCoverageFlags& flags = |
| 2834 | mCompositionCoverage.try_emplace(display->getId()).first->second; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2835 | |
| 2836 | if (state.usesDeviceComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2837 | flags |= CompositionCoverage::Hwc; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | if (state.reusedClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2841 | flags |= CompositionCoverage::GpuReuse; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2842 | } else if (state.usesClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2843 | flags |= CompositionCoverage::Gpu; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2844 | } |
| 2845 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2846 | clientCompositionRecord.predicted |= |
| 2847 | (state.strategyPrediction != CompositionStrategyPredictionState::DISABLED); |
| 2848 | clientCompositionRecord.predictionSucceeded |= |
| 2849 | (state.strategyPrediction == CompositionStrategyPredictionState::SUCCESS); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2850 | } |
| 2851 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2852 | const auto coverage = multiDisplayUnion(mCompositionCoverage); |
| 2853 | const bool hasGpuComposited = coverage.test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2854 | |
| 2855 | clientCompositionRecord.hadClientComposition = hasGpuComposited; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2856 | clientCompositionRecord.reused = coverage.test(CompositionCoverage::GpuReuse); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2857 | clientCompositionRecord.changed = hadGpuComposited != hasGpuComposited; |
| 2858 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2859 | mTimeStats->pushCompositionStrategyState(clientCompositionRecord); |
| 2860 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2861 | using namespace ftl::flag_operators; |
| 2862 | |
| 2863 | // TODO(b/160583065): Enable skip validation when SF caches all client composition layers. |
| 2864 | const bool hasGpuUseOrReuse = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2865 | coverage.any(CompositionCoverage::Gpu | CompositionCoverage::GpuReuse); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2866 | mScheduler->modulateVsync({}, &VsyncModulator::onDisplayRefresh, hasGpuUseOrReuse); |
Dan Stoza | 14cd37c | 2015-07-09 12:43:33 -0700 | [diff] [blame] | 2867 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 2868 | mLayersWithQueuedFrames.clear(); |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2869 | mLayersIdsWithQueuedFrames.clear(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2870 | doActiveLayersTracingIfNeeded(true, mVisibleRegionsDirty, pacesetterTarget.frameBeginTime(), |
| 2871 | vsyncId); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2872 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2873 | updateInputFlinger(vsyncId, pacesetterTarget.frameBeginTime()); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2874 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2875 | if (mVisibleRegionsDirty) mHdrLayerInfoChanged = true; |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 2876 | mVisibleRegionsDirty = false; |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2877 | |
| 2878 | if (mCompositionEngine->needsAnotherUpdate()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2879 | scheduleCommit(FrameHint::kNone); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2880 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2881 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2882 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2883 | mPowerAdvisor->setCompositeEnd(TimePoint::now()); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2884 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2885 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2886 | CompositeResultsPerDisplay resultsPerDisplay; |
| 2887 | |
| 2888 | // Filter out virtual displays. |
| 2889 | for (const auto& [id, coverage] : mCompositionCoverage) { |
| 2890 | if (const auto idOpt = PhysicalDisplayId::tryCast(id)) { |
| 2891 | resultsPerDisplay.try_emplace(*idOpt, CompositeResult{coverage}); |
| 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | return resultsPerDisplay; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2896 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2897 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2898 | void SurfaceFlinger::updateLayerGeometry() { |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2899 | ATRACE_CALL(); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 2900 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2901 | if (mVisibleRegionsDirty) { |
| 2902 | computeLayerBounds(); |
| 2903 | } |
| 2904 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2905 | for (auto& layer : mLayersPendingRefresh) { |
| 2906 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2907 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2908 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2909 | } |
| 2910 | mLayersPendingRefresh.clear(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2911 | } |
| 2912 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2913 | bool SurfaceFlinger::isHdrLayer(const frontend::LayerSnapshot& snapshot) const { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2914 | // Even though the camera layer may be using an HDR transfer function or otherwise be "HDR" |
| 2915 | // the device may need to avoid boosting the brightness as a result of these layers to |
| 2916 | // reduce power consumption during camera recording |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2917 | if (mIgnoreHdrCameraLayers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2918 | if (snapshot.externalTexture && |
| 2919 | (snapshot.externalTexture->getUsage() & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) { |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2920 | return false; |
| 2921 | } |
| 2922 | } |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 2923 | // RANGE_EXTENDED layer may identify themselves as being "HDR" |
| 2924 | // via a desired hdr/sdr ratio |
| 2925 | auto pixelFormat = snapshot.buffer |
| 2926 | ? std::make_optional(static_cast<ui::PixelFormat>(snapshot.buffer->getPixelFormat())) |
| 2927 | : std::nullopt; |
| 2928 | |
| 2929 | if (getHdrRenderType(snapshot.dataspace, pixelFormat, snapshot.desiredHdrSdrRatio) != |
| 2930 | HdrRenderType::SDR) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2931 | return true; |
| 2932 | } |
| 2933 | // If the layer is not allowed to be dimmed, treat it as HDR. WindowManager may disable |
| 2934 | // dimming in order to keep animations invoking SDR screenshots of HDR layers seamless. |
| 2935 | // Treat such tagged layers as HDR so that DisplayManagerService does not try to change |
| 2936 | // the screen brightness |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2937 | if (!snapshot.dimmingEnabled) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2938 | return true; |
| 2939 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2940 | return false; |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2941 | } |
| 2942 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2943 | ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId, |
| 2944 | bool isPrimary) const { |
| 2945 | const auto id = PhysicalDisplayId::tryCast(displayId); |
| 2946 | if (!id) { |
| 2947 | return ui::ROTATION_0; |
| 2948 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2949 | if (!mIgnoreHwcPhysicalDisplayOrientation && |
Neha Jain | 7b31cca | 2023-01-09 23:10:42 +0000 | [diff] [blame] | 2950 | getHwComposer().getComposer()->isSupported( |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2951 | Hwc2::Composer::OptionalFeature::PhysicalDisplayOrientation)) { |
| 2952 | switch (getHwComposer().getPhysicalDisplayOrientation(*id)) { |
| 2953 | case Hwc2::AidlTransform::ROT_90: |
| 2954 | return ui::ROTATION_90; |
| 2955 | case Hwc2::AidlTransform::ROT_180: |
| 2956 | return ui::ROTATION_180; |
| 2957 | case Hwc2::AidlTransform::ROT_270: |
| 2958 | return ui::ROTATION_270; |
| 2959 | default: |
| 2960 | return ui::ROTATION_0; |
| 2961 | } |
| 2962 | } |
| 2963 | |
| 2964 | if (isPrimary) { |
| 2965 | using Values = SurfaceFlingerProperties::primary_display_orientation_values; |
| 2966 | switch (primary_display_orientation(Values::ORIENTATION_0)) { |
| 2967 | case Values::ORIENTATION_90: |
| 2968 | return ui::ROTATION_90; |
| 2969 | case Values::ORIENTATION_180: |
| 2970 | return ui::ROTATION_180; |
| 2971 | case Values::ORIENTATION_270: |
| 2972 | return ui::ROTATION_270; |
| 2973 | default: |
| 2974 | break; |
| 2975 | } |
| 2976 | } |
| 2977 | return ui::ROTATION_0; |
| 2978 | } |
| 2979 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2980 | void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId, |
| 2981 | const scheduler::FrameTargeters& frameTargeters, |
| 2982 | nsecs_t presentStartTime) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2983 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2984 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2985 | ui::PhysicalDisplayMap<PhysicalDisplayId, std::shared_ptr<FenceTime>> presentFences; |
| 2986 | ui::PhysicalDisplayMap<PhysicalDisplayId, const sp<Fence>> gpuCompositionDoneFences; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2987 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2988 | for (const auto& [id, targeter] : frameTargeters) { |
| 2989 | auto presentFence = getHwComposer().getPresentFence(id); |
| 2990 | |
| 2991 | if (id == pacesetterId) { |
| 2992 | mTransactionCallbackInvoker.addPresentFence(presentFence); |
| 2993 | } |
| 2994 | |
| 2995 | if (auto fenceTime = targeter->setPresentFence(std::move(presentFence)); |
| 2996 | fenceTime->isValid()) { |
| 2997 | presentFences.try_emplace(id, std::move(fenceTime)); |
| 2998 | } |
| 2999 | |
| 3000 | ftl::FakeGuard guard(mStateLock); |
| 3001 | if (const auto display = getCompositionDisplayLocked(id); |
| 3002 | display && display->getState().usesClientComposition) { |
| 3003 | gpuCompositionDoneFences |
| 3004 | .try_emplace(id, display->getRenderSurface()->getClientTargetAcquireFence()); |
| 3005 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3006 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3007 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3008 | const auto pacesetterDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(pacesetterId)); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3009 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3010 | std::shared_ptr<FenceTime> pacesetterPresentFenceTime = |
| 3011 | presentFences.get(pacesetterId) |
| 3012 | .transform([](const FenceTimePtr& ptr) { return ptr; }) |
| 3013 | .value_or(FenceTime::NO_FENCE); |
| 3014 | |
| 3015 | std::shared_ptr<FenceTime> pacesetterGpuCompositionDoneFenceTime = |
| 3016 | gpuCompositionDoneFences.get(pacesetterId) |
| 3017 | .transform([](sp<Fence> fence) { |
| 3018 | return std::make_shared<FenceTime>(std::move(fence)); |
| 3019 | }) |
| 3020 | .value_or(FenceTime::NO_FENCE); |
| 3021 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 3022 | const TimePoint presentTime = TimePoint::now(); |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 3023 | |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 3024 | // Set presentation information before calling Layer::releasePendingBuffer, such that jank |
| 3025 | // information from previous' frame classification is already available when sending jank info |
| 3026 | // to clients, so they get jank classification as early as possible. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3027 | mFrameTimeline->setSfPresent(presentTime.ns(), pacesetterPresentFenceTime, |
| 3028 | pacesetterGpuCompositionDoneFenceTime); |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 3029 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 3030 | // We use the CompositionEngine::getLastFrameRefreshTimestamp() which might |
| 3031 | // 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] | 3032 | // but that should be okay since CompositorTiming has snapping logic. |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 3033 | const TimePoint compositeTime = |
| 3034 | TimePoint::fromNs(mCompositionEngine->getLastFrameRefreshTimestamp()); |
| 3035 | const Duration presentLatency = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3036 | getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE) |
| 3037 | ? Duration::zero() |
| 3038 | : mPresentLatencyTracker.trackPendingFrame(compositeTime, pacesetterPresentFenceTime); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3039 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3040 | const auto schedule = mScheduler->getVsyncSchedule(); |
| 3041 | const TimePoint vsyncDeadline = schedule->vsyncDeadlineAfter(presentTime); |
| 3042 | const Period vsyncPeriod = schedule->period(); |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 3043 | const nsecs_t vsyncPhase = |
| 3044 | mScheduler->getVsyncConfiguration().getCurrentConfigs().late.sfOffset; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3045 | |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 3046 | const CompositorTiming compositorTiming(vsyncDeadline.ns(), vsyncPeriod.ns(), vsyncPhase, |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 3047 | presentLatency.ns()); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 3048 | |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 3049 | ui::DisplayMap<ui::LayerStack, const DisplayDevice*> layerStackToDisplay; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3050 | { |
| 3051 | if (!mLayersWithBuffersRemoved.empty() || mNumTrustedPresentationListeners > 0) { |
| 3052 | Mutex::Autolock lock(mStateLock); |
| 3053 | for (const auto& [token, display] : mDisplays) { |
| 3054 | layerStackToDisplay.emplace_or_replace(display->getLayerStack(), display.get()); |
| 3055 | } |
| 3056 | } |
| 3057 | } |
| 3058 | |
| 3059 | for (auto layer : mLayersWithBuffersRemoved) { |
Vishnu Nair | f10a87b | 2023-05-01 14:02:51 -0700 | [diff] [blame] | 3060 | std::vector<ui::LayerStack> previouslyPresentedLayerStacks = |
| 3061 | std::move(layer->mPreviouslyPresentedLayerStacks); |
| 3062 | layer->mPreviouslyPresentedLayerStacks.clear(); |
| 3063 | for (auto layerStack : previouslyPresentedLayerStacks) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3064 | auto optDisplay = layerStackToDisplay.get(layerStack); |
| 3065 | if (optDisplay && !optDisplay->get()->isVirtual()) { |
| 3066 | auto fence = getHwComposer().getPresentFence(optDisplay->get()->getPhysicalId()); |
| 3067 | layer->onLayerDisplayed(ftl::yield<FenceResult>(fence).share(), |
| 3068 | ui::INVALID_LAYER_STACK); |
| 3069 | } |
| 3070 | } |
| 3071 | layer->releasePendingBuffer(presentTime.ns()); |
| 3072 | } |
| 3073 | mLayersWithBuffersRemoved.clear(); |
| 3074 | |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 3075 | for (const auto& layer: mLayersWithQueuedFrames) { |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 3076 | layer->onCompositionPresented(pacesetterDisplay.get(), |
| 3077 | pacesetterGpuCompositionDoneFenceTime, |
| 3078 | pacesetterPresentFenceTime, compositorTiming); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3079 | layer->releasePendingBuffer(presentTime.ns()); |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 3080 | } |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 3081 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3082 | std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>> |
| 3083 | hdrInfoListeners; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3084 | bool haveNewListeners = false; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3085 | { |
| 3086 | Mutex::Autolock lock(mStateLock); |
| 3087 | if (mFpsReporter) { |
Andy Yu | aef688b | 2024-01-23 17:14:23 -0800 | [diff] [blame] | 3088 | mFpsReporter->dispatchLayerFps(mLayerHierarchyBuilder.getHierarchy()); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3089 | } |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 3090 | |
| 3091 | if (mTunnelModeEnabledReporter) { |
| 3092 | mTunnelModeEnabledReporter->updateTunnelModeStatus(); |
| 3093 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3094 | hdrInfoListeners.reserve(mHdrLayerInfoListeners.size()); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 3095 | for (const auto& [displayId, reporter] : mHdrLayerInfoListeners) { |
| 3096 | if (reporter && reporter->hasListeners()) { |
| 3097 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 3098 | hdrInfoListeners.emplace_back(display->getCompositionDisplay(), reporter); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3099 | } |
| 3100 | } |
| 3101 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3102 | haveNewListeners = mAddingHDRLayerInfoListener; // grab this with state lock |
| 3103 | mAddingHDRLayerInfoListener = false; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3104 | } |
| 3105 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3106 | if (haveNewListeners || mHdrLayerInfoChanged) { |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3107 | for (auto& [compositionDisplay, listener] : hdrInfoListeners) { |
| 3108 | HdrLayerInfoReporter::HdrLayerInfo info; |
| 3109 | int32_t maxArea = 0; |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 3110 | |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3111 | auto updateInfoFn = |
| 3112 | [&](const std::shared_ptr<compositionengine::Display>& compositionDisplay, |
| 3113 | const frontend::LayerSnapshot& snapshot, const sp<LayerFE>& layerFe) { |
| 3114 | if (snapshot.isVisible && |
| 3115 | compositionDisplay->includesLayer(snapshot.outputFilter)) { |
| 3116 | if (isHdrLayer(snapshot)) { |
| 3117 | const auto* outputLayer = |
| 3118 | compositionDisplay->getOutputLayerForLayer(layerFe); |
| 3119 | if (outputLayer) { |
| 3120 | const float desiredHdrSdrRatio = |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 3121 | snapshot.desiredHdrSdrRatio < 1.f |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3122 | ? std::numeric_limits<float>::infinity() |
| 3123 | : snapshot.desiredHdrSdrRatio; |
| 3124 | info.mergeDesiredRatio(desiredHdrSdrRatio); |
| 3125 | info.numberOfHdrLayers++; |
| 3126 | const auto displayFrame = outputLayer->getState().displayFrame; |
| 3127 | const int32_t area = |
| 3128 | displayFrame.width() * displayFrame.height(); |
| 3129 | if (area > maxArea) { |
| 3130 | maxArea = area; |
| 3131 | info.maxW = displayFrame.width(); |
| 3132 | info.maxH = displayFrame.height(); |
| 3133 | } |
| 3134 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3135 | } |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 3136 | } |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3137 | }; |
| 3138 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3139 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3140 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 3141 | [&, compositionDisplay = compositionDisplay]( |
| 3142 | std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 3143 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 3144 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 3145 | "Couldnt find layer object for %s", |
| 3146 | snapshot->getDebugString().c_str()); |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3147 | auto& legacyLayer = it->second; |
| 3148 | sp<LayerFE> layerFe = |
| 3149 | legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
| 3150 | |
| 3151 | updateInfoFn(compositionDisplay, *snapshot, layerFe); |
| 3152 | }); |
| 3153 | } else { |
| 3154 | mDrawingState.traverse([&, compositionDisplay = compositionDisplay](Layer* layer) { |
| 3155 | const auto layerFe = layer->getCompositionEngineLayerFE(); |
| 3156 | const frontend::LayerSnapshot& snapshot = *layer->getLayerSnapshot(); |
| 3157 | updateInfoFn(compositionDisplay, snapshot, layerFe); |
| 3158 | }); |
| 3159 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3160 | listener->dispatchHdrLayerInfo(info); |
| 3161 | } |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3162 | } |
| 3163 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3164 | mHdrLayerInfoChanged = false; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3165 | |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 3166 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 3167 | mTransactionCallbackInvoker.clearCompletedTransactions(); |
| 3168 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3169 | mTimeStats->incrementTotalFrames(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3170 | mTimeStats->setPresentFenceGlobal(pacesetterPresentFenceTime); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3171 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3172 | for (auto&& [id, presentFence] : presentFences) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3173 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3174 | const bool isInternalDisplay = |
| 3175 | mPhysicalDisplays.get(id).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 3176 | |
| 3177 | if (isInternalDisplay) { |
| 3178 | mScheduler->addPresentFence(id, std::move(presentFence)); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3179 | } |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3180 | } |
| 3181 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3182 | const bool hasPacesetterDisplay = |
| 3183 | pacesetterDisplay && getHwComposer().isConnected(pacesetterId); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3184 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3185 | if (!hasSyncFramework) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3186 | if (hasPacesetterDisplay && pacesetterDisplay->isPoweredOn()) { |
| 3187 | mScheduler->enableHardwareVsync(pacesetterId); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3188 | } |
| 3189 | } |
| 3190 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3191 | if (hasPacesetterDisplay && !pacesetterDisplay->isPoweredOn()) { |
Lars Svensson | d9e5469 | 2021-12-21 07:41:57 +0100 | [diff] [blame] | 3192 | getRenderEngine().cleanupPostRender(); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 3193 | return; |
| 3194 | } |
| 3195 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 3196 | // Cleanup any outstanding resources due to rendering a prior frame. |
| 3197 | getRenderEngine().cleanupPostRender(); |
| 3198 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3199 | if (mNumTrustedPresentationListeners > 0) { |
| 3200 | // We avoid any reverse traversal upwards so this shouldn't be too expensive |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3201 | traverseLegacyLayers([&](Layer* layer) { |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3202 | if (!layer->hasTrustedPresentationListener()) { |
| 3203 | return; |
| 3204 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3205 | const frontend::LayerSnapshot* snapshot = mLayerLifecycleManagerEnabled |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3206 | ? mLayerSnapshotBuilder.getSnapshot(layer->sequence) |
| 3207 | : layer->getLayerSnapshot(); |
| 3208 | std::optional<const DisplayDevice*> displayOpt = std::nullopt; |
| 3209 | if (snapshot) { |
| 3210 | displayOpt = layerStackToDisplay.get(snapshot->outputFilter.layerStack); |
| 3211 | } |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 3212 | const DisplayDevice* display = displayOpt.value_or(nullptr); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3213 | layer->updateTrustedPresentationState(display, snapshot, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 3214 | nanoseconds_to_milliseconds(presentStartTime), |
| 3215 | false); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3216 | }); |
| 3217 | } |
| 3218 | |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3219 | // Even though ATRACE_INT64 already checks if tracing is enabled, it doesn't prevent the |
| 3220 | // side-effect of getTotalSize(), so we check that again here |
| 3221 | if (ATRACE_ENABLED()) { |
Marissa Wall | 22b2de1 | 2019-12-02 18:11:43 -0800 | [diff] [blame] | 3222 | // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3223 | ATRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize()); |
| 3224 | } |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3225 | |
| 3226 | logFrameStats(presentTime); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 3227 | } |
| 3228 | |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3229 | FloatRect SurfaceFlinger::getMaxDisplayBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3230 | const ui::Size maxSize = [this] { |
| 3231 | ftl::FakeGuard guard(mStateLock); |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3232 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3233 | // The LayerTraceGenerator tool runs without displays. |
| 3234 | if (mDisplays.empty()) return ui::Size{5000, 5000}; |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3235 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3236 | return std::accumulate(mDisplays.begin(), mDisplays.end(), ui::kEmptySize, |
| 3237 | [](ui::Size size, const auto& pair) -> ui::Size { |
| 3238 | const auto& display = pair.second; |
| 3239 | return {std::max(size.getWidth(), display->getWidth()), |
| 3240 | std::max(size.getHeight(), display->getHeight())}; |
| 3241 | }); |
| 3242 | }(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3243 | |
| 3244 | // Ignore display bounds for now since they will be computed later. Use a large Rect bound |
| 3245 | // to ensure it's bigger than an actual display will be. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3246 | const float xMax = maxSize.getWidth() * 10.f; |
| 3247 | const float yMax = maxSize.getHeight() * 10.f; |
| 3248 | |
| 3249 | return {-xMax, -yMax, xMax, yMax}; |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | void SurfaceFlinger::computeLayerBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3253 | const FloatRect maxBounds = getMaxDisplayBounds(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3254 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 3255 | layer->computeBounds(maxBounds, ui::Transform(), 0.f /* shadowRadius */); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3256 | } |
| 3257 | } |
| 3258 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3259 | void SurfaceFlinger::commitTransactions() { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 3260 | ATRACE_CALL(); |
| 3261 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3262 | // Keep a copy of the drawing state (that is going to be overwritten |
| 3263 | // by commitTransactionsLocked) outside of mStateLock so that the side |
| 3264 | // effects of the State assignment don't happen with mStateLock held, |
| 3265 | // which can cause deadlocks. |
Mathias Agopian | 7cc6df5 | 2013-06-05 14:30:54 -0700 | [diff] [blame] | 3266 | State drawingState(mDrawingState); |
| 3267 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3268 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 3269 | mDebugInTransaction = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3270 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3271 | // Here we're guaranteed that some transaction flags are set |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3272 | // so we can call commitTransactionsLocked unconditionally. |
| 3273 | // We clear the flags with mStateLock held to guarantee that |
| 3274 | // mCurrentState won't change until the transaction is committed. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3275 | mScheduler->modulateVsync({}, &VsyncModulator::onTransactionCommit); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3276 | commitTransactionsLocked(clearTransactionFlags(eTransactionMask)); |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 3277 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3278 | mDebugInTransaction = 0; |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 3279 | } |
| 3280 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3281 | std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes( |
| 3282 | PhysicalDisplayId displayId) const { |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3283 | std::vector<HWComposer::HWCDisplayMode> hwcModes; |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3284 | std::optional<hal::HWConfigId> activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3285 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3286 | const bool isExternalDisplay = FlagManager::getInstance().connected_display() && |
| 3287 | getHwComposer().getDisplayConnectionType(displayId) == |
| 3288 | ui::DisplayConnectionType::External; |
| 3289 | |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3290 | int attempt = 0; |
| 3291 | constexpr int kMaxAttempts = 3; |
| 3292 | do { |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 3293 | hwcModes = getHwComposer().getModes(displayId, |
| 3294 | scheduler::RefreshRateSelector::kMinSupportedFrameRate |
| 3295 | .getPeriodNsecs()); |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3296 | const auto activeModeHwcIdExp = getHwComposer().getActiveMode(displayId); |
| 3297 | activeModeHwcIdOpt = activeModeHwcIdExp.value_opt(); |
| 3298 | |
| 3299 | if (isExternalDisplay && |
| 3300 | activeModeHwcIdExp.has_error([](status_t error) { return error == NO_INIT; })) { |
| 3301 | constexpr nsecs_t k59HzVsyncPeriod = 16949153; |
| 3302 | constexpr nsecs_t k60HzVsyncPeriod = 16666667; |
| 3303 | |
| 3304 | // DM sets the initial mode for an external display to 1080p@60, but |
| 3305 | // this comes after SF creates its own state (including the |
| 3306 | // DisplayDevice). For now, pick the same mode in order to avoid |
| 3307 | // inconsistent state and unnecessary mode switching. |
| 3308 | // TODO (b/318534874): Let DM decide the initial mode. |
| 3309 | // |
| 3310 | // Try to find 1920x1080 @ 60 Hz |
| 3311 | if (const auto iter = std::find_if(hwcModes.begin(), hwcModes.end(), |
| 3312 | [](const auto& mode) { |
| 3313 | return mode.width == 1920 && |
| 3314 | mode.height == 1080 && |
| 3315 | mode.vsyncPeriod == k60HzVsyncPeriod; |
| 3316 | }); |
| 3317 | iter != hwcModes.end()) { |
| 3318 | activeModeHwcIdOpt = iter->hwcId; |
| 3319 | break; |
| 3320 | } |
| 3321 | |
| 3322 | // Try to find 1920x1080 @ 59-60 Hz |
| 3323 | if (const auto iter = std::find_if(hwcModes.begin(), hwcModes.end(), |
| 3324 | [](const auto& mode) { |
| 3325 | return mode.width == 1920 && |
| 3326 | mode.height == 1080 && |
| 3327 | mode.vsyncPeriod >= k60HzVsyncPeriod && |
| 3328 | mode.vsyncPeriod <= k59HzVsyncPeriod; |
| 3329 | }); |
| 3330 | iter != hwcModes.end()) { |
| 3331 | activeModeHwcIdOpt = iter->hwcId; |
| 3332 | break; |
| 3333 | } |
| 3334 | |
| 3335 | // The display does not support 1080p@60, and this is the last attempt to pick a display |
| 3336 | // mode. Prefer 60 Hz if available, with the closest resolution to 1080p. |
| 3337 | if (attempt + 1 == kMaxAttempts) { |
| 3338 | std::vector<HWComposer::HWCDisplayMode> hwcModeOpts; |
| 3339 | |
| 3340 | for (const auto& mode : hwcModes) { |
| 3341 | if (mode.width <= 1920 && mode.height <= 1080 && |
| 3342 | mode.vsyncPeriod >= k60HzVsyncPeriod && |
| 3343 | mode.vsyncPeriod <= k59HzVsyncPeriod) { |
| 3344 | hwcModeOpts.push_back(mode); |
| 3345 | } |
| 3346 | } |
| 3347 | |
| 3348 | if (const auto iter = std::max_element(hwcModeOpts.begin(), hwcModeOpts.end(), |
| 3349 | [](const auto& a, const auto& b) { |
| 3350 | const auto aSize = a.width * a.height; |
| 3351 | const auto bSize = b.width * b.height; |
| 3352 | if (aSize < bSize) |
| 3353 | return true; |
| 3354 | else if (aSize == bSize) |
| 3355 | return a.vsyncPeriod > b.vsyncPeriod; |
| 3356 | else |
| 3357 | return false; |
| 3358 | }); |
| 3359 | iter != hwcModeOpts.end()) { |
| 3360 | activeModeHwcIdOpt = iter->hwcId; |
| 3361 | break; |
| 3362 | } |
| 3363 | |
| 3364 | // hwcModeOpts was empty, use hwcModes[0] as the last resort |
| 3365 | activeModeHwcIdOpt = hwcModes[0].hwcId; |
| 3366 | } |
| 3367 | } |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3368 | |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3369 | const auto isActiveMode = [activeModeHwcIdOpt](const HWComposer::HWCDisplayMode& mode) { |
| 3370 | return mode.hwcId == activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3371 | }; |
| 3372 | |
| 3373 | if (std::any_of(hwcModes.begin(), hwcModes.end(), isActiveMode)) { |
| 3374 | break; |
| 3375 | } |
| 3376 | } while (++attempt < kMaxAttempts); |
| 3377 | |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3378 | if (attempt == kMaxAttempts) { |
| 3379 | const std::string activeMode = |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3380 | activeModeHwcIdOpt ? std::to_string(*activeModeHwcIdOpt) : "unknown"s; |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3381 | ALOGE("HWC failed to report an active mode that is supported: activeModeHwcId=%s, " |
| 3382 | "hwcModes={%s}", |
| 3383 | activeMode.c_str(), base::Join(hwcModes, ", ").c_str()); |
| 3384 | return {}; |
| 3385 | } |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3386 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3387 | const DisplayModes oldModes = mPhysicalDisplays.get(displayId) |
| 3388 | .transform([](const PhysicalDisplay& display) { |
| 3389 | return display.snapshot().displayModes(); |
| 3390 | }) |
| 3391 | .value_or(DisplayModes{}); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3392 | |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 3393 | DisplayModeId nextModeId = std::accumulate(oldModes.begin(), oldModes.end(), DisplayModeId(-1), |
| 3394 | [](DisplayModeId max, const auto& pair) { |
| 3395 | return std::max(max, pair.first); |
| 3396 | }); |
| 3397 | ++nextModeId; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3398 | |
| 3399 | DisplayModes newModes; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3400 | for (const auto& hwcMode : hwcModes) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 3401 | const auto id = nextModeId++; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3402 | newModes.try_emplace(id, |
| 3403 | DisplayMode::Builder(hwcMode.hwcId) |
| 3404 | .setId(id) |
| 3405 | .setPhysicalDisplayId(displayId) |
| 3406 | .setResolution({hwcMode.width, hwcMode.height}) |
| 3407 | .setVsyncPeriod(hwcMode.vsyncPeriod) |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 3408 | .setVrrConfig(hwcMode.vrrConfig) |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3409 | .setDpiX(hwcMode.dpiX) |
| 3410 | .setDpiY(hwcMode.dpiY) |
| 3411 | .setGroup(hwcMode.configGroup) |
| 3412 | .build()); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3413 | } |
| 3414 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3415 | const bool sameModes = |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3416 | std::equal(newModes.begin(), newModes.end(), oldModes.begin(), oldModes.end(), |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3417 | [](const auto& lhs, const auto& rhs) { |
| 3418 | return equalsExceptDisplayModeId(*lhs.second, *rhs.second); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3419 | }); |
| 3420 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3421 | // Keep IDs if modes have not changed. |
| 3422 | const auto& modes = sameModes ? oldModes : newModes; |
| 3423 | const DisplayModePtr activeMode = |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3424 | std::find_if(modes.begin(), modes.end(), [activeModeHwcIdOpt](const auto& pair) { |
| 3425 | return pair.second->getHwcId() == activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3426 | })->second; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3427 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3428 | if (isExternalDisplay) { |
| 3429 | ALOGI("External display %s initial mode: {%s}", to_string(displayId).c_str(), |
| 3430 | to_string(*activeMode).c_str()); |
| 3431 | } |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3432 | return {modes, activeMode}; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3433 | } |
| 3434 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3435 | bool SurfaceFlinger::configureLocked() { |
| 3436 | std::vector<HotplugEvent> events; |
| 3437 | { |
| 3438 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 3439 | events = std::move(mPendingHotplugEvents); |
| 3440 | } |
| 3441 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3442 | for (const auto [hwcDisplayId, connection] : events) { |
| 3443 | if (auto info = getHwComposer().onHotplug(hwcDisplayId, connection)) { |
| 3444 | const auto displayId = info->id; |
| 3445 | const bool connected = connection == hal::Connection::CONNECTED; |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3446 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3447 | if (const char* const log = |
| 3448 | processHotplug(displayId, hwcDisplayId, connected, std::move(*info))) { |
| 3449 | ALOGI("%s display %s (HAL ID %" PRIu64 ")", log, to_string(displayId).c_str(), |
| 3450 | hwcDisplayId); |
| 3451 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3452 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3453 | } |
| 3454 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3455 | return !events.empty(); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3456 | } |
| 3457 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3458 | const char* SurfaceFlinger::processHotplug(PhysicalDisplayId displayId, |
| 3459 | hal::HWDisplayId hwcDisplayId, bool connected, |
| 3460 | DisplayIdentificationInfo&& info) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3461 | const auto displayOpt = mPhysicalDisplays.get(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3462 | if (!connected) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3463 | LOG_ALWAYS_FATAL_IF(!displayOpt); |
| 3464 | const auto& display = displayOpt->get(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3465 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3466 | if (const ssize_t index = mCurrentState.displays.indexOfKey(display.token()); index >= 0) { |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3467 | mCurrentState.displays.removeItemsAt(index); |
| 3468 | } |
| 3469 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3470 | mPhysicalDisplays.erase(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3471 | return "Disconnecting"; |
| 3472 | } |
| 3473 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3474 | auto [displayModes, activeMode] = loadDisplayModes(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3475 | if (!activeMode) { |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3476 | ALOGE("Failed to hotplug display %s", to_string(displayId).c_str()); |
Huihong Luo | 9f0fc59 | 2024-01-17 12:29:26 -0800 | [diff] [blame] | 3477 | if (FlagManager::getInstance().hotplug2()) { |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3478 | mScheduler->dispatchHotplugError( |
| 3479 | static_cast<int32_t>(DisplayHotplugEvent::ERROR_UNKNOWN)); |
Huihong Luo | 9f0fc59 | 2024-01-17 12:29:26 -0800 | [diff] [blame] | 3480 | } |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3481 | getHwComposer().disconnectDisplay(displayId); |
| 3482 | return nullptr; |
| 3483 | } |
| 3484 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3485 | ui::ColorModes colorModes = getHwComposer().getColorModes(displayId); |
| 3486 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3487 | if (displayOpt) { |
| 3488 | const auto& display = displayOpt->get(); |
| 3489 | const auto& snapshot = display.snapshot(); |
| 3490 | |
| 3491 | std::optional<DeviceProductInfo> deviceProductInfo; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3492 | if (getHwComposer().updatesDeviceProductInfoOnHotplugReconnect()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3493 | deviceProductInfo = std::move(info.deviceProductInfo); |
| 3494 | } else { |
| 3495 | deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3496 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3497 | |
| 3498 | const auto it = |
| 3499 | mPhysicalDisplays.try_replace(displayId, display.token(), displayId, |
| 3500 | snapshot.connectionType(), std::move(displayModes), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3501 | std::move(colorModes), std::move(deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3502 | |
| 3503 | auto& state = mCurrentState.displays.editValueFor(it->second.token()); |
| 3504 | state.sequenceId = DisplayDeviceState{}.sequenceId; // Generate new sequenceId. |
| 3505 | state.physical->activeMode = std::move(activeMode); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3506 | return "Reconnecting"; |
| 3507 | } |
| 3508 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3509 | const sp<IBinder> token = sp<BBinder>::make(); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3510 | const ui::DisplayConnectionType connectionType = |
| 3511 | getHwComposer().getDisplayConnectionType(displayId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3512 | |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3513 | mPhysicalDisplays.try_emplace(displayId, token, displayId, connectionType, |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3514 | std::move(displayModes), std::move(colorModes), |
| 3515 | std::move(info.deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3516 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3517 | DisplayDeviceState state; |
| 3518 | state.physical = {.id = displayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3519 | .hwcDisplayId = hwcDisplayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3520 | .activeMode = std::move(activeMode)}; |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3521 | state.isSecure = connectionType == ui::DisplayConnectionType::Internal; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3522 | state.isProtected = true; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3523 | state.displayName = std::move(info.name); |
| 3524 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3525 | mCurrentState.displays.add(token, state); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3526 | return "Connecting"; |
| 3527 | } |
| 3528 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3529 | void SurfaceFlinger::dispatchDisplayModeChangeEvent(PhysicalDisplayId displayId, |
| 3530 | const scheduler::FrameRateMode& mode) { |
| 3531 | // TODO(b/255635821): Merge code paths and move to Scheduler. |
| 3532 | const auto onDisplayModeChanged = displayId == mActiveDisplayId |
| 3533 | ? &scheduler::Scheduler::onPrimaryDisplayModeChanged |
| 3534 | : &scheduler::Scheduler::onNonPrimaryDisplayModeChanged; |
| 3535 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 3536 | ((*mScheduler).*onDisplayModeChanged)(scheduler::Cycle::Render, mode); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3537 | } |
| 3538 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3539 | sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3540 | const wp<IBinder>& displayToken, |
| 3541 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3542 | const DisplayDeviceState& state, |
| 3543 | const sp<compositionengine::DisplaySurface>& displaySurface, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3544 | const sp<IGraphicBufferProducer>& producer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3545 | DisplayDeviceCreationArgs creationArgs(sp<SurfaceFlinger>::fromExisting(this), getHwComposer(), |
| 3546 | displayToken, compositionDisplay); |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 3547 | creationArgs.sequenceId = state.sequenceId; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3548 | creationArgs.isSecure = state.isSecure; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3549 | creationArgs.isProtected = state.isProtected; |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3550 | creationArgs.displaySurface = displaySurface; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3551 | creationArgs.hasWideColorGamut = false; |
| 3552 | creationArgs.supportedPerFrameMetadata = 0; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 3553 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3554 | if (const auto& physical = state.physical) { |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3555 | creationArgs.activeModeId = physical->activeMode->getId(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3556 | const auto [kernelIdleTimerController, idleTimerTimeoutMs] = |
| 3557 | getKernelIdleTimerProperties(compositionDisplay->getId()); |
| 3558 | |
Ady Abraham | 0c8b723 | 2023-01-27 21:12:16 -0800 | [diff] [blame] | 3559 | using Config = scheduler::RefreshRateSelector::Config; |
| 3560 | const auto enableFrameRateOverride = sysprop::enable_frame_rate_override(true) |
| 3561 | ? Config::FrameRateOverride::Enabled |
| 3562 | : Config::FrameRateOverride::Disabled; |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 3563 | const Config config = |
Ady Abraham | 8ca643a | 2022-10-18 18:26:47 -0700 | [diff] [blame] | 3564 | {.enableFrameRateOverride = enableFrameRateOverride, |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3565 | .frameRateMultipleThreshold = |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 3566 | base::GetIntProperty("debug.sf.frame_rate_multiple_threshold"s, 0), |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3567 | .idleTimerTimeout = idleTimerTimeoutMs, |
| 3568 | .kernelIdleTimerController = kernelIdleTimerController}; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3569 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3570 | creationArgs.refreshRateSelector = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3571 | mPhysicalDisplays.get(physical->id) |
| 3572 | .transform(&PhysicalDisplay::snapshotRef) |
| 3573 | .transform([&](const display::DisplaySnapshot& snapshot) { |
| 3574 | return std::make_shared< |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3575 | scheduler::RefreshRateSelector>(snapshot.displayModes(), |
| 3576 | creationArgs.activeModeId, |
| 3577 | config); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3578 | }) |
| 3579 | .value_or(nullptr); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3580 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3581 | creationArgs.isPrimary = physical->id == getPrimaryDisplayIdLocked(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3582 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 3583 | mPhysicalDisplays.get(physical->id) |
| 3584 | .transform(&PhysicalDisplay::snapshotRef) |
| 3585 | .transform(ftl::unit_fn([&](const display::DisplaySnapshot& snapshot) { |
| 3586 | for (const auto mode : snapshot.colorModes()) { |
| 3587 | creationArgs.hasWideColorGamut |= ui::isWideColorMode(mode); |
| 3588 | creationArgs.hwcColorModes |
| 3589 | .emplace(mode, |
| 3590 | getHwComposer().getRenderIntents(physical->id, mode)); |
| 3591 | } |
| 3592 | })); |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 3593 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3594 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3595 | if (const auto id = HalDisplayId::tryCast(compositionDisplay->getId())) { |
| 3596 | getHwComposer().getHdrCapabilities(*id, &creationArgs.hdrCapabilities); |
| 3597 | creationArgs.supportedPerFrameMetadata = getHwComposer().getSupportedPerFrameMetadata(*id); |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 3598 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3599 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 3600 | auto nativeWindowSurface = getFactory().createNativeWindowSurface(producer); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3601 | auto nativeWindow = nativeWindowSurface->getNativeWindow(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3602 | creationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3603 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3604 | // Make sure that composition can never be stalled by a virtual display |
| 3605 | // 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] | 3606 | // here, in case the display is composed entirely by HWC. |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 3607 | if (state.isVirtual()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3608 | nativeWindow->setSwapInterval(nativeWindow.get(), 0); |
| 3609 | } |
| 3610 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 3611 | creationArgs.physicalOrientation = |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3612 | getPhysicalDisplayOrientation(compositionDisplay->getId(), creationArgs.isPrimary); |
| 3613 | ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 3614 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 3615 | creationArgs.initialPowerMode = state.isVirtual() ? hal::PowerMode::ON : hal::PowerMode::OFF; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3616 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3617 | creationArgs.requestedRefreshRate = state.requestedRefreshRate; |
| 3618 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3619 | sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3620 | |
Ady Abraham | 8565ad2 | 2021-06-22 17:45:44 -0700 | [diff] [blame] | 3621 | nativeWindowSurface->preallocateBuffers(); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3622 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3623 | ui::ColorMode defaultColorMode = ui::ColorMode::NATIVE; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 3624 | Dataspace defaultDataSpace = Dataspace::UNKNOWN; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3625 | if (display->hasWideColorGamut()) { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3626 | defaultColorMode = ui::ColorMode::SRGB; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 3627 | defaultDataSpace = Dataspace::V0_SRGB; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3628 | } |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 3629 | display->getCompositionDisplay()->setColorProfile( |
| 3630 | compositionengine::Output::ColorProfile{defaultColorMode, defaultDataSpace, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 3631 | RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3632 | |
| 3633 | if (const auto& physical = state.physical) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3634 | const auto& mode = *physical->activeMode; |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 3635 | display->setActiveMode(mode.getId(), mode.getVsyncRate(), mode.getVsyncRate()); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 3636 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3637 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3638 | display->setLayerFilter(makeLayerFilterForDisplay(display->getId(), state.layerStack)); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3639 | display->setProjection(state.orientation, state.layerStackSpaceRect, |
| 3640 | state.orientedDisplaySpaceRect); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3641 | display->setDisplayName(state.displayName); |
Vishnu Nair | a119aaa | 2021-09-24 07:19:35 -0700 | [diff] [blame] | 3642 | display->setFlags(state.flags); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3643 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3644 | return display; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3645 | } |
| 3646 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3647 | void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, |
| 3648 | const DisplayDeviceState& state) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3649 | ui::Size resolution(0, 0); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3650 | ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN); |
| 3651 | if (state.physical) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3652 | resolution = state.physical->activeMode->getResolution(); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3653 | pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888); |
| 3654 | } else if (state.surface != nullptr) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3655 | int status = state.surface->query(NATIVE_WINDOW_WIDTH, &resolution.width); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3656 | ALOGE_IF(status != NO_ERROR, "Unable to query width (%d)", status); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3657 | status = state.surface->query(NATIVE_WINDOW_HEIGHT, &resolution.height); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3658 | ALOGE_IF(status != NO_ERROR, "Unable to query height (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3659 | int format; |
| 3660 | status = state.surface->query(NATIVE_WINDOW_FORMAT, &format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3661 | ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3662 | pixelFormat = static_cast<ui::PixelFormat>(format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3663 | } else { |
| 3664 | // Virtual displays without a surface are dormant: |
| 3665 | // they have external state (layer stack, projection, |
| 3666 | // etc.) but no internal state (i.e. a DisplayDevice). |
| 3667 | return; |
| 3668 | } |
| 3669 | |
| 3670 | compositionengine::DisplayCreationArgsBuilder builder; |
| 3671 | if (const auto& physical = state.physical) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3672 | builder.setId(physical->id); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3673 | } else { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 3674 | builder.setId(acquireVirtualDisplay(resolution, pixelFormat)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3675 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3676 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3677 | builder.setPixels(resolution); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3678 | builder.setIsSecure(state.isSecure); |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3679 | builder.setIsProtected(state.isProtected); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 3680 | builder.setPowerAdvisor(mPowerAdvisor.get()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3681 | builder.setName(state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3682 | auto compositionDisplay = getCompositionEngine().createDisplay(builder.build()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3683 | compositionDisplay->setLayerCachingEnabled(mLayerCachingEnabled); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3684 | |
| 3685 | sp<compositionengine::DisplaySurface> displaySurface; |
| 3686 | sp<IGraphicBufferProducer> producer; |
| 3687 | sp<IGraphicBufferProducer> bqProducer; |
| 3688 | sp<IGraphicBufferConsumer> bqConsumer; |
| 3689 | getFactory().createBufferQueue(&bqProducer, &bqConsumer, /*consumerIsSurfaceFlinger =*/false); |
| 3690 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3691 | if (state.isVirtual()) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3692 | const auto displayId = VirtualDisplayId::tryCast(compositionDisplay->getId()); |
| 3693 | LOG_FATAL_IF(!displayId); |
| 3694 | auto surface = sp<VirtualDisplaySurface>::make(getHwComposer(), *displayId, state.surface, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3695 | bqProducer, bqConsumer, state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3696 | displaySurface = surface; |
| 3697 | producer = std::move(surface); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3698 | } else { |
| 3699 | ALOGE_IF(state.surface != nullptr, |
| 3700 | "adding a supported display, but rendering " |
| 3701 | "surface is provided (%p), ignoring it", |
| 3702 | state.surface.get()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3703 | const auto displayId = PhysicalDisplayId::tryCast(compositionDisplay->getId()); |
| 3704 | LOG_FATAL_IF(!displayId); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3705 | displaySurface = |
| 3706 | sp<FramebufferSurface>::make(getHwComposer(), *displayId, bqConsumer, |
| 3707 | state.physical->activeMode->getResolution(), |
| 3708 | ui::Size(maxGraphicsWidth, maxGraphicsHeight)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3709 | producer = bqProducer; |
| 3710 | } |
| 3711 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3712 | LOG_FATAL_IF(!displaySurface); |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3713 | auto display = setupNewDisplayDeviceInternal(displayToken, std::move(compositionDisplay), state, |
| 3714 | displaySurface, producer); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3715 | |
| 3716 | if (mScheduler && !display->isVirtual()) { |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3717 | // TODO(b/241285876): Annotate `processDisplayAdded` instead. |
| 3718 | ftl::FakeGuard guard(kMainThreadContext); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3719 | |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3720 | // For hotplug reconnect, renew the registration since display modes have been reloaded. |
| 3721 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector()); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3722 | } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3723 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3724 | if (display->isVirtual()) { |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 3725 | display->adjustRefreshRate(mScheduler->getPacesetterRefreshRate()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3726 | } |
| 3727 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3728 | mDisplays.try_emplace(displayToken, std::move(display)); |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3729 | |
| 3730 | // For an external display, loadDisplayModes already attempted to select the same mode |
| 3731 | // as DM, but SF still needs to be updated to match. |
| 3732 | // TODO (b/318534874): Let DM decide the initial mode. |
| 3733 | if (const auto& physical = state.physical; |
| 3734 | mScheduler && physical && FlagManager::getInstance().connected_display()) { |
| 3735 | const bool isInternalDisplay = mPhysicalDisplays.get(physical->id) |
| 3736 | .transform(&PhysicalDisplay::isInternal) |
| 3737 | .value_or(false); |
| 3738 | |
| 3739 | if (!isInternalDisplay) { |
| 3740 | auto activeModePtr = physical->activeMode; |
| 3741 | const auto fps = activeModePtr->getPeakFps(); |
| 3742 | |
| 3743 | setDesiredMode( |
| 3744 | {.mode = scheduler::FrameRateMode{fps, |
| 3745 | ftl::as_non_null(std::move(activeModePtr))}, |
| 3746 | .emitEvent = false, |
| 3747 | .force = true}); |
| 3748 | } |
| 3749 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3753 | auto display = getDisplayDeviceLocked(displayToken); |
| 3754 | if (display) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3755 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3756 | |
| 3757 | if (display->isVirtual()) { |
| 3758 | releaseVirtualDisplay(display->getVirtualId()); |
| 3759 | } else { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 3760 | mScheduler->unregisterDisplay(display->getPhysicalId()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3761 | } |
| 3762 | } |
| 3763 | |
| 3764 | mDisplays.erase(displayToken); |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3765 | |
| 3766 | if (display && display->isVirtual()) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 3767 | static_cast<void>(mScheduler->schedule([display = std::move(display)] { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3768 | // Destroy the display without holding the mStateLock. |
| 3769 | // This is a temporary solution until we can manage transaction queues without |
| 3770 | // holding the mStateLock. |
| 3771 | // With blast, the IGBP that is passed to the VirtualDisplaySurface is owned by the |
| 3772 | // client. When the IGBP is disconnected, its buffer cache in SF will be cleared |
| 3773 | // via SurfaceComposerClient::doUncacheBufferTransaction. This call from the client |
| 3774 | // ends up running on the main thread causing a deadlock since setTransactionstate |
| 3775 | // will try to acquire the mStateLock. Instead we extend the lifetime of |
| 3776 | // DisplayDevice and destroy it in the main thread without holding the mStateLock. |
| 3777 | // The display will be disconnected and removed from the mDisplays list so it will |
| 3778 | // not be accessible. |
| 3779 | })); |
| 3780 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, |
| 3784 | const DisplayDeviceState& currentState, |
| 3785 | const DisplayDeviceState& drawingState) { |
| 3786 | const sp<IBinder> currentBinder = IInterface::asBinder(currentState.surface); |
| 3787 | const sp<IBinder> drawingBinder = IInterface::asBinder(drawingState.surface); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3788 | |
| 3789 | // Recreate the DisplayDevice if the surface or sequence ID changed. |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3790 | if (currentBinder != drawingBinder || currentState.sequenceId != drawingState.sequenceId) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3791 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3792 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3793 | if (display->isVirtual()) { |
| 3794 | releaseVirtualDisplay(display->getVirtualId()); |
| 3795 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3796 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3797 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3798 | mDisplays.erase(displayToken); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3799 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3800 | if (const auto& physical = currentState.physical) { |
| 3801 | getHwComposer().allocatePhysicalDisplay(physical->hwcDisplayId, physical->id); |
| 3802 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3803 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3804 | processDisplayAdded(displayToken, currentState); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3805 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3806 | if (currentState.physical) { |
Marin Shalamanov | 4c5e301 | 2020-06-04 21:41:42 +0200 | [diff] [blame] | 3807 | const auto display = getDisplayDeviceLocked(displayToken); |
| 3808 | setPowerModeInternal(display, hal::PowerMode::ON); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3809 | |
| 3810 | // TODO(b/175678251) Call a listener instead. |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 3811 | if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 3812 | mScheduler->resetPhaseConfiguration(display->getActiveMode().fps); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3813 | } |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3814 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3815 | return; |
| 3816 | } |
| 3817 | |
| 3818 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3819 | if (currentState.layerStack != drawingState.layerStack) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3820 | display->setLayerFilter( |
| 3821 | makeLayerFilterForDisplay(display->getId(), currentState.layerStack)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3822 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 3823 | if (currentState.flags != drawingState.flags) { |
| 3824 | display->setFlags(currentState.flags); |
| 3825 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3826 | if ((currentState.orientation != drawingState.orientation) || |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3827 | (currentState.layerStackSpaceRect != drawingState.layerStackSpaceRect) || |
| 3828 | (currentState.orientedDisplaySpaceRect != drawingState.orientedDisplaySpaceRect)) { |
| 3829 | display->setProjection(currentState.orientation, currentState.layerStackSpaceRect, |
| 3830 | currentState.orientedDisplaySpaceRect); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3831 | if (display->getId() == mActiveDisplayId) { |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 3832 | mActiveDisplayTransformHint = display->getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 3833 | sActiveDisplayRotationFlags = |
| 3834 | ui::Transform::toRotationFlags(display->getOrientation()); |
Arthur Hung | b6aa9a0 | 2021-06-09 14:23:01 +0800 | [diff] [blame] | 3835 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3836 | } |
| 3837 | if (currentState.width != drawingState.width || |
| 3838 | currentState.height != drawingState.height) { |
| 3839 | display->setDisplaySize(currentState.width, currentState.height); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 3840 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3841 | if (display->getId() == mActiveDisplayId) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 3842 | onActiveDisplaySizeChanged(*display); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3843 | } |
| 3844 | } |
| 3845 | } |
| 3846 | } |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 3847 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3848 | void SurfaceFlinger::processDisplayChangesLocked() { |
| 3849 | // here we take advantage of Vector's copy-on-write semantics to |
| 3850 | // improve performance by skipping the transaction entirely when |
| 3851 | // know that the lists are identical |
| 3852 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays); |
| 3853 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays); |
| 3854 | if (!curr.isIdenticalTo(draw)) { |
| 3855 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3856 | mUpdateInputInfo = true; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3857 | |
Dominik Laskowski | 01f191c | 2024-01-29 11:51:23 -0500 | [diff] [blame] | 3858 | // Apply the current color matrix to any added or changed display. |
| 3859 | mCurrentState.colorMatrixChanged = true; |
| 3860 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3861 | // find the displays that were removed |
| 3862 | // (ie: in drawing state but not in current state) |
| 3863 | // also handle displays that changed |
| 3864 | // (ie: displays that are in both lists) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3865 | for (size_t i = 0; i < draw.size(); i++) { |
| 3866 | const wp<IBinder>& displayToken = draw.keyAt(i); |
| 3867 | const ssize_t j = curr.indexOfKey(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3868 | if (j < 0) { |
| 3869 | // in drawing state but not in current state |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3870 | processDisplayRemoved(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3871 | } else { |
| 3872 | // this display is in both lists. see if something changed. |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3873 | const DisplayDeviceState& currentState = curr[j]; |
| 3874 | const DisplayDeviceState& drawingState = draw[i]; |
| 3875 | processDisplayChanged(displayToken, currentState, drawingState); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3876 | } |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | // find displays that were added |
| 3880 | // (ie: in current state but not in drawing state) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3881 | for (size_t i = 0; i < curr.size(); i++) { |
| 3882 | const wp<IBinder>& displayToken = curr.keyAt(i); |
| 3883 | if (draw.indexOfKey(displayToken) < 0) { |
| 3884 | processDisplayAdded(displayToken, curr[i]); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3885 | } |
| 3886 | } |
| 3887 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3888 | |
| 3889 | mDrawingState.displays = mCurrentState.displays; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3890 | } |
| 3891 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3892 | void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { |
| 3893 | // Commit display transactions. |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3894 | const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3895 | mFrontEndDisplayInfosChanged = displayTransactionNeeded; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3896 | if (displayTransactionNeeded && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3897 | processDisplayChangesLocked(); |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 3898 | mFrontEndDisplayInfos.clear(); |
| 3899 | for (const auto& [_, display] : mDisplays) { |
| 3900 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 3901 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3902 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 3903 | mForceTransactionDisplayChange = displayTransactionNeeded; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3904 | |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3905 | if (mSomeChildrenChanged) { |
| 3906 | mVisibleRegionsDirty = true; |
| 3907 | mSomeChildrenChanged = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3908 | mUpdateInputInfo = true; |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3909 | } |
| 3910 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3911 | // Update transform hint. |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 3912 | if (transactionFlags & (eTransformHintUpdateNeeded | eDisplayTransactionNeeded)) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3913 | // 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] | 3914 | // |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 3915 | // 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] | 3916 | // the hint is set before we acquire a buffer from the surface texture. |
| 3917 | // |
| 3918 | // NOTE: layer transactions have taken place already, so we use their |
| 3919 | // drawing state. However, SurfaceFlinger's own transaction has not |
| 3920 | // happened yet, so we must use the current state layer list |
| 3921 | // (soon to become the drawing state list). |
| 3922 | // |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3923 | sp<const DisplayDevice> hintDisplay; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3924 | ui::LayerStack layerStack; |
| 3925 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3926 | mCurrentState.traverse([&](Layer* layer) REQUIRES(mStateLock) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3927 | // NOTE: we rely on the fact that layers are sorted by |
| 3928 | // layerStack first (so we don't have to traverse the list |
| 3929 | // of displays for every layer). |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3930 | if (const auto filter = layer->getOutputFilter(); layerStack != filter.layerStack) { |
| 3931 | layerStack = filter.layerStack; |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3932 | hintDisplay = nullptr; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3933 | |
| 3934 | // Find the display that includes the layer. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3935 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3936 | if (!display->getCompositionDisplay()->includesLayer(filter)) { |
| 3937 | continue; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3938 | } |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3939 | |
| 3940 | // Pick the primary display if another display mirrors the layer. |
| 3941 | if (hintDisplay) { |
| 3942 | hintDisplay = nullptr; |
| 3943 | break; |
| 3944 | } |
| 3945 | |
| 3946 | hintDisplay = display; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3947 | } |
| 3948 | } |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 3949 | |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3950 | if (!hintDisplay) { |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3951 | // NOTE: TEMPORARY FIX ONLY. Real fix should cause layers to |
| 3952 | // redraw after transform hint changes. See bug 8508397. |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3953 | // could be null when this layer is using a layerStack |
| 3954 | // that is not visible on any display. Also can occur at |
| 3955 | // screen off/on times. |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3956 | // U Update: Don't provide stale hints to the clients. For |
| 3957 | // special cases where we want the app to draw its |
| 3958 | // first frame before the display is available, we rely |
| 3959 | // on WMS and DMS to provide the right information |
| 3960 | // so the client can calculate the hint. |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3961 | layer->skipReportingTransformHint(); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3962 | } else { |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3963 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3964 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3965 | }); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3966 | } |
| 3967 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3968 | if (mLayersAdded) { |
| 3969 | mLayersAdded = false; |
| 3970 | // Layers have been added. |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3971 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3972 | mUpdateInputInfo = true; |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3973 | } |
| 3974 | |
| 3975 | // some layers might have been removed, so |
| 3976 | // we need to update the regions they're exposing. |
| 3977 | if (mLayersRemoved) { |
| 3978 | mLayersRemoved = false; |
| 3979 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3980 | mUpdateInputInfo = true; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3981 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3982 | if (mLayersPendingRemoval.indexOf(sp<Layer>::fromExisting(layer)) >= 0) { |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3983 | // this layer is not visible anymore |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3984 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3985 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3986 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 3987 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3988 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3989 | } |
| 3990 | |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 3991 | if (transactionFlags & eInputInfoUpdateNeeded) { |
| 3992 | mUpdateInputInfo = true; |
| 3993 | } |
| 3994 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3995 | doCommitTransactions(); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3998 | void SurfaceFlinger::updateInputFlinger(VsyncId vsyncId, TimePoint frameTime) { |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3999 | if (!mInputFlinger || (!mUpdateInputInfo && mInputWindowCommands.empty())) { |
Vishnu Nair | 42a27b5 | 2021-11-18 15:35:22 -0800 | [diff] [blame] | 4000 | return; |
| 4001 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4002 | ATRACE_CALL(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4003 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4004 | std::vector<WindowInfo> windowInfos; |
| 4005 | std::vector<DisplayInfo> displayInfos; |
| 4006 | bool updateWindowInfo = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4007 | if (mUpdateInputInfo) { |
| 4008 | mUpdateInputInfo = false; |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4009 | updateWindowInfo = true; |
| 4010 | buildWindowInfos(windowInfos, displayInfos); |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4011 | } |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4012 | |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4013 | std::unordered_set<int32_t> visibleWindowIds; |
| 4014 | for (WindowInfo& windowInfo : windowInfos) { |
| 4015 | if (!windowInfo.inputConfig.test(WindowInfo::InputConfig::NOT_VISIBLE)) { |
| 4016 | visibleWindowIds.insert(windowInfo.id); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4017 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4018 | } |
| 4019 | bool visibleWindowsChanged = false; |
| 4020 | if (visibleWindowIds != mVisibleWindowIds) { |
| 4021 | visibleWindowsChanged = true; |
| 4022 | mVisibleWindowIds = std::move(visibleWindowIds); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4023 | } |
| 4024 | |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 4025 | BackgroundExecutor::getInstance().sendCallbacks({[updateWindowInfo, |
| 4026 | windowInfos = std::move(windowInfos), |
| 4027 | displayInfos = std::move(displayInfos), |
| 4028 | inputWindowCommands = |
| 4029 | std::move(mInputWindowCommands), |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4030 | inputFlinger = mInputFlinger, this, |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4031 | visibleWindowsChanged, vsyncId, frameTime]() { |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4032 | ATRACE_NAME("BackgroundExecutor::updateInputFlinger"); |
| 4033 | if (updateWindowInfo) { |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 4034 | mWindowInfosListenerInvoker |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4035 | ->windowInfosChanged(gui::WindowInfosUpdate{std::move(windowInfos), |
| 4036 | std::move(displayInfos), |
| 4037 | ftl::to_underlying(vsyncId), |
| 4038 | frameTime.ns()}, |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4039 | std::move( |
| 4040 | inputWindowCommands.windowInfosReportedListeners), |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4041 | /* forceImmediateCall= */ visibleWindowsChanged || |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4042 | !inputWindowCommands.focusRequests.empty()); |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 4043 | } else { |
| 4044 | // If there are listeners but no changes to input windows, call the listeners |
| 4045 | // immediately. |
| 4046 | for (const auto& listener : inputWindowCommands.windowInfosReportedListeners) { |
| 4047 | if (IInterface::asBinder(listener)->isBinderAlive()) { |
| 4048 | listener->onWindowInfosReported(); |
| 4049 | } |
| 4050 | } |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4051 | } |
| 4052 | for (const auto& focusRequest : inputWindowCommands.focusRequests) { |
| 4053 | inputFlinger->setFocusedWindow(focusRequest); |
| 4054 | } |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 4055 | }}); |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 4056 | |
Arthur Hung | 6cbb975 | 2019-09-05 16:38:18 +0800 | [diff] [blame] | 4057 | mInputWindowCommands.clear(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4058 | } |
| 4059 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4060 | void SurfaceFlinger::persistDisplayBrightness(bool needsComposite) { |
| 4061 | const bool supportsDisplayBrightnessCommand = getHwComposer().getComposer()->isSupported( |
| 4062 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 4063 | if (!supportsDisplayBrightnessCommand) { |
| 4064 | return; |
| 4065 | } |
| 4066 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4067 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4068 | if (const auto brightness = display->getStagedBrightness(); brightness) { |
| 4069 | if (!needsComposite) { |
| 4070 | const status_t error = |
| 4071 | getHwComposer() |
| 4072 | .setDisplayBrightness(display->getPhysicalId(), *brightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 4073 | display->getCompositionDisplay() |
| 4074 | ->getState() |
| 4075 | .displayBrightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4076 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 4077 | .applyImmediately = true}) |
| 4078 | .get(); |
| 4079 | |
| 4080 | ALOGE_IF(error != NO_ERROR, |
| 4081 | "Error setting display brightness for display %s: %d (%s)", |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 4082 | to_string(display->getId()).c_str(), error, strerror(error)); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4083 | } |
| 4084 | display->persistBrightness(needsComposite); |
| 4085 | } |
| 4086 | } |
| 4087 | } |
| 4088 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4089 | void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, |
| 4090 | std::vector<DisplayInfo>& outDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4091 | static size_t sNumWindowInfos = 0; |
| 4092 | outWindowInfos.reserve(sNumWindowInfos); |
| 4093 | sNumWindowInfos = 0; |
| 4094 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4095 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4096 | mLayerSnapshotBuilder.forEachInputSnapshot( |
| 4097 | [&outWindowInfos](const frontend::LayerSnapshot& snapshot) { |
| 4098 | outWindowInfos.push_back(snapshot.inputInfo); |
| 4099 | }); |
| 4100 | } else { |
| 4101 | mDrawingState.traverseInReverseZOrder([&](Layer* layer) { |
| 4102 | if (!layer->needsInputInfo()) return; |
| 4103 | const auto opt = |
| 4104 | mFrontEndDisplayInfos.get(layer->getLayerStack()) |
| 4105 | .transform([](const frontend::DisplayInfo& info) { |
| 4106 | return Layer::InputDisplayArgs{&info.transform, info.isSecure}; |
| 4107 | }); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4108 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4109 | outWindowInfos.push_back(layer->fillInputInfo(opt.value_or(Layer::InputDisplayArgs{}))); |
| 4110 | }); |
| 4111 | } |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 4112 | |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4113 | sNumWindowInfos = outWindowInfos.size(); |
| 4114 | |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 4115 | outDisplayInfos.reserve(mFrontEndDisplayInfos.size()); |
| 4116 | for (const auto& [_, info] : mFrontEndDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4117 | outDisplayInfos.push_back(info.info); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 4118 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 4119 | } |
| 4120 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 4121 | void SurfaceFlinger::updateCursorAsync() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4122 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4123 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 4124 | if (HalDisplayId::tryCast(display->getId())) { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4125 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 4126 | } |
| 4127 | } |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 4128 | |
| 4129 | constexpr bool kCursorOnly = true; |
| 4130 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4131 | mCompositionEngine->updateCursorAsync(refreshArgs); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4132 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4133 | } |
| 4134 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 4135 | void SurfaceFlinger::requestHardwareVsync(PhysicalDisplayId displayId, bool enable) { |
| 4136 | getHwComposer().setVsyncEnabled(displayId, enable ? hal::Vsync::ENABLE : hal::Vsync::DISABLE); |
| 4137 | } |
| 4138 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4139 | void SurfaceFlinger::requestDisplayModes(std::vector<display::DisplayModeRequest> modeRequests) { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 4140 | if (mBootStage != BootStage::FINISHED) { |
| 4141 | ALOGV("Currently in the boot stage, skipping display mode changes"); |
| 4142 | return; |
| 4143 | } |
| 4144 | |
| 4145 | ATRACE_CALL(); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4146 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 4147 | // If this is called from the main thread mStateLock must be locked before |
| 4148 | // 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] | 4149 | // Scheduler::chooseRefreshRateForContent |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 4150 | |
| 4151 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
Marin Shalamanov | a63f9ae | 2021-11-03 15:05:16 +0100 | [diff] [blame] | 4152 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4153 | for (auto& request : modeRequests) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4154 | const auto& modePtr = request.mode.modePtr; |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 4155 | |
| 4156 | const auto displayId = modePtr->getPhysicalDisplayId(); |
| 4157 | const auto display = getDisplayDeviceLocked(displayId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4158 | |
| 4159 | if (!display) continue; |
| 4160 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 4161 | if (ftl::FakeGuard guard(kMainThreadContext); |
| 4162 | !shouldApplyRefreshRateSelectorPolicy(*display)) { |
| 4163 | ALOGV("%s(%s): Skipped applying policy", __func__, to_string(displayId).c_str()); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 4164 | continue; |
| 4165 | } |
| 4166 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4167 | if (display->refreshRateSelector().isModeAllowed(request.mode)) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 4168 | setDesiredMode(std::move(request)); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4169 | } else { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 4170 | ALOGV("%s: Mode %d is disallowed for display %s", __func__, |
| 4171 | ftl::to_underlying(modePtr->getId()), to_string(displayId).c_str()); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4172 | } |
| 4173 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 4174 | } |
| 4175 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 4176 | void SurfaceFlinger::triggerOnFrameRateOverridesChanged() { |
| 4177 | PhysicalDisplayId displayId = [&]() { |
| 4178 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 4179 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 4180 | }(); |
| 4181 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4182 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 4183 | } |
| 4184 | |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 4185 | void SurfaceFlinger::notifyCpuLoadUp() { |
| 4186 | mPowerAdvisor->notifyCpuLoadUp(); |
| 4187 | } |
| 4188 | |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 4189 | void SurfaceFlinger::onChoreographerAttached() { |
| 4190 | ATRACE_CALL(); |
| 4191 | if (mLayerLifecycleManagerEnabled) { |
| 4192 | mUpdateAttachedChoreographer = true; |
| 4193 | scheduleCommit(FrameHint::kNone); |
| 4194 | } |
| 4195 | } |
| 4196 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4197 | void SurfaceFlinger::onExpectedPresentTimePosted(TimePoint expectedPresentTime, |
| 4198 | ftl::NonNull<DisplayModePtr> modePtr, |
| 4199 | Fps renderRate) { |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4200 | const auto vsyncPeriod = modePtr->getVsyncRate().getPeriod(); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4201 | const auto timeoutOpt = [&]() -> std::optional<Period> { |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4202 | const auto vrrConfig = modePtr->getVrrConfig(); |
| 4203 | if (!vrrConfig) return std::nullopt; |
| 4204 | |
| 4205 | const auto notifyExpectedPresentConfig = |
| 4206 | modePtr->getVrrConfig()->notifyExpectedPresentConfig; |
| 4207 | if (!notifyExpectedPresentConfig) return std::nullopt; |
ramindani | cbd7a6d | 2023-12-19 16:00:30 -0800 | [diff] [blame] | 4208 | return Period::fromNs(notifyExpectedPresentConfig->timeoutNs); |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4209 | }(); |
| 4210 | |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4211 | notifyExpectedPresentIfRequired(modePtr->getPhysicalDisplayId(), vsyncPeriod, |
| 4212 | expectedPresentTime, renderRate, timeoutOpt); |
| 4213 | } |
| 4214 | |
| 4215 | void SurfaceFlinger::notifyExpectedPresentIfRequired(PhysicalDisplayId displayId, |
| 4216 | Period vsyncPeriod, |
| 4217 | TimePoint expectedPresentTime, |
| 4218 | Fps frameInterval, |
| 4219 | std::optional<Period> timeoutOpt) { |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4220 | auto& data = mNotifyExpectedPresentMap[displayId]; |
| 4221 | const auto lastExpectedPresentTimestamp = data.lastExpectedPresentTimestamp; |
| 4222 | const auto lastFrameInterval = data.lastFrameInterval; |
| 4223 | data.lastFrameInterval = frameInterval; |
| 4224 | data.lastExpectedPresentTimestamp = expectedPresentTime; |
| 4225 | const auto threshold = Duration::fromNs(vsyncPeriod.ns() / 2); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4226 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4227 | const constexpr nsecs_t kOneSecondNs = |
| 4228 | std::chrono::duration_cast<std::chrono::nanoseconds>(1s).count(); |
| 4229 | const auto timeout = |
| 4230 | Period::fromNs(timeoutOpt && timeoutOpt->ns() > 0 ? timeoutOpt->ns() : kOneSecondNs); |
| 4231 | const bool frameIntervalIsOnCadence = |
| 4232 | isFrameIntervalOnCadence(expectedPresentTime, lastExpectedPresentTimestamp, |
| 4233 | lastFrameInterval, timeout, threshold); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4234 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4235 | const bool expectedPresentWithinTimeout = |
| 4236 | isExpectedPresentWithinTimeout(expectedPresentTime, lastExpectedPresentTimestamp, |
| 4237 | timeoutOpt, threshold); |
| 4238 | if (expectedPresentWithinTimeout && frameIntervalIsOnCadence) { |
| 4239 | return; |
| 4240 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4241 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4242 | auto hintStatus = data.hintStatus.load(); |
| 4243 | if (!expectedPresentWithinTimeout) { |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4244 | if ((hintStatus != NotifyExpectedPresentHintStatus::Sent && |
| 4245 | hintStatus != NotifyExpectedPresentHintStatus::ScheduleOnTx) || |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4246 | (timeoutOpt && timeoutOpt->ns() == 0)) { |
| 4247 | // Send the hint immediately if timeout, as the hint gets |
| 4248 | // delayed otherwise, as the frame is scheduled close |
| 4249 | // to the actual present. |
| 4250 | if (data.hintStatus |
| 4251 | .compare_exchange_strong(hintStatus, |
| 4252 | NotifyExpectedPresentHintStatus::ScheduleOnTx)) { |
| 4253 | scheduleNotifyExpectedPresentHint(displayId); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4254 | return; |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4255 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4256 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4257 | } |
| 4258 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4259 | if (hintStatus == NotifyExpectedPresentHintStatus::Sent && |
| 4260 | data.hintStatus.compare_exchange_strong(hintStatus, |
| 4261 | NotifyExpectedPresentHintStatus::ScheduleOnTx)) { |
| 4262 | return; |
| 4263 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4264 | if (hintStatus != NotifyExpectedPresentHintStatus::Start) { |
| 4265 | return; |
| 4266 | } |
| 4267 | data.hintStatus.store(NotifyExpectedPresentHintStatus::ScheduleOnPresent); |
| 4268 | mScheduler->scheduleFrame(); |
| 4269 | } |
| 4270 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4271 | void SurfaceFlinger::scheduleNotifyExpectedPresentHint(PhysicalDisplayId displayId, |
| 4272 | VsyncId vsyncId) { |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4273 | auto itr = mNotifyExpectedPresentMap.find(displayId); |
| 4274 | if (itr == mNotifyExpectedPresentMap.end()) { |
| 4275 | return; |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4276 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4277 | |
| 4278 | const char* const whence = __func__; |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4279 | const auto sendHint = [=, this]() { |
| 4280 | auto& data = mNotifyExpectedPresentMap.at(displayId); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4281 | TimePoint expectedPresentTime = data.lastExpectedPresentTimestamp; |
| 4282 | if (ftl::to_underlying(vsyncId) != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 4283 | const auto predictionOpt = mFrameTimeline->getTokenManager()->getPredictionsForToken( |
| 4284 | ftl::to_underlying(vsyncId)); |
| 4285 | const auto expectedPresentTimeOnPredictor = TimePoint::fromNs( |
| 4286 | predictionOpt ? predictionOpt->presentTime : expectedPresentTime.ns()); |
| 4287 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 4288 | const auto expectedPresentTimeOnScheduler = scheduledFrameResultOpt.has_value() |
| 4289 | ? scheduledFrameResultOpt->vsyncTime |
| 4290 | : TimePoint::fromNs(0); |
| 4291 | expectedPresentTime = |
| 4292 | std::max(expectedPresentTimeOnPredictor, expectedPresentTimeOnScheduler); |
| 4293 | } |
| 4294 | |
| 4295 | if (expectedPresentTime < TimePoint::now()) { |
| 4296 | expectedPresentTime = |
| 4297 | mScheduler->getVsyncSchedule()->vsyncDeadlineAfter(TimePoint::now()); |
| 4298 | if (mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration > |
| 4299 | mScheduler->getVsyncSchedule(displayId)->period()) { |
| 4300 | expectedPresentTime += mScheduler->getVsyncSchedule(displayId)->period(); |
| 4301 | } |
| 4302 | } |
| 4303 | const auto status = getHwComposer().notifyExpectedPresent(displayId, expectedPresentTime, |
| 4304 | data.lastFrameInterval); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4305 | if (status != NO_ERROR) { |
| 4306 | ALOGE("%s failed to notifyExpectedPresentHint for display %" PRId64, whence, |
| 4307 | displayId.value); |
| 4308 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4309 | }; |
| 4310 | |
| 4311 | if (itr->second.hintStatus == NotifyExpectedPresentHintStatus::ScheduleOnTx) { |
| 4312 | return static_cast<void>(mScheduler->schedule([=, |
| 4313 | this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 4314 | auto& data = mNotifyExpectedPresentMap.at(displayId); |
| 4315 | auto scheduleHintOnTx = NotifyExpectedPresentHintStatus::ScheduleOnTx; |
| 4316 | if (data.hintStatus.compare_exchange_strong(scheduleHintOnTx, |
| 4317 | NotifyExpectedPresentHintStatus::Sent)) { |
| 4318 | sendHint(); |
| 4319 | } |
| 4320 | })); |
| 4321 | } |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4322 | auto scheduleHintOnPresent = NotifyExpectedPresentHintStatus::ScheduleOnPresent; |
| 4323 | if (itr->second.hintStatus.compare_exchange_strong(scheduleHintOnPresent, |
| 4324 | NotifyExpectedPresentHintStatus::Sent)) { |
| 4325 | sendHint(); |
| 4326 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4327 | } |
| 4328 | |
| 4329 | void SurfaceFlinger::sendNotifyExpectedPresentHint(PhysicalDisplayId displayId) { |
| 4330 | if (auto itr = mNotifyExpectedPresentMap.find(displayId); |
| 4331 | itr == mNotifyExpectedPresentMap.end() || |
| 4332 | itr->second.hintStatus != NotifyExpectedPresentHintStatus::ScheduleOnPresent) { |
| 4333 | return; |
| 4334 | } |
| 4335 | scheduleNotifyExpectedPresentHint(displayId); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4336 | } |
| 4337 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 4338 | void SurfaceFlinger::initScheduler(const sp<const DisplayDevice>& display) { |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4339 | using namespace scheduler; |
| 4340 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 4341 | LOG_ALWAYS_FATAL_IF(mScheduler); |
| 4342 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4343 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 4344 | const Fps activeRefreshRate = activeMode.fps; |
Ady Abraham | 9e16a48 | 2019-12-03 17:19:41 -0800 | [diff] [blame] | 4345 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4346 | FeatureFlags features; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4347 | |
Ady Abraham | 3f84c50 | 2023-11-30 18:18:06 -0800 | [diff] [blame] | 4348 | const auto defaultContentDetectionValue = |
| 4349 | FlagManager::getInstance().enable_fro_dependent_features() && |
| 4350 | sysprop::enable_frame_rate_override(true); |
| 4351 | if (sysprop::use_content_detection_for_refresh_rate(defaultContentDetectionValue)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4352 | features |= Feature::kContentDetection; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 4353 | if (FlagManager::getInstance().enable_small_area_detection()) { |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 4354 | features |= Feature::kSmallDirtyContentDetection; |
| 4355 | } |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4356 | } |
| 4357 | if (base::GetBoolProperty("debug.sf.show_predicted_vsync"s, false)) { |
| 4358 | features |= Feature::kTracePredictedVsync; |
| 4359 | } |
| 4360 | if (!base::GetBoolProperty("debug.sf.vsync_reactor_ignore_present_fences"s, false) && |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 4361 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4362 | features |= Feature::kPresentFences; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4363 | } |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4364 | if (display->refreshRateSelector().kernelIdleTimerController()) { |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4365 | features |= Feature::kKernelIdleTimer; |
| 4366 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4367 | if (mBackpressureGpuComposition) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4368 | features |= Feature::kBackpressureGpuComposition; |
| 4369 | } |
Leon Scroggins III | 0bd0d4c | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 4370 | if (getHwComposer().getComposer()->isSupported( |
| 4371 | Hwc2::Composer::OptionalFeature::ExpectedPresentTime)) { |
| 4372 | features |= Feature::kExpectedPresentTime; |
| 4373 | } |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4374 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4375 | mScheduler = std::make_unique<Scheduler>(static_cast<ICompositor&>(*this), |
| 4376 | static_cast<ISchedulerCallback&>(*this), features, |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4377 | getFactory(), activeRefreshRate, *mTimeStats); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4378 | |
| 4379 | // The pacesetter must be registered before EventThread creation below. |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4380 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector()); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4381 | if (FlagManager::getInstance().vrr_config()) { |
| 4382 | mScheduler->setRenderRate(display->getPhysicalId(), activeMode.fps); |
| 4383 | } |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4384 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 4385 | const auto configs = mScheduler->getVsyncConfiguration().getCurrentConfigs(); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4386 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4387 | mScheduler->createEventThread(scheduler::Cycle::Render, mFrameTimeline->getTokenManager(), |
| 4388 | /* workDuration */ configs.late.appWorkDuration, |
| 4389 | /* readyDuration */ configs.late.sfWorkDuration); |
| 4390 | mScheduler->createEventThread(scheduler::Cycle::LastComposite, |
| 4391 | mFrameTimeline->getTokenManager(), |
| 4392 | /* workDuration */ activeRefreshRate.getPeriod(), |
| 4393 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4394 | |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 4395 | // Dispatch after EventThread creation, since registerDisplay above skipped dispatch. |
| 4396 | mScheduler->dispatchHotplug(display->getPhysicalId(), scheduler::Scheduler::Hotplug::Connected); |
| 4397 | |
Leon Scroggins III | a7be94e | 2024-01-23 12:24:30 -0500 | [diff] [blame] | 4398 | mScheduler->initVsync(*mFrameTimeline->getTokenManager(), configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4399 | |
| 4400 | mRegionSamplingThread = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4401 | sp<RegionSamplingThread>::make(*this, |
| 4402 | RegionSamplingThread::EnvironmentTimingTunables()); |
Andy Yu | aef688b | 2024-01-23 17:14:23 -0800 | [diff] [blame] | 4403 | mFpsReporter = sp<FpsReporter>::make(*mFrameTimeline); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4404 | |
| 4405 | // Timer callbacks may fire, so do this last. |
| 4406 | mScheduler->startTimers(); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4407 | } |
| 4408 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4409 | void SurfaceFlinger::doCommitTransactions() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 4410 | ATRACE_CALL(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4411 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4412 | if (!mLayersPendingRemoval.isEmpty()) { |
| 4413 | // Notify removed layers now that they can't be drawn from |
| 4414 | for (const auto& l : mLayersPendingRemoval) { |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4415 | // Ensure any buffers set to display on any children are released. |
| 4416 | if (l->isRemovedFromCurrentState()) { |
| 4417 | l->latchAndReleaseBuffer(); |
| 4418 | } |
| 4419 | |
chaviw | 6852bff | 2022-04-19 17:35:11 -0500 | [diff] [blame] | 4420 | // If a layer has a parent, we allow it to out-live it's handle |
| 4421 | // with the idea that the parent holds a reference and will eventually |
| 4422 | // be cleaned up. However no one cleans up the top-level so we do so |
| 4423 | // here. |
| 4424 | if (l->isAtRoot()) { |
| 4425 | l->setIsAtRoot(false); |
| 4426 | mCurrentState.layersSortedByZ.remove(l); |
| 4427 | } |
| 4428 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4429 | // If the layer has been removed and has no parent, then it will not be reachable |
| 4430 | // when traversing layers on screen. Add the layer to the offscreenLayers set to |
| 4431 | // ensure we can copy its current to drawing state. |
| 4432 | if (!l->getParent()) { |
| 4433 | mOffscreenLayers.emplace(l.get()); |
| 4434 | } |
| 4435 | } |
| 4436 | mLayersPendingRemoval.clear(); |
| 4437 | } |
| 4438 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4439 | mDrawingState = mCurrentState; |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4440 | mCurrentState.colorMatrixChanged = false; |
| 4441 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4442 | if (mVisibleRegionsDirty) { |
| 4443 | for (const auto& rootLayer : mDrawingState.layersSortedByZ) { |
| 4444 | rootLayer->commitChildList(); |
| 4445 | } |
Andrei Stanciu | dadac5a | 2020-08-05 17:02:34 +0300 | [diff] [blame] | 4446 | } |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4447 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4448 | commitOffscreenLayers(); |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4449 | if (mLayerMirrorRoots.size() > 0) { |
| 4450 | std::deque<Layer*> pendingUpdates; |
| 4451 | pendingUpdates.insert(pendingUpdates.end(), mLayerMirrorRoots.begin(), |
| 4452 | mLayerMirrorRoots.end()); |
| 4453 | std::vector<Layer*> needsUpdating; |
| 4454 | for (Layer* cloneRoot : mLayerMirrorRoots) { |
| 4455 | pendingUpdates.pop_front(); |
| 4456 | if (cloneRoot->isRemovedFromCurrentState()) { |
| 4457 | continue; |
| 4458 | } |
| 4459 | if (cloneRoot->updateMirrorInfo(pendingUpdates)) { |
| 4460 | } else { |
| 4461 | needsUpdating.push_back(cloneRoot); |
| 4462 | } |
| 4463 | } |
| 4464 | for (Layer* cloneRoot : needsUpdating) { |
| 4465 | cloneRoot->updateMirrorInfo({}); |
| 4466 | } |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4467 | } |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4468 | } |
| 4469 | |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4470 | void SurfaceFlinger::commitOffscreenLayers() { |
| 4471 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4472 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, [](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4473 | if (layer->clearTransactionFlags(eTransactionNeeded)) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4474 | layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4475 | layer->commitChildList(); |
| 4476 | } |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4477 | }); |
| 4478 | } |
| 4479 | } |
| 4480 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4481 | void SurfaceFlinger::invalidateLayerStack(const ui::LayerFilter& layerFilter, const Region& dirty) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4482 | for (const auto& [token, displayDevice] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4483 | auto display = displayDevice->getCompositionDisplay(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4484 | if (display->includesLayer(layerFilter)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4485 | display->editState().dirtyRegion.orSelf(dirty); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 4486 | } |
| 4487 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 4488 | } |
| 4489 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4490 | bool SurfaceFlinger::latchBuffers() { |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 4491 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 4492 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4493 | const nsecs_t latchTime = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4494 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4495 | bool visibleRegions = false; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4496 | bool frameQueued = false; |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4497 | bool newDataLatched = false; |
Eric Penner | 51c59cd | 2014-07-28 19:51:58 -0700 | [diff] [blame] | 4498 | |
| 4499 | // Store the set of layers that need updates. This set must not change as |
| 4500 | // buffers are being latched, as this could result in a deadlock. |
| 4501 | // Example: Two producers share the same command stream and: |
| 4502 | // 1.) Layer 0 is latched |
| 4503 | // 2.) Layer 0 gets a new frame |
| 4504 | // 2.) Layer 1 gets a new frame |
| 4505 | // 3.) Layer 1 is latched. |
| 4506 | // Display is now waiting on Layer 1's frame, which is behind layer 0's |
| 4507 | // 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] | 4508 | mDrawingState.traverse([&](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4509 | if (layer->clearTransactionFlags(eTransactionNeeded) || mForceTransactionDisplayChange) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4510 | const uint32_t flags = layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4511 | if (flags & Layer::eVisibleRegion) { |
| 4512 | mVisibleRegionsDirty = true; |
| 4513 | } |
| 4514 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4515 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4516 | if (layer->hasReadyFrame() || layer->willReleaseBufferOnLatch()) { |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4517 | frameQueued = true; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4518 | mLayersWithQueuedFrames.emplace(sp<Layer>::fromExisting(layer)); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4519 | } else { |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 4520 | layer->useEmptyDamage(); |
Vishnu Nair | c09c023 | 2023-03-02 03:22:35 +0000 | [diff] [blame] | 4521 | if (!layer->hasBuffer()) { |
| 4522 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 4523 | // instead of a missed frame. This is used to identify scenarios where we |
| 4524 | // could not latch a buffer or apply a transaction due to backpressure. |
| 4525 | // We only update the latch time for buffer less layers here, the latch time |
| 4526 | // is updated for buffer layers when the buffer is latched. |
| 4527 | layer->updateLastLatchTime(latchTime); |
| 4528 | } |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4529 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4530 | }); |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4531 | mForceTransactionDisplayChange = false; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4532 | |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4533 | // The client can continue submitting buffers for offscreen layers, but they will not |
| 4534 | // be shown on screen. Therefore, we need to latch and release buffers of offscreen |
| 4535 | // layers to ensure dequeueBuffer doesn't block indefinitely. |
| 4536 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4537 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4538 | [&](Layer* l) { l->latchAndReleaseBuffer(); }); |
| 4539 | } |
| 4540 | |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4541 | if (!mLayersWithQueuedFrames.empty()) { |
| 4542 | // mStateLock is needed for latchBuffer as LayerRejecter::reject() |
| 4543 | // writes to Layer current state. See also b/119481871 |
| 4544 | Mutex::Autolock lock(mStateLock); |
| 4545 | |
Alec Mouri | 2f7d9ae | 2020-11-30 19:32:33 -0800 | [diff] [blame] | 4546 | for (const auto& layer : mLayersWithQueuedFrames) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4547 | if (layer->willReleaseBufferOnLatch()) { |
| 4548 | mLayersWithBuffersRemoved.emplace(layer); |
| 4549 | } |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 4550 | if (layer->latchBuffer(visibleRegions, latchTime)) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4551 | mLayersPendingRefresh.push_back(layer); |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4552 | newDataLatched = true; |
| 4553 | } |
Vishnu Nair | 1b70019 | 2022-02-04 10:09:47 -0800 | [diff] [blame] | 4554 | layer->useSurfaceDamage(); |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4555 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4556 | } |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 4557 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 4558 | mVisibleRegionsDirty |= visibleRegions; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4559 | |
| 4560 | // If we will need to wake up at some time in the future to deal with a |
| 4561 | // queued frame that shouldn't be displayed during this vsync period, wake |
| 4562 | // up during the next vsync period to check again. |
Chia-I Wu | a36bf92 | 2017-06-30 12:51:05 -0700 | [diff] [blame] | 4563 | if (frameQueued && (mLayersWithQueuedFrames.empty() || !newDataLatched)) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4564 | scheduleCommit(FrameHint::kNone); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4565 | } |
| 4566 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 4567 | // enter boot animation on first buffer latch |
| 4568 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 4569 | ALOGI("Enter boot animation"); |
| 4570 | mBootStage = BootStage::BOOTANIMATION; |
| 4571 | } |
| 4572 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4573 | if (mLayerMirrorRoots.size() > 0) { |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4574 | mDrawingState.traverse([&](Layer* layer) { layer->updateCloneBufferInfo(); }); |
| 4575 | } |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 4576 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4577 | // 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] | 4578 | return !mLayersWithQueuedFrames.empty() && newDataLatched; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4579 | } |
| 4580 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4581 | status_t SurfaceFlinger::addClientLayer(LayerCreationArgs& args, const sp<IBinder>& handle, |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4582 | const sp<Layer>& layer, const wp<Layer>& parent, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4583 | uint32_t* outTransformHint) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4584 | if (mNumLayers >= MAX_LAYERS) { |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4585 | ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(), |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4586 | MAX_LAYERS); |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 4587 | static_cast<void>(mScheduler->schedule([=, this] { |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4588 | ALOGE("Dumping layer keeping > 20 children alive:"); |
| 4589 | bool leakingParentLayerFound = false; |
| 4590 | mDrawingState.traverse([&](Layer* layer) { |
| 4591 | if (leakingParentLayerFound) { |
| 4592 | return; |
| 4593 | } |
| 4594 | if (layer->getChildrenCount() > 20) { |
| 4595 | leakingParentLayerFound = true; |
| 4596 | sp<Layer> parent = sp<Layer>::fromExisting(layer); |
| 4597 | while (parent) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4598 | ALOGE("Parent Layer: %s%s", parent->getName().c_str(), |
| 4599 | (parent->isHandleAlive() ? "handleAlive" : "")); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4600 | parent = parent->getParent(); |
| 4601 | } |
| 4602 | // Sample up to 100 layers |
| 4603 | ALOGE("Dumping random sampling of child layers total(%zu): ", |
| 4604 | layer->getChildrenCount()); |
| 4605 | int sampleSize = (layer->getChildrenCount() / 100) + 1; |
| 4606 | layer->traverseChildren([&](Layer* layer) { |
| 4607 | if (rand() % sampleSize == 0) { |
jiayongqiang | c476a34 | 2023-12-06 17:04:54 +0800 | [diff] [blame] | 4608 | ALOGE("Child Layer: %s%s", layer->getName().c_str(), |
| 4609 | (layer->isHandleAlive() ? "handleAlive" : "")); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4610 | } |
| 4611 | }); |
| 4612 | } |
| 4613 | }); |
| 4614 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4615 | int numLayers = 0; |
| 4616 | mDrawingState.traverse([&](Layer* layer) { numLayers++; }); |
| 4617 | |
| 4618 | ALOGE("Dumping random sampling of on-screen layers total(%u):", numLayers); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4619 | mDrawingState.traverse([&](Layer* layer) { |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4620 | // Aim to dump about 200 layers to avoid totally trashing |
| 4621 | // logcat. On the other hand, if there really are 4096 layers |
| 4622 | // something has gone totally wrong its probably the most |
| 4623 | // useful information in logcat. |
| 4624 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4625 | ALOGE("Layer: %s%s", layer->getName().c_str(), |
| 4626 | (layer->isHandleAlive() ? "handleAlive" : "")); |
| 4627 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4628 | } |
| 4629 | }); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4630 | ALOGE("Dumping random sampling of off-screen layers total(%zu): ", |
| 4631 | mOffscreenLayers.size()); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4632 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 4633 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4634 | ALOGE("Offscreen-layer: %s%s", offscreenLayer->getName().c_str(), |
| 4635 | (offscreenLayer->isHandleAlive() ? "handleAlive" : "")); |
| 4636 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4637 | } |
| 4638 | } |
| 4639 | })); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4640 | return NO_MEMORY; |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4641 | } |
| 4642 | |
Vishnu Nair | 86e1190 | 2022-09-06 16:03:27 +0000 | [diff] [blame] | 4643 | layer->updateTransformHint(mActiveDisplayTransformHint); |
| 4644 | if (outTransformHint) { |
| 4645 | *outTransformHint = mActiveDisplayTransformHint; |
| 4646 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4647 | args.parentId = LayerHandle::getLayerId(args.parentHandle.promote()); |
| 4648 | args.layerIdToMirror = LayerHandle::getLayerId(args.mirrorLayerHandle.promote()); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4649 | { |
| 4650 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4651 | mCreatedLayers.emplace_back(layer, parent, args.addToRoot); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4652 | mNewLayers.emplace_back(std::make_unique<frontend::RequestedLayerState>(args)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 4653 | args.mirrorLayerHandle.clear(); |
| 4654 | args.parentHandle.clear(); |
| 4655 | mNewLayerArgs.emplace_back(std::move(args)); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4656 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4657 | |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4658 | setTransactionFlags(eTransactionNeeded); |
| 4659 | return NO_ERROR; |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 4660 | } |
| 4661 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4662 | uint32_t SurfaceFlinger::getTransactionFlags() const { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 4663 | return mTransactionFlags; |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 4664 | } |
| 4665 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4666 | uint32_t SurfaceFlinger::clearTransactionFlags(uint32_t mask) { |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4667 | uint32_t transactionFlags = mTransactionFlags.fetch_and(~mask); |
| 4668 | ATRACE_INT("mTransactionFlags", transactionFlags); |
| 4669 | return transactionFlags & mask; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4670 | } |
| 4671 | |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4672 | void SurfaceFlinger::setTransactionFlags(uint32_t mask, TransactionSchedule schedule, |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4673 | const sp<IBinder>& applyToken, FrameHint frameHint) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4674 | mScheduler->modulateVsync({}, &VsyncModulator::setTransactionSchedule, schedule, applyToken); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4675 | uint32_t transactionFlags = mTransactionFlags.fetch_or(mask); |
| 4676 | ATRACE_INT("mTransactionFlags", transactionFlags); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4677 | |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4678 | if (const bool scheduled = transactionFlags & mask; !scheduled) { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4679 | scheduleCommit(frameHint); |
Ady Abraham | 27bcb55 | 2023-01-21 04:34:22 +0000 | [diff] [blame] | 4680 | } else if (frameHint == FrameHint::kActive) { |
| 4681 | // Even if the next frame is already scheduled, we should reset the idle timer |
| 4682 | // as a new activity just happened. |
| 4683 | mScheduler->resetIdleTimer(); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4684 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4685 | } |
| 4686 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4687 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyTimelineCheck( |
| 4688 | const TransactionHandler::TransactionFlushState& flushState) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 4689 | const auto& transaction = *flushState.transaction; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4690 | |
| 4691 | const TimePoint desiredPresentTime = TimePoint::fromNs(transaction.desiredPresentTime); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 4692 | const TimePoint expectedPresentTime = mScheduler->expectedPresentTimeForPacesetter(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4693 | |
| 4694 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4695 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4696 | // Do not present if the desiredPresentTime has not passed unless it is more than |
| 4697 | // one second in the future. We ignore timestamps more than 1 second in the future |
| 4698 | // for stability reasons. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4699 | if (!transaction.isAutoTimestamp && desiredPresentTime >= expectedPresentTime && |
| 4700 | desiredPresentTime < expectedPresentTime + 1s) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4701 | ATRACE_FORMAT("not current desiredPresentTime: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4702 | desiredPresentTime, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4703 | return TransactionReadiness::NotReady; |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4704 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4705 | |
Ady Abraham | 9633f8e | 2024-03-04 19:38:12 +0000 | [diff] [blame] | 4706 | if (!mScheduler->isVsyncValid(expectedPresentTime, transaction.originUid)) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4707 | ATRACE_FORMAT("!isVsyncValid expectedPresentTime: %" PRId64 " uid: %d", expectedPresentTime, |
| 4708 | transaction.originUid); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4709 | return TransactionReadiness::NotReady; |
| 4710 | } |
| 4711 | |
| 4712 | // If the client didn't specify desiredPresentTime, use the vsyncId to determine the |
| 4713 | // expected present time of this transaction. |
Ady Abraham | 9633f8e | 2024-03-04 19:38:12 +0000 | [diff] [blame] | 4714 | if (transaction.isAutoTimestamp && |
| 4715 | frameIsEarly(expectedPresentTime, VsyncId{transaction.frameTimelineInfo.vsyncId})) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4716 | ATRACE_FORMAT("frameIsEarly vsyncId: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4717 | transaction.frameTimelineInfo.vsyncId, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4718 | return TransactionReadiness::NotReady; |
| 4719 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4720 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4721 | return TransactionReadiness::Ready; |
| 4722 | } |
| 4723 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4724 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheckLegacy( |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4725 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4726 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4727 | auto ready = TransactionReadiness::Ready; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4728 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const ResolvedComposerState& |
| 4729 | resolvedState) -> bool { |
| 4730 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 4731 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4732 | const auto& transaction = *flushState.transaction; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4733 | const auto& s = resolvedState.state; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4734 | // check for barrier frames |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4735 | if (s.bufferData->hasBarrier) { |
| 4736 | // The current producerId is already a newer producer than the buffer that has a |
| 4737 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4738 | // 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] | 4739 | if (layer->getDrawingState().barrierProducerId > s.bufferData->producerId) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4740 | layer->callReleaseBufferCallback(s.bufferData->releaseBufferListener, |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4741 | resolvedState.externalTexture->getBuffer(), |
Chavi Weingarten | c8bcb68 | 2023-03-06 22:20:42 +0000 | [diff] [blame] | 4742 | s.bufferData->frameNumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4743 | s.bufferData->acquireFence); |
| 4744 | // Delete the entire state at this point and not just release the buffer because |
| 4745 | // 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] | 4746 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", |
| 4747 | layer->getDebugName(), layer->getDrawingState().barrierProducerId, |
| 4748 | s.bufferData->producerId); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4749 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4750 | } |
| 4751 | |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 4752 | if (layer->getDrawingState().barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4753 | const bool willApplyBarrierFrame = |
| 4754 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4755 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4756 | s.bufferData->barrierFrameNumber)); |
| 4757 | if (!willApplyBarrierFrame) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4758 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4759 | layer->getDebugName(), |
| 4760 | layer->getDrawingState().barrierFrameNumber, |
| 4761 | s.bufferData->barrierFrameNumber); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4762 | ready = TransactionReadiness::NotReadyBarrier; |
| 4763 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4764 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4765 | } |
| 4766 | } |
| 4767 | |
| 4768 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4769 | // the transaction in the queue. |
| 4770 | const bool hasPendingBuffer = |
| 4771 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4772 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4773 | ATRACE_FORMAT("hasPendingBuffer %s", layer->getDebugName()); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4774 | ready = TransactionReadiness::NotReady; |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4775 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4776 | } |
| 4777 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4778 | const bool acquireFenceAvailable = s.bufferData && |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4779 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4780 | s.bufferData->acquireFence; |
Ying Wei | 1fd9bfc | 2023-06-29 16:47:00 +0000 | [diff] [blame] | 4781 | const bool fenceSignaled = !acquireFenceAvailable || |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4782 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4783 | if (!fenceSignaled) { |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4784 | // check fence status |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4785 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(s, transaction.states.size(), |
| 4786 | flushState.firstTransaction) && |
| 4787 | layer->isSimpleBufferUpdate(s); |
| 4788 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4789 | if (allowLatchUnsignaled) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4790 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", |
| 4791 | layer->getDebugName()); |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4792 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4793 | } else { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4794 | ready = TransactionReadiness::NotReady; |
| 4795 | auto& listener = s.bufferData->releaseBufferListener; |
| 4796 | if (listener && |
| 4797 | (flushState.queueProcessTime - transaction.postTime) > |
| 4798 | std::chrono::nanoseconds(4s).count()) { |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 4799 | mTransactionHandler |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 4800 | .onTransactionQueueStalled(transaction.id, |
| 4801 | {.pid = layer->getOwnerPid(), |
| 4802 | .layerId = static_cast<uint32_t>( |
| 4803 | layer->getSequence()), |
| 4804 | .layerName = layer->getDebugName(), |
| 4805 | .bufferId = s.bufferData->getId(), |
| 4806 | .frameNumber = s.bufferData->frameNumber}); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4807 | } |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4808 | ATRACE_FORMAT("fence unsignaled %s", layer->getDebugName()); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4809 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4810 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4811 | } |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4812 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4813 | }); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4814 | return ready; |
| 4815 | } |
| 4816 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4817 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheck( |
| 4818 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4819 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4820 | auto ready = TransactionReadiness::Ready; |
| 4821 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const ResolvedComposerState& |
| 4822 | resolvedState) -> bool { |
| 4823 | const frontend::RequestedLayerState* layer = |
| 4824 | mLayerLifecycleManager.getLayerFromId(resolvedState.layerId); |
| 4825 | const auto& transaction = *flushState.transaction; |
| 4826 | const auto& s = resolvedState.state; |
| 4827 | // check for barrier frames |
| 4828 | if (s.bufferData->hasBarrier) { |
| 4829 | // The current producerId is already a newer producer than the buffer that has a |
| 4830 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4831 | // don't wait on the barrier since we know that's stale information. |
| 4832 | if (layer->barrierProducerId > s.bufferData->producerId) { |
| 4833 | if (s.bufferData->releaseBufferListener) { |
| 4834 | uint32_t currentMaxAcquiredBufferCount = |
| 4835 | getMaxAcquiredBufferCountForCurrentRefreshRate(layer->ownerUid.val()); |
| 4836 | ATRACE_FORMAT_INSTANT("callReleaseBufferCallback %s - %" PRIu64, |
| 4837 | layer->name.c_str(), s.bufferData->frameNumber); |
| 4838 | s.bufferData->releaseBufferListener |
| 4839 | ->onReleaseBuffer({resolvedState.externalTexture->getBuffer()->getId(), |
| 4840 | s.bufferData->frameNumber}, |
| 4841 | s.bufferData->acquireFence |
| 4842 | ? s.bufferData->acquireFence |
| 4843 | : Fence::NO_FENCE, |
| 4844 | currentMaxAcquiredBufferCount); |
| 4845 | } |
| 4846 | |
| 4847 | // Delete the entire state at this point and not just release the buffer because |
| 4848 | // everything associated with the Layer in this Transaction is now out of date. |
| 4849 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", layer->name.c_str(), |
| 4850 | layer->barrierProducerId, s.bufferData->producerId); |
| 4851 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4852 | } |
| 4853 | |
| 4854 | if (layer->barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
| 4855 | const bool willApplyBarrierFrame = |
| 4856 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4857 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4858 | s.bufferData->barrierFrameNumber)); |
| 4859 | if (!willApplyBarrierFrame) { |
| 4860 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4861 | layer->name.c_str(), layer->barrierFrameNumber, |
| 4862 | s.bufferData->barrierFrameNumber); |
| 4863 | ready = TransactionReadiness::NotReadyBarrier; |
| 4864 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4865 | } |
| 4866 | } |
| 4867 | } |
| 4868 | |
| 4869 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4870 | // the transaction in the queue. |
| 4871 | const bool hasPendingBuffer = |
| 4872 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4873 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
| 4874 | ATRACE_FORMAT("hasPendingBuffer %s", layer->name.c_str()); |
| 4875 | ready = TransactionReadiness::NotReady; |
| 4876 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4877 | } |
| 4878 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4879 | const bool acquireFenceAvailable = s.bufferData && |
| 4880 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4881 | s.bufferData->acquireFence; |
Ying Wei | 1fd9bfc | 2023-06-29 16:47:00 +0000 | [diff] [blame] | 4882 | const bool fenceSignaled = !acquireFenceAvailable || |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4883 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
| 4884 | if (!fenceSignaled) { |
| 4885 | // check fence status |
| 4886 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(s, transaction.states.size(), |
| 4887 | flushState.firstTransaction) && |
| 4888 | layer->isSimpleBufferUpdate(s); |
| 4889 | if (allowLatchUnsignaled) { |
| 4890 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", layer->name.c_str()); |
| 4891 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4892 | } else { |
| 4893 | ready = TransactionReadiness::NotReady; |
| 4894 | auto& listener = s.bufferData->releaseBufferListener; |
| 4895 | if (listener && |
| 4896 | (flushState.queueProcessTime - transaction.postTime) > |
| 4897 | std::chrono::nanoseconds(4s).count()) { |
| 4898 | mTransactionHandler |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 4899 | .onTransactionQueueStalled(transaction.id, |
| 4900 | {.pid = layer->ownerPid.val(), |
| 4901 | .layerId = layer->id, |
| 4902 | .layerName = layer->name, |
| 4903 | .bufferId = s.bufferData->getId(), |
| 4904 | .frameNumber = s.bufferData->frameNumber}); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4905 | } |
| 4906 | ATRACE_FORMAT("fence unsignaled %s", layer->name.c_str()); |
| 4907 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4908 | } |
| 4909 | } |
| 4910 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
| 4911 | }); |
| 4912 | return ready; |
| 4913 | } |
| 4914 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4915 | void SurfaceFlinger::addTransactionReadyFilters() { |
| 4916 | mTransactionHandler.addTransactionReadyFilter( |
| 4917 | std::bind(&SurfaceFlinger::transactionReadyTimelineCheck, this, std::placeholders::_1)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4918 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4919 | mTransactionHandler.addTransactionReadyFilter( |
| 4920 | std::bind(&SurfaceFlinger::transactionReadyBufferCheck, this, |
| 4921 | std::placeholders::_1)); |
| 4922 | } else { |
| 4923 | mTransactionHandler.addTransactionReadyFilter( |
| 4924 | std::bind(&SurfaceFlinger::transactionReadyBufferCheckLegacy, this, |
| 4925 | std::placeholders::_1)); |
| 4926 | } |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4927 | } |
| 4928 | |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4929 | // For tests only |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4930 | bool SurfaceFlinger::flushTransactionQueues(VsyncId vsyncId) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4931 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4932 | std::vector<TransactionState> transactions = mTransactionHandler.flushTransactions(); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4933 | return applyTransactions(transactions, vsyncId); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4934 | } |
| 4935 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4936 | bool SurfaceFlinger::applyTransactions(std::vector<TransactionState>& transactions, |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4937 | VsyncId vsyncId) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 4938 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4939 | return applyTransactionsLocked(transactions, vsyncId); |
| 4940 | } |
| 4941 | |
| 4942 | bool SurfaceFlinger::applyTransactionsLocked(std::vector<TransactionState>& transactions, |
| 4943 | VsyncId vsyncId) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4944 | bool needsTraversal = false; |
| 4945 | // Now apply all transactions. |
Robert Carr | ff7663b | 2022-02-08 12:46:49 -0800 | [diff] [blame] | 4946 | for (auto& transaction : transactions) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4947 | needsTraversal |= |
| 4948 | applyTransactionState(transaction.frameTimelineInfo, transaction.states, |
| 4949 | transaction.displays, transaction.flags, |
| 4950 | transaction.inputWindowCommands, |
| 4951 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4952 | std::move(transaction.uncacheBufferIds), transaction.postTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4953 | transaction.hasListenerCallbacks, |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4954 | transaction.listenerCallbacks, transaction.originPid, |
| 4955 | transaction.originUid, transaction.id); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4956 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4957 | return needsTraversal; |
Marissa Wall | e6e3c0d | 2019-03-29 10:28:30 -0700 | [diff] [blame] | 4958 | } |
| 4959 | |
| 4960 | bool SurfaceFlinger::transactionFlushNeeded() { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4961 | return mTransactionHandler.hasPendingTransactions(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4962 | } |
| 4963 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4964 | bool SurfaceFlinger::frameIsEarly(TimePoint expectedPresentTime, VsyncId vsyncId) const { |
| 4965 | const auto prediction = |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 4966 | mFrameTimeline->getTokenManager()->getPredictionsForToken(ftl::to_underlying(vsyncId)); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4967 | if (!prediction) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4968 | return false; |
| 4969 | } |
| 4970 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4971 | const auto predictedPresentTime = TimePoint::fromNs(prediction->presentTime); |
| 4972 | |
Rachel Lee | 0655a91 | 2023-04-20 19:54:18 -0700 | [diff] [blame] | 4973 | if (std::chrono::abs(predictedPresentTime - expectedPresentTime) >= |
| 4974 | scheduler::VsyncConfig::kEarlyLatchMaxThreshold) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4975 | return false; |
| 4976 | } |
| 4977 | |
Ady Abraham | 3db8a3c | 2023-11-20 17:53:47 -0800 | [diff] [blame] | 4978 | const Duration earlyLatchVsyncThreshold = mScheduler->getVsyncSchedule()->minFramePeriod() / 2; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4979 | |
| 4980 | return predictedPresentTime >= expectedPresentTime && |
| 4981 | predictedPresentTime - expectedPresentTime >= earlyLatchVsyncThreshold; |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4982 | } |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4983 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4984 | bool SurfaceFlinger::shouldLatchUnsignaled(const layer_state_t& state, size_t numStates, |
| 4985 | bool firstTransaction) const { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4986 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Disabled) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4987 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::Disabled)", __func__); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4988 | return false; |
| 4989 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4990 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4991 | // We only want to latch unsignaled when a single layer is updated in this |
| 4992 | // transaction (i.e. not a blast sync transaction). |
| 4993 | if (numStates != 1) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4994 | ATRACE_FORMAT_INSTANT("%s: false (numStates=%zu)", __func__, numStates); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4995 | return false; |
| 4996 | } |
| 4997 | |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4998 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::AutoSingleLayer) { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4999 | if (!firstTransaction) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 5000 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; not first " |
| 5001 | "transaction)", |
| 5002 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 5003 | return false; |
| 5004 | } |
| 5005 | |
| 5006 | // We don't want to latch unsignaled if are in early / client composition |
| 5007 | // as it leads to jank due to RenderEngine waiting for unsignaled buffer |
| 5008 | // or window animations being slow. |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 5009 | if (mScheduler->vsyncModulator().isVsyncConfigEarly()) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 5010 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; " |
| 5011 | "isVsyncConfigEarly)", |
| 5012 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 5013 | return false; |
| 5014 | } |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5015 | } |
| 5016 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5017 | return true; |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5018 | } |
| 5019 | |
chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 5020 | status_t SurfaceFlinger::setTransactionState( |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5021 | const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 5022 | const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5023 | InputWindowCommands inputWindowCommands, int64_t desiredPresentTime, bool isAutoTimestamp, |
| 5024 | const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 5025 | const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId, |
| 5026 | const std::vector<uint64_t>& mergedTransactionIds) { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 5027 | ATRACE_CALL(); |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 5028 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5029 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5030 | const int originPid = ipc->getCallingPid(); |
| 5031 | const int originUid = ipc->getCallingUid(); |
| 5032 | uint32_t permissions = LayerStatePermissions::getTransactionPermissions(originPid, originUid); |
| 5033 | for (auto composerState : states) { |
| 5034 | composerState.state.sanitize(permissions); |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 5035 | } |
| 5036 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5037 | for (DisplayState display : displays) { |
| 5038 | display.sanitize(permissions); |
| 5039 | } |
| 5040 | |
| 5041 | if (!inputWindowCommands.empty() && |
| 5042 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) == 0) { |
| 5043 | ALOGE("Only privileged callers are allowed to send input commands."); |
| 5044 | inputWindowCommands.clear(); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 5045 | } |
| 5046 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 5047 | if (flags & (eEarlyWakeupStart | eEarlyWakeupEnd)) { |
| 5048 | const bool hasPermission = |
| 5049 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) || |
| 5050 | callingThreadHasPermission(sWakeupSurfaceFlinger); |
| 5051 | if (!hasPermission) { |
| 5052 | ALOGE("Caller needs permission android.permission.WAKEUP_SURFACE_FLINGER to use " |
| 5053 | "eEarlyWakeup[Start|End] flags"); |
| 5054 | flags &= ~(eEarlyWakeupStart | eEarlyWakeupEnd); |
| 5055 | } |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 5056 | } |
| 5057 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 5058 | const int64_t postTime = systemTime(); |
| 5059 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5060 | std::vector<uint64_t> uncacheBufferIds; |
| 5061 | uncacheBufferIds.reserve(uncacheBuffers.size()); |
| 5062 | for (const auto& uncacheBuffer : uncacheBuffers) { |
| 5063 | sp<GraphicBuffer> buffer = ClientCache::getInstance().erase(uncacheBuffer); |
| 5064 | if (buffer != nullptr) { |
| 5065 | uncacheBufferIds.push_back(buffer->getId()); |
| 5066 | } |
| 5067 | } |
| 5068 | |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5069 | std::vector<ResolvedComposerState> resolvedStates; |
| 5070 | resolvedStates.reserve(states.size()); |
| 5071 | for (auto& state : states) { |
| 5072 | resolvedStates.emplace_back(std::move(state)); |
| 5073 | auto& resolvedState = resolvedStates.back(); |
| 5074 | if (resolvedState.state.hasBufferChanges() && resolvedState.state.hasValidBuffer() && |
| 5075 | resolvedState.state.surface) { |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 5076 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 5077 | std::string layerName = (layer) ? |
| 5078 | layer->getDebugName() : std::to_string(resolvedState.state.layerId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5079 | resolvedState.externalTexture = |
| 5080 | getExternalTextureFromBufferData(*resolvedState.state.bufferData, |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 5081 | layerName.c_str(), transactionId); |
Patrick Williams | 38d920e | 2023-08-31 17:31:18 -0500 | [diff] [blame] | 5082 | if (resolvedState.externalTexture) { |
| 5083 | resolvedState.state.bufferData->buffer = resolvedState.externalTexture->getBuffer(); |
| 5084 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5085 | mBufferCountTracker.increment(resolvedState.state.surface->localBinder()); |
| 5086 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 5087 | resolvedState.layerId = LayerHandle::getLayerId(resolvedState.state.surface); |
| 5088 | if (resolvedState.state.what & layer_state_t::eReparent) { |
| 5089 | resolvedState.parentId = |
| 5090 | getLayerIdFromSurfaceControl(resolvedState.state.parentSurfaceControlForChild); |
| 5091 | } |
| 5092 | if (resolvedState.state.what & layer_state_t::eRelativeLayerChanged) { |
| 5093 | resolvedState.relativeParentId = |
| 5094 | getLayerIdFromSurfaceControl(resolvedState.state.relativeLayerSurfaceControl); |
| 5095 | } |
| 5096 | if (resolvedState.state.what & layer_state_t::eInputInfoChanged) { |
| 5097 | wp<IBinder>& touchableRegionCropHandle = |
| 5098 | resolvedState.state.windowInfoHandle->editInfo()->touchableRegionCropHandle; |
| 5099 | resolvedState.touchCropId = |
| 5100 | LayerHandle::getLayerId(touchableRegionCropHandle.promote()); |
| 5101 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5102 | } |
| 5103 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5104 | TransactionState state{frameTimelineInfo, |
| 5105 | resolvedStates, |
| 5106 | displays, |
| 5107 | flags, |
| 5108 | applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5109 | std::move(inputWindowCommands), |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5110 | desiredPresentTime, |
| 5111 | isAutoTimestamp, |
| 5112 | std::move(uncacheBufferIds), |
| 5113 | postTime, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5114 | hasListenerCallbacks, |
| 5115 | listenerCallbacks, |
| 5116 | originPid, |
| 5117 | originUid, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 5118 | transactionId, |
| 5119 | mergedTransactionIds}; |
Vishnu Nair | 83df034 | 2021-03-30 11:50:44 -0700 | [diff] [blame] | 5120 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 5121 | if (mTransactionTracing) { |
| 5122 | mTransactionTracing->addQueuedTransaction(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5123 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5124 | |
| 5125 | const auto schedule = [](uint32_t flags) { |
| 5126 | if (flags & eEarlyWakeupEnd) return TransactionSchedule::EarlyEnd; |
| 5127 | if (flags & eEarlyWakeupStart) return TransactionSchedule::EarlyStart; |
| 5128 | return TransactionSchedule::Late; |
| 5129 | }(state.flags); |
| 5130 | |
| 5131 | const auto frameHint = state.isFrameActive() ? FrameHint::kActive : FrameHint::kNone; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5132 | mTransactionHandler.queueTransaction(std::move(state)); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 5133 | for (const auto& [displayId, data] : mNotifyExpectedPresentMap) { |
| 5134 | if (data.hintStatus.load() == NotifyExpectedPresentHintStatus::ScheduleOnTx) { |
| 5135 | scheduleNotifyExpectedPresentHint(displayId, VsyncId{frameTimelineInfo.vsyncId}); |
| 5136 | } |
| 5137 | } |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 5138 | setTransactionFlags(eTransactionFlushNeeded, schedule, applyToken, frameHint); |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 5139 | return NO_ERROR; |
| 5140 | } |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 5141 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5142 | bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5143 | std::vector<ResolvedComposerState>& states, |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 5144 | Vector<DisplayState>& displays, uint32_t flags, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5145 | const InputWindowCommands& inputWindowCommands, |
| 5146 | const int64_t desiredPresentTime, bool isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5147 | const std::vector<uint64_t>& uncacheBufferIds, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5148 | const int64_t postTime, bool hasListenerCallbacks, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5149 | const std::vector<ListenerCallbacks>& listenerCallbacks, |
| 5150 | int originPid, int originUid, uint64_t transactionId) { |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 5151 | uint32_t transactionFlags = 0; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5152 | if (!mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5153 | for (DisplayState& display : displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5154 | transactionFlags |= setDisplayStateLocked(display); |
| 5155 | } |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 5156 | } |
| 5157 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5158 | // start and end registration for listeners w/ no surface so they can get their callback. Note |
| 5159 | // that listeners with SurfaceControls will start registration during setClientStateLocked |
| 5160 | // below. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5161 | for (const auto& listener : listenerCallbacks) { |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5162 | mTransactionCallbackInvoker.addEmptyTransaction(listener); |
Marissa Wall | d600d57 | 2019-03-26 15:38:50 -0700 | [diff] [blame] | 5163 | } |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 5164 | nsecs_t now = systemTime(); |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5165 | uint32_t clientStateFlags = 0; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5166 | for (auto& resolvedState : states) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5167 | if (mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5168 | clientStateFlags |= |
| 5169 | setClientStateLocked(frameTimelineInfo, resolvedState, desiredPresentTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5170 | isAutoTimestamp, postTime, transactionId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5171 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5172 | } else /*mLayerLifecycleManagerEnabled*/ { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5173 | clientStateFlags |= updateLayerCallbacksAndStats(frameTimelineInfo, resolvedState, |
| 5174 | desiredPresentTime, isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5175 | postTime, transactionId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5176 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5177 | if ((flags & eAnimation) && resolvedState.state.surface) { |
| 5178 | if (const auto layer = LayerHandle::getLayer(resolvedState.state.surface)) { |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5179 | const auto layerProps = scheduler::LayerProps{ |
| 5180 | .visible = layer->isVisible(), |
| 5181 | .bounds = layer->getBounds(), |
| 5182 | .transform = layer->getTransform(), |
| 5183 | .setFrameRateVote = layer->getFrameRateForLayerTree(), |
| 5184 | .frameRateSelectionPriority = layer->getFrameRateSelectionPriority(), |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 5185 | .isFrontBuffered = layer->isFrontBuffered(), |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5186 | }; |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 5187 | layer->recordLayerHistoryAnimationTx(layerProps, now); |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 5188 | } |
| 5189 | } |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 5190 | } |
| 5191 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5192 | transactionFlags |= clientStateFlags; |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5193 | transactionFlags |= addInputWindowCommands(inputWindowCommands); |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5194 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5195 | for (uint64_t uncacheBufferId : uncacheBufferIds) { |
| 5196 | mBufferIdsToUncache.push_back(uncacheBufferId); |
Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 5197 | } |
| 5198 | |
Jorim Jaggi | bdcf09c | 2017-08-08 15:22:08 +0200 | [diff] [blame] | 5199 | // If a synchronous transaction is explicitly requested without any changes, force a transaction |
| 5200 | // anyway. This can be used as a flush mechanism for previous async transactions. |
| 5201 | // Empty animation transaction can be used to simulate back-pressure, so also force a |
| 5202 | // transaction for empty animation transactions. |
Vishnu Nair | 1523dad | 2022-09-29 16:05:18 -0700 | [diff] [blame] | 5203 | if (transactionFlags == 0 && (flags & eAnimation)) { |
Robert Carr | 2a7dbb4 | 2016-05-24 11:41:28 -0700 | [diff] [blame] | 5204 | transactionFlags = eTransactionNeeded; |
| 5205 | } |
| 5206 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5207 | bool needsTraversal = false; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 5208 | if (transactionFlags) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5209 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 5210 | // 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] | 5211 | if (transactionFlags & eTraversalNeeded) { |
| 5212 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5213 | needsTraversal = true; |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 5214 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5215 | if (transactionFlags) { |
| 5216 | setTransactionFlags(transactionFlags); |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 5217 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5218 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5219 | |
| 5220 | return needsTraversal; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5221 | } |
| 5222 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5223 | bool SurfaceFlinger::applyAndCommitDisplayTransactionStates( |
| 5224 | std::vector<TransactionState>& transactions) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5225 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5226 | bool needsTraversal = false; |
| 5227 | uint32_t transactionFlags = 0; |
| 5228 | for (auto& transaction : transactions) { |
| 5229 | for (DisplayState& display : transaction.displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5230 | transactionFlags |= setDisplayStateLocked(display); |
| 5231 | } |
| 5232 | } |
| 5233 | |
| 5234 | if (transactionFlags) { |
| 5235 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 5236 | // so we don't have to wake up again next frame to perform an unnecessary traversal. |
| 5237 | if (transactionFlags & eTraversalNeeded) { |
| 5238 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
| 5239 | needsTraversal = true; |
| 5240 | } |
| 5241 | if (transactionFlags) { |
| 5242 | setTransactionFlags(transactionFlags); |
| 5243 | } |
| 5244 | } |
| 5245 | |
| 5246 | mFrontEndDisplayInfosChanged = mTransactionFlags & eDisplayTransactionNeeded; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5247 | if (mFrontEndDisplayInfosChanged && !mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5248 | processDisplayChangesLocked(); |
| 5249 | mFrontEndDisplayInfos.clear(); |
| 5250 | for (const auto& [_, display] : mDisplays) { |
| 5251 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 5252 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5253 | needsTraversal = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5254 | } |
| 5255 | |
| 5256 | return needsTraversal; |
| 5257 | } |
| 5258 | |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5259 | uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s) { |
| 5260 | const ssize_t index = mCurrentState.displays.indexOfKey(s.token); |
| 5261 | if (index < 0) return 0; |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 5262 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5263 | uint32_t flags = 0; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5264 | DisplayDeviceState& state = mCurrentState.displays.editValueAt(index); |
| 5265 | |
| 5266 | const uint32_t what = s.what; |
| 5267 | if (what & DisplayState::eSurfaceChanged) { |
| 5268 | if (IInterface::asBinder(state.surface) != IInterface::asBinder(s.surface)) { |
| 5269 | state.surface = s.surface; |
| 5270 | flags |= eDisplayTransactionNeeded; |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 5271 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5272 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5273 | if (what & DisplayState::eLayerStackChanged) { |
| 5274 | if (state.layerStack != s.layerStack) { |
| 5275 | state.layerStack = s.layerStack; |
| 5276 | flags |= eDisplayTransactionNeeded; |
| 5277 | } |
| 5278 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 5279 | if (what & DisplayState::eFlagsChanged) { |
| 5280 | if (state.flags != s.flags) { |
| 5281 | state.flags = s.flags; |
| 5282 | flags |= eDisplayTransactionNeeded; |
| 5283 | } |
| 5284 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5285 | if (what & DisplayState::eDisplayProjectionChanged) { |
| 5286 | if (state.orientation != s.orientation) { |
| 5287 | state.orientation = s.orientation; |
| 5288 | flags |= eDisplayTransactionNeeded; |
| 5289 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5290 | if (state.orientedDisplaySpaceRect != s.orientedDisplaySpaceRect) { |
| 5291 | state.orientedDisplaySpaceRect = s.orientedDisplaySpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5292 | flags |= eDisplayTransactionNeeded; |
| 5293 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5294 | if (state.layerStackSpaceRect != s.layerStackSpaceRect) { |
| 5295 | state.layerStackSpaceRect = s.layerStackSpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5296 | flags |= eDisplayTransactionNeeded; |
| 5297 | } |
| 5298 | } |
| 5299 | if (what & DisplayState::eDisplaySizeChanged) { |
| 5300 | if (state.width != s.width) { |
| 5301 | state.width = s.width; |
| 5302 | flags |= eDisplayTransactionNeeded; |
| 5303 | } |
| 5304 | if (state.height != s.height) { |
| 5305 | state.height = s.height; |
| 5306 | flags |= eDisplayTransactionNeeded; |
| 5307 | } |
| 5308 | } |
| 5309 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5310 | return flags; |
| 5311 | } |
| 5312 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5313 | bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5314 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5315 | const int pid = ipc->getCallingPid(); |
| 5316 | const int uid = ipc->getCallingUid(); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5317 | if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) && |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5318 | (usePermissionCache ? !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid) |
| 5319 | : !checkPermission(sAccessSurfaceFlinger, pid, uid))) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5320 | return false; |
| 5321 | } |
| 5322 | return true; |
| 5323 | } |
| 5324 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5325 | uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5326 | ResolvedComposerState& composerState, |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5327 | int64_t desiredPresentTime, bool isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5328 | int64_t postTime, uint64_t transactionId) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5329 | layer_state_t& s = composerState.state; |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5330 | |
| 5331 | std::vector<ListenerCallbacks> filteredListeners; |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5332 | for (auto& listener : s.listeners) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5333 | // Starts a registration but separates the callback ids according to callback type. This |
| 5334 | // allows the callback invoker to send on latch callbacks earlier. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5335 | // note that startRegistration will not re-register if the listener has |
| 5336 | // already be registered for a prior surface control |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5337 | |
| 5338 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5339 | if (!onCommitCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5340 | filteredListeners.push_back(onCommitCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5341 | } |
| 5342 | |
| 5343 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5344 | if (!onCompleteCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5345 | filteredListeners.push_back(onCompleteCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5346 | } |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5347 | } |
| 5348 | |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 5349 | const uint64_t what = s.what; |
| 5350 | uint32_t flags = 0; |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 5351 | sp<Layer> layer = nullptr; |
| 5352 | if (s.surface) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5353 | layer = LayerHandle::getLayer(s.surface); |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 5354 | } else { |
| 5355 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5356 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5357 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5358 | if (layer == nullptr) { |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5359 | for (auto& [listener, callbackIds] : s.listeners) { |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 5360 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5361 | callbackIds, |
| 5362 | s.surface), |
| 5363 | std::vector<JankData>()); |
Marissa Wall | 88e2048 | 2019-06-24 10:49:42 -0700 | [diff] [blame] | 5364 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5365 | return 0; |
| 5366 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 5367 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5368 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 5369 | ui::LayerStack oldLayerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5370 | |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 5371 | // Only set by BLAST adapter layers |
| 5372 | if (what & layer_state_t::eProducerDisconnect) { |
| 5373 | layer->onDisconnect(); |
| 5374 | } |
| 5375 | |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5376 | if (what & layer_state_t::ePositionChanged) { |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 5377 | if (layer->setPosition(s.x, s.y)) { |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5378 | flags |= eTraversalNeeded; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5379 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5380 | } |
| 5381 | if (what & layer_state_t::eLayerChanged) { |
| 5382 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5383 | const auto& p = layer->getParent(); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5384 | if (p == nullptr) { |
chaviw | 64f7b42 | 2017-07-12 10:31:58 -0700 | [diff] [blame] | 5385 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5386 | if (layer->setLayer(s.z) && idx >= 0) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5387 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5388 | mCurrentState.layersSortedByZ.add(layer); |
| 5389 | // we need traversal (state changed) |
| 5390 | // AND transaction (list changed) |
| 5391 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5392 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5393 | } else { |
| 5394 | if (p->setChildLayer(layer, s.z)) { |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 5395 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5396 | } |
| 5397 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5398 | } |
| 5399 | if (what & layer_state_t::eRelativeLayerChanged) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5400 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5401 | const auto& p = layer->getParent(); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5402 | const auto& relativeHandle = s.relativeLayerSurfaceControl ? |
| 5403 | s.relativeLayerSurfaceControl->getHandle() : nullptr; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5404 | if (p == nullptr) { |
| 5405 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5406 | if (layer->setRelativeLayer(relativeHandle, s.z) && |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5407 | idx >= 0) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5408 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5409 | mCurrentState.layersSortedByZ.add(layer); |
| 5410 | // we need traversal (state changed) |
| 5411 | // AND transaction (list changed) |
| 5412 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5413 | } |
| 5414 | } else { |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5415 | if (p->setChildRelativeLayer(layer, relativeHandle, s.z)) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5416 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5417 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5418 | } |
| 5419 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5420 | if (what & layer_state_t::eAlphaChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5421 | if (layer->setAlpha(s.color.a)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5422 | } |
| 5423 | if (what & layer_state_t::eColorChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5424 | if (layer->setColor(s.color.rgb)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5425 | } |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 5426 | if (what & layer_state_t::eColorTransformChanged) { |
| 5427 | if (layer->setColorTransform(s.colorTransform)) { |
| 5428 | flags |= eTraversalNeeded; |
| 5429 | } |
| 5430 | } |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5431 | if (what & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5432 | if (layer->setBackgroundColor(s.bgColor.rgb, s.bgColor.a, s.bgColorDataspace)) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5433 | flags |= eTraversalNeeded; |
| 5434 | } |
| 5435 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5436 | if (what & layer_state_t::eMatrixChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5437 | if (layer->setMatrix(s.matrix)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5438 | } |
| 5439 | if (what & layer_state_t::eTransparentRegionChanged) { |
| 5440 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 5441 | flags |= eTraversalNeeded; |
| 5442 | } |
| 5443 | if (what & layer_state_t::eFlagsChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5444 | if (layer->setFlags(s.flags, s.mask)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5445 | } |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 5446 | if (what & layer_state_t::eCornerRadiusChanged) { |
| 5447 | if (layer->setCornerRadius(s.cornerRadius)) |
| 5448 | flags |= eTraversalNeeded; |
| 5449 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5450 | if (what & layer_state_t::eBackgroundBlurRadiusChanged && mSupportsBlur) { |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5451 | if (layer->setBackgroundBlurRadius(s.backgroundBlurRadius)) flags |= eTraversalNeeded; |
| 5452 | } |
Galia Peycheva | e11d575 | 2021-01-22 13:50:16 +0000 | [diff] [blame] | 5453 | if (what & layer_state_t::eBlurRegionsChanged) { |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5454 | if (layer->setBlurRegions(s.blurRegions)) flags |= eTraversalNeeded; |
| 5455 | } |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 5456 | if (what & layer_state_t::eRenderBorderChanged) { |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 5457 | if (layer->enableBorder(s.borderEnabled, s.borderWidth, s.borderColor)) { |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 5458 | flags |= eTraversalNeeded; |
| 5459 | } |
| 5460 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5461 | if (what & layer_state_t::eLayerStackChanged) { |
| 5462 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 5463 | // We only allow setting layer stacks for top level layers, |
| 5464 | // everything else inherits layer stack from its parent. |
| 5465 | if (layer->hasParent()) { |
| 5466 | 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] | 5467 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5468 | } else if (idx < 0) { |
| 5469 | ALOGE("Attempt to set layer stack on layer without parent (%s) that " |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5470 | "that also does not appear in the top level layer list. Something" |
| 5471 | " has gone wrong.", |
| 5472 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5473 | } else if (layer->setLayerStack(s.layerStack)) { |
| 5474 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5475 | mCurrentState.layersSortedByZ.add(layer); |
| 5476 | // we need traversal (state changed) |
| 5477 | // AND transaction (list changed) |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5478 | flags |= eTransactionNeeded | eTraversalNeeded | eTransformHintUpdateNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5479 | } |
| 5480 | } |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5481 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5482 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5483 | } |
| 5484 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5485 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5486 | flags |= eTraversalNeeded; |
| 5487 | } |
| 5488 | if (what & layer_state_t::eCropChanged) { |
| 5489 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5490 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5491 | if (what & layer_state_t::eDataspaceChanged) { |
| 5492 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5493 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5494 | if (what & layer_state_t::eSurfaceDamageRegionChanged) { |
| 5495 | if (layer->setSurfaceDamageRegion(s.surfaceDamageRegion)) flags |= eTraversalNeeded; |
| 5496 | } |
| 5497 | if (what & layer_state_t::eApiChanged) { |
| 5498 | if (layer->setApi(s.api)) flags |= eTraversalNeeded; |
| 5499 | } |
| 5500 | if (what & layer_state_t::eSidebandStreamChanged) { |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 5501 | if (layer->setSidebandStream(s.sidebandStream, frameTimelineInfo, postTime)) |
| 5502 | flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5503 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5504 | if (what & layer_state_t::eInputInfoChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5505 | layer->setInputInfo(*s.windowInfoHandle->getInfo()); |
| 5506 | flags |= eTraversalNeeded; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5507 | } |
Vishnu Nair | adf632b | 2021-01-07 14:05:08 -0800 | [diff] [blame] | 5508 | std::optional<nsecs_t> dequeueBufferTimestamp; |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5509 | if (what & layer_state_t::eMetadataChanged) { |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5510 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5511 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5512 | if (const int32_t gameMode = s.metadata.getInt32(gui::METADATA_GAME_MODE, -1); |
| 5513 | gameMode != -1) { |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5514 | // The transaction will be received on the Task layer and needs to be applied to all |
| 5515 | // child layers. Child layers that are added at a later point will obtain the game mode |
| 5516 | // info through addChild(). |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5517 | layer->setGameModeForTree(static_cast<GameMode>(gameMode)); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5518 | } |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5519 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 5520 | if (layer->setMetadata(s.metadata)) { |
| 5521 | flags |= eTraversalNeeded; |
| 5522 | mLayerMetadataSnapshotNeeded = true; |
| 5523 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5524 | } |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 5525 | if (what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 5526 | if (layer->setColorSpaceAgnostic(s.colorSpaceAgnostic)) { |
| 5527 | flags |= eTraversalNeeded; |
| 5528 | } |
| 5529 | } |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 5530 | if (what & layer_state_t::eShadowRadiusChanged) { |
| 5531 | if (layer->setShadowRadius(s.shadowRadius)) flags |= eTraversalNeeded; |
| 5532 | } |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 5533 | if (what & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 5534 | const auto compatibility = |
| 5535 | Layer::FrameRate::convertCompatibility(s.defaultFrameRateCompatibility); |
| 5536 | |
| 5537 | if (layer->setDefaultFrameRateCompatibility(compatibility)) { |
| 5538 | flags |= eTraversalNeeded; |
| 5539 | } |
| 5540 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5541 | if (what & layer_state_t::eFrameRateSelectionPriority) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5542 | if (layer->setFrameRateSelectionPriority(s.frameRateSelectionPriority)) { |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5543 | flags |= eTraversalNeeded; |
| 5544 | } |
| 5545 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5546 | if (what & layer_state_t::eFrameRateChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5547 | const auto compatibility = |
| 5548 | Layer::FrameRate::convertCompatibility(s.frameRateCompatibility); |
| 5549 | const auto strategy = |
| 5550 | Layer::FrameRate::convertChangeFrameRateStrategy(s.changeFrameRateStrategy); |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 5551 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 5552 | if (layer->setFrameRate(Layer::FrameRate::FrameRateVote(Fps::fromValue(s.frameRate), |
| 5553 | compatibility, strategy))) { |
| 5554 | flags |= eTraversalNeeded; |
| 5555 | } |
| 5556 | } |
| 5557 | if (what & layer_state_t::eFrameRateCategoryChanged) { |
| 5558 | const FrameRateCategory category = Layer::FrameRate::convertCategory(s.frameRateCategory); |
Rachel Lee | 67afbea | 2023-09-28 15:35:07 -0700 | [diff] [blame] | 5559 | if (layer->setFrameRateCategory(category, s.frameRateCategorySmoothSwitchOnly)) { |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 5560 | flags |= eTraversalNeeded; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 5561 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5562 | } |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 5563 | if (what & layer_state_t::eFrameRateSelectionStrategyChanged) { |
| 5564 | const scheduler::LayerInfo::FrameRateSelectionStrategy strategy = |
| 5565 | scheduler::LayerInfo::convertFrameRateSelectionStrategy( |
| 5566 | s.frameRateSelectionStrategy); |
| 5567 | if (layer->setFrameRateSelectionStrategy(strategy)) { |
| 5568 | flags |= eTraversalNeeded; |
| 5569 | } |
| 5570 | } |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5571 | if (what & layer_state_t::eFixedTransformHintChanged) { |
| 5572 | if (layer->setFixedTransformHint(s.fixedTransformHint)) { |
| 5573 | flags |= eTraversalNeeded | eTransformHintUpdateNeeded; |
| 5574 | } |
| 5575 | } |
Vishnu Nair | cf26a0a | 2020-11-13 12:56:20 -0800 | [diff] [blame] | 5576 | if (what & layer_state_t::eAutoRefreshChanged) { |
| 5577 | layer->setAutoRefresh(s.autoRefresh); |
| 5578 | } |
Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 5579 | if (what & layer_state_t::eDimmingEnabledChanged) { |
| 5580 | if (layer->setDimmingEnabled(s.dimmingEnabled)) flags |= eTraversalNeeded; |
| 5581 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5582 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 5583 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5584 | flags |= eTraversalNeeded; |
| 5585 | } |
| 5586 | } |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 5587 | if (what & layer_state_t::eDesiredHdrHeadroomChanged) { |
| 5588 | if (layer->setDesiredHdrHeadroom(s.desiredHdrSdrRatio)) { |
| 5589 | flags |= eTraversalNeeded; |
| 5590 | } |
| 5591 | } |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 5592 | if (what & layer_state_t::eCachingHintChanged) { |
| 5593 | if (layer->setCachingHint(s.cachingHint)) { |
| 5594 | flags |= eTraversalNeeded; |
| 5595 | } |
| 5596 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5597 | if (what & layer_state_t::eHdrMetadataChanged) { |
| 5598 | if (layer->setHdrMetadata(s.hdrMetadata)) flags |= eTraversalNeeded; |
| 5599 | } |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5600 | if (what & layer_state_t::eTrustedOverlayChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5601 | if (layer->setTrustedOverlay(s.isTrustedOverlay)) { |
| 5602 | flags |= eTraversalNeeded; |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5603 | } |
| 5604 | } |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 5605 | if (what & layer_state_t::eStretchChanged) { |
| 5606 | if (layer->setStretchEffect(s.stretchEffect)) { |
| 5607 | flags |= eTraversalNeeded; |
| 5608 | } |
| 5609 | } |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 5610 | if (what & layer_state_t::eBufferCropChanged) { |
| 5611 | if (layer->setBufferCrop(s.bufferCrop)) { |
| 5612 | flags |= eTraversalNeeded; |
| 5613 | } |
| 5614 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 5615 | if (what & layer_state_t::eDestinationFrameChanged) { |
| 5616 | if (layer->setDestinationFrame(s.destinationFrame)) { |
| 5617 | flags |= eTraversalNeeded; |
| 5618 | } |
| 5619 | } |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5620 | if (what & layer_state_t::eDropInputModeChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5621 | if (layer->setDropInputMode(s.dropInputMode)) { |
| 5622 | flags |= eTraversalNeeded; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 5623 | mUpdateInputInfo = true; |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5624 | } |
| 5625 | } |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5626 | // This has to happen after we reparent children because when we reparent to null we remove |
| 5627 | // child layers from current state and remove its relative z. If the children are reparented in |
| 5628 | // the same transaction, then we have to make sure we reparent the children first so we do not |
| 5629 | // lose its relative z order. |
| 5630 | if (what & layer_state_t::eReparent) { |
| 5631 | bool hadParent = layer->hasParent(); |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5632 | auto parentHandle = (s.parentSurfaceControlForChild) |
| 5633 | ? s.parentSurfaceControlForChild->getHandle() |
| 5634 | : nullptr; |
| 5635 | if (layer->reparent(parentHandle)) { |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5636 | if (!hadParent) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 5637 | layer->setIsAtRoot(false); |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5638 | mCurrentState.layersSortedByZ.remove(layer); |
| 5639 | } |
| 5640 | flags |= eTransactionNeeded | eTraversalNeeded; |
| 5641 | } |
| 5642 | } |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5643 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5644 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5645 | for (auto& [listener, callbackIds] : filteredListeners) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 5646 | callbackHandles.emplace_back( |
| 5647 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5648 | } |
| 5649 | } |
Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 5650 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5651 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5652 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5653 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 5654 | frameTimelineInfo)) { |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5655 | flags |= eTraversalNeeded; |
| 5656 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5657 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5658 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 5659 | } |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 5660 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5661 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5662 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5663 | } |
| 5664 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5665 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5666 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5667 | s.trustedPresentationListener)) { |
| 5668 | flags |= eTraversalNeeded; |
| 5669 | } |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5670 | } |
| 5671 | |
Pascal Muetschard | b39918f | 2023-01-27 11:36:11 +0100 | [diff] [blame] | 5672 | if (what & layer_state_t::eFlushJankData) { |
| 5673 | // Do nothing. Processing the transaction completed listeners currently cause the flush. |
| 5674 | } |
| 5675 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5676 | if (layer->setTransactionCompletedListeners(callbackHandles, |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5677 | layer->willPresentCurrentTransaction() || |
| 5678 | layer->willReleaseBufferOnLatch())) { |
Vishnu Nair | d691322 | 2023-02-01 22:56:21 +0000 | [diff] [blame] | 5679 | flags |= eTraversalNeeded; |
| 5680 | } |
| 5681 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5682 | // Do not put anything that updates layer state or modifies flags after |
| 5683 | // setTransactionCompletedListener |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5684 | |
| 5685 | // 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] | 5686 | if (((flags & eTransformHintUpdateNeeded) == 0) && |
| 5687 | oldLayerStack != layer->getLayerStack(LayerVector::StateSet::Current)) { |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5688 | flags |= eTransformHintUpdateNeeded; |
| 5689 | } |
| 5690 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5691 | return flags; |
| 5692 | } |
| 5693 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5694 | uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& frameTimelineInfo, |
| 5695 | ResolvedComposerState& composerState, |
| 5696 | int64_t desiredPresentTime, |
| 5697 | bool isAutoTimestamp, int64_t postTime, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5698 | uint64_t transactionId) { |
| 5699 | layer_state_t& s = composerState.state; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5700 | |
| 5701 | std::vector<ListenerCallbacks> filteredListeners; |
| 5702 | for (auto& listener : s.listeners) { |
| 5703 | // Starts a registration but separates the callback ids according to callback type. This |
| 5704 | // allows the callback invoker to send on latch callbacks earlier. |
| 5705 | // note that startRegistration will not re-register if the listener has |
| 5706 | // already be registered for a prior surface control |
| 5707 | |
| 5708 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5709 | if (!onCommitCallbacks.callbackIds.empty()) { |
| 5710 | filteredListeners.push_back(onCommitCallbacks); |
| 5711 | } |
| 5712 | |
| 5713 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5714 | if (!onCompleteCallbacks.callbackIds.empty()) { |
| 5715 | filteredListeners.push_back(onCompleteCallbacks); |
| 5716 | } |
| 5717 | } |
| 5718 | |
| 5719 | const uint64_t what = s.what; |
| 5720 | uint32_t flags = 0; |
| 5721 | sp<Layer> layer = nullptr; |
| 5722 | if (s.surface) { |
| 5723 | layer = LayerHandle::getLayer(s.surface); |
| 5724 | } else { |
| 5725 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5726 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5727 | } |
| 5728 | if (layer == nullptr) { |
| 5729 | for (auto& [listener, callbackIds] : s.listeners) { |
| 5730 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5731 | callbackIds, |
| 5732 | s.surface), |
| 5733 | std::vector<JankData>()); |
| 5734 | } |
| 5735 | return 0; |
| 5736 | } |
| 5737 | if (what & layer_state_t::eProducerDisconnect) { |
| 5738 | layer->onDisconnect(); |
| 5739 | } |
| 5740 | std::optional<nsecs_t> dequeueBufferTimestamp; |
| 5741 | if (what & layer_state_t::eMetadataChanged) { |
| 5742 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
| 5743 | } |
| 5744 | |
| 5745 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5746 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5747 | for (auto& [listener, callbackIds] : filteredListeners) { |
| 5748 | callbackHandles.emplace_back( |
| 5749 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
| 5750 | } |
| 5751 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5752 | // TODO(b/238781169) remove after screenshot refactor, currently screenshots |
| 5753 | // requires to read drawing state from binder thread. So we need to fix that |
| 5754 | // before removing this. |
Vishnu Nair | aeaf9d7 | 2023-09-12 15:47:41 -0700 | [diff] [blame] | 5755 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5756 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
| 5757 | } |
| 5758 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5759 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5760 | flags |= eTraversalNeeded; |
| 5761 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5762 | if (what & layer_state_t::eCropChanged) { |
| 5763 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5764 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5765 | if (what & layer_state_t::eSidebandStreamChanged) { |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 5766 | if (layer->setSidebandStream(s.sidebandStream, frameTimelineInfo, postTime)) |
| 5767 | flags |= eTraversalNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5768 | } |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 5769 | if (what & layer_state_t::eDataspaceChanged) { |
| 5770 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5771 | } |
Vishnu Nair | c5e3416 | 2023-08-22 13:21:20 -0700 | [diff] [blame] | 5772 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
| 5773 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
| 5774 | flags |= eTraversalNeeded; |
| 5775 | } |
| 5776 | } |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 5777 | if (what & layer_state_t::eDesiredHdrHeadroomChanged) { |
| 5778 | if (layer->setDesiredHdrHeadroom(s.desiredHdrSdrRatio)) { |
| 5779 | flags |= eTraversalNeeded; |
| 5780 | } |
| 5781 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5782 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 5783 | std::optional<ui::Transform::RotationFlags> transformHint = std::nullopt; |
| 5784 | frontend::LayerSnapshot* snapshot = mLayerSnapshotBuilder.getSnapshot(layer->sequence); |
| 5785 | if (snapshot) { |
| 5786 | transformHint = snapshot->transformHint; |
| 5787 | } |
| 5788 | layer->setTransformHint(transformHint); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5789 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5790 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
| 5791 | frameTimelineInfo)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5792 | flags |= eTraversalNeeded; |
| 5793 | } |
| 5794 | mLayersWithQueuedFrames.emplace(layer); |
| 5795 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5796 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
| 5797 | } |
| 5798 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5799 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5800 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5801 | } |
| 5802 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5803 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5804 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5805 | s.trustedPresentationListener)) { |
| 5806 | flags |= eTraversalNeeded; |
| 5807 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5808 | } |
| 5809 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5810 | const auto& requestedLayerState = mLayerLifecycleManager.getLayerFromId(layer->getSequence()); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5811 | bool willPresentCurrentTransaction = requestedLayerState && |
| 5812 | (requestedLayerState->hasReadyFrame() || |
| 5813 | requestedLayerState->willReleaseBufferOnLatch()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5814 | if (layer->setTransactionCompletedListeners(callbackHandles, willPresentCurrentTransaction)) |
| 5815 | flags |= eTraversalNeeded; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5816 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5817 | return flags; |
| 5818 | } |
| 5819 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5820 | uint32_t SurfaceFlinger::addInputWindowCommands(const InputWindowCommands& inputWindowCommands) { |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5821 | bool hasChanges = mInputWindowCommands.merge(inputWindowCommands); |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 5822 | return hasChanges ? eTraversalNeeded : 0; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5823 | } |
| 5824 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5825 | status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5826 | const sp<IBinder>& mirrorFromHandle, |
| 5827 | gui::CreateSurfaceResult& outResult) { |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5828 | if (!mirrorFromHandle) { |
| 5829 | return NAME_NOT_FOUND; |
| 5830 | } |
| 5831 | |
| 5832 | sp<Layer> mirrorLayer; |
| 5833 | sp<Layer> mirrorFrom; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5834 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5835 | { |
| 5836 | Mutex::Autolock _l(mStateLock); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5837 | mirrorFrom = LayerHandle::getLayer(mirrorFromHandle); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5838 | if (!mirrorFrom) { |
| 5839 | return NAME_NOT_FOUND; |
| 5840 | } |
Vishnu Nair | b21272e | 2022-07-01 22:47:33 +0000 | [diff] [blame] | 5841 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5842 | mirrorArgs.mirrorLayerHandle = mirrorFromHandle; |
| 5843 | mirrorArgs.addToRoot = false; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5844 | status_t result = createEffectLayer(mirrorArgs, &outResult.handle, &mirrorLayer); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5845 | if (result != NO_ERROR) { |
| 5846 | return result; |
| 5847 | } |
| 5848 | |
Vishnu Nair | de17725 | 2023-04-21 12:44:10 -0700 | [diff] [blame] | 5849 | mirrorLayer->setClonedChild(mirrorFrom->createClone(mirrorLayer->getSequence())); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5850 | } |
| 5851 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5852 | outResult.layerId = mirrorLayer->sequence; |
| 5853 | outResult.layerName = String16(mirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5854 | return addClientLayer(mirrorArgs, outResult.handle, mirrorLayer /* layer */, |
| 5855 | nullptr /* parent */, nullptr /* outTransformHint */); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5856 | } |
| 5857 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5858 | status_t SurfaceFlinger::mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5859 | gui::CreateSurfaceResult& outResult) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5860 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5861 | const int uid = ipc->getCallingUid(); |
| 5862 | if (uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM && uid != AID_SHELL) { |
| 5863 | ALOGE("Permission denied when trying to mirror display"); |
| 5864 | return PERMISSION_DENIED; |
| 5865 | } |
| 5866 | |
| 5867 | ui::LayerStack layerStack; |
| 5868 | sp<Layer> rootMirrorLayer; |
| 5869 | status_t result = 0; |
| 5870 | |
| 5871 | { |
| 5872 | Mutex::Autolock lock(mStateLock); |
| 5873 | |
| 5874 | const auto display = getDisplayDeviceLocked(displayId); |
| 5875 | if (!display) { |
| 5876 | return NAME_NOT_FOUND; |
| 5877 | } |
| 5878 | |
| 5879 | layerStack = display->getLayerStack(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5880 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5881 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5882 | mirrorArgs.addToRoot = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5883 | mirrorArgs.layerStackToMirror = layerStack; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5884 | result = createEffectLayer(mirrorArgs, &outResult.handle, &rootMirrorLayer); |
| 5885 | outResult.layerId = rootMirrorLayer->sequence; |
| 5886 | outResult.layerName = String16(rootMirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5887 | result |= addClientLayer(mirrorArgs, outResult.handle, rootMirrorLayer /* layer */, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5888 | nullptr /* parent */, nullptr /* outTransformHint */); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5889 | } |
| 5890 | |
| 5891 | if (result != NO_ERROR) { |
| 5892 | return result; |
| 5893 | } |
| 5894 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5895 | if (mLegacyFrontEndEnabled) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5896 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5897 | mMirrorDisplays.emplace_back(layerStack, outResult.handle, args.client); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5898 | } |
| 5899 | |
| 5900 | setTransactionFlags(eTransactionFlushNeeded); |
| 5901 | return NO_ERROR; |
| 5902 | } |
| 5903 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5904 | status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, gui::CreateSurfaceResult& outResult) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5905 | status_t result = NO_ERROR; |
| 5906 | |
| 5907 | sp<Layer> layer; |
| 5908 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5909 | switch (args.flags & ISurfaceComposerClient::eFXSurfaceMask) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5910 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 5911 | case ISurfaceComposerClient::eFXSurfaceContainer: |
| 5912 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 5913 | args.flags |= ISurfaceComposerClient::eNoColorFill; |
Siarhei Vishniakou | 8d66013 | 2024-01-11 16:48:44 -0800 | [diff] [blame] | 5914 | [[fallthrough]]; |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 5915 | case ISurfaceComposerClient::eFXSurfaceEffect: { |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5916 | result = createBufferStateLayer(args, &outResult.handle, &layer); |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5917 | std::atomic<int32_t>* pendingBufferCounter = layer->getPendingBufferCounter(); |
| 5918 | if (pendingBufferCounter) { |
| 5919 | std::string counterName = layer->getPendingBufferCounterName(); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5920 | mBufferCountTracker.add(outResult.handle->localBinder(), counterName, |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5921 | pendingBufferCounter); |
| 5922 | } |
| 5923 | } break; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5924 | default: |
| 5925 | result = BAD_VALUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5926 | break; |
| 5927 | } |
| 5928 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5929 | if (result != NO_ERROR) { |
| 5930 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5931 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5932 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5933 | args.addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess(); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5934 | // We can safely promote the parent layer in binder thread because we have a strong reference |
| 5935 | // to the layer's handle inside this scope. |
| 5936 | sp<Layer> parent = LayerHandle::getLayer(args.parentHandle.promote()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5937 | if (args.parentHandle != nullptr && parent == nullptr) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5938 | ALOGE("Invalid parent handle %p", args.parentHandle.promote().get()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5939 | args.addToRoot = false; |
Garfield Tan | dbc93d7 | 2021-10-26 18:28:57 -0700 | [diff] [blame] | 5940 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5941 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5942 | uint32_t outTransformHint; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5943 | result = addClientLayer(args, outResult.handle, layer, parent, &outTransformHint); |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 5944 | if (result != NO_ERROR) { |
| 5945 | return result; |
| 5946 | } |
| 5947 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5948 | outResult.transformHint = static_cast<int32_t>(outTransformHint); |
| 5949 | outResult.layerId = layer->sequence; |
| 5950 | outResult.layerName = String16(layer->getDebugName()); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5951 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5952 | } |
| 5953 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5954 | status_t SurfaceFlinger::createBufferStateLayer(LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5955 | sp<Layer>* outLayer) { |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5956 | *outLayer = getFactory().createBufferStateLayer(args); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5957 | *handle = (*outLayer)->getHandle(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5958 | return NO_ERROR; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 5959 | } |
| 5960 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5961 | status_t SurfaceFlinger::createEffectLayer(const LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5962 | sp<Layer>* outLayer) { |
| 5963 | *outLayer = getFactory().createEffectLayer(args); |
| 5964 | *handle = (*outLayer)->getHandle(); |
| 5965 | return NO_ERROR; |
| 5966 | } |
| 5967 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5968 | void SurfaceFlinger::markLayerPendingRemovalLocked(const sp<Layer>& layer) { |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5969 | mLayersPendingRemoval.add(layer); |
| 5970 | mLayersRemoved = true; |
| 5971 | setTransactionFlags(eTransactionNeeded); |
| 5972 | } |
| 5973 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5974 | void SurfaceFlinger::onHandleDestroyed(BBinder* handle, sp<Layer>& layer, uint32_t layerId) { |
| 5975 | { |
| 5976 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | 606d9d0 | 2023-08-19 14:20:18 -0700 | [diff] [blame] | 5977 | mDestroyedHandles.emplace_back(layerId, layer->getDebugName()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5978 | } |
| 5979 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 5980 | mTransactionHandler.onLayerDestroyed(layerId); |
| 5981 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5982 | Mutex::Autolock lock(mStateLock); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5983 | markLayerPendingRemovalLocked(layer); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 5984 | layer->onHandleDestroyed(); |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 5985 | mBufferCountTracker.remove(handle); |
Robert Carr | 695d528 | 2018-12-18 15:27:58 -0800 | [diff] [blame] | 5986 | layer.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5987 | |
| 5988 | setTransactionFlags(eTransactionFlushNeeded); |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 5989 | } |
| 5990 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 5991 | void SurfaceFlinger::initializeDisplays() { |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5992 | TransactionState state; |
| 5993 | state.inputWindowCommands = mInputWindowCommands; |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5994 | const nsecs_t now = systemTime(); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5995 | state.desiredPresentTime = now; |
| 5996 | state.postTime = now; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5997 | state.originPid = mPid; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5998 | state.originUid = static_cast<int>(getuid()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5999 | const uint64_t transactionId = (static_cast<uint64_t>(mPid) << 32) | mUniqueTransactionId++; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6000 | state.id = transactionId; |
| 6001 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6002 | auto layerStack = ui::DEFAULT_LAYER_STACK.id; |
| 6003 | for (const auto& [id, display] : FTL_FAKE_GUARD(mStateLock, mPhysicalDisplays)) { |
| 6004 | state.displays.push(DisplayState(display.token(), ui::LayerStack::fromValue(layerStack++))); |
| 6005 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 6006 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6007 | std::vector<TransactionState> transactions; |
| 6008 | transactions.emplace_back(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 6009 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6010 | if (mLegacyFrontEndEnabled) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6011 | applyTransactions(transactions, VsyncId{0}); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6012 | } else { |
| 6013 | applyAndCommitDisplayTransactionStates(transactions); |
| 6014 | } |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 6015 | |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6016 | { |
| 6017 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6018 | |
| 6019 | // In case of a restart, ensure all displays are off. |
| 6020 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6021 | setPowerModeInternal(getDisplayDeviceLocked(id), hal::PowerMode::OFF); |
| 6022 | } |
| 6023 | |
| 6024 | // Power on all displays. The primary display is first, so becomes the active display. Also, |
| 6025 | // the DisplayCapability set of a display is populated on its first powering on. Do this now |
| 6026 | // before responding to any Binder query from DisplayManager about display capabilities. |
| 6027 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6028 | setPowerModeInternal(getDisplayDeviceLocked(id), hal::PowerMode::ON); |
| 6029 | } |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6030 | } |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 6031 | } |
| 6032 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6033 | void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6034 | if (display->isVirtual()) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6035 | // TODO(b/241285876): This code path should not be reachable, so enforce this at compile |
| 6036 | // time. |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 6037 | ALOGE("%s: Invalid operation on virtual display", __func__); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6038 | return; |
| 6039 | } |
| 6040 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6041 | const auto displayId = display->getPhysicalId(); |
| 6042 | 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] | 6043 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6044 | const auto currentMode = display->getPowerMode(); |
| 6045 | if (currentMode == mode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6046 | return; |
| 6047 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6048 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6049 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 6050 | .transform(&PhysicalDisplay::isInternal) |
| 6051 | .value_or(false); |
| 6052 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 6053 | const auto activeDisplay = getDisplayDeviceLocked(mActiveDisplayId); |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 6054 | |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6055 | ALOGW_IF(display != activeDisplay && isInternalDisplay && activeDisplay && |
| 6056 | activeDisplay->isPoweredOn(), |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 6057 | "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] | 6058 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6059 | display->setPowerMode(mode); |
| 6060 | |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 6061 | const auto activeMode = display->refreshRateSelector().getActiveMode().modePtr; |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6062 | if (currentMode == hal::PowerMode::OFF) { |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 6063 | // Turn on the display |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6064 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 6065 | // Activate the display (which involves a modeset to the active mode) when the inner or |
| 6066 | // outer display of a foldable is powered on. This condition relies on the above |
| 6067 | // DisplayDevice::setPowerMode. If `display` and `activeDisplay` are the same display, |
| 6068 | // then the `activeDisplay->isPoweredOn()` below is true, such that the display is not |
| 6069 | // activated every time it is powered on. |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6070 | // |
| 6071 | // TODO(b/255635821): Remove the concept of active display. |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 6072 | if (isInternalDisplay && (!activeDisplay || !activeDisplay->isPoweredOn())) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 6073 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 6074 | } |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6075 | |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6076 | if (displayId == mActiveDisplayId) { |
| 6077 | // TODO(b/281692563): Merge the syscalls. For now, keep uclamp in a separate syscall and |
| 6078 | // set it before SCHED_FIFO due to b/190237315. |
| 6079 | if (setSchedAttr(true) != NO_ERROR) { |
| 6080 | ALOGW("Failed to set uclamp.min after powering on active display: %s", |
| 6081 | strerror(errno)); |
| 6082 | } |
| 6083 | if (setSchedFifo(true) != NO_ERROR) { |
| 6084 | ALOGW("Failed to set SCHED_FIFO after powering on active display: %s", |
| 6085 | strerror(errno)); |
| 6086 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 6087 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6088 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6089 | getHwComposer().setPowerMode(displayId, mode); |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6090 | if (mode != hal::PowerMode::DOZE_SUSPEND && |
| 6091 | (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present())) { |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6092 | const bool enable = |
| 6093 | mScheduler->getVsyncSchedule(displayId)->getPendingHardwareVsyncState(); |
| 6094 | requestHardwareVsync(displayId, enable); |
| 6095 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6096 | if (displayId == mActiveDisplayId) { |
| 6097 | mScheduler->enableSyntheticVsync(false); |
| 6098 | } |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6099 | |
| 6100 | constexpr bool kAllowToEnable = true; |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 6101 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, activeMode.get()); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6102 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6103 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6104 | mVisibleRegionsDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6105 | scheduleComposite(FrameHint::kActive); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6106 | } else if (mode == hal::PowerMode::OFF) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6107 | const bool currentModeNotDozeSuspend = (currentMode != hal::PowerMode::DOZE_SUSPEND); |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 6108 | // Turn off the display |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6109 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 6110 | if (const auto display = getActivatableDisplay()) { |
| 6111 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
| 6112 | } else { |
| 6113 | if (setSchedFifo(false) != NO_ERROR) { |
| 6114 | ALOGW("Failed to set SCHED_OTHER after powering off active display: %s", |
| 6115 | strerror(errno)); |
| 6116 | } |
| 6117 | if (setSchedAttr(false) != NO_ERROR) { |
| 6118 | ALOGW("Failed set uclamp.min after powering off active display: %s", |
| 6119 | strerror(errno)); |
| 6120 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6121 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6122 | if (currentModeNotDozeSuspend) { |
| 6123 | if (!FlagManager::getInstance().multithreaded_present()) { |
| 6124 | mScheduler->disableHardwareVsync(displayId, true); |
| 6125 | } |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 6126 | mScheduler->enableSyntheticVsync(); |
| 6127 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6128 | } |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 6129 | } |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6130 | if (currentModeNotDozeSuspend && FlagManager::getInstance().multithreaded_present()) { |
| 6131 | constexpr bool kDisallow = true; |
| 6132 | mScheduler->disableHardwareVsync(displayId, kDisallow); |
| 6133 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6134 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6135 | // We must disable VSYNC *before* turning off the display. The call to |
| 6136 | // disableHardwareVsync, above, schedules a task to turn it off after |
| 6137 | // this method returns. But by that point, the display is OFF, so the |
| 6138 | // call just updates the pending state, without actually disabling |
| 6139 | // VSYNC. |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6140 | requestHardwareVsync(displayId, false); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6141 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6142 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6143 | mVisibleRegionsDirty = true; |
| 6144 | // from this point on, SF will stop drawing on this display |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6145 | } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6146 | // Update display while dozing |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6147 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6148 | if (currentMode == hal::PowerMode::DOZE_SUSPEND && |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6149 | (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present())) { |
| 6150 | if (displayId == mActiveDisplayId) { |
| 6151 | ALOGI("Force repainting for DOZE_SUSPEND -> DOZE or ON."); |
| 6152 | mVisibleRegionsDirty = true; |
| 6153 | scheduleRepaint(); |
| 6154 | mScheduler->enableSyntheticVsync(false); |
| 6155 | } |
| 6156 | constexpr bool kAllowToEnable = true; |
| 6157 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, activeMode.get()); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6158 | } |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6159 | } else if (mode == hal::PowerMode::DOZE_SUSPEND) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6160 | // Leave display going to doze |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6161 | if (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present()) { |
| 6162 | constexpr bool kDisallow = true; |
| 6163 | mScheduler->disableHardwareVsync(displayId, kDisallow); |
| 6164 | } |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6165 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6166 | mScheduler->enableSyntheticVsync(); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6167 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6168 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6169 | } else { |
Matthew Bouyack | 38d4961 | 2017-05-12 12:49:32 -0700 | [diff] [blame] | 6170 | ALOGE("Attempting to set unknown power mode: %d\n", mode); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6171 | getHwComposer().setPowerMode(displayId, mode); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6172 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6173 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6174 | if (displayId == mActiveDisplayId) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 6175 | mTimeStats->setPowerMode(mode); |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 6176 | mScheduler->setActiveDisplayPowerModeForRefreshRateStats(mode); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 6177 | } |
| 6178 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6179 | mScheduler->setDisplayPowerMode(displayId, mode); |
| 6180 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6181 | 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] | 6182 | } |
| 6183 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6184 | void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) { |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 6185 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 6186 | kMainThreadContext) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 6187 | const auto display = getDisplayDeviceLocked(displayToken); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6188 | if (!display) { |
| 6189 | ALOGE("Attempt to set power mode %d for invalid display token %p", mode, |
| 6190 | displayToken.get()); |
| 6191 | } else if (display->isVirtual()) { |
| 6192 | ALOGW("Attempt to set power mode %d for virtual display", mode); |
| 6193 | } else { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6194 | setPowerModeInternal(display, static_cast<hal::PowerMode>(mode)); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6195 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6196 | }); |
| 6197 | |
| 6198 | future.wait(); |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 6199 | } |
| 6200 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 6201 | status_t SurfaceFlinger::doDump(int fd, const DumpArgs& args, bool asProto) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6202 | std::string result; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 6203 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 6204 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6205 | const int pid = ipc->getCallingPid(); |
| 6206 | const int uid = ipc->getCallingUid(); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 6207 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 6208 | if ((uid != AID_SHELL) && |
| 6209 | !PermissionCache::checkPermission(sDump, pid, uid)) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6210 | StringAppendF(&result, "Permission Denial: can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 6211 | pid, uid); |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6212 | write(fd, result.c_str(), result.size()); |
| 6213 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6214 | } |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 6215 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6216 | if (asProto && args.empty()) { |
| 6217 | perfetto::protos::LayersTraceFileProto traceFileProto = |
| 6218 | mLayerTracing.createTraceFileProto(); |
| 6219 | perfetto::protos::LayersSnapshotProto* layersTrace = traceFileProto.add_entry(); |
| 6220 | perfetto::protos::LayersProto layersProto = dumpProtoFromMainThread(); |
| 6221 | layersTrace->mutable_layers()->Swap(&layersProto); |
| 6222 | auto displayProtos = dumpDisplayProto(); |
| 6223 | layersTrace->mutable_displays()->Swap(&displayProtos); |
| 6224 | result.append(traceFileProto.SerializeAsString()); |
| 6225 | write(fd, result.c_str(), result.size()); |
| 6226 | return NO_ERROR; |
| 6227 | } |
| 6228 | |
| 6229 | static const std::unordered_map<std::string, Dumper> dumpers = { |
| 6230 | {"--comp-displays"s, dumper(&SurfaceFlinger::dumpCompositionDisplays)}, |
| 6231 | {"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)}, |
| 6232 | {"--displays"s, dumper(&SurfaceFlinger::dumpDisplays)}, |
| 6233 | {"--edid"s, argsDumper(&SurfaceFlinger::dumpRawDisplayIdentificationData)}, |
| 6234 | {"--events"s, dumper(&SurfaceFlinger::dumpEvents)}, |
| 6235 | {"--frametimeline"s, argsDumper(&SurfaceFlinger::dumpFrameTimeline)}, |
| 6236 | {"--frontend"s, mainThreadDumper(&SurfaceFlinger::dumpFrontEnd)}, |
| 6237 | {"--hdrinfo"s, dumper(&SurfaceFlinger::dumpHdrInfo)}, |
| 6238 | {"--hwclayers"s, mainThreadDumper(&SurfaceFlinger::dumpHwcLayersMinidump)}, |
| 6239 | {"--latency"s, argsDumper(&SurfaceFlinger::dumpStatsLocked)}, |
| 6240 | {"--latency-clear"s, argsDumper(&SurfaceFlinger::clearStatsLocked)}, |
| 6241 | {"--list"s, dumper(&SurfaceFlinger::listLayersLocked)}, |
| 6242 | {"--planner"s, argsDumper(&SurfaceFlinger::dumpPlannerInfo)}, |
| 6243 | {"--scheduler"s, dumper(&SurfaceFlinger::dumpScheduler)}, |
| 6244 | {"--timestats"s, protoDumper(&SurfaceFlinger::dumpTimeStats)}, |
| 6245 | {"--vsync"s, dumper(&SurfaceFlinger::dumpVsync)}, |
| 6246 | {"--wide-color"s, dumper(&SurfaceFlinger::dumpWideColorInfo)}, |
| 6247 | }; |
| 6248 | |
| 6249 | const auto flag = args.empty() ? ""s : std::string(String8(args[0])); |
| 6250 | if (const auto it = dumpers.find(flag); it != dumpers.end()) { |
| 6251 | (it->second)(args, asProto, result); |
| 6252 | write(fd, result.c_str(), result.size()); |
| 6253 | return NO_ERROR; |
| 6254 | } |
| 6255 | |
| 6256 | // Traversal of drawing state must happen on the main thread. |
| 6257 | // Otherwise, SortedVector may have shared ownership during concurrent |
| 6258 | // traversals, which can result in use-after-frees. |
| 6259 | std::string compositionLayers; |
| 6260 | mScheduler |
| 6261 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 6262 | dumpVisibleFrontEnd(compositionLayers); |
| 6263 | }) |
| 6264 | .get(); |
| 6265 | dumpAll(args, compositionLayers, result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6266 | write(fd, result.c_str(), result.size()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6267 | return NO_ERROR; |
| 6268 | } |
| 6269 | |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 6270 | status_t SurfaceFlinger::dumpCritical(int fd, const DumpArgs&, bool asProto) { |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 6271 | return doDump(fd, DumpArgs(), asProto); |
| 6272 | } |
| 6273 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6274 | void SurfaceFlinger::listLayersLocked(std::string& result) const { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6275 | mCurrentState.traverseInZOrder( |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 6276 | [&](Layer* layer) { StringAppendF(&result, "%s\n", layer->getDebugName()); }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6277 | } |
| 6278 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6279 | void SurfaceFlinger::dumpStatsLocked(const DumpArgs& args, std::string& result) const { |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 6280 | StringAppendF(&result, "%" PRId64 "\n", getVsyncPeriodFromHWC()); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6281 | if (args.size() < 2) return; |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 6282 | |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6283 | const auto name = String8(args[1]); |
| 6284 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 6285 | if (layer->getName() == name.c_str()) { |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6286 | layer->dumpFrameStats(result); |
| 6287 | } |
| 6288 | }); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6289 | } |
| 6290 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6291 | void SurfaceFlinger::clearStatsLocked(const DumpArgs& args, std::string&) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 6292 | const bool clearAll = args.size() < 2; |
| 6293 | const auto name = clearAll ? String8() : String8(args[1]); |
| 6294 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 6295 | mCurrentState.traverse([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 6296 | if (clearAll || layer->getName() == name.c_str()) { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 6297 | layer->clearFrameStats(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6298 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 6299 | }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6300 | } |
| 6301 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6302 | void SurfaceFlinger::dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const { |
| 6303 | mTimeStats->parseArgs(asProto, args, result); |
| 6304 | } |
| 6305 | |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 6306 | void SurfaceFlinger::dumpFrameTimeline(const DumpArgs& args, std::string& result) const { |
| 6307 | mFrameTimeline->parseArgs(args, result); |
| 6308 | } |
| 6309 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6310 | void SurfaceFlinger::logFrameStats(TimePoint now) { |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6311 | static TimePoint sTimestamp = now; |
| 6312 | if (now - sTimestamp < 30min) return; |
| 6313 | sTimestamp = now; |
| 6314 | |
| 6315 | ATRACE_CALL(); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6316 | mDrawingState.traverse([&](Layer* layer) { layer->logFrameStats(); }); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 6317 | } |
| 6318 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6319 | void SurfaceFlinger::appendSfConfigString(std::string& result) const { |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 6320 | result.append(" [sf"); |
Fabien Sanglard | c93afd5 | 2017-03-13 13:02:42 -0700 | [diff] [blame] | 6321 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6322 | StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); |
| 6323 | StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 6324 | StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%zu", |
| 6325 | getHwComposer().getMaxVirtualDisplayDimension()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6326 | StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6327 | StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6328 | maxFrameBufferAcquiredBuffers); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 6329 | result.append("]"); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6330 | } |
| 6331 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6332 | void SurfaceFlinger::dumpScheduler(std::string& result) const { |
| 6333 | utils::Dumper dumper{result}; |
| 6334 | |
| 6335 | mScheduler->dump(dumper); |
| 6336 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6337 | // TODO(b/241285876): Move to DisplayModeController. |
| 6338 | dumper.dump("debugDisplayModeSetByBackdoor"sv, mDebugDisplayModeSetByBackdoor); |
| 6339 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6340 | |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6341 | StringAppendF(&result, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6342 | " present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64 |
| 6343 | " ns\n\n", |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6344 | dispSyncPresentTimeOffset, getVsyncPeriodFromHWC()); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6345 | } |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6346 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6347 | void SurfaceFlinger::dumpEvents(std::string& result) const { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 6348 | mScheduler->dump(scheduler::Cycle::Render, result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6349 | } |
| 6350 | |
| 6351 | void SurfaceFlinger::dumpVsync(std::string& result) const { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 6352 | mScheduler->dumpVsync(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6353 | } |
| 6354 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 6355 | void SurfaceFlinger::dumpPlannerInfo(const DumpArgs& args, std::string& result) const { |
| 6356 | for (const auto& [token, display] : mDisplays) { |
| 6357 | const auto compositionDisplay = display->getCompositionDisplay(); |
| 6358 | compositionDisplay->dumpPlannerInfo(args, result); |
| 6359 | } |
| 6360 | } |
| 6361 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6362 | void SurfaceFlinger::dumpCompositionDisplays(std::string& result) const { |
| 6363 | for (const auto& [token, display] : mDisplays) { |
| 6364 | display->getCompositionDisplay()->dump(result); |
| 6365 | result += '\n'; |
| 6366 | } |
| 6367 | } |
| 6368 | |
| 6369 | void SurfaceFlinger::dumpDisplays(std::string& result) const { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6370 | utils::Dumper dumper{result}; |
| 6371 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6372 | for (const auto& [id, display] : mPhysicalDisplays) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6373 | utils::Dumper::Section section(dumper, ftl::Concat("Display ", id.value).str()); |
| 6374 | |
| 6375 | display.snapshot().dump(dumper); |
| 6376 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6377 | if (const auto device = getDisplayDeviceLocked(id)) { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6378 | device->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6379 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6380 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6381 | |
| 6382 | for (const auto& [token, display] : mDisplays) { |
| 6383 | if (display->isVirtual()) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6384 | const auto displayId = display->getId(); |
| 6385 | utils::Dumper::Section section(dumper, |
| 6386 | ftl::Concat("Virtual Display ", displayId.value).str()); |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6387 | display->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6388 | } |
| 6389 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6390 | } |
| 6391 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6392 | void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 6393 | for (const auto& [token, display] : mDisplays) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6394 | const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6395 | if (!displayId) { |
| 6396 | continue; |
| 6397 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6398 | const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId); |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6399 | if (!hwcDisplayId) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6400 | continue; |
| 6401 | } |
| 6402 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6403 | StringAppendF(&result, |
| 6404 | "Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), |
| 6405 | *hwcDisplayId); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6406 | uint8_t port; |
| 6407 | DisplayIdentificationData data; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6408 | if (!getHwComposer().getDisplayIdentificationData(*hwcDisplayId, &port, &data)) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6409 | result.append("no identification data\n"); |
| 6410 | continue; |
| 6411 | } |
| 6412 | |
| 6413 | if (!isEdid(data)) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6414 | result.append("unknown identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6415 | continue; |
| 6416 | } |
| 6417 | |
| 6418 | const auto edid = parseEdid(data); |
| 6419 | if (!edid) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6420 | result.append("invalid EDID\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6421 | continue; |
| 6422 | } |
| 6423 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6424 | StringAppendF(&result, "port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6425 | result.append(edid->displayName.data(), edid->displayName.length()); |
| 6426 | result.append("\"\n"); |
| 6427 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6428 | } |
| 6429 | |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6430 | void SurfaceFlinger::dumpRawDisplayIdentificationData(const DumpArgs& args, |
| 6431 | std::string& result) const { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 6432 | hal::HWDisplayId hwcDisplayId; |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6433 | uint8_t port; |
| 6434 | DisplayIdentificationData data; |
| 6435 | |
| 6436 | if (args.size() > 1 && base::ParseUint(String8(args[1]), &hwcDisplayId) && |
| 6437 | getHwComposer().getDisplayIdentificationData(hwcDisplayId, &port, &data)) { |
| 6438 | result.append(reinterpret_cast<const char*>(data.data()), data.size()); |
| 6439 | } |
| 6440 | } |
| 6441 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6442 | void SurfaceFlinger::dumpWideColorInfo(std::string& result) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6443 | StringAppendF(&result, "Device supports wide color: %d\n", mSupportsWideColor); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6444 | StringAppendF(&result, "DisplayColorSetting: %s\n", |
| 6445 | decodeDisplayColorSetting(mDisplayColorSetting).c_str()); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6446 | |
| 6447 | // TODO: print out if wide-color mode is active or not |
| 6448 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6449 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6450 | StringAppendF(&result, "Display %s color modes:\n", to_string(id).c_str()); |
| 6451 | for (const auto mode : display.snapshot().colorModes()) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6452 | StringAppendF(&result, " %s (%d)\n", decodeColorMode(mode).c_str(), mode); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6453 | } |
| 6454 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6455 | if (const auto display = getDisplayDeviceLocked(id)) { |
| 6456 | ui::ColorMode currentMode = display->getCompositionDisplay()->getState().colorMode; |
| 6457 | StringAppendF(&result, " Current color mode: %s (%d)\n", |
| 6458 | decodeColorMode(currentMode).c_str(), currentMode); |
| 6459 | } |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6460 | } |
| 6461 | result.append("\n"); |
| 6462 | } |
| 6463 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6464 | void SurfaceFlinger::dumpHdrInfo(std::string& result) const { |
| 6465 | for (const auto& [displayId, listener] : mHdrLayerInfoListeners) { |
| 6466 | StringAppendF(&result, "HDR events for display %" PRIu64 "\n", displayId.value); |
| 6467 | listener->dump(result); |
| 6468 | result.append("\n"); |
| 6469 | } |
| 6470 | } |
| 6471 | |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6472 | void SurfaceFlinger::dumpFrontEnd(std::string& result) { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6473 | std::ostringstream out; |
| 6474 | out << "\nComposition list\n"; |
| 6475 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6476 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 6477 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 6478 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 6479 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6480 | } |
| 6481 | out << " " << *snapshot << "\n"; |
| 6482 | } |
| 6483 | |
| 6484 | out << "\nInput list\n"; |
| 6485 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6486 | mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6487 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 6488 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 6489 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6490 | } |
| 6491 | out << " " << snapshot << "\n"; |
| 6492 | }); |
| 6493 | |
| 6494 | out << "\nLayer Hierarchy\n" |
| 6495 | << mLayerHierarchyBuilder.getHierarchy().dump() << "\nOffscreen Hierarchy\n" |
| 6496 | << mLayerHierarchyBuilder.getOffscreenHierarchy().dump() << "\n\n"; |
| 6497 | result.append(out.str()); |
| 6498 | } |
| 6499 | |
| 6500 | void SurfaceFlinger::dumpVisibleFrontEnd(std::string& result) { |
| 6501 | if (!mLayerLifecycleManagerEnabled) { |
| 6502 | StringAppendF(&result, "Composition layers\n"); |
| 6503 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 6504 | auto* compositionState = layer->getCompositionState(); |
| 6505 | if (!compositionState || !compositionState->isVisible) return; |
| 6506 | android::base::StringAppendF(&result, "* Layer %p (%s)\n", layer, |
| 6507 | layer->getDebugName() ? layer->getDebugName() |
| 6508 | : "<unknown>"); |
| 6509 | compositionState->dump(result); |
| 6510 | }); |
| 6511 | |
| 6512 | StringAppendF(&result, "Offscreen Layers\n"); |
| 6513 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6514 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
| 6515 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
| 6516 | } |
| 6517 | } else { |
| 6518 | std::ostringstream out; |
| 6519 | out << "\nComposition list\n"; |
| 6520 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6521 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 6522 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 6523 | if (snapshot->hasSomethingToDraw()) { |
| 6524 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 6525 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 6526 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6527 | } |
| 6528 | out << " " << *snapshot << "\n"; |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6529 | } |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6530 | }); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6531 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6532 | out << "\nInput list\n"; |
| 6533 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6534 | mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6535 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 6536 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 6537 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6538 | } |
| 6539 | out << " " << snapshot << "\n"; |
| 6540 | }); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6541 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6542 | out << "\nLayer Hierarchy\n" |
| 6543 | << mLayerHierarchyBuilder.getHierarchy() << "\nOffscreen Hierarchy\n" |
| 6544 | << mLayerHierarchyBuilder.getOffscreenHierarchy() << "\n\n"; |
| 6545 | result = out.str(); |
| 6546 | dumpHwcLayersMinidump(result); |
| 6547 | } |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6548 | } |
| 6549 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6550 | perfetto::protos::LayersProto SurfaceFlinger::dumpDrawingStateProto(uint32_t traceFlags) const { |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 6551 | std::unordered_set<uint64_t> stackIdsToSkip; |
| 6552 | |
| 6553 | // Determine if virtual layers display should be skipped |
| 6554 | if ((traceFlags & LayerTracing::TRACE_VIRTUAL_DISPLAYS) == 0) { |
| 6555 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 6556 | if (display->isVirtual()) { |
| 6557 | stackIdsToSkip.insert(display->getLayerStack().id); |
| 6558 | } |
| 6559 | } |
| 6560 | } |
| 6561 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6562 | if (mLegacyFrontEndEnabled) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6563 | perfetto::protos::LayersProto layersProto; |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 6564 | for (const sp<Layer>& layer : mDrawingState.layersSortedByZ) { |
| 6565 | if (stackIdsToSkip.find(layer->getLayerStack().id) != stackIdsToSkip.end()) { |
| 6566 | continue; |
| 6567 | } |
| 6568 | layer->writeToProto(layersProto, traceFlags); |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 6569 | } |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 6570 | return layersProto; |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 6571 | } |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 6572 | |
Vishnu Nair | 22be349 | 2023-04-20 10:08:21 -0700 | [diff] [blame] | 6573 | return LayerProtoFromSnapshotGenerator(mLayerSnapshotBuilder, mFrontEndDisplayInfos, |
| 6574 | mLegacyLayers, traceFlags) |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 6575 | .generate(mLayerHierarchyBuilder.getHierarchy()); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6576 | } |
| 6577 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6578 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> |
| 6579 | SurfaceFlinger::dumpDisplayProto() const { |
| 6580 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> displays; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6581 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6582 | perfetto::protos::DisplayProto* displayProto = displays.Add(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6583 | displayProto->set_id(display->getId().value); |
| 6584 | displayProto->set_name(display->getDisplayName()); |
| 6585 | displayProto->set_layer_stack(display->getLayerStack().id); |
DoÄŸancan Emek | fc4b6ed | 2023-07-26 15:24:04 +0000 | [diff] [blame] | 6586 | |
| 6587 | if (!display->isVirtual()) { |
| 6588 | const auto dpi = display->refreshRateSelector().getActiveMode().modePtr->getDpi(); |
| 6589 | displayProto->set_dpi_x(dpi.x); |
| 6590 | displayProto->set_dpi_y(dpi.y); |
| 6591 | } |
| 6592 | |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6593 | LayerProtoHelper::writeSizeToProto(display->getWidth(), display->getHeight(), |
| 6594 | [&]() { return displayProto->mutable_size(); }); |
| 6595 | LayerProtoHelper::writeToProto(display->getLayerStackSpaceRect(), [&]() { |
| 6596 | return displayProto->mutable_layer_stack_space_rect(); |
| 6597 | }); |
| 6598 | LayerProtoHelper::writeTransformToProto(display->getTransform(), |
| 6599 | displayProto->mutable_transform()); |
Vishnu Nair | 791d48a | 2021-12-02 16:55:13 -0800 | [diff] [blame] | 6600 | displayProto->set_is_virtual(display->isVirtual()); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6601 | } |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 6602 | return displays; |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6603 | } |
| 6604 | |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 6605 | void SurfaceFlinger::dumpHwc(std::string& result) const { |
| 6606 | getHwComposer().dump(result); |
| 6607 | } |
| 6608 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6609 | void SurfaceFlinger::dumpOffscreenLayersProto(perfetto::protos::LayersProto& layersProto, |
| 6610 | uint32_t traceFlags) const { |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6611 | // Add a fake invisible root layer to the proto output and parent all the offscreen layers to |
| 6612 | // it. |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6613 | perfetto::protos::LayerProto* rootProto = layersProto.add_layers(); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6614 | const int32_t offscreenRootLayerId = INT32_MAX - 2; |
| 6615 | rootProto->set_id(offscreenRootLayerId); |
| 6616 | rootProto->set_name("Offscreen Root"); |
Vishnu Nair | d5aeb61 | 2019-09-20 14:39:39 -0700 | [diff] [blame] | 6617 | rootProto->set_parent(-1); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6618 | |
| 6619 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6620 | // Add layer as child of the fake root |
| 6621 | rootProto->add_children(offscreenLayer->sequence); |
| 6622 | |
| 6623 | // Add layer |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6624 | auto* layerProto = offscreenLayer->writeToProto(layersProto, traceFlags); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6625 | layerProto->set_parent(offscreenRootLayerId); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6626 | } |
| 6627 | } |
| 6628 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6629 | perfetto::protos::LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) { |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 6630 | return mScheduler->schedule([=, this] { return dumpDrawingStateProto(traceFlags); }).get(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 6631 | } |
| 6632 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6633 | void SurfaceFlinger::dumpOffscreenLayers(std::string& result) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6634 | auto future = mScheduler->schedule([this] { |
| 6635 | std::string result; |
| 6636 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6637 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
Vishnu Nair | 76554eb | 2022-12-09 03:38:36 +0000 | [diff] [blame] | 6638 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6639 | } |
| 6640 | return result; |
| 6641 | }); |
| 6642 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6643 | result.append("Offscreen Layers:\n"); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6644 | result.append(future.get()); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6645 | } |
| 6646 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6647 | void SurfaceFlinger::dumpHwcLayersMinidumpLockedLegacy(std::string& result) const { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6648 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6649 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6650 | if (!displayId) { |
| 6651 | continue; |
| 6652 | } |
| 6653 | |
| 6654 | 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] | 6655 | displayId == mActiveDisplayId ? "active" : "inactive"); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6656 | Layer::miniDumpHeader(result); |
| 6657 | |
| 6658 | const DisplayDevice& ref = *display; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6659 | mDrawingState.traverseInZOrder([&](Layer* layer) { layer->miniDumpLegacy(result, ref); }); |
| 6660 | result.append("\n"); |
| 6661 | } |
| 6662 | } |
| 6663 | |
| 6664 | void SurfaceFlinger::dumpHwcLayersMinidump(std::string& result) const { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6665 | if (!mLayerLifecycleManagerEnabled) { |
| 6666 | return dumpHwcLayersMinidumpLockedLegacy(result); |
| 6667 | } |
| 6668 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6669 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6670 | if (!displayId) { |
| 6671 | continue; |
| 6672 | } |
| 6673 | |
| 6674 | StringAppendF(&result, "Display %s (%s) HWC layers:\n", to_string(*displayId).c_str(), |
| 6675 | displayId == mActiveDisplayId ? "active" : "inactive"); |
| 6676 | Layer::miniDumpHeader(result); |
| 6677 | |
| 6678 | const DisplayDevice& ref = *display; |
| 6679 | mLayerSnapshotBuilder.forEachVisibleSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6680 | if (!snapshot.hasSomethingToDraw() || |
| 6681 | ref.getLayerStack() != snapshot.outputFilter.layerStack) { |
| 6682 | return; |
| 6683 | } |
| 6684 | auto it = mLegacyLayers.find(snapshot.sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 6685 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 6686 | "Couldnt find layer object for %s", |
| 6687 | snapshot.getDebugString().c_str()); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6688 | it->second->miniDump(result, snapshot, ref); |
| 6689 | }); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6690 | result.append("\n"); |
| 6691 | } |
| 6692 | } |
| 6693 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6694 | void SurfaceFlinger::dumpAll(const DumpArgs& args, const std::string& compositionLayers, |
| 6695 | std::string& result) const { |
| 6696 | TimedLock lock(mStateLock, s2ns(1), __func__); |
| 6697 | if (!lock.locked()) { |
| 6698 | StringAppendF(&result, "Dumping without lock after timeout: %s (%d)\n", |
| 6699 | strerror(-lock.status), lock.status); |
| 6700 | } |
| 6701 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6702 | const bool colorize = !args.empty() && args[0] == String16("--color"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6703 | Colorizer colorizer(colorize); |
| 6704 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6705 | // figure out if we're stuck somewhere |
| 6706 | const nsecs_t now = systemTime(); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6707 | const nsecs_t inTransaction(mDebugInTransaction); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6708 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 6709 | |
| 6710 | /* |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6711 | * Dump library configuration. |
| 6712 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6713 | |
| 6714 | colorizer.bold(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6715 | result.append("Build configuration:"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6716 | colorizer.reset(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6717 | appendSfConfigString(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6718 | result.append("\n"); |
| 6719 | |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6720 | result.append("\nDisplay identification data:\n"); |
| 6721 | dumpDisplayIdentificationData(result); |
| 6722 | |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6723 | result.append("\nWide-Color information:\n"); |
| 6724 | dumpWideColorInfo(result); |
| 6725 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6726 | dumpHdrInfo(result); |
| 6727 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6728 | colorizer.bold(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6729 | result.append("Sync configuration: "); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6730 | colorizer.reset(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6731 | result.append(SyncFeatures::getInstance().toString()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6732 | result.append("\n\n"); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6733 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6734 | colorizer.bold(result); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6735 | result.append("Scheduler:\n"); |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6736 | colorizer.reset(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6737 | dumpScheduler(result); |
| 6738 | dumpEvents(result); |
| 6739 | dumpVsync(result); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 6740 | result.append("\n"); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6741 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6742 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6743 | * Dump the visible layer list |
| 6744 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6745 | colorizer.bold(result); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6746 | StringAppendF(&result, "SurfaceFlinger New Frontend Enabled:%s\n", |
| 6747 | mLayerLifecycleManagerEnabled ? "true" : "false"); |
| 6748 | StringAppendF(&result, "Active Layers - layers with client handles (count = %zu)\n", |
| 6749 | mNumLayers.load()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6750 | colorizer.reset(result); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6751 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 6752 | result.append(compositionLayers); |
Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 6753 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6754 | colorizer.bold(result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6755 | StringAppendF(&result, "Displays (%zu entries)\n", mDisplays.size()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6756 | colorizer.reset(result); |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6757 | dumpDisplays(result); |
| 6758 | dumpCompositionDisplays(result); |
| 6759 | result.push_back('\n'); |
Lloyd Pique | c3cb729 | 2019-05-17 15:25:14 -0700 | [diff] [blame] | 6760 | |
| 6761 | mCompositionEngine->dump(result); |
| 6762 | |
| 6763 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6764 | * Dump SurfaceFlinger global state |
| 6765 | */ |
| 6766 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6767 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6768 | result.append("SurfaceFlinger global state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6769 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6770 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 6771 | getRenderEngine().dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6772 | |
Robert Carr | beba6f0 | 2021-02-10 21:06:27 -0800 | [diff] [blame] | 6773 | result.append("ClientCache state:\n"); |
| 6774 | ClientCache::getInstance().dump(result); |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 6775 | DebugEGLImageTracker::getInstance()->dump(result); |
| 6776 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6777 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 6778 | display->getCompositionDisplay()->getState().undefinedRegion.dump(result, |
| 6779 | "undefinedRegion"); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 6780 | StringAppendF(&result, " orientation=%s, isPoweredOn=%d\n", |
| 6781 | toCString(display->getOrientation()), display->isPoweredOn()); |
Lloyd Pique | 2ae2b3b | 2017-12-14 17:18:17 -0800 | [diff] [blame] | 6782 | } |
Carlos Martinez Romero | 779dc1f | 2022-10-27 23:23:30 +0000 | [diff] [blame] | 6783 | StringAppendF(&result, " transaction-flags : %08x\n", mTransactionFlags.load()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6784 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 6785 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6786 | std::string fps, xDpi, yDpi; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 6787 | if (const auto activeModePtr = |
| 6788 | display->refreshRateSelector().getActiveMode().modePtr.get()) { |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 6789 | fps = to_string(activeModePtr->getVsyncRate()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6790 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6791 | const auto dpi = activeModePtr->getDpi(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6792 | xDpi = base::StringPrintf("%.2f", dpi.x); |
| 6793 | yDpi = base::StringPrintf("%.2f", dpi.y); |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6794 | } else { |
| 6795 | fps = "unknown"; |
| 6796 | xDpi = "unknown"; |
| 6797 | yDpi = "unknown"; |
| 6798 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6799 | StringAppendF(&result, |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6800 | " refresh-rate : %s\n" |
| 6801 | " x-dpi : %s\n" |
| 6802 | " y-dpi : %s\n", |
| 6803 | fps.c_str(), xDpi.c_str(), yDpi.c_str()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6804 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6805 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6806 | StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6807 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6808 | result.append("\nTransaction tracing: "); |
| 6809 | if (mTransactionTracing) { |
| 6810 | result.append("enabled\n"); |
| 6811 | mTransactionTracing->dump(result); |
| 6812 | } else { |
| 6813 | result.append("disabled\n"); |
| 6814 | } |
| 6815 | result.push_back('\n'); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6816 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6817 | if (mLegacyFrontEndEnabled) { |
| 6818 | dumpHwcLayersMinidumpLockedLegacy(result); |
| 6819 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6820 | |
Ady Abraham | 2790e9f | 2021-04-28 13:14:20 -0700 | [diff] [blame] | 6821 | { |
| 6822 | DumpArgs plannerArgs; |
| 6823 | plannerArgs.add(); // first argument is ignored |
| 6824 | plannerArgs.add(String16("--layers")); |
| 6825 | dumpPlannerInfo(plannerArgs, result); |
| 6826 | } |
| 6827 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6828 | /* |
| 6829 | * Dump HWComposer state |
| 6830 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6831 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6832 | result.append("h/w composer state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6833 | colorizer.reset(result); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6834 | const bool hwcDisabled = mDebugDisableHWC || mDebugFlashDelay; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6835 | StringAppendF(&result, " h/w composer %s\n", hwcDisabled ? "disabled" : "enabled"); |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 6836 | dumpHwc(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6837 | |
| 6838 | /* |
| 6839 | * Dump gralloc state |
| 6840 | */ |
| 6841 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 6842 | alloc.dump(result); |
Karthik Ravi Shankar | 171155a | 2017-06-28 15:40:24 -0700 | [diff] [blame] | 6843 | |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6844 | /* |
| 6845 | * Dump flag/property manager state |
| 6846 | */ |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 6847 | FlagManager::getInstance().dump(result); |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6848 | |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 6849 | result.append(mTimeStats->miniDump()); |
| 6850 | result.append("\n"); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 6851 | |
| 6852 | result.append("Window Infos:\n"); |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 6853 | auto windowInfosDebug = mWindowInfosListenerInvoker->getDebugInfo(); |
| 6854 | StringAppendF(&result, " max send vsync id: %" PRId64 "\n", |
| 6855 | ftl::to_underlying(windowInfosDebug.maxSendDelayVsyncId)); |
| 6856 | StringAppendF(&result, " max send delay (ns): %" PRId64 " ns\n", |
| 6857 | windowInfosDebug.maxSendDelayDuration); |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 6858 | StringAppendF(&result, " unsent messages: %zu\n", windowInfosDebug.pendingMessageCount); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 6859 | result.append("\n"); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6860 | } |
| 6861 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6862 | mat4 SurfaceFlinger::calculateColorMatrix(float saturation) { |
| 6863 | if (saturation == 1) { |
| 6864 | return mat4(); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6865 | } |
| 6866 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6867 | float3 luminance{0.213f, 0.715f, 0.072f}; |
| 6868 | luminance *= 1.0f - saturation; |
| 6869 | mat4 saturationMatrix = mat4(vec4{luminance.r + saturation, luminance.r, luminance.r, 0.0f}, |
| 6870 | vec4{luminance.g, luminance.g + saturation, luminance.g, 0.0f}, |
| 6871 | vec4{luminance.b, luminance.b, luminance.b + saturation, 0.0f}, |
| 6872 | vec4{0.0f, 0.0f, 0.0f, 1.0f}); |
| 6873 | return saturationMatrix; |
| 6874 | } |
| 6875 | |
| 6876 | void SurfaceFlinger::updateColorMatrixLocked() { |
| 6877 | mat4 colorMatrix = |
| 6878 | mClientColorMatrix * calculateColorMatrix(mGlobalSaturationFactor) * mDaltonizer(); |
| 6879 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6880 | if (mCurrentState.colorMatrix != colorMatrix) { |
| 6881 | mCurrentState.colorMatrix = colorMatrix; |
| 6882 | mCurrentState.colorMatrixChanged = true; |
| 6883 | setTransactionFlags(eTransactionNeeded); |
| 6884 | } |
| 6885 | } |
| 6886 | |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6887 | status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6888 | #pragma clang diagnostic push |
| 6889 | #pragma clang diagnostic error "-Wswitch-enum" |
| 6890 | switch (static_cast<ISurfaceComposerTag>(code)) { |
| 6891 | // These methods should at minimum make sure that the client requested |
| 6892 | // access to SF. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6893 | case GET_HDR_CAPABILITIES: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6894 | case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6895 | case GET_GAME_CONTENT_TYPE_SUPPORT: |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6896 | case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6897 | // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary |
| 6898 | // permission dynamically. Don't use the permission cache for this check. |
| 6899 | bool usePermissionCache = code != OVERRIDE_HDR_TYPES; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6900 | if (!callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 6901 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6902 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", |
| 6903 | ipc->getCallingPid(), ipc->getCallingUid()); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6904 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6905 | } |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 6906 | return OK; |
| 6907 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6908 | // The following calls are currently used by clients that do not |
| 6909 | // request necessary permissions. However, they do not expose any secret |
| 6910 | // information, so it is OK to pass them. |
Peiyong Lin | d1fedb4 | 2019-03-11 17:48:41 -0700 | [diff] [blame] | 6911 | case GET_ACTIVE_COLOR_MODE: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6912 | case GET_ACTIVE_DISPLAY_MODE: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6913 | case GET_DISPLAY_COLOR_MODES: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6914 | case GET_DISPLAY_MODES: |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 6915 | case GET_SCHEDULING_POLICY: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6916 | // Calling setTransactionState is safe, because you need to have been |
| 6917 | // granted a reference to Client* and Handle* to do anything with it. |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6918 | case SET_TRANSACTION_STATE: { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 6919 | // This is not sensitive information, so should not require permission control. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6920 | return OK; |
| 6921 | } |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 6922 | case BOOT_FINISHED: |
| 6923 | // Used by apps to hook Choreographer to SurfaceFlinger. |
| 6924 | case CREATE_DISPLAY_EVENT_CONNECTION: |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6925 | case CREATE_CONNECTION: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6926 | case CREATE_DISPLAY: |
| 6927 | case DESTROY_DISPLAY: |
| 6928 | case GET_PRIMARY_PHYSICAL_DISPLAY_ID: |
| 6929 | case GET_PHYSICAL_DISPLAY_IDS: |
| 6930 | case GET_PHYSICAL_DISPLAY_TOKEN: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6931 | case AUTHENTICATE_SURFACE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6932 | case SET_POWER_MODE: |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 6933 | case GET_SUPPORTED_FRAME_TIMESTAMPS: |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6934 | case GET_DISPLAY_STATE: |
| 6935 | case GET_DISPLAY_STATS: |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 6936 | case GET_STATIC_DISPLAY_INFO: |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 6937 | case GET_DYNAMIC_DISPLAY_INFO: |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 6938 | case GET_DISPLAY_NATIVE_PRIMARIES: |
| 6939 | case SET_ACTIVE_COLOR_MODE: |
| 6940 | case SET_BOOT_DISPLAY_MODE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6941 | case CLEAR_BOOT_DISPLAY_MODE: |
| 6942 | case GET_BOOT_DISPLAY_MODE_SUPPORT: |
| 6943 | case SET_AUTO_LOW_LATENCY_MODE: |
| 6944 | case SET_GAME_CONTENT_TYPE: |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6945 | case CAPTURE_LAYERS: |
| 6946 | case CAPTURE_DISPLAY: |
| 6947 | case CAPTURE_DISPLAY_BY_ID: |
Huihong Luo | 4ed1c91 | 2022-02-22 14:30:01 -0800 | [diff] [blame] | 6948 | case CLEAR_ANIMATION_FRAME_STATS: |
| 6949 | case GET_ANIMATION_FRAME_STATS: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6950 | case OVERRIDE_HDR_TYPES: |
| 6951 | case ON_PULL_ATOM: |
| 6952 | case ENABLE_VSYNC_INJECTIONS: |
| 6953 | case INJECT_VSYNC: |
| 6954 | case GET_LAYER_DEBUG_INFO: |
| 6955 | case GET_COLOR_MANAGEMENT: |
| 6956 | case GET_COMPOSITION_PREFERENCE: |
| 6957 | case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: |
| 6958 | case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6959 | case GET_DISPLAYED_CONTENT_SAMPLE: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6960 | case GET_PROTECTED_CONTENT_SUPPORT: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6961 | case IS_WIDE_COLOR_DISPLAY: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6962 | case ADD_REGION_SAMPLING_LISTENER: |
| 6963 | case REMOVE_REGION_SAMPLING_LISTENER: |
| 6964 | case ADD_FPS_LISTENER: |
| 6965 | case REMOVE_FPS_LISTENER: |
| 6966 | case ADD_TUNNEL_MODE_ENABLED_LISTENER: |
| 6967 | case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: |
| 6968 | case ADD_WINDOW_INFOS_LISTENER: |
| 6969 | case REMOVE_WINDOW_INFOS_LISTENER: |
| 6970 | case SET_DESIRED_DISPLAY_MODE_SPECS: |
| 6971 | case GET_DESIRED_DISPLAY_MODE_SPECS: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6972 | case GET_DISPLAY_BRIGHTNESS_SUPPORT: |
| 6973 | case SET_DISPLAY_BRIGHTNESS: |
| 6974 | case ADD_HDR_LAYER_INFO_LISTENER: |
| 6975 | case REMOVE_HDR_LAYER_INFO_LISTENER: |
| 6976 | case NOTIFY_POWER_BOOST: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6977 | case SET_GLOBAL_SHADOW_SETTINGS: |
| 6978 | case GET_DISPLAY_DECORATION_SUPPORT: |
| 6979 | case SET_FRAME_RATE: |
| 6980 | case SET_OVERRIDE_FRAME_RATE: |
| 6981 | case SET_FRAME_TIMELINE_INFO: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6982 | case ADD_TRANSACTION_TRACE_LISTENER: |
| 6983 | case GET_GPU_CONTEXT_PRIORITY: |
| 6984 | case GET_MAX_ACQUIRED_BUFFER_COUNT: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6985 | LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6986 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6987 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6988 | |
| 6989 | // These codes are used for the IBinder protocol to either interrogate the recipient |
| 6990 | // side of the transaction for its canonical interface descriptor or to dump its state. |
| 6991 | // We let them pass by default. |
| 6992 | if (code == IBinder::INTERFACE_TRANSACTION || code == IBinder::DUMP_TRANSACTION || |
| 6993 | code == IBinder::PING_TRANSACTION || code == IBinder::SHELL_COMMAND_TRANSACTION || |
| 6994 | code == IBinder::SYSPROPS_TRANSACTION) { |
| 6995 | return OK; |
| 6996 | } |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 6997 | // Numbers from 1000 to 1045 are currently used for backdoors. The code |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6998 | // 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] | 6999 | if (code >= 1000 && code <= 1045) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7000 | ALOGV("Accessing SurfaceFlinger through backdoor code: %u", code); |
| 7001 | return OK; |
| 7002 | } |
| 7003 | ALOGE("Permission Denial: SurfaceFlinger did not recognize request code: %u", code); |
| 7004 | return PERMISSION_DENIED; |
| 7005 | #pragma clang diagnostic pop |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 7006 | } |
| 7007 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7008 | status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 7009 | uint32_t flags) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7010 | if (const status_t error = CheckTransactCodeCredentials(code); error != OK) { |
| 7011 | return error; |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 7012 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 7013 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7014 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 7015 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 7016 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Romain Guy | 8c6bbd6 | 2017-06-05 13:51:43 -0700 | [diff] [blame] | 7017 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7018 | const int uid = ipc->getCallingUid(); |
| 7019 | if (CC_UNLIKELY(uid != AID_SYSTEM |
| 7020 | && !PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 7021 | const int pid = ipc->getCallingPid(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 7022 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 7023 | "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] | 7024 | return PERMISSION_DENIED; |
| 7025 | } |
| 7026 | int n; |
| 7027 | switch (code) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7028 | case 1000: // Unused. |
| 7029 | case 1001: |
| 7030 | return NAME_NOT_FOUND; |
| 7031 | case 1002: // Toggle flashing on surface damage. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7032 | sfdo_setDebugFlash(data.readInt32()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7033 | return NO_ERROR; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 7034 | case 1004: // Force composite ahead of next VSYNC. |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 7035 | case 1006: |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7036 | sfdo_scheduleComposite(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7037 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7038 | case 1005: { // Force commit ahead of next VSYNC. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7039 | sfdo_scheduleCommit(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 7040 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7041 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7042 | case 1007: // Unused. |
| 7043 | return NAME_NOT_FOUND; |
| 7044 | case 1008: // Toggle forced GPU composition. |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 7045 | sfdo_forceClientComposition(data.readInt32() != 0); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 7046 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7047 | case 1009: // Toggle use of transform hint. |
| 7048 | mDebugDisableTransformHint = data.readInt32() != 0; |
| 7049 | scheduleRepaint(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 7050 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7051 | case 1010: // Interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 7052 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7053 | reply->writeInt32(0); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7054 | reply->writeInt32(mDebugFlashDelay); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 7055 | reply->writeInt32(0); |
Dianne Hackborn | 12839be | 2012-02-06 21:21:05 -0800 | [diff] [blame] | 7056 | reply->writeInt32(mDebugDisableHWC); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7057 | return NO_ERROR; |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 7058 | case 1013: // Unused. |
| 7059 | return NAME_NOT_FOUND; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7060 | case 1014: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7061 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7062 | // daltonize |
| 7063 | n = data.readInt32(); |
| 7064 | switch (n % 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7065 | case 1: |
| 7066 | mDaltonizer.setType(ColorBlindnessType::Protanomaly); |
| 7067 | break; |
| 7068 | case 2: |
| 7069 | mDaltonizer.setType(ColorBlindnessType::Deuteranomaly); |
| 7070 | break; |
| 7071 | case 3: |
| 7072 | mDaltonizer.setType(ColorBlindnessType::Tritanomaly); |
| 7073 | break; |
| 7074 | default: |
| 7075 | mDaltonizer.setType(ColorBlindnessType::None); |
| 7076 | break; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7077 | } |
| 7078 | if (n >= 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7079 | mDaltonizer.setMode(ColorBlindnessMode::Correction); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7080 | } else { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7081 | mDaltonizer.setMode(ColorBlindnessMode::Simulation); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7082 | } |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7083 | |
| 7084 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7085 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7086 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7087 | case 1015: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7088 | Mutex::Autolock _l(mStateLock); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7089 | // apply a color matrix |
| 7090 | n = data.readInt32(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7091 | if (n) { |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7092 | // color matrix is sent as a column-major mat4 matrix |
Alan Viverette | 794c5ba | 2013-10-03 16:40:52 -0700 | [diff] [blame] | 7093 | for (size_t i = 0 ; i < 4; i++) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7094 | for (size_t j = 0; j < 4; j++) { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7095 | mClientColorMatrix[i][j] = data.readFloat(); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7096 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7097 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7098 | } else { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7099 | mClientColorMatrix = mat4(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7100 | } |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 7101 | |
| 7102 | // Check that supplied matrix's last row is {0,0,0,1} so we can avoid |
| 7103 | // the division by w in the fragment shader |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7104 | float4 lastRow(transpose(mClientColorMatrix)[3]); |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 7105 | if (any(greaterThan(abs(lastRow - float4{0, 0, 0, 1}), float4{1e-4f}))) { |
| 7106 | ALOGE("The color transform's last row must be (0, 0, 0, 1)"); |
| 7107 | } |
| 7108 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7109 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7110 | return NO_ERROR; |
| 7111 | } |
Dominik Laskowski | 8d32ddc | 2019-08-07 11:25:35 -0700 | [diff] [blame] | 7112 | case 1016: { // Unused. |
| 7113 | return NAME_NOT_FOUND; |
Ruchi Kandoi | f52b3c8 | 2014-04-24 16:42:35 -0700 | [diff] [blame] | 7114 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 7115 | case 1017: { |
| 7116 | n = data.readInt32(); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 7117 | mForceFullDamage = n != 0; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 7118 | return NO_ERROR; |
| 7119 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7120 | case 1018: { // Set the render deadline as a duration until VSYNC. |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7121 | n = data.readInt32(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7122 | mScheduler->setDuration(scheduler::Cycle::Render, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7123 | return NO_ERROR; |
| 7124 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7125 | 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] | 7126 | n = data.readInt32(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7127 | mScheduler->setDuration(scheduler::Cycle::LastComposite, |
| 7128 | std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7129 | return NO_ERROR; |
| 7130 | } |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 7131 | case 1020: { // Unused |
| 7132 | return NAME_NOT_FOUND; |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 7133 | } |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 7134 | case 1021: { // Disable HWC virtual displays |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 7135 | const bool enable = data.readInt32() != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7136 | static_cast<void>( |
| 7137 | mScheduler->schedule([this, enable] { enableHalVirtualDisplays(enable); })); |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 7138 | return NO_ERROR; |
| 7139 | } |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7140 | case 1022: { // Set saturation boost |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7141 | Mutex::Autolock _l(mStateLock); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7142 | mGlobalSaturationFactor = std::max(0.0f, std::min(data.readFloat(), 2.0f)); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7143 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7144 | updateColorMatrixLocked(); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7145 | return NO_ERROR; |
| 7146 | } |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7147 | case 1023: { // Set color mode. |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7148 | mDisplayColorSetting = static_cast<DisplayColorSetting>(data.readInt32()); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7149 | |
| 7150 | if (int32_t colorMode; data.readInt32(&colorMode) == NO_ERROR) { |
| 7151 | mForceColorMode = static_cast<ui::ColorMode>(colorMode); |
Daniel Solomon | 7c7ede2 | 2019-07-11 16:35:40 -0700 | [diff] [blame] | 7152 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7153 | scheduleRepaint(); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 7154 | return NO_ERROR; |
| 7155 | } |
Peiyong Lin | 4bac91c | 2018-10-25 09:48:33 -0700 | [diff] [blame] | 7156 | // Deprecate, use 1030 to check whether the device is color managed. |
| 7157 | case 1024: { |
| 7158 | return NAME_NOT_FOUND; |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 7159 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7160 | // Deprecated, use perfetto to start/stop the layer tracing |
| 7161 | case 1025: { |
| 7162 | return NAME_NOT_FOUND; |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 7163 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7164 | // Deprecated, execute "adb shell perfetto --query" to see the ongoing tracing sessions |
| 7165 | case 1026: { |
| 7166 | return NAME_NOT_FOUND; |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 7167 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7168 | // Is a DisplayColorSetting supported? |
| 7169 | case 1027: { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7170 | const auto display = getDefaultDisplayDevice(); |
| 7171 | if (!display) { |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7172 | return NAME_NOT_FOUND; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7173 | } |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7174 | |
| 7175 | DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32()); |
| 7176 | switch (setting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7177 | case DisplayColorSetting::kManaged: |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7178 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7179 | reply->writeBool(true); |
| 7180 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7181 | case DisplayColorSetting::kEnhanced: |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7182 | reply->writeBool(display->hasRenderIntent(RenderIntent::ENHANCE)); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7183 | break; |
| 7184 | default: // vendor display color setting |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7185 | reply->writeBool( |
| 7186 | display->hasRenderIntent(static_cast<RenderIntent>(setting))); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7187 | break; |
| 7188 | } |
| 7189 | return NO_ERROR; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7190 | } |
Alec Mouri | 9c58bcd | 2020-09-09 18:57:07 -0700 | [diff] [blame] | 7191 | case 1028: { // Unused. |
| 7192 | return NAME_NOT_FOUND; |
Steven Thomas | 97f1f4c | 2018-06-01 12:04:16 -0700 | [diff] [blame] | 7193 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7194 | // Deprecated, use perfetto to set the active layer tracing buffer size |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 7195 | case 1029: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7196 | return NAME_NOT_FOUND; |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 7197 | } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 7198 | // Is device color managed? |
| 7199 | case 1030: { |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 7200 | // ColorDisplayManager stil calls this |
| 7201 | reply->writeBool(true); |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 7202 | return NO_ERROR; |
| 7203 | } |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7204 | // Override default composition data space |
| 7205 | // adb shell service call SurfaceFlinger 1031 i32 1 DATASPACE_NUMBER DATASPACE_NUMBER \ |
| 7206 | // && adb shell stop zygote && adb shell start zygote |
| 7207 | // to restore: adb shell service call SurfaceFlinger 1031 i32 0 && \ |
| 7208 | // adb shell stop zygote && adb shell start zygote |
| 7209 | case 1031: { |
| 7210 | Mutex::Autolock _l(mStateLock); |
| 7211 | n = data.readInt32(); |
| 7212 | if (n) { |
| 7213 | n = data.readInt32(); |
| 7214 | if (n) { |
| 7215 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 7216 | if (!validateCompositionDataspace(dataspace)) { |
| 7217 | return BAD_VALUE; |
| 7218 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7219 | mDefaultCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7220 | } |
| 7221 | n = data.readInt32(); |
| 7222 | if (n) { |
| 7223 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 7224 | if (!validateCompositionDataspace(dataspace)) { |
| 7225 | return BAD_VALUE; |
| 7226 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7227 | mWideColorGamutCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7228 | } |
| 7229 | } else { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7230 | // restore composition data space. |
| 7231 | mDefaultCompositionDataspace = defaultCompositionDataspace; |
| 7232 | mWideColorGamutCompositionDataspace = wideColorGamutCompositionDataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7233 | } |
| 7234 | return NO_ERROR; |
| 7235 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7236 | // Deprecated, use perfetto to set layer trace flags |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 7237 | case 1033: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7238 | return NAME_NOT_FOUND; |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 7239 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 7240 | case 1034: { |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7241 | n = data.readInt32(); |
| 7242 | if (n == 0 || n == 1) { |
| 7243 | sfdo_enableRefreshRateOverlay(static_cast<bool>(n)); |
| 7244 | } else { |
| 7245 | Mutex::Autolock lock(mStateLock); |
| 7246 | reply->writeBool(isRefreshRateOverlayEnabled()); |
| 7247 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 7248 | return NO_ERROR; |
| 7249 | } |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 7250 | case 1035: { |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7251 | // Parameters: |
| 7252 | // - (required) i32 mode id. |
| 7253 | // - (optional) i64 display id. Using default display if not provided. |
| 7254 | // - (optional) f min render rate. Using mode's fps is not provided. |
| 7255 | // - (optional) f max render rate. Using mode's fps is not provided. |
| 7256 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 7257 | const int modeId = data.readInt32(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 7258 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7259 | const auto display = [&]() -> sp<IBinder> { |
| 7260 | uint64_t value; |
| 7261 | if (data.readUint64(&value) != NO_ERROR) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7262 | return getDefaultDisplayDevice()->getDisplayToken().promote(); |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7263 | } |
| 7264 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7265 | if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(value)) { |
| 7266 | return getPhysicalDisplayToken(*id); |
| 7267 | } |
| 7268 | |
| 7269 | ALOGE("Invalid physical display ID"); |
| 7270 | return nullptr; |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7271 | }(); |
| 7272 | |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7273 | const auto getFps = [&] { |
| 7274 | float value; |
| 7275 | if (data.readFloat(&value) == NO_ERROR) { |
| 7276 | return Fps::fromValue(value); |
| 7277 | } |
| 7278 | |
| 7279 | return Fps(); |
| 7280 | }; |
| 7281 | |
| 7282 | const auto minFps = getFps(); |
| 7283 | const auto maxFps = getFps(); |
| 7284 | |
Shiyong Li | 2bcece9 | 2021-08-30 20:38:50 +0000 | [diff] [blame] | 7285 | mDebugDisplayModeSetByBackdoor = false; |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7286 | const status_t result = |
| 7287 | setActiveModeFromBackdoor(display, DisplayModeId{modeId}, minFps, maxFps); |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7288 | mDebugDisplayModeSetByBackdoor = result == NO_ERROR; |
| 7289 | return result; |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 7290 | } |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7291 | // Turn on/off frame rate flexibility mode. When turned on it overrides the display |
| 7292 | // manager frame rate policy a new policy which allows switching between all refresh |
| 7293 | // rates. |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7294 | case 1036: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7295 | if (data.readInt32() > 0) { // turn on |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7296 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7297 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7298 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7299 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7300 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7301 | // This is a little racy, but not in a way that hurts anything. As |
| 7302 | // we grab the defaultMode from the display manager policy, we could |
| 7303 | // be setting a new display manager policy, leaving us using a stale |
| 7304 | // defaultMode. The defaultMode doesn't matter for the override |
| 7305 | // policy though, since we set allowGroupSwitching to true, so it's |
| 7306 | // not a problem. |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7307 | scheduler::RefreshRateSelector::OverridePolicy overridePolicy; |
| 7308 | overridePolicy.defaultMode = display->refreshRateSelector() |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7309 | .getDisplayManagerPolicy() |
| 7310 | .defaultMode; |
| 7311 | overridePolicy.allowGroupSwitching = true; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7312 | return setDesiredDisplayModeSpecsInternal(display, overridePolicy); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7313 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7314 | .get(); |
| 7315 | } else { // turn off |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7316 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7317 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7318 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7319 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7320 | return setDesiredDisplayModeSpecsInternal( |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7321 | display, |
| 7322 | scheduler::RefreshRateSelector::NoOverridePolicy{}); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7323 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7324 | .get(); |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7325 | } |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7326 | } |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 7327 | // Inject a hotplug connected event for the primary display. This will deallocate and |
| 7328 | // reallocate the display state including framebuffers. |
| 7329 | case 1037: { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7330 | const hal::HWDisplayId hwcId = |
| 7331 | (Mutex::Autolock(mStateLock), getHwComposer().getPrimaryHwcDisplayId()); |
| 7332 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 7333 | onComposerHalHotplugEvent(hwcId, DisplayHotplugEvent::CONNECTED); |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 7334 | return NO_ERROR; |
| 7335 | } |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 7336 | // Modify the max number of display frames stored within FrameTimeline |
| 7337 | case 1038: { |
| 7338 | n = data.readInt32(); |
| 7339 | if (n < 0 || n > MAX_ALLOWED_DISPLAY_FRAMES) { |
| 7340 | ALOGW("Invalid max size. Maximum allowed is %d", MAX_ALLOWED_DISPLAY_FRAMES); |
| 7341 | return BAD_VALUE; |
| 7342 | } |
| 7343 | if (n == 0) { |
| 7344 | // restore to default |
| 7345 | mFrameTimeline->reset(); |
| 7346 | return NO_ERROR; |
| 7347 | } |
| 7348 | mFrameTimeline->setMaxDisplayFrames(n); |
| 7349 | return NO_ERROR; |
| 7350 | } |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 7351 | case 1039: { |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 7352 | PhysicalDisplayId displayId = [&]() { |
| 7353 | Mutex::Autolock lock(mStateLock); |
| 7354 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 7355 | }(); |
| 7356 | |
| 7357 | auto inUid = static_cast<uid_t>(data.readInt32()); |
| 7358 | const auto refreshRate = data.readFloat(); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 7359 | mScheduler->setPreferredRefreshRateForUid(FrameRateOverride{inUid, refreshRate}); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7360 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 7361 | return NO_ERROR; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 7362 | } |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7363 | // Toggle caching feature |
| 7364 | // First argument is an int32 - nonzero enables caching and zero disables caching |
| 7365 | // Second argument is an optional uint64 - if present, then limits enabling/disabling |
| 7366 | // caching to a particular physical display |
| 7367 | case 1040: { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7368 | auto future = mScheduler->schedule([&] { |
| 7369 | n = data.readInt32(); |
| 7370 | std::optional<PhysicalDisplayId> inputId = std::nullopt; |
| 7371 | if (uint64_t inputDisplayId; data.readUint64(&inputDisplayId) == NO_ERROR) { |
| 7372 | inputId = DisplayId::fromValue<PhysicalDisplayId>(inputDisplayId); |
| 7373 | if (!inputId || getPhysicalDisplayToken(*inputId)) { |
| 7374 | ALOGE("No display with id: %" PRIu64, inputDisplayId); |
| 7375 | return NAME_NOT_FOUND; |
| 7376 | } |
| 7377 | } |
| 7378 | { |
| 7379 | Mutex::Autolock lock(mStateLock); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7380 | mLayerCachingEnabled = n != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7381 | for (const auto& [_, display] : mDisplays) { |
| 7382 | if (!inputId || *inputId == display->getPhysicalId()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7383 | display->enableLayerCaching(mLayerCachingEnabled); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7384 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7385 | } |
| 7386 | } |
| 7387 | return OK; |
| 7388 | }); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7389 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7390 | if (const status_t error = future.get(); error != OK) { |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7391 | return error; |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7392 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7393 | scheduleRepaint(); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7394 | return NO_ERROR; |
| 7395 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 7396 | case 1041: { // Transaction tracing |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7397 | if (mTransactionTracing) { |
Vishnu Nair | 640261c | 2023-09-21 21:22:51 -0700 | [diff] [blame] | 7398 | int arg = data.readInt32(); |
| 7399 | if (arg == -1) { |
Vishnu Nair | 50858e6 | 2023-10-13 23:28:24 +0000 | [diff] [blame] | 7400 | mScheduler->schedule([&]() { mTransactionTracing.reset(); }).get(); |
Vishnu Nair | 640261c | 2023-09-21 21:22:51 -0700 | [diff] [blame] | 7401 | } else if (arg > 0) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7402 | // Transaction tracing is always running but allow the user to temporarily |
| 7403 | // increase the buffer when actively debugging. |
| 7404 | mTransactionTracing->setBufferSize( |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 7405 | TransactionTracing::LEGACY_ACTIVE_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7406 | } else { |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 7407 | TransactionTraceWriter::getInstance().invoke("", /* overwrite= */ true); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7408 | mTransactionTracing->setBufferSize( |
| 7409 | TransactionTracing::CONTINUOUS_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7410 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 7411 | } |
| 7412 | reply->writeInt32(NO_ERROR); |
| 7413 | return NO_ERROR; |
| 7414 | } |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 7415 | case 1042: { // Write transaction trace to file |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7416 | if (mTransactionTracing) { |
| 7417 | mTransactionTracing->writeToFile(); |
| 7418 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7419 | reply->writeInt32(NO_ERROR); |
| 7420 | return NO_ERROR; |
| 7421 | } |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 7422 | // hdr sdr ratio overlay |
| 7423 | case 1043: { |
| 7424 | auto future = mScheduler->schedule( |
| 7425 | [&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 7426 | n = data.readInt32(); |
| 7427 | mHdrSdrRatioOverlay = n != 0; |
| 7428 | switch (n) { |
| 7429 | case 0: |
| 7430 | case 1: |
| 7431 | enableHdrSdrRatioOverlay(mHdrSdrRatioOverlay); |
| 7432 | break; |
| 7433 | default: |
| 7434 | reply->writeBool(isHdrSdrRatioOverlayEnabled()); |
| 7435 | } |
| 7436 | }); |
| 7437 | future.wait(); |
| 7438 | return NO_ERROR; |
| 7439 | } |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 7440 | |
| 7441 | case 1044: { // Enable/Disable mirroring from one display to another |
| 7442 | /* |
| 7443 | * Mirror one display onto another. |
| 7444 | * Ensure the source and destination displays are on. |
| 7445 | * Commands: |
| 7446 | * 0: Mirror one display to another |
| 7447 | * 1: Disable mirroring to a previously mirrored display |
| 7448 | * 2: Disable mirroring on previously mirrored displays |
| 7449 | * |
| 7450 | * Ex: |
| 7451 | * Get the display ids: |
| 7452 | * adb shell dumpsys SurfaceFlinger --display-id |
| 7453 | * Mirror first display to the second: |
| 7454 | * adb shell service call SurfaceFlinger 1044 i64 0 i64 4619827677550801152 i64 |
| 7455 | * 4619827677550801153 |
| 7456 | * Stop mirroring: |
| 7457 | * adb shell service call SurfaceFlinger 1044 i64 1 |
| 7458 | */ |
| 7459 | |
| 7460 | int64_t arg0 = data.readInt64(); |
| 7461 | |
| 7462 | switch (arg0) { |
| 7463 | case 0: { |
| 7464 | // Mirror arg1 to arg2 |
| 7465 | int64_t arg1 = data.readInt64(); |
| 7466 | int64_t arg2 = data.readInt64(); |
| 7467 | // Enable mirroring for one display |
| 7468 | const auto display1id = DisplayId::fromValue(arg1); |
| 7469 | auto mirrorRoot = SurfaceComposerClient::getDefault()->mirrorDisplay( |
| 7470 | display1id.value()); |
| 7471 | auto id2 = DisplayId::fromValue<PhysicalDisplayId>(arg2); |
| 7472 | const auto token2 = getPhysicalDisplayToken(*id2); |
| 7473 | ui::LayerStack layerStack; |
| 7474 | { |
| 7475 | Mutex::Autolock lock(mStateLock); |
| 7476 | sp<DisplayDevice> display = getDisplayDeviceLocked(token2); |
| 7477 | layerStack = display->getLayerStack(); |
| 7478 | } |
| 7479 | SurfaceComposerClient::Transaction t; |
| 7480 | t.setDisplayLayerStack(token2, layerStack); |
| 7481 | t.setLayer(mirrorRoot, INT_MAX); // Top-most layer |
| 7482 | t.setLayerStack(mirrorRoot, layerStack); |
| 7483 | t.apply(); |
| 7484 | |
| 7485 | mMirrorMapForDebug.emplace_or_replace(arg2, mirrorRoot); |
| 7486 | break; |
| 7487 | } |
| 7488 | |
| 7489 | case 1: { |
| 7490 | // Disable mirroring for arg1 |
| 7491 | int64_t arg1 = data.readInt64(); |
| 7492 | mMirrorMapForDebug.erase(arg1); |
| 7493 | break; |
| 7494 | } |
| 7495 | |
| 7496 | case 2: { |
| 7497 | // Disable mirroring for all displays |
| 7498 | mMirrorMapForDebug.clear(); |
| 7499 | break; |
| 7500 | } |
| 7501 | |
| 7502 | default: |
| 7503 | return BAD_VALUE; |
| 7504 | } |
| 7505 | return NO_ERROR; |
| 7506 | } |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7507 | // Inject jank |
| 7508 | // First argument is a float that describes the fraction of frame duration to jank by. |
| 7509 | // Second argument is a delay in ms for triggering the jank. This is useful for working |
| 7510 | // with tools that steal the adb connection. This argument is optional. |
| 7511 | case 1045: { |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 7512 | if (FlagManager::getInstance().vrr_config()) { |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7513 | float jankAmount = data.readFloat(); |
| 7514 | int32_t jankDelayMs = 0; |
| 7515 | if (data.readInt32(&jankDelayMs) != NO_ERROR) { |
| 7516 | jankDelayMs = 0; |
| 7517 | } |
| 7518 | |
| 7519 | const auto jankDelayDuration = Duration(std::chrono::milliseconds(jankDelayMs)); |
| 7520 | |
| 7521 | const bool jankAmountValid = jankAmount > 0.0 && jankAmount < 100.0; |
| 7522 | |
| 7523 | if (!jankAmountValid) { |
| 7524 | ALOGD("Ignoring invalid jank amount: %f", jankAmount); |
| 7525 | reply->writeInt32(BAD_VALUE); |
| 7526 | return BAD_VALUE; |
| 7527 | } |
| 7528 | |
| 7529 | (void)mScheduler->scheduleDelayed( |
| 7530 | [&, jankAmount]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 7531 | mScheduler->injectPacesetterDelay(jankAmount); |
| 7532 | scheduleComposite(FrameHint::kActive); |
| 7533 | }, |
| 7534 | jankDelayDuration.ns()); |
| 7535 | reply->writeInt32(NO_ERROR); |
| 7536 | return NO_ERROR; |
| 7537 | } |
| 7538 | return err; |
| 7539 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7540 | } |
| 7541 | } |
| 7542 | return err; |
| 7543 | } |
| 7544 | |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7545 | void SurfaceFlinger::kernelTimerChanged(bool expired) { |
| 7546 | static bool updateOverlay = |
| 7547 | property_get_bool("debug.sf.kernel_idle_timer_update_overlay", true); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7548 | if (!updateOverlay) return; |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7549 | |
| 7550 | // Update the overlay on the main thread to avoid race conditions with |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 7551 | // RefreshRateSelector::getActiveMode |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 7552 | static_cast<void>(mScheduler->schedule([=, this] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7553 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7554 | if (!display) { |
| 7555 | ALOGW("%s: default display is null", __func__); |
| 7556 | return; |
| 7557 | } |
Adrian Salido | a942af8 | 2022-02-17 19:22:31 -0800 | [diff] [blame] | 7558 | if (!display->isRefreshRateOverlayEnabled()) return; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7559 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7560 | const auto desiredModeIdOpt = |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 7561 | display->getDesiredMode().transform([](const display::DisplayModeRequest& request) { |
| 7562 | return request.mode.modePtr->getId(); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7563 | }); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7564 | |
| 7565 | const bool timerExpired = mKernelIdleTimerEnabled && expired; |
| 7566 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7567 | if (display->onKernelTimerChanged(desiredModeIdOpt, timerExpired)) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 7568 | mScheduler->scheduleFrame(); |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7569 | } |
| 7570 | })); |
| 7571 | } |
| 7572 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7573 | std::pair<std::optional<KernelIdleTimerController>, std::chrono::milliseconds> |
| 7574 | SurfaceFlinger::getKernelIdleTimerProperties(DisplayId displayId) { |
| 7575 | const bool isKernelIdleTimerHwcSupported = getHwComposer().getComposer()->isSupported( |
| 7576 | android::Hwc2::Composer::OptionalFeature::KernelIdleTimer); |
| 7577 | const auto timeout = getIdleTimerTimeout(displayId); |
| 7578 | if (isKernelIdleTimerHwcSupported) { |
| 7579 | if (const auto id = PhysicalDisplayId::tryCast(displayId); |
| 7580 | getHwComposer().hasDisplayIdleTimerCapability(*id)) { |
| 7581 | // In order to decide if we can use the HWC api for idle timer |
| 7582 | // we query DisplayCapability::DISPLAY_IDLE_TIMER directly on the composer |
| 7583 | // without relying on hasDisplayCapability. |
| 7584 | // hasDisplayCapability relies on DisplayCapabilities |
| 7585 | // which are updated after we set the PowerMode::ON. |
| 7586 | // DISPLAY_IDLE_TIMER is a display driver property |
| 7587 | // and is available before the PowerMode::ON |
| 7588 | return {KernelIdleTimerController::HwcApi, timeout}; |
| 7589 | } |
| 7590 | return {std::nullopt, timeout}; |
| 7591 | } |
| 7592 | if (getKernelIdleTimerSyspropConfig(displayId)) { |
| 7593 | return {KernelIdleTimerController::Sysprop, timeout}; |
| 7594 | } |
| 7595 | |
| 7596 | return {std::nullopt, timeout}; |
| 7597 | } |
| 7598 | |
| 7599 | void SurfaceFlinger::updateKernelIdleTimer(std::chrono::milliseconds timeout, |
| 7600 | KernelIdleTimerController controller, |
| 7601 | PhysicalDisplayId displayId) { |
| 7602 | switch (controller) { |
| 7603 | case KernelIdleTimerController::HwcApi: { |
| 7604 | getHwComposer().setIdleTimerEnabled(displayId, timeout); |
| 7605 | break; |
| 7606 | } |
| 7607 | case KernelIdleTimerController::Sysprop: { |
| 7608 | base::SetProperty(KERNEL_IDLE_TIMER_PROP, timeout > 0ms ? "true" : "false"); |
| 7609 | break; |
| 7610 | } |
| 7611 | } |
| 7612 | } |
| 7613 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7614 | void SurfaceFlinger::toggleKernelIdleTimer() { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7615 | using KernelIdleTimerAction = scheduler::RefreshRateSelector::KernelIdleTimerAction; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7616 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7617 | const auto display = getDefaultDisplayDeviceLocked(); |
| 7618 | if (!display) { |
| 7619 | ALOGW("%s: default display is null", __func__); |
| 7620 | return; |
| 7621 | } |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7622 | |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7623 | // If the support for kernel idle timer is disabled for the active display, |
| 7624 | // don't do anything. |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7625 | const std::optional<KernelIdleTimerController> kernelIdleTimerController = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7626 | display->refreshRateSelector().kernelIdleTimerController(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7627 | if (!kernelIdleTimerController.has_value()) { |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7628 | return; |
| 7629 | } |
| 7630 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7631 | const KernelIdleTimerAction action = display->refreshRateSelector().getIdleTimerAction(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7632 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7633 | switch (action) { |
| 7634 | case KernelIdleTimerAction::TurnOff: |
| 7635 | if (mKernelIdleTimerEnabled) { |
| 7636 | ATRACE_INT("KernelIdleTimer", 0); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7637 | std::chrono::milliseconds constexpr kTimerDisabledTimeout = 0ms; |
| 7638 | updateKernelIdleTimer(kTimerDisabledTimeout, kernelIdleTimerController.value(), |
| 7639 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7640 | mKernelIdleTimerEnabled = false; |
| 7641 | } |
| 7642 | break; |
| 7643 | case KernelIdleTimerAction::TurnOn: |
| 7644 | if (!mKernelIdleTimerEnabled) { |
| 7645 | ATRACE_INT("KernelIdleTimer", 1); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7646 | const std::chrono::milliseconds timeout = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7647 | display->refreshRateSelector().getIdleTimerTimeout(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7648 | updateKernelIdleTimer(timeout, kernelIdleTimerController.value(), |
| 7649 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7650 | mKernelIdleTimerEnabled = true; |
| 7651 | } |
| 7652 | break; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7653 | } |
| 7654 | } |
| 7655 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7656 | // A simple RAII class to disconnect from an ANativeWindow* when it goes out of scope |
| 7657 | class WindowDisconnector { |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7658 | public: |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7659 | WindowDisconnector(ANativeWindow* window, int api) : mWindow(window), mApi(api) {} |
| 7660 | ~WindowDisconnector() { |
| 7661 | native_window_api_disconnect(mWindow, mApi); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7662 | } |
| 7663 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7664 | private: |
| 7665 | ANativeWindow* mWindow; |
| 7666 | const int mApi; |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7667 | }; |
| 7668 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7669 | static bool hasCaptureBlackoutContentPermission() { |
| 7670 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7671 | const int pid = ipc->getCallingPid(); |
| 7672 | const int uid = ipc->getCallingUid(); |
| 7673 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 7674 | PermissionCache::checkPermission(sCaptureBlackoutContent, pid, uid); |
| 7675 | } |
| 7676 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7677 | static status_t validateScreenshotPermissions(const CaptureArgs& captureArgs) { |
| 7678 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7679 | const int pid = ipc->getCallingPid(); |
| 7680 | const int uid = ipc->getCallingUid(); |
| 7681 | if (uid == AID_GRAPHICS || PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 7682 | return OK; |
| 7683 | } |
| 7684 | |
| 7685 | // If the caller doesn't have the correct permissions but is only attempting to screenshot |
| 7686 | // itself, we allow it to continue. |
| 7687 | if (captureArgs.uid == uid) { |
| 7688 | return OK; |
| 7689 | } |
| 7690 | |
| 7691 | ALOGE("Permission Denial: can't take screenshot pid=%d, uid=%d", pid, uid); |
| 7692 | return PERMISSION_DENIED; |
| 7693 | } |
| 7694 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7695 | status_t SurfaceFlinger::setSchedFifo(bool enabled) { |
| 7696 | static constexpr int kFifoPriority = 2; |
| 7697 | static constexpr int kOtherPriority = 0; |
| 7698 | |
| 7699 | struct sched_param param = {0}; |
| 7700 | int sched_policy; |
| 7701 | if (enabled) { |
| 7702 | sched_policy = SCHED_FIFO; |
| 7703 | param.sched_priority = kFifoPriority; |
| 7704 | } else { |
| 7705 | sched_policy = SCHED_OTHER; |
| 7706 | param.sched_priority = kOtherPriority; |
| 7707 | } |
| 7708 | |
| 7709 | if (sched_setscheduler(0, sched_policy, ¶m) != 0) { |
| 7710 | return -errno; |
| 7711 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7712 | |
| 7713 | return NO_ERROR; |
| 7714 | } |
| 7715 | |
| 7716 | status_t SurfaceFlinger::setSchedAttr(bool enabled) { |
| 7717 | static const unsigned int kUclampMin = |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 7718 | base::GetUintProperty<unsigned int>("ro.surface_flinger.uclamp.min"s, 0U); |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7719 | |
| 7720 | if (!kUclampMin) { |
| 7721 | // uclamp.min set to 0 (default), skip setting |
| 7722 | return NO_ERROR; |
| 7723 | } |
| 7724 | |
| 7725 | // Currently, there is no wrapper in bionic: b/183240349. |
| 7726 | struct sched_attr { |
| 7727 | uint32_t size; |
| 7728 | uint32_t sched_policy; |
| 7729 | uint64_t sched_flags; |
| 7730 | int32_t sched_nice; |
| 7731 | uint32_t sched_priority; |
| 7732 | uint64_t sched_runtime; |
| 7733 | uint64_t sched_deadline; |
| 7734 | uint64_t sched_period; |
| 7735 | uint32_t sched_util_min; |
| 7736 | uint32_t sched_util_max; |
| 7737 | }; |
| 7738 | |
| 7739 | sched_attr attr = {}; |
| 7740 | attr.size = sizeof(attr); |
| 7741 | |
| 7742 | attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP); |
| 7743 | attr.sched_util_min = enabled ? kUclampMin : 0; |
| 7744 | attr.sched_util_max = 1024; |
| 7745 | |
| 7746 | if (syscall(__NR_sched_setattr, 0, &attr, 0)) { |
| 7747 | return -errno; |
| 7748 | } |
| 7749 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7750 | return NO_ERROR; |
| 7751 | } |
| 7752 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7753 | namespace { |
| 7754 | |
| 7755 | ui::Dataspace pickBestDataspace(ui::Dataspace requestedDataspace, const DisplayDevice* display, |
| 7756 | bool capturingHdrLayers, bool hintForSeamlessTransition) { |
| 7757 | if (requestedDataspace != ui::Dataspace::UNKNOWN || display == nullptr) { |
| 7758 | return requestedDataspace; |
| 7759 | } |
| 7760 | |
| 7761 | const auto& state = display->getCompositionDisplay()->getState(); |
| 7762 | |
| 7763 | const auto dataspaceForColorMode = ui::pickDataspaceFor(state.colorMode); |
| 7764 | |
Alec Mouri | 2964072 | 2023-05-16 23:22:41 +0000 | [diff] [blame] | 7765 | // TODO: Enable once HDR screenshots are ready. |
| 7766 | if constexpr (/* DISABLES CODE */ (false)) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7767 | // For now since we only support 8-bit screenshots, just use HLG and |
| 7768 | // assume that 1.0 >= display max luminance. This isn't quite as future |
| 7769 | // proof as PQ is, but is good enough. |
| 7770 | // Consider using PQ once we support 16-bit screenshots and we're able |
| 7771 | // to consistently supply metadata to image encoders. |
| 7772 | return ui::Dataspace::BT2020_HLG; |
| 7773 | } |
| 7774 | |
| 7775 | return dataspaceForColorMode; |
| 7776 | } |
| 7777 | |
| 7778 | } // namespace |
| 7779 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7780 | static void invokeScreenCaptureError(const status_t status, |
| 7781 | const sp<IScreenCaptureListener>& captureListener) { |
| 7782 | ScreenCaptureResults captureResults; |
| 7783 | captureResults.fenceResult = base::unexpected(status); |
| 7784 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7785 | } |
| 7786 | |
| 7787 | void SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, |
| 7788 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7789 | ATRACE_CALL(); |
| 7790 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7791 | status_t validate = validateScreenshotPermissions(args); |
| 7792 | if (validate != OK) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7793 | invokeScreenCaptureError(validate, captureListener); |
| 7794 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7795 | } |
| 7796 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7797 | if (!args.displayToken) { |
| 7798 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7799 | return; |
| 7800 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7801 | |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 7802 | if (args.captureSecureLayers && !hasCaptureBlackoutContentPermission()) { |
| 7803 | ALOGE("Attempting to capture secure layers without CAPTURE_BLACKOUT_CONTENT"); |
| 7804 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 7805 | return; |
| 7806 | } |
| 7807 | |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7808 | wp<const DisplayDevice> displayWeak; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7809 | ui::LayerStack layerStack; |
| 7810 | ui::Size reqSize(args.width, args.height); |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7811 | std::unordered_set<uint32_t> excludeLayerIds; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7812 | { |
| 7813 | Mutex::Autolock lock(mStateLock); |
| 7814 | sp<DisplayDevice> display = getDisplayDeviceLocked(args.displayToken); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7815 | if (!display) { |
| 7816 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7817 | return; |
| 7818 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7819 | displayWeak = display; |
| 7820 | layerStack = display->getLayerStack(); |
| 7821 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7822 | // 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] | 7823 | if (args.width == 0 || args.height == 0) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7824 | reqSize = display->getLayerStackSpaceRect().getSize(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7825 | } |
| 7826 | |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7827 | for (const auto& handle : args.excludeHandles) { |
| 7828 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7829 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7830 | excludeLayerIds.emplace(excludeLayer); |
| 7831 | } else { |
| 7832 | ALOGW("Invalid layer handle passed as excludeLayer to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7833 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7834 | return; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7835 | } |
| 7836 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7837 | } |
| 7838 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7839 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
Alec Mouri | c44a1ff | 2023-05-19 23:49:05 +0000 | [diff] [blame] | 7840 | return DisplayRenderArea::create(displayWeak, args.sourceCrop, reqSize, args.dataspace, |
Melody Hsu | 70a63e5 | 2023-11-17 19:49:12 +0000 | [diff] [blame] | 7841 | args.hintForSeamlessTransition, args.captureSecureLayers); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7842 | }); |
| 7843 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7844 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7845 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7846 | getLayerSnapshots = |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7847 | getLayerSnapshotsForScreenshots(layerStack, args.uid, std::move(excludeLayerIds)); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7848 | } else { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7849 | auto traverseLayers = [this, args, excludeLayerIds, |
| 7850 | layerStack](const LayerVector::Visitor& visitor) { |
| 7851 | traverseLayersInLayerStack(layerStack, args.uid, std::move(excludeLayerIds), visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7852 | }; |
| 7853 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7854 | } |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 7855 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7856 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, args.pixelFormat, |
| 7857 | args.allowProtected, args.grayscale, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7858 | } |
| 7859 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7860 | void SurfaceFlinger::captureDisplay(DisplayId displayId, const CaptureArgs& args, |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7861 | const sp<IScreenCaptureListener>& captureListener) { |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7862 | ui::LayerStack layerStack; |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7863 | wp<const DisplayDevice> displayWeak; |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7864 | ui::Size size; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7865 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7866 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7867 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7868 | const auto display = getDisplayDeviceLocked(displayId); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7869 | if (!display) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7870 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7871 | return; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7872 | } |
| 7873 | |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7874 | displayWeak = display; |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7875 | layerStack = display->getLayerStack(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7876 | size = display->getLayerStackSpaceRect().getSize(); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7877 | } |
| 7878 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7879 | size.width *= args.frameScaleX; |
| 7880 | size.height *= args.frameScaleY; |
| 7881 | |
| 7882 | // We could query a real value for this but it'll be a long, long time until we support |
| 7883 | // displays that need upwards of 1GB per buffer so... |
| 7884 | constexpr auto kMaxTextureSize = 16384; |
| 7885 | if (size.width <= 0 || size.height <= 0 || size.width >= kMaxTextureSize || |
| 7886 | size.height >= kMaxTextureSize) { |
| 7887 | ALOGE("capture display resolved to invalid size %d x %d", size.width, size.height); |
| 7888 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7889 | return; |
| 7890 | } |
| 7891 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7892 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7893 | return DisplayRenderArea::create(displayWeak, Rect(), size, args.dataspace, |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7894 | args.hintForSeamlessTransition, |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7895 | false /* captureSecureLayers */); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7896 | }); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7897 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7898 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7899 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7900 | getLayerSnapshots = getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID, |
| 7901 | /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7902 | } else { |
| 7903 | auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7904 | traverseLayersInLayerStack(layerStack, CaptureArgs::UNSET_UID, {}, visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7905 | }; |
| 7906 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7907 | } |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7908 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7909 | if (captureListener == nullptr) { |
| 7910 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7911 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7912 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7913 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7914 | |
| 7915 | constexpr bool kAllowProtected = false; |
| 7916 | constexpr bool kGrayscale = false; |
| 7917 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7918 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, size, args.pixelFormat, |
| 7919 | kAllowProtected, kGrayscale, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7920 | } |
| 7921 | |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 7922 | ScreenCaptureResults SurfaceFlinger::captureLayersSync(const LayerCaptureArgs& args) { |
| 7923 | sp<SyncScreenCaptureListener> captureListener = sp<SyncScreenCaptureListener>::make(); |
| 7924 | captureLayers(args, captureListener); |
| 7925 | return captureListener->waitForResults(); |
| 7926 | } |
| 7927 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7928 | void SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, |
| 7929 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7930 | ATRACE_CALL(); |
| 7931 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7932 | status_t validate = validateScreenshotPermissions(args); |
| 7933 | if (validate != OK) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7934 | invokeScreenCaptureError(validate, captureListener); |
| 7935 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7936 | } |
| 7937 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7938 | ui::Size reqSize; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7939 | sp<Layer> parent; |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7940 | Rect crop(args.sourceCrop); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7941 | std::unordered_set<uint32_t> excludeLayerIds; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7942 | ui::Dataspace dataspace = args.dataspace; |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7943 | |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 7944 | if (args.captureSecureLayers && !hasCaptureBlackoutContentPermission()) { |
| 7945 | ALOGE("Attempting to capture secure layers without CAPTURE_BLACKOUT_CONTENT"); |
| 7946 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 7947 | return; |
| 7948 | } |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7949 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7950 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7951 | Mutex::Autolock lock(mStateLock); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7952 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 7953 | parent = LayerHandle::getLayer(args.layerHandle); |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7954 | if (parent == nullptr) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7955 | ALOGE("captureLayers called with an invalid or removed parent"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7956 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7957 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7958 | } |
| 7959 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 7960 | Rect parentSourceBounds = parent->getCroppedBufferSize(parent->getDrawingState()); |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7961 | if (args.sourceCrop.width() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7962 | crop.left = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7963 | crop.right = parentSourceBounds.getWidth(); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7964 | } |
| 7965 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7966 | if (args.sourceCrop.height() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7967 | crop.top = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7968 | crop.bottom = parentSourceBounds.getHeight(); |
| 7969 | } |
| 7970 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7971 | if (crop.isEmpty() || args.frameScaleX <= 0.0f || args.frameScaleY <= 0.0f) { |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7972 | // Error out if the layer has no source bounds (i.e. they are boundless) and a source |
| 7973 | // crop was not specified, or an invalid frame scale was provided. |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7974 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7975 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7976 | } |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7977 | reqSize = ui::Size(crop.width() * args.frameScaleX, crop.height() * args.frameScaleY); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7978 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7979 | for (const auto& handle : args.excludeHandles) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7980 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7981 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7982 | excludeLayerIds.emplace(excludeLayer); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7983 | } else { |
| 7984 | ALOGW("Invalid layer handle passed as excludeLayer to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7985 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7986 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7987 | } |
| 7988 | } |
| 7989 | } // mStateLock |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7990 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7991 | // really small crop or frameScale |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7992 | if (reqSize.width <= 0 || reqSize.height <= 0) { |
| 7993 | ALOGW("Failed to captureLayes: crop or scale too small"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7994 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7995 | return; |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7996 | } |
| 7997 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7998 | bool childrenOnly = args.childrenOnly; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 7999 | RenderAreaFuture renderAreaFuture = ftl::defer([=, this]() -> std::unique_ptr<RenderArea> { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8000 | ui::Transform layerTransform; |
| 8001 | Rect layerBufferSize; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8002 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8003 | frontend::LayerSnapshot* snapshot = |
| 8004 | mLayerSnapshotBuilder.getSnapshot(parent->getSequence()); |
| 8005 | if (!snapshot) { |
| 8006 | ALOGW("Couldn't find layer snapshot for %d", parent->getSequence()); |
| 8007 | } else { |
| 8008 | layerTransform = snapshot->localTransform; |
| 8009 | layerBufferSize = snapshot->bufferSize; |
| 8010 | } |
| 8011 | } else { |
| 8012 | layerTransform = parent->getTransform(); |
| 8013 | layerBufferSize = parent->getBufferSize(parent->getDrawingState()); |
| 8014 | } |
| 8015 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 8016 | return std::make_unique<LayerRenderArea>(*this, parent, crop, reqSize, dataspace, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8017 | childrenOnly, args.captureSecureLayers, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8018 | layerTransform, layerBufferSize, |
| 8019 | args.hintForSeamlessTransition); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 8020 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8021 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8022 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8023 | std::optional<FloatRect> parentCrop = std::nullopt; |
| 8024 | if (args.childrenOnly) { |
| 8025 | parentCrop = crop.isEmpty() ? FloatRect(0, 0, reqSize.width, reqSize.height) |
| 8026 | : crop.toFloatRect(); |
| 8027 | } |
| 8028 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8029 | getLayerSnapshots = getLayerSnapshotsForScreenshots(parent->sequence, args.uid, |
| 8030 | std::move(excludeLayerIds), |
| 8031 | args.childrenOnly, parentCrop); |
| 8032 | } else { |
| 8033 | auto traverseLayers = [parent, args, excludeLayerIds](const LayerVector::Visitor& visitor) { |
| 8034 | parent->traverseChildrenInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
| 8035 | if (!layer->isVisible()) { |
| 8036 | return; |
| 8037 | } else if (args.childrenOnly && layer == parent.get()) { |
| 8038 | return; |
| 8039 | } else if (args.uid != CaptureArgs::UNSET_UID && args.uid != layer->getOwnerUid()) { |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 8040 | return; |
| 8041 | } |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 8042 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8043 | auto p = sp<Layer>::fromExisting(layer); |
| 8044 | while (p != nullptr) { |
| 8045 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 8046 | return; |
| 8047 | } |
| 8048 | p = p->getParent(); |
| 8049 | } |
| 8050 | |
| 8051 | visitor(layer); |
| 8052 | }); |
| 8053 | }; |
| 8054 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 8055 | } |
Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 8056 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 8057 | if (captureListener == nullptr) { |
| 8058 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8059 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8060 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 8061 | } |
| 8062 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8063 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, args.pixelFormat, |
| 8064 | args.allowProtected, args.grayscale, captureListener); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8065 | } |
| 8066 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8067 | void SurfaceFlinger::captureScreenCommon(RenderAreaFuture renderAreaFuture, |
| 8068 | GetLayerSnapshotsFunction getLayerSnapshots, |
| 8069 | ui::Size bufferSize, ui::PixelFormat reqPixelFormat, |
| 8070 | bool allowProtected, bool grayscale, |
| 8071 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8072 | ATRACE_CALL(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 8073 | |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 8074 | if (exceedsMaxRenderTargetSize(bufferSize.getWidth(), bufferSize.getHeight())) { |
| 8075 | ALOGE("Attempted to capture screen with size (%" PRId32 ", %" PRId32 |
| 8076 | ") that exceeds render target size limit.", |
| 8077 | bufferSize.getWidth(), bufferSize.getHeight()); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8078 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8079 | return; |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 8080 | } |
| 8081 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 8082 | // Loop over all visible layers to see whether there's any protected layer. A protected layer is |
| 8083 | // typically a layer with DRM contents, or have the GRALLOC_USAGE_PROTECTED set on the buffer. |
| 8084 | // A protected layer has no implication on whether it's secure, which is explicitly set by |
| 8085 | // application to avoid being screenshot or drawn via unsecure display. |
| 8086 | const bool supportsProtected = getRenderEngine().supportsProtectedContent(); |
| 8087 | bool hasProtectedLayer = false; |
| 8088 | if (allowProtected && supportsProtected) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8089 | hasProtectedLayer = mScheduler |
| 8090 | ->schedule([=]() { |
| 8091 | bool protectedLayerFound = false; |
| 8092 | auto layers = getLayerSnapshots(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8093 | for (auto& [_, layerFe] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8094 | protectedLayerFound |= |
| 8095 | (layerFe->mSnapshot->isVisible && |
| 8096 | layerFe->mSnapshot->hasProtectedContent); |
| 8097 | } |
| 8098 | return protectedLayerFound; |
| 8099 | }) |
| 8100 | .get(); |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 8101 | } |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8102 | const bool isProtected = hasProtectedLayer && allowProtected && supportsProtected; |
Richard Liu | cbcb895 | 2020-04-08 10:51:55 +0000 | [diff] [blame] | 8103 | const uint32_t usage = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER | |
| 8104 | GRALLOC_USAGE_HW_TEXTURE | |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8105 | (isProtected ? GRALLOC_USAGE_PROTECTED |
| 8106 | : GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8107 | sp<GraphicBuffer> buffer = |
| 8108 | getFactory().createGraphicBuffer(bufferSize.getWidth(), bufferSize.getHeight(), |
| 8109 | static_cast<android_pixel_format>(reqPixelFormat), |
| 8110 | 1 /* layerCount */, usage, "screenshot"); |
Alec Mouri | 7013b6f | 2021-02-12 11:16:54 -0800 | [diff] [blame] | 8111 | |
| 8112 | const status_t bufferStatus = buffer->initCheck(); |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 8113 | if (bufferStatus != OK) { |
| 8114 | // Animations may end up being really janky, but don't crash here. |
| 8115 | // Otherwise an irreponsible process may cause an SF crash by allocating |
| 8116 | // too much. |
| 8117 | ALOGE("%s: Buffer failed to allocate: %d", __func__, bufferStatus); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8118 | invokeScreenCaptureError(bufferStatus, captureListener); |
| 8119 | return; |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 8120 | } |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8121 | const std::shared_ptr<renderengine::ExternalTexture> texture = std::make_shared< |
| 8122 | renderengine::impl::ExternalTexture>(buffer, getRenderEngine(), |
| 8123 | renderengine::impl::ExternalTexture::Usage:: |
| 8124 | WRITEABLE); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8125 | auto fence = captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, texture, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8126 | false /* regionSampling */, grayscale, isProtected, |
| 8127 | captureListener); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8128 | fence.get(); |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 8129 | } |
| 8130 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 8131 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenCommon( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8132 | RenderAreaFuture renderAreaFuture, GetLayerSnapshotsFunction getLayerSnapshots, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 8133 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8134 | bool grayscale, bool isProtected, const sp<IScreenCaptureListener>& captureListener) { |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 8135 | ATRACE_CALL(); |
| 8136 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 8137 | auto future = mScheduler->schedule( |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 8138 | [=, this, renderAreaFuture = std::move(renderAreaFuture)]() FTL_FAKE_GUARD( |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 8139 | kMainThreadContext) mutable -> ftl::SharedFuture<FenceResult> { |
| 8140 | ScreenCaptureResults captureResults; |
Patrick Williams | 3190813 | 2023-01-09 13:38:48 -0600 | [diff] [blame] | 8141 | std::shared_ptr<RenderArea> renderArea = renderAreaFuture.get(); |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 8142 | if (!renderArea) { |
| 8143 | ALOGW("Skipping screen capture because of invalid render area."); |
Nolan Scobie | 1d2deb2 | 2022-11-18 12:57:47 -0500 | [diff] [blame] | 8144 | if (captureListener) { |
| 8145 | captureResults.fenceResult = base::unexpected(NO_MEMORY); |
| 8146 | captureListener->onScreenCaptureCompleted(captureResults); |
| 8147 | } |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 8148 | return ftl::yield<FenceResult>(base::unexpected(NO_ERROR)).share(); |
| 8149 | } |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 8150 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 8151 | ftl::SharedFuture<FenceResult> renderFuture; |
| 8152 | renderArea->render([&]() FTL_FAKE_GUARD(kMainThreadContext) { |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8153 | renderFuture = |
| 8154 | renderScreenImpl(renderArea, getLayerSnapshots, buffer, regionSampling, |
| 8155 | grayscale, isProtected, captureResults); |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 8156 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8157 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 8158 | if (captureListener) { |
| 8159 | // Defer blocking on renderFuture back to the Binder thread. |
| 8160 | return ftl::Future(std::move(renderFuture)) |
| 8161 | .then([captureListener, captureResults = std::move(captureResults)]( |
| 8162 | FenceResult fenceResult) mutable -> FenceResult { |
| 8163 | captureResults.fenceResult = std::move(fenceResult); |
| 8164 | captureListener->onScreenCaptureCompleted(captureResults); |
| 8165 | return base::unexpected(NO_ERROR); |
| 8166 | }) |
| 8167 | .share(); |
| 8168 | } |
| 8169 | return renderFuture; |
| 8170 | }); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 8171 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8172 | // Flatten nested futures. |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 8173 | auto chain = ftl::Future(std::move(future)).then([](ftl::SharedFuture<FenceResult> future) { |
| 8174 | return future; |
| 8175 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8176 | |
| 8177 | return chain.share(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 8178 | } |
| 8179 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 8180 | ftl::SharedFuture<FenceResult> SurfaceFlinger::renderScreenImpl( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8181 | std::shared_ptr<const RenderArea> renderArea, GetLayerSnapshotsFunction getLayerSnapshots, |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 8182 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8183 | bool grayscale, bool isProtected, ScreenCaptureResults& captureResults) { |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 8184 | ATRACE_CALL(); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8185 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8186 | auto layers = getLayerSnapshots(); |
Alec Mouri | b4814de | 2023-09-11 22:09:03 +0000 | [diff] [blame] | 8187 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8188 | for (auto& [_, layerFE] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8189 | frontend::LayerSnapshot* snapshot = layerFE->mSnapshot.get(); |
| 8190 | captureResults.capturedSecureLayers |= (snapshot->isVisible && snapshot->isSecure); |
| 8191 | captureResults.capturedHdrLayers |= isHdrLayer(*snapshot); |
| 8192 | layerFE->mSnapshot->geomLayerTransform = |
| 8193 | renderArea->getTransform() * layerFE->mSnapshot->geomLayerTransform; |
Patrick Williams | c6e0cce | 2023-02-28 23:04:45 -0600 | [diff] [blame] | 8194 | layerFE->mSnapshot->geomInverseLayerTransform = |
| 8195 | layerFE->mSnapshot->geomLayerTransform.inverse(); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8196 | } |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8197 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8198 | auto capturedBuffer = buffer; |
| 8199 | |
| 8200 | auto requestedDataspace = renderArea->getReqDataSpace(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8201 | auto parent = renderArea->getParentLayer(); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 8202 | auto renderIntent = RenderIntent::TONE_MAP_COLORIMETRIC; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 8203 | auto sdrWhitePointNits = DisplayDevice::sDefaultMaxLumiance; |
| 8204 | auto displayBrightnessNits = DisplayDevice::sDefaultMaxLumiance; |
| 8205 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8206 | captureResults.capturedDataspace = requestedDataspace; |
| 8207 | |
| 8208 | { |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8209 | Mutex::Autolock lock(mStateLock); |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8210 | const DisplayDevice* display = nullptr; |
| 8211 | if (parent) { |
| 8212 | display = findDisplay([layerStack = parent->getLayerStack()](const auto& display) { |
| 8213 | return display.getLayerStack() == layerStack; |
| 8214 | }).get(); |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8215 | } |
| 8216 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8217 | if (display == nullptr) { |
| 8218 | display = renderArea->getDisplayDevice().get(); |
| 8219 | } |
| 8220 | |
| 8221 | if (display == nullptr) { |
| 8222 | display = getDefaultDisplayDeviceLocked().get(); |
| 8223 | } |
| 8224 | |
| 8225 | if (display != nullptr) { |
| 8226 | const auto& state = display->getCompositionDisplay()->getState(); |
| 8227 | captureResults.capturedDataspace = |
| 8228 | pickBestDataspace(requestedDataspace, display, captureResults.capturedHdrLayers, |
| 8229 | renderArea->getHintForSeamlessTransition()); |
| 8230 | sdrWhitePointNits = state.sdrWhitePointNits; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8231 | |
Alec Mouri | b4814de | 2023-09-11 22:09:03 +0000 | [diff] [blame] | 8232 | // TODO(b/298219334): Clean this up once we verify this doesn't break anything |
| 8233 | static constexpr bool kScreenshotsDontDim = true; |
| 8234 | |
| 8235 | if (kScreenshotsDontDim && !captureResults.capturedHdrLayers) { |
| 8236 | displayBrightnessNits = sdrWhitePointNits; |
| 8237 | } else { |
| 8238 | displayBrightnessNits = state.displayBrightnessNits; |
| 8239 | // Only clamp the display brightness if this is not a seamless transition. Otherwise |
| 8240 | // for seamless transitions it's important to match the current display state as the |
| 8241 | // buffer will be shown under these same conditions, and we want to avoid any |
| 8242 | // flickers |
| 8243 | if (sdrWhitePointNits > 1.0f && !renderArea->getHintForSeamlessTransition()) { |
| 8244 | // Restrict the amount of HDR "headroom" in the screenshot to avoid over-dimming |
| 8245 | // the SDR portion. 2.0 chosen by experimentation |
| 8246 | constexpr float kMaxScreenshotHeadroom = 2.0f; |
| 8247 | displayBrightnessNits = std::min(sdrWhitePointNits * kMaxScreenshotHeadroom, |
| 8248 | displayBrightnessNits); |
| 8249 | } |
Alec Mouri | 5e488f8 | 2023-09-15 01:27:49 +0000 | [diff] [blame] | 8250 | } |
Alec Mouri | ffb3221 | 2023-09-16 19:29:15 +0000 | [diff] [blame] | 8251 | |
| 8252 | // Screenshots leaving the device should be colorimetric |
| 8253 | if (requestedDataspace == ui::Dataspace::UNKNOWN && |
| 8254 | renderArea->getHintForSeamlessTransition()) { |
Alec Mouri | 5e488f8 | 2023-09-15 01:27:49 +0000 | [diff] [blame] | 8255 | renderIntent = state.renderIntent; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8256 | } |
| 8257 | } |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8258 | } |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8259 | |
| 8260 | captureResults.buffer = capturedBuffer->getBuffer(); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8261 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8262 | ui::LayerStack layerStack{ui::DEFAULT_LAYER_STACK}; |
| 8263 | if (!layers.empty()) { |
| 8264 | const sp<LayerFE>& layerFE = layers.back().second; |
| 8265 | layerStack = layerFE->getCompositionState()->outputFilter.layerStack; |
Yichi Chen | 40773d9 | 2020-04-01 10:10:18 +0800 | [diff] [blame] | 8266 | } |
Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 8267 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8268 | auto copyLayerFEs = [&layers]() { |
| 8269 | std::vector<sp<compositionengine::LayerFE>> layerFEs; |
| 8270 | layerFEs.reserve(layers.size()); |
| 8271 | for (const auto& [_, layerFE] : layers) { |
| 8272 | layerFEs.push_back(layerFE); |
| 8273 | } |
| 8274 | return layerFEs; |
| 8275 | }; |
| 8276 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8277 | auto present = [this, buffer = capturedBuffer, dataspace = captureResults.capturedDataspace, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8278 | sdrWhitePointNits, displayBrightnessNits, grayscale, isProtected, |
| 8279 | layerFEs = copyLayerFEs(), layerStack, regionSampling, |
| 8280 | renderArea = std::move(renderArea), renderIntent]() -> FenceResult { |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8281 | std::unique_ptr<compositionengine::CompositionEngine> compositionEngine = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8282 | mFactory.createCompositionEngine(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8283 | compositionEngine->setRenderEngine(mRenderEngine.get()); |
| 8284 | |
| 8285 | compositionengine::Output::ColorProfile colorProfile{.dataspace = dataspace, |
| 8286 | .renderIntent = renderIntent}; |
| 8287 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8288 | float targetBrightness = 1.0f; |
| 8289 | if (dataspace == ui::Dataspace::BT2020_HLG) { |
| 8290 | const float maxBrightnessNits = displayBrightnessNits / sdrWhitePointNits * 203; |
| 8291 | // With a low dimming ratio, don't fit the entire curve. Otherwise mixed content |
| 8292 | // will appear way too bright. |
| 8293 | if (maxBrightnessNits < 1000.f) { |
| 8294 | targetBrightness = 1000.f / maxBrightnessNits; |
| 8295 | } |
| 8296 | } |
| 8297 | |
Alec Mouri | ffb3221 | 2023-09-16 19:29:15 +0000 | [diff] [blame] | 8298 | // Screenshots leaving the device must not dim in gamma space. |
| 8299 | const bool dimInGammaSpaceForEnhancedScreenshots = mDimInGammaSpaceForEnhancedScreenshots && |
| 8300 | renderArea->getHintForSeamlessTransition(); |
| 8301 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8302 | std::shared_ptr<ScreenCaptureOutput> output = createScreenCaptureOutput( |
| 8303 | ScreenCaptureOutputArgs{.compositionEngine = *compositionEngine, |
| 8304 | .colorProfile = colorProfile, |
| 8305 | .renderArea = *renderArea, |
| 8306 | .layerStack = layerStack, |
| 8307 | .buffer = std::move(buffer), |
| 8308 | .sdrWhitePointNits = sdrWhitePointNits, |
| 8309 | .displayBrightnessNits = displayBrightnessNits, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8310 | .targetBrightness = targetBrightness, |
Alec Mouri | 7dae9c1 | 2023-07-13 19:40:53 +0000 | [diff] [blame] | 8311 | .regionSampling = regionSampling, |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 8312 | .treat170mAsSrgb = mTreat170mAsSrgb, |
| 8313 | .dimInGammaSpaceForEnhancedScreenshots = |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8314 | dimInGammaSpaceForEnhancedScreenshots, |
| 8315 | .isProtected = isProtected}); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8316 | |
| 8317 | const float colorSaturation = grayscale ? 0 : 1; |
| 8318 | compositionengine::CompositionRefreshArgs refreshArgs{ |
| 8319 | .outputs = {output}, |
| 8320 | .layers = std::move(layerFEs), |
| 8321 | .updatingOutputGeometryThisFrame = true, |
| 8322 | .updatingGeometryThisFrame = true, |
| 8323 | .colorTransformMatrix = calculateColorMatrix(colorSaturation), |
| 8324 | }; |
| 8325 | compositionEngine->present(refreshArgs); |
| 8326 | |
| 8327 | return output->getRenderSurface()->getClientTargetAcquireFence(); |
| 8328 | }; |
| 8329 | |
| 8330 | // If RenderEngine is threaded, we can safely call CompositionEngine::present off the main |
| 8331 | // thread as the RenderEngine::drawLayers call will run on RenderEngine's thread. Otherwise, |
| 8332 | // we need RenderEngine to run on the main thread so we call CompositionEngine::present |
| 8333 | // immediately. |
| 8334 | // |
| 8335 | // TODO(b/196334700) Once we use RenderEngineThreaded everywhere we can always defer the call |
| 8336 | // to CompositionEngine::present. |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 8337 | auto presentFuture = mRenderEngine->isThreaded() ? ftl::defer(std::move(present)).share() |
| 8338 | : ftl::yield(present()).share(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8339 | |
| 8340 | for (auto& [layer, layerFE] : layers) { |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 8341 | layer->onLayerDisplayed(presentFuture, ui::INVALID_LAYER_STACK, |
| 8342 | [layerFE = std::move(layerFE)](FenceResult) { |
| 8343 | if (FlagManager::getInstance() |
| 8344 | .screenshot_fence_preservation()) { |
| 8345 | const auto compositionResult = |
| 8346 | layerFE->stealCompositionResult(); |
| 8347 | const auto& fences = compositionResult.releaseFences; |
| 8348 | // CompositionEngine may choose to cull layers that |
| 8349 | // aren't visible, so pass a non-fence. |
| 8350 | return fences.empty() ? Fence::NO_FENCE |
| 8351 | : fences.back().first.get(); |
| 8352 | } else { |
| 8353 | return layerFE->stealCompositionResult() |
| 8354 | .releaseFences.back() |
| 8355 | .first.get(); |
| 8356 | } |
| 8357 | }); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8358 | } |
| 8359 | |
| 8360 | return presentFuture; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 8361 | } |
| 8362 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8363 | void SurfaceFlinger::traverseLegacyLayers(const LayerVector::Visitor& visitor) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8364 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8365 | for (auto& layer : mLegacyLayers) { |
| 8366 | visitor(layer.second.get()); |
| 8367 | } |
| 8368 | } else { |
| 8369 | mDrawingState.traverse(visitor); |
| 8370 | } |
| 8371 | } |
| 8372 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 8373 | // --------------------------------------------------------------------------- |
| 8374 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 8375 | void SurfaceFlinger::State::traverse(const LayerVector::Visitor& visitor) const { |
| 8376 | layersSortedByZ.traverse(visitor); |
| 8377 | } |
| 8378 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 8379 | void SurfaceFlinger::State::traverseInZOrder(const LayerVector::Visitor& visitor) const { |
| 8380 | layersSortedByZ.traverseInZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 8381 | } |
| 8382 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 8383 | void SurfaceFlinger::State::traverseInReverseZOrder(const LayerVector::Visitor& visitor) const { |
| 8384 | layersSortedByZ.traverseInReverseZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 8385 | } |
| 8386 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8387 | void SurfaceFlinger::traverseLayersInLayerStack(ui::LayerStack layerStack, const int32_t uid, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8388 | std::unordered_set<uint32_t> excludeLayerIds, |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 8389 | const LayerVector::Visitor& visitor) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8390 | // We loop through the first level of layers without traversing, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 8391 | // as we need to determine which layers belong to the requested display. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8392 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 8393 | if (layer->getLayerStack() != layerStack) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8394 | continue; |
| 8395 | } |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 8396 | // relative layers are traversed in Layer::traverseInZOrder |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8397 | layer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 8398 | if (layer->isInternalDisplayOverlay()) { |
Adrian Roos | 8acf5a0 | 2018-01-17 21:28:19 +0100 | [diff] [blame] | 8399 | return; |
| 8400 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8401 | if (!layer->isVisible()) { |
| 8402 | return; |
| 8403 | } |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8404 | if (uid != CaptureArgs::UNSET_UID && layer->getOwnerUid() != uid) { |
| 8405 | return; |
| 8406 | } |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8407 | |
| 8408 | if (!excludeLayerIds.empty()) { |
| 8409 | auto p = sp<Layer>::fromExisting(layer); |
| 8410 | while (p != nullptr) { |
| 8411 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 8412 | return; |
| 8413 | } |
| 8414 | p = p->getParent(); |
| 8415 | } |
| 8416 | } |
| 8417 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8418 | visitor(layer); |
| 8419 | }); |
| 8420 | } |
| 8421 | } |
| 8422 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8423 | ftl::Optional<scheduler::FrameRateMode> SurfaceFlinger::getPreferredDisplayMode( |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8424 | PhysicalDisplayId displayId, DisplayModeId defaultModeId) const { |
| 8425 | if (const auto schedulerMode = mScheduler->getPreferredDisplayMode(); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8426 | schedulerMode.modePtr->getPhysicalDisplayId() == displayId) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8427 | return schedulerMode; |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8428 | } |
| 8429 | |
| 8430 | return mPhysicalDisplays.get(displayId) |
| 8431 | .transform(&PhysicalDisplay::snapshotRef) |
| 8432 | .and_then([&](const display::DisplaySnapshot& snapshot) { |
| 8433 | return snapshot.displayModes().get(defaultModeId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 8434 | }) |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8435 | .transform([](const DisplayModePtr& modePtr) { |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 8436 | return scheduler::FrameRateMode{modePtr->getPeakFps(), ftl::as_non_null(modePtr)}; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8437 | }); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8438 | } |
| 8439 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8440 | status_t SurfaceFlinger::setDesiredDisplayModeSpecsInternal( |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 8441 | const sp<DisplayDevice>& display, |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8442 | const scheduler::RefreshRateSelector::PolicyVariant& policy) { |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8443 | const auto displayId = display->getPhysicalId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8444 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8445 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 8446 | Mutex::Autolock lock(mStateLock); |
| 8447 | |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 8448 | if (mDebugDisplayModeSetByBackdoor) { |
| 8449 | // ignore this request as mode is overridden by backdoor |
| 8450 | return NO_ERROR; |
| 8451 | } |
| 8452 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8453 | auto& selector = display->refreshRateSelector(); |
| 8454 | using SetPolicyResult = scheduler::RefreshRateSelector::SetPolicyResult; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8455 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8456 | switch (selector.setPolicy(policy)) { |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8457 | case SetPolicyResult::Invalid: |
| 8458 | return BAD_VALUE; |
| 8459 | case SetPolicyResult::Unchanged: |
| 8460 | return NO_ERROR; |
| 8461 | case SetPolicyResult::Changed: |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8462 | break; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8463 | } |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8464 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 8465 | if (!shouldApplyRefreshRateSelectorPolicy(*display)) { |
| 8466 | ALOGV("%s(%s): Skipped applying policy", __func__, to_string(displayId).c_str()); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8467 | return NO_ERROR; |
| 8468 | } |
| 8469 | |
| 8470 | return applyRefreshRateSelectorPolicy(displayId, selector); |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8471 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8472 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 8473 | bool SurfaceFlinger::shouldApplyRefreshRateSelectorPolicy(const DisplayDevice& display) const { |
| 8474 | if (display.isPoweredOn() || mPhysicalDisplays.size() == 1) return true; |
| 8475 | |
| 8476 | LOG_ALWAYS_FATAL_IF(display.isVirtual()); |
| 8477 | const auto displayId = display.getPhysicalId(); |
| 8478 | |
| 8479 | // The display is powered off, and this is a multi-display device. If the display is the |
| 8480 | // inactive internal display of a dual-display foldable, then the policy will be applied |
| 8481 | // when it becomes active upon powering on. |
| 8482 | // |
| 8483 | // TODO(b/255635711): Remove this function (i.e. returning `false` as a special case) once |
| 8484 | // concurrent mode setting across multiple (potentially powered off) displays is supported. |
| 8485 | // |
| 8486 | return displayId == mActiveDisplayId || |
| 8487 | !mPhysicalDisplays.get(displayId) |
| 8488 | .transform(&PhysicalDisplay::isInternal) |
| 8489 | .value_or(false); |
| 8490 | } |
| 8491 | |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8492 | status_t SurfaceFlinger::applyRefreshRateSelectorPolicy( |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8493 | PhysicalDisplayId displayId, const scheduler::RefreshRateSelector& selector, bool force) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8494 | const scheduler::RefreshRateSelector::Policy currentPolicy = selector.getCurrentPolicy(); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8495 | ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str()); |
Adrian Salido | ab6ef6c | 2019-08-28 10:02:49 -0700 | [diff] [blame] | 8496 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 8497 | // TODO(b/140204874): Leave the event in until we do proper testing with all apps that might |
| 8498 | // be depending in this callback. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8499 | if (const auto activeMode = selector.getActiveMode(); displayId == mActiveDisplayId) { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8500 | mScheduler->onPrimaryDisplayModeChanged(scheduler::Cycle::Render, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8501 | toggleKernelIdleTimer(); |
| 8502 | } else { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8503 | mScheduler->onNonPrimaryDisplayModeChanged(scheduler::Cycle::Render, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8504 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 8505 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8506 | auto preferredModeOpt = getPreferredDisplayMode(displayId, currentPolicy.defaultMode); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8507 | if (!preferredModeOpt) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8508 | ALOGE("%s: Preferred mode is unknown", __func__); |
| 8509 | return NAME_NOT_FOUND; |
| 8510 | } |
| 8511 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8512 | auto preferredMode = std::move(*preferredModeOpt); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8513 | const auto preferredModeId = preferredMode.modePtr->getId(); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 8514 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8515 | const Fps preferredFps = preferredMode.fps; |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8516 | ALOGV("Switching to Scheduler preferred mode %d (%s)", ftl::to_underlying(preferredModeId), |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8517 | to_string(preferredFps).c_str()); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8518 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8519 | if (!selector.isModeAllowed(preferredMode)) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8520 | ALOGE("%s: Preferred mode %d is disallowed", __func__, ftl::to_underlying(preferredModeId)); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8521 | return INVALID_OPERATION; |
Dominik Laskowski | 4f1dd8c | 2019-04-17 15:54:30 -0700 | [diff] [blame] | 8522 | } |
| 8523 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 8524 | setDesiredMode({std::move(preferredMode), .emitEvent = true, .force = force}); |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 8525 | |
| 8526 | // Update the frameRateOverride list as the display render rate might have changed |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8527 | if (mScheduler->updateFrameRateOverrides(scheduler::GlobalSignals{}, preferredFps)) { |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 8528 | triggerOnFrameRateOverridesChanged(); |
| 8529 | } |
| 8530 | |
Ady Abraham | d9b3ea6 | 2019-02-26 14:08:03 -0800 | [diff] [blame] | 8531 | return NO_ERROR; |
| 8532 | } |
| 8533 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8534 | namespace { |
| 8535 | FpsRange translate(const gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange& aidlRange) { |
| 8536 | return FpsRange{Fps::fromValue(aidlRange.min), Fps::fromValue(aidlRange.max)}; |
| 8537 | } |
| 8538 | |
| 8539 | FpsRanges translate(const gui::DisplayModeSpecs::RefreshRateRanges& aidlRanges) { |
| 8540 | return FpsRanges{translate(aidlRanges.physical), translate(aidlRanges.render)}; |
| 8541 | } |
| 8542 | |
| 8543 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange translate(const FpsRange& range) { |
| 8544 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange aidlRange; |
| 8545 | aidlRange.min = range.min.getValue(); |
| 8546 | aidlRange.max = range.max.getValue(); |
| 8547 | return aidlRange; |
| 8548 | } |
| 8549 | |
| 8550 | gui::DisplayModeSpecs::RefreshRateRanges translate(const FpsRanges& ranges) { |
| 8551 | gui::DisplayModeSpecs::RefreshRateRanges aidlRanges; |
| 8552 | aidlRanges.physical = translate(ranges.physical); |
| 8553 | aidlRanges.render = translate(ranges.render); |
| 8554 | return aidlRanges; |
| 8555 | } |
| 8556 | |
| 8557 | } // namespace |
| 8558 | |
| 8559 | status_t SurfaceFlinger::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 8560 | const gui::DisplayModeSpecs& specs) { |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8561 | ATRACE_CALL(); |
| 8562 | |
| 8563 | if (!displayToken) { |
| 8564 | return BAD_VALUE; |
| 8565 | } |
| 8566 | |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 8567 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8568 | const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayToken)); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8569 | if (!display) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8570 | ALOGE("Attempt to set desired display modes for invalid display token %p", |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8571 | displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8572 | return NAME_NOT_FOUND; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8573 | } else if (display->isVirtual()) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8574 | ALOGW("Attempt to set desired display modes for virtual display"); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8575 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8576 | } else { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8577 | using Policy = scheduler::RefreshRateSelector::DisplayManagerPolicy; |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8578 | const Policy policy{DisplayModeId(specs.defaultMode), translate(specs.primaryRanges), |
| 8579 | translate(specs.appRequestRanges), specs.allowGroupSwitching}; |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 8580 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8581 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8582 | } |
| 8583 | }); |
| 8584 | |
| 8585 | return future.get(); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8586 | } |
| 8587 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 8588 | status_t SurfaceFlinger::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8589 | gui::DisplayModeSpecs* outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8590 | ATRACE_CALL(); |
| 8591 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8592 | if (!displayToken || !outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8593 | return BAD_VALUE; |
| 8594 | } |
| 8595 | |
| 8596 | Mutex::Autolock lock(mStateLock); |
| 8597 | const auto display = getDisplayDeviceLocked(displayToken); |
| 8598 | if (!display) { |
| 8599 | return NAME_NOT_FOUND; |
| 8600 | } |
| 8601 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8602 | if (display->isVirtual()) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 8603 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8604 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8605 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8606 | scheduler::RefreshRateSelector::Policy policy = |
| 8607 | display->refreshRateSelector().getDisplayManagerPolicy(); |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8608 | outSpecs->defaultMode = ftl::to_underlying(policy.defaultMode); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8609 | outSpecs->allowGroupSwitching = policy.allowGroupSwitching; |
| 8610 | outSpecs->primaryRanges = translate(policy.primaryRanges); |
| 8611 | outSpecs->appRequestRanges = translate(policy.appRequestRanges); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8612 | return NO_ERROR; |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8613 | } |
| 8614 | |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 8615 | void SurfaceFlinger::onLayerFirstRef(Layer* layer) { |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8616 | mNumLayers++; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8617 | if (!layer->isRemovedFromCurrentState()) { |
| 8618 | mScheduler->registerLayer(layer); |
| 8619 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8620 | } |
| 8621 | |
| 8622 | void SurfaceFlinger::onLayerDestroyed(Layer* layer) { |
| 8623 | mNumLayers--; |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8624 | removeHierarchyFromOffscreenLayers(layer); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8625 | if (!layer->isRemovedFromCurrentState()) { |
| 8626 | mScheduler->deregisterLayer(layer); |
| 8627 | } |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 8628 | if (mTransactionTracing) { |
| 8629 | mTransactionTracing->onLayerRemoved(layer->getSequence()); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 8630 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 8631 | mScheduler->onLayerDestroyed(layer); |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8632 | } |
| 8633 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8634 | void SurfaceFlinger::onLayerUpdate() { |
| 8635 | scheduleCommit(FrameHint::kActive); |
| 8636 | } |
| 8637 | |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8638 | // WARNING: ONLY CALL THIS FROM LAYER DTOR |
| 8639 | // Here we add children in the current state to offscreen layers and remove the |
| 8640 | // layer itself from the offscreen layer list. Since |
| 8641 | // this is the dtor, it is safe to access the current state. This keeps us |
| 8642 | // from dangling children layers such that they are not reachable from the |
| 8643 | // Drawing state nor the offscreen layer list |
| 8644 | // See b/141111965 |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8645 | void SurfaceFlinger::removeHierarchyFromOffscreenLayers(Layer* layer) { |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8646 | for (auto& child : layer->getCurrentChildren()) { |
| 8647 | mOffscreenLayers.emplace(child.get()); |
| 8648 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8649 | mOffscreenLayers.erase(layer); |
| 8650 | } |
| 8651 | |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8652 | void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) { |
| 8653 | mOffscreenLayers.erase(layer); |
| 8654 | } |
| 8655 | |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 8656 | status_t SurfaceFlinger::setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, |
| 8657 | float lightPosY, float lightPosZ, |
| 8658 | float lightRadius) { |
| 8659 | Mutex::Autolock _l(mStateLock); |
| 8660 | mCurrentState.globalShadowSettings.ambientColor = vec4(ambientColor); |
| 8661 | mCurrentState.globalShadowSettings.spotColor = vec4(spotColor); |
| 8662 | mCurrentState.globalShadowSettings.lightPos.y = lightPosY; |
| 8663 | mCurrentState.globalShadowSettings.lightPos.z = lightPosZ; |
| 8664 | mCurrentState.globalShadowSettings.lightRadius = lightRadius; |
| 8665 | |
| 8666 | // these values are overridden when calculating the shadow settings for a layer. |
| 8667 | mCurrentState.globalShadowSettings.lightPos.x = 0.f; |
| 8668 | mCurrentState.globalShadowSettings.length = 0.f; |
Vishnu Nair | b13bb95 | 2019-11-15 10:24:08 -0800 | [diff] [blame] | 8669 | return NO_ERROR; |
| 8670 | } |
| 8671 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8672 | const std::unordered_map<std::string, uint32_t>& SurfaceFlinger::getGenericLayerMetadataKeyMap() |
| 8673 | const { |
| 8674 | // TODO(b/149500060): Remove this fixed/static mapping. Please prefer taking |
| 8675 | // on the work to remove the table in that bug rather than adding more to |
| 8676 | // it. |
| 8677 | static const std::unordered_map<std::string, uint32_t> genericLayerMetadataKeyMap{ |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8678 | {"org.chromium.arc.V1_0.TaskId", gui::METADATA_TASK_ID}, |
| 8679 | {"org.chromium.arc.V1_0.CursorInfo", gui::METADATA_MOUSE_CURSOR}, |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8680 | }; |
| 8681 | return genericLayerMetadataKeyMap; |
| 8682 | } |
| 8683 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8684 | status_t SurfaceFlinger::setGameModeFrameRateOverride(uid_t uid, float frameRate) { |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 8685 | PhysicalDisplayId displayId = [&]() { |
| 8686 | Mutex::Autolock lock(mStateLock); |
| 8687 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 8688 | }(); |
| 8689 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8690 | mScheduler->setGameModeFrameRateForUid(FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8691 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 8692 | return NO_ERROR; |
| 8693 | } |
| 8694 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8695 | status_t SurfaceFlinger::setGameDefaultFrameRateOverride(uid_t uid, float frameRate) { |
| 8696 | if (FlagManager::getInstance().game_default_frame_rate()) { |
| 8697 | mScheduler->setGameDefaultFrameRateForUid( |
| 8698 | FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
| 8699 | } |
| 8700 | return NO_ERROR; |
| 8701 | } |
| 8702 | |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8703 | status_t SurfaceFlinger::updateSmallAreaDetection( |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 8704 | std::vector<std::pair<int32_t, float>>& appIdThresholdMappings) { |
| 8705 | mScheduler->updateSmallAreaDetection(appIdThresholdMappings); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8706 | return NO_ERROR; |
| 8707 | } |
| 8708 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 8709 | status_t SurfaceFlinger::setSmallAreaDetectionThreshold(int32_t appId, float threshold) { |
| 8710 | mScheduler->setSmallAreaDetectionThreshold(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8711 | return NO_ERROR; |
| 8712 | } |
| 8713 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8714 | void SurfaceFlinger::enableRefreshRateOverlay(bool enable) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 8715 | bool setByHwc = getHwComposer().hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8716 | for (const auto& [id, display] : mPhysicalDisplays) { |
Sally Qi | de329f2 | 2023-09-26 16:21:39 -0700 | [diff] [blame] | 8717 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal || |
| 8718 | FlagManager::getInstance().refresh_rate_overlay_on_external_display()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8719 | if (const auto device = getDisplayDeviceLocked(id)) { |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 8720 | const auto enableOverlay = [&](const bool setByHwc) FTL_FAKE_GUARD( |
| 8721 | kMainThreadContext) { |
| 8722 | device->enableRefreshRateOverlay(enable, setByHwc, mRefreshRateOverlaySpinner, |
| 8723 | mRefreshRateOverlayRenderRate, |
| 8724 | mRefreshRateOverlayShowInMiddle); |
| 8725 | }; |
| 8726 | enableOverlay(setByHwc); |
| 8727 | if (setByHwc) { |
| 8728 | const auto status = |
| 8729 | getHwComposer().setRefreshRateChangedCallbackDebugEnabled(id, enable); |
| 8730 | if (status != NO_ERROR) { |
| 8731 | ALOGE("Error updating the refresh rate changed callback debug enabled"); |
| 8732 | enableOverlay(/*setByHwc*/ false); |
| 8733 | } |
| 8734 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8735 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8736 | } |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 8737 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8738 | } |
| 8739 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 8740 | void SurfaceFlinger::enableHdrSdrRatioOverlay(bool enable) { |
| 8741 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 8742 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal) { |
| 8743 | if (const auto device = getDisplayDeviceLocked(id)) { |
| 8744 | device->enableHdrSdrRatioOverlay(enable); |
| 8745 | } |
| 8746 | } |
| 8747 | } |
| 8748 | } |
| 8749 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8750 | int SurfaceFlinger::getGpuContextPriority() { |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 8751 | return getRenderEngine().getContextPriority(); |
Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 8752 | } |
| 8753 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8754 | int SurfaceFlinger::calculateMaxAcquiredBufferCount(Fps refreshRate, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8755 | std::chrono::nanoseconds presentLatency) { |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8756 | auto pipelineDepth = presentLatency.count() / refreshRate.getPeriodNsecs(); |
| 8757 | if (presentLatency.count() % refreshRate.getPeriodNsecs()) { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8758 | pipelineDepth++; |
| 8759 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8760 | return std::max(minAcquiredBuffers, static_cast<int64_t>(pipelineDepth - 1)); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8761 | } |
| 8762 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8763 | status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 8764 | Fps maxRefreshRate = 60_Hz; |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8765 | |
| 8766 | if (!getHwComposer().isHeadless()) { |
| 8767 | if (const auto display = getDefaultDisplayDevice()) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8768 | maxRefreshRate = display->refreshRateSelector().getSupportedRefreshRateRange().max; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8769 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8770 | } |
| 8771 | |
| 8772 | *buffers = getMaxAcquiredBufferCountForRefreshRate(maxRefreshRate); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8773 | return NO_ERROR; |
| 8774 | } |
| 8775 | |
rnlee | ed20fa4 | 2021-08-10 18:00:03 -0700 | [diff] [blame] | 8776 | uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 8777 | Fps refreshRate = 60_Hz; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8778 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8779 | if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) { |
| 8780 | refreshRate = *frameRateOverride; |
| 8781 | } else if (!getHwComposer().isHeadless()) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8782 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked())) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8783 | refreshRate = display->refreshRateSelector().getActiveMode().fps; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8784 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8785 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8786 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8787 | return getMaxAcquiredBufferCountForRefreshRate(refreshRate); |
| 8788 | } |
| 8789 | |
| 8790 | int SurfaceFlinger::getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 8791 | const auto vsyncConfig = |
| 8792 | mScheduler->getVsyncConfiguration().getConfigsForRefreshRate(refreshRate).late; |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8793 | const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration; |
| 8794 | return calculateMaxAcquiredBufferCount(refreshRate, presentLatency); |
| 8795 | } |
| 8796 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 8797 | void SurfaceFlinger::handleLayerCreatedLocked(const LayerCreatedState& state, VsyncId vsyncId) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8798 | sp<Layer> layer = state.layer.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8799 | if (!layer) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8800 | ALOGD("Layer was destroyed soon after creation %p", state.layer.unsafe_get()); |
| 8801 | return; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8802 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 8803 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8804 | |
| 8805 | sp<Layer> parent; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8806 | bool addToRoot = state.addToRoot; |
| 8807 | if (state.initialParent != nullptr) { |
| 8808 | parent = state.initialParent.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8809 | if (parent == nullptr) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8810 | ALOGD("Parent was destroyed soon after creation %p", state.initialParent.unsafe_get()); |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 8811 | addToRoot = false; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8812 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8813 | } |
| 8814 | |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 8815 | if (parent == nullptr && addToRoot) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 8816 | layer->setIsAtRoot(true); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8817 | mCurrentState.layersSortedByZ.add(layer); |
| 8818 | } else if (parent == nullptr) { |
| 8819 | layer->onRemovedFromCurrentState(); |
| 8820 | } else if (parent->isRemovedFromCurrentState()) { |
| 8821 | parent->addChild(layer); |
| 8822 | layer->onRemovedFromCurrentState(); |
| 8823 | } else { |
| 8824 | parent->addChild(layer); |
| 8825 | } |
| 8826 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 8827 | ui::LayerStack layerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 8828 | sp<const DisplayDevice> hintDisplay; |
| 8829 | // Find the display that includes the layer. |
| 8830 | for (const auto& [token, display] : mDisplays) { |
| 8831 | if (display->getLayerStack() == layerStack) { |
| 8832 | hintDisplay = display; |
| 8833 | break; |
| 8834 | } |
| 8835 | } |
| 8836 | |
| 8837 | if (hintDisplay) { |
| 8838 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
| 8839 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8840 | } |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8841 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8842 | void SurfaceFlinger::sample() { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8843 | if (!mLumaSampling || !mRegionSamplingThread) { |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8844 | return; |
| 8845 | } |
| 8846 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 8847 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 8848 | const auto scheduleFrameTimeOpt = scheduledFrameResultOpt |
| 8849 | ? std::optional{scheduledFrameResultOpt->callbackTime} |
| 8850 | : std::nullopt; |
| 8851 | mRegionSamplingThread->onCompositionComplete(scheduleFrameTimeOpt); |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8852 | } |
| 8853 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8854 | void SurfaceFlinger::onActiveDisplaySizeChanged(const DisplayDevice& activeDisplay) { |
| 8855 | mScheduler->onActiveDisplayAreaChanged(activeDisplay.getWidth() * activeDisplay.getHeight()); |
| 8856 | getRenderEngine().onActiveDisplaySizeChanged(activeDisplay.getSize()); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8857 | } |
| 8858 | |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 8859 | sp<DisplayDevice> SurfaceFlinger::getActivatableDisplay() const { |
| 8860 | if (mPhysicalDisplays.size() == 1) return nullptr; |
| 8861 | |
| 8862 | // TODO(b/255635821): Choose the pacesetter display, considering both internal and external |
| 8863 | // displays. For now, pick the other internal display, assuming a dual-display foldable. |
| 8864 | return findDisplay([this](const DisplayDevice& display) REQUIRES(mStateLock) { |
| 8865 | const auto idOpt = PhysicalDisplayId::tryCast(display.getId()); |
| 8866 | return idOpt && *idOpt != mActiveDisplayId && display.isPoweredOn() && |
| 8867 | mPhysicalDisplays.get(*idOpt) |
| 8868 | .transform(&PhysicalDisplay::isInternal) |
| 8869 | .value_or(false); |
| 8870 | }); |
| 8871 | } |
| 8872 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8873 | void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveDisplayPtr, |
| 8874 | const DisplayDevice& activeDisplay) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8875 | ATRACE_CALL(); |
| 8876 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8877 | // For the first display activated during boot, there is no need to force setDesiredMode, |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 8878 | // because DM is about to send its policy via setDesiredDisplayModeSpecs. |
| 8879 | bool forceApplyPolicy = false; |
| 8880 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8881 | if (inactiveDisplayPtr) { |
| 8882 | inactiveDisplayPtr->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false); |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 8883 | forceApplyPolicy = true; |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 8884 | } |
| 8885 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8886 | mActiveDisplayId = activeDisplay.getPhysicalId(); |
| 8887 | activeDisplay.getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 8888 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 8889 | mScheduler->resetPhaseConfiguration(activeDisplay.getActiveMode().fps); |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 8890 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8891 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8892 | mScheduler->setModeChangePending(false); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8893 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 8894 | mScheduler->setPacesetterDisplay(mActiveDisplayId); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 8895 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8896 | onActiveDisplaySizeChanged(activeDisplay); |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8897 | mActiveDisplayTransformHint = activeDisplay.getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 8898 | sActiveDisplayRotationFlags = ui::Transform::toRotationFlags(activeDisplay.getOrientation()); |
Ady Abraham | 85d692d | 2021-09-28 14:08:54 -0700 | [diff] [blame] | 8899 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 8900 | // The policy of the new active/pacesetter display may have changed while it was inactive. In |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8901 | // that case, its preferred mode has not been propagated to HWC (via setDesiredMode). In either |
| 8902 | // case, the Scheduler's cachedModeChangedParams must be initialized to the newly active mode, |
| 8903 | // and the kernel idle timer of the newly active display must be toggled. |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 8904 | applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay.refreshRateSelector(), |
| 8905 | forceApplyPolicy); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8906 | } |
| 8907 | |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 8908 | status_t SurfaceFlinger::addWindowInfosListener(const sp<IWindowInfosListener>& windowInfosListener, |
| 8909 | gui::WindowInfosListenerInfo* outInfo) { |
| 8910 | mWindowInfosListenerInvoker->addWindowInfosListener(windowInfosListener, outInfo); |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 8911 | setTransactionFlags(eInputInfoUpdateNeeded); |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 8912 | return NO_ERROR; |
| 8913 | } |
| 8914 | |
| 8915 | status_t SurfaceFlinger::removeWindowInfosListener( |
| 8916 | const sp<IWindowInfosListener>& windowInfosListener) const { |
| 8917 | mWindowInfosListenerInvoker->removeWindowInfosListener(windowInfosListener); |
| 8918 | return NO_ERROR; |
| 8919 | } |
| 8920 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 8921 | status_t SurfaceFlinger::getStalledTransactionInfo( |
| 8922 | int pid, std::optional<TransactionHandler::StalledTransactionInfo>& result) { |
| 8923 | result = mTransactionHandler.getStalledTransactionInfo(pid); |
| 8924 | return NO_ERROR; |
| 8925 | } |
| 8926 | |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 8927 | void SurfaceFlinger::updateHdcpLevels(hal::HWDisplayId hwcDisplayId, int32_t connectedLevel, |
| 8928 | int32_t maxLevel) { |
| 8929 | if (!FlagManager::getInstance().connected_display()) { |
| 8930 | return; |
| 8931 | } |
| 8932 | |
| 8933 | Mutex::Autolock lock(mStateLock); |
| 8934 | |
| 8935 | const auto idOpt = getHwComposer().toPhysicalDisplayId(hwcDisplayId); |
| 8936 | if (!idOpt) { |
| 8937 | ALOGE("No display found for HDCP level changed event: connected=%d, max=%d for " |
| 8938 | "display=%" PRIu64, |
| 8939 | connectedLevel, maxLevel, hwcDisplayId); |
| 8940 | return; |
| 8941 | } |
| 8942 | |
| 8943 | const bool isInternalDisplay = |
| 8944 | mPhysicalDisplays.get(*idOpt).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 8945 | if (isInternalDisplay) { |
| 8946 | ALOGW("Unexpected HDCP level changed for internal display: connected=%d, max=%d for " |
| 8947 | "display=%" PRIu64, |
| 8948 | connectedLevel, maxLevel, hwcDisplayId); |
| 8949 | return; |
| 8950 | } |
| 8951 | |
| 8952 | static_cast<void>(mScheduler->schedule([this, displayId = *idOpt, connectedLevel, maxLevel]() { |
| 8953 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayId))) { |
| 8954 | Mutex::Autolock lock(mStateLock); |
| 8955 | display->setSecure(connectedLevel >= 2 /* HDCP_V1 */); |
| 8956 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8957 | mScheduler->onHdcpLevelsChanged(scheduler::Cycle::Render, displayId, connectedLevel, |
| 8958 | maxLevel); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 8959 | })); |
| 8960 | } |
| 8961 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8962 | std::shared_ptr<renderengine::ExternalTexture> SurfaceFlinger::getExternalTextureFromBufferData( |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8963 | BufferData& bufferData, const char* layerName, uint64_t transactionId) { |
| 8964 | if (bufferData.buffer && |
| 8965 | exceedsMaxRenderTargetSize(bufferData.buffer->getWidth(), bufferData.buffer->getHeight())) { |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 8966 | std::string errorMessage = |
| 8967 | base::StringPrintf("Attempted to create an ExternalTexture with size (%u, %u) for " |
| 8968 | "layer %s that exceeds render target size limit of %u.", |
| 8969 | bufferData.buffer->getWidth(), bufferData.buffer->getHeight(), |
| 8970 | layerName, static_cast<uint32_t>(mMaxRenderTargetSize)); |
| 8971 | ALOGD("%s", errorMessage.c_str()); |
| 8972 | if (bufferData.releaseBufferListener) { |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 8973 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
| 8974 | String8(errorMessage.c_str())); |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 8975 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8976 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8977 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8978 | |
| 8979 | bool cachedBufferChanged = |
| 8980 | bufferData.flags.test(BufferData::BufferDataChange::cachedBufferChanged); |
| 8981 | if (cachedBufferChanged && bufferData.buffer) { |
| 8982 | auto result = ClientCache::getInstance().add(bufferData.cachedBuffer, bufferData.buffer); |
| 8983 | if (result.ok()) { |
| 8984 | return result.value(); |
| 8985 | } |
| 8986 | |
| 8987 | if (result.error() == ClientCache::AddError::CacheFull) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 8988 | ALOGE("Attempted to create an ExternalTexture for layer %s but CacheFull", layerName); |
| 8989 | |
| 8990 | if (bufferData.releaseBufferListener) { |
| 8991 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 8992 | String8("Buffer processing hung due to full buffer cache")); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 8993 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8994 | } |
| 8995 | |
| 8996 | return nullptr; |
| 8997 | } |
| 8998 | |
| 8999 | if (cachedBufferChanged) { |
| 9000 | return ClientCache::getInstance().get(bufferData.cachedBuffer); |
| 9001 | } |
| 9002 | |
| 9003 | if (bufferData.buffer) { |
| 9004 | return std::make_shared< |
| 9005 | renderengine::impl::ExternalTexture>(bufferData.buffer, getRenderEngine(), |
| 9006 | renderengine::impl::ExternalTexture::Usage:: |
| 9007 | READABLE); |
| 9008 | } |
| 9009 | |
| 9010 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 9011 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9012 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 9013 | bool SurfaceFlinger::commitMirrorDisplays(VsyncId vsyncId) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9014 | std::vector<MirrorDisplayState> mirrorDisplays; |
| 9015 | { |
| 9016 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
| 9017 | mirrorDisplays = std::move(mMirrorDisplays); |
| 9018 | mMirrorDisplays.clear(); |
| 9019 | if (mirrorDisplays.size() == 0) { |
| 9020 | return false; |
| 9021 | } |
| 9022 | } |
| 9023 | |
| 9024 | sp<IBinder> unused; |
| 9025 | for (const auto& mirrorDisplay : mirrorDisplays) { |
| 9026 | // Set mirror layer's default layer stack to -1 so it doesn't end up rendered on a display |
| 9027 | // accidentally. |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 9028 | sp<Layer> rootMirrorLayer = LayerHandle::getLayer(mirrorDisplay.rootHandle); |
Qi Jing | b8e4c13 | 2023-08-25 23:01:47 +0000 | [diff] [blame] | 9029 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(rootMirrorLayer); |
| 9030 | bool ret = rootMirrorLayer->setLayerStack(ui::LayerStack::fromValue(-1)); |
| 9031 | if (idx >= 0 && ret) { |
| 9032 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 9033 | mCurrentState.layersSortedByZ.add(rootMirrorLayer); |
| 9034 | } |
| 9035 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9036 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 9037 | if (layer->getLayerStack() != mirrorDisplay.layerStack || |
| 9038 | layer->isInternalDisplayOverlay()) { |
| 9039 | continue; |
| 9040 | } |
| 9041 | |
| 9042 | LayerCreationArgs mirrorArgs(this, mirrorDisplay.client, "MirrorLayerParent", |
| 9043 | ISurfaceComposerClient::eNoColorFill, |
| 9044 | gui::LayerMetadata()); |
| 9045 | sp<Layer> childMirror; |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 9046 | { |
| 9047 | Mutex::Autolock lock(mStateLock); |
| 9048 | createEffectLayer(mirrorArgs, &unused, &childMirror); |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 9049 | MUTEX_ALIAS(mStateLock, childMirror->mFlinger->mStateLock); |
Vishnu Nair | de17725 | 2023-04-21 12:44:10 -0700 | [diff] [blame] | 9050 | childMirror->setClonedChild(layer->createClone(childMirror->getSequence())); |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 9051 | childMirror->reparent(mirrorDisplay.rootHandle); |
| 9052 | } |
| 9053 | // lock on mStateLock needs to be released before binder handle gets destroyed |
| 9054 | unused.clear(); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9055 | } |
| 9056 | } |
| 9057 | return true; |
| 9058 | } |
| 9059 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9060 | bool SurfaceFlinger::commitCreatedLayers(VsyncId vsyncId, |
| 9061 | std::vector<LayerCreatedState>& createdLayers) { |
| 9062 | if (createdLayers.size() == 0) { |
| 9063 | return false; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9064 | } |
| 9065 | |
| 9066 | Mutex::Autolock _l(mStateLock); |
| 9067 | for (const auto& createdLayer : createdLayers) { |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 9068 | handleLayerCreatedLocked(createdLayer, vsyncId); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9069 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9070 | mLayersAdded = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9071 | return mLayersAdded; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9072 | } |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9073 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 9074 | void SurfaceFlinger::updateLayerMetadataSnapshot() { |
| 9075 | LayerMetadata parentMetadata; |
| 9076 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 9077 | layer->updateMetadataSnapshot(parentMetadata); |
| 9078 | } |
| 9079 | |
| 9080 | std::unordered_set<Layer*> visited; |
| 9081 | mDrawingState.traverse([&visited](Layer* layer) { |
| 9082 | if (visited.find(layer) != visited.end()) { |
| 9083 | return; |
| 9084 | } |
| 9085 | |
| 9086 | // If the layer isRelativeOf, then either it's relative metadata will be set |
| 9087 | // recursively when updateRelativeMetadataSnapshot is called on its relative parent or |
| 9088 | // it's relative parent has been deleted. Clear the layer's relativeLayerMetadata to ensure |
| 9089 | // that layers with deleted relative parents don't hold stale relativeLayerMetadata. |
| 9090 | if (layer->getDrawingState().isRelativeOf) { |
| 9091 | layer->editLayerSnapshot()->relativeLayerMetadata = {}; |
| 9092 | return; |
| 9093 | } |
| 9094 | |
| 9095 | layer->updateRelativeMetadataSnapshot({}, visited); |
| 9096 | }); |
| 9097 | } |
| 9098 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9099 | void SurfaceFlinger::moveSnapshotsFromCompositionArgs( |
| 9100 | compositionengine::CompositionRefreshArgs& refreshArgs, |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 9101 | const std::vector<std::pair<Layer*, LayerFE*>>& layers) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9102 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9103 | std::vector<std::unique_ptr<frontend::LayerSnapshot>>& snapshots = |
| 9104 | mLayerSnapshotBuilder.getSnapshots(); |
| 9105 | for (auto [_, layerFE] : layers) { |
| 9106 | auto i = layerFE->mSnapshot->globalZ; |
| 9107 | snapshots[i] = std::move(layerFE->mSnapshot); |
| 9108 | } |
| 9109 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9110 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9111 | for (auto [layer, layerFE] : layers) { |
| 9112 | layer->updateLayerSnapshot(std::move(layerFE->mSnapshot)); |
| 9113 | } |
| 9114 | } |
| 9115 | } |
| 9116 | |
| 9117 | std::vector<std::pair<Layer*, LayerFE*>> SurfaceFlinger::moveSnapshotsToCompositionArgs( |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 9118 | compositionengine::CompositionRefreshArgs& refreshArgs, bool cursorOnly) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9119 | std::vector<std::pair<Layer*, LayerFE*>> layers; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9120 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9121 | nsecs_t currentTime = systemTime(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9122 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 9123 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 9124 | if (cursorOnly && |
| 9125 | snapshot->compositionType != |
| 9126 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) { |
| 9127 | return; |
| 9128 | } |
| 9129 | |
| 9130 | if (!snapshot->hasSomethingToDraw()) { |
| 9131 | return; |
| 9132 | } |
| 9133 | |
| 9134 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 9135 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 9136 | "Couldnt find layer object for %s", |
| 9137 | snapshot->getDebugString().c_str()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9138 | auto& legacyLayer = it->second; |
| 9139 | sp<LayerFE> layerFE = legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9140 | snapshot->fps = getLayerFramerate(currentTime, snapshot->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9141 | layerFE->mSnapshot = std::move(snapshot); |
| 9142 | refreshArgs.layers.push_back(layerFE); |
| 9143 | layers.emplace_back(legacyLayer.get(), layerFE.get()); |
| 9144 | }); |
| 9145 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9146 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 9147 | auto moveSnapshots = [&layers, &refreshArgs, cursorOnly](Layer* layer) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9148 | if (const auto& layerFE = layer->getCompositionEngineLayerFE()) { |
| 9149 | if (cursorOnly && |
| 9150 | layer->getLayerSnapshot()->compositionType != |
| 9151 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) |
| 9152 | return; |
| 9153 | layer->updateSnapshot(refreshArgs.updatingGeometryThisFrame); |
| 9154 | layerFE->mSnapshot = layer->stealLayerSnapshot(); |
| 9155 | refreshArgs.layers.push_back(layerFE); |
| 9156 | layers.emplace_back(layer, layerFE.get()); |
| 9157 | } |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 9158 | }; |
| 9159 | |
| 9160 | if (cursorOnly || !mVisibleRegionsDirty) { |
| 9161 | // for hot path avoid traversals by walking though the previous composition list |
| 9162 | for (sp<Layer> layer : mPreviouslyComposedLayers) { |
| 9163 | moveSnapshots(layer.get()); |
| 9164 | } |
| 9165 | } else { |
| 9166 | mPreviouslyComposedLayers.clear(); |
| 9167 | mDrawingState.traverseInZOrder( |
| 9168 | [&moveSnapshots](Layer* layer) { moveSnapshots(layer); }); |
| 9169 | mPreviouslyComposedLayers.reserve(layers.size()); |
| 9170 | for (auto [layer, _] : layers) { |
| 9171 | mPreviouslyComposedLayers.push_back(sp<Layer>::fromExisting(layer)); |
| 9172 | } |
| 9173 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9174 | } |
| 9175 | |
| 9176 | return layers; |
| 9177 | } |
| 9178 | |
| 9179 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9180 | SurfaceFlinger::getLayerSnapshotsForScreenshots( |
| 9181 | std::optional<ui::LayerStack> layerStack, uint32_t uid, |
| 9182 | std::function<bool(const frontend::LayerSnapshot&, bool& outStopTraversal)> |
| 9183 | snapshotFilterFn) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9184 | return [&, layerStack, uid]() { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9185 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers; |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9186 | bool stopTraversal = false; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9187 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 9188 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9189 | if (stopTraversal) { |
| 9190 | return; |
| 9191 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9192 | if (layerStack && snapshot->outputFilter.layerStack != *layerStack) { |
| 9193 | return; |
| 9194 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 9195 | if (uid != CaptureArgs::UNSET_UID && snapshot->uid != gui::Uid(uid)) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9196 | return; |
| 9197 | } |
| 9198 | if (!snapshot->hasSomethingToDraw()) { |
| 9199 | return; |
| 9200 | } |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9201 | if (snapshotFilterFn && !snapshotFilterFn(*snapshot, stopTraversal)) { |
| 9202 | return; |
| 9203 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9204 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9205 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 9206 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 9207 | "Couldnt find layer object for %s", |
| 9208 | snapshot->getDebugString().c_str()); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9209 | Layer* legacyLayer = (it == mLegacyLayers.end()) ? nullptr : it->second.get(); |
| 9210 | sp<LayerFE> layerFE = getFactory().createLayerFE(snapshot->name); |
| 9211 | layerFE->mSnapshot = std::make_unique<frontend::LayerSnapshot>(*snapshot); |
| 9212 | layers.emplace_back(legacyLayer, std::move(layerFE)); |
| 9213 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9214 | |
| 9215 | return layers; |
| 9216 | }; |
| 9217 | } |
| 9218 | |
| 9219 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9220 | SurfaceFlinger::getLayerSnapshotsForScreenshots(std::optional<ui::LayerStack> layerStack, |
| 9221 | uint32_t uid, |
| 9222 | std::unordered_set<uint32_t> excludeLayerIds) { |
| 9223 | return [&, layerStack, uid, excludeLayerIds = std::move(excludeLayerIds)]() { |
| 9224 | if (excludeLayerIds.empty()) { |
| 9225 | auto getLayerSnapshotsFn = |
| 9226 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 9227 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9228 | return layers; |
| 9229 | } |
| 9230 | |
| 9231 | frontend::LayerSnapshotBuilder::Args |
| 9232 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 9233 | .layerLifecycleManager = mLayerLifecycleManager, |
| 9234 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
| 9235 | .displays = mFrontEndDisplayInfos, |
| 9236 | .displayChanges = true, |
| 9237 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9238 | .supportsBlur = mSupportsBlur, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9239 | .forceFullDamage = mForceFullDamage, |
| 9240 | .excludeLayerIds = std::move(excludeLayerIds), |
| 9241 | .supportedLayerGenericMetadata = |
| 9242 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 9243 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 9244 | .skipRoundCornersWhenProtected = |
| 9245 | !getRenderEngine().supportsProtectedContent()}; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9246 | mLayerSnapshotBuilder.update(args); |
| 9247 | |
| 9248 | auto getLayerSnapshotsFn = |
| 9249 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 9250 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9251 | |
| 9252 | args.excludeLayerIds.clear(); |
| 9253 | mLayerSnapshotBuilder.update(args); |
| 9254 | |
| 9255 | return layers; |
| 9256 | }; |
| 9257 | } |
| 9258 | |
| 9259 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9260 | SurfaceFlinger::getLayerSnapshotsForScreenshots(uint32_t rootLayerId, uint32_t uid, |
| 9261 | std::unordered_set<uint32_t> excludeLayerIds, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 9262 | bool childrenOnly, |
| 9263 | const std::optional<FloatRect>& parentCrop) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9264 | return [&, rootLayerId, uid, excludeLayerIds = std::move(excludeLayerIds), childrenOnly, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9265 | parentCrop]() { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9266 | auto root = mLayerHierarchyBuilder.getPartialHierarchy(rootLayerId, childrenOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9267 | frontend::LayerSnapshotBuilder::Args |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9268 | args{.root = root, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9269 | .layerLifecycleManager = mLayerLifecycleManager, |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9270 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9271 | .displays = mFrontEndDisplayInfos, |
| 9272 | .displayChanges = true, |
| 9273 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9274 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9275 | .forceFullDamage = mForceFullDamage, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 9276 | .parentCrop = parentCrop, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9277 | .excludeLayerIds = std::move(excludeLayerIds), |
| 9278 | .supportedLayerGenericMetadata = |
| 9279 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 9280 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 9281 | .skipRoundCornersWhenProtected = |
| 9282 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | c54fdb0 | 2023-11-21 17:19:58 -0800 | [diff] [blame] | 9283 | // The layer may not exist if it was just created and a screenshot was requested immediately |
| 9284 | // after. In this case, the hierarchy will be empty so we will not render any layers. |
| 9285 | args.rootSnapshot.isSecure = mLayerLifecycleManager.getLayerFromId(rootLayerId) && |
| 9286 | mLayerLifecycleManager.isLayerSecure(rootLayerId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9287 | mLayerSnapshotBuilder.update(args); |
| 9288 | |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9289 | auto getLayerSnapshotsFn = |
| 9290 | getLayerSnapshotsForScreenshots({}, uid, /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9291 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9292 | args.root = mLayerHierarchyBuilder.getHierarchy(); |
| 9293 | args.parentCrop.reset(); |
| 9294 | args.excludeLayerIds.clear(); |
| 9295 | mLayerSnapshotBuilder.update(args); |
| 9296 | return layers; |
| 9297 | }; |
| 9298 | } |
| 9299 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9300 | frontend::Update SurfaceFlinger::flushLifecycleUpdates() { |
| 9301 | frontend::Update update; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9302 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 9303 | // Locking: |
| 9304 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 9305 | // we must keep a copy of the transactions (specifically the composer |
| 9306 | // states) around outside the scope of the lock. |
| 9307 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 9308 | // transactions with layers still in the createdLayer queue, flush the transactions |
| 9309 | // before committing the created layers. |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 9310 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9311 | update.transactions = mTransactionHandler.flushTransactions(); |
| 9312 | { |
| 9313 | // TODO(b/238781169) lockless queue this and keep order. |
| 9314 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 9315 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 9316 | mCreatedLayers.clear(); |
| 9317 | update.newLayers = std::move(mNewLayers); |
| 9318 | mNewLayers.clear(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9319 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 9320 | mNewLayerArgs.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9321 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 9322 | mDestroyedHandles.clear(); |
| 9323 | } |
| 9324 | return update; |
| 9325 | } |
| 9326 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9327 | void SurfaceFlinger::doActiveLayersTracingIfNeeded(bool isCompositionComputed, |
| 9328 | bool visibleRegionDirty, TimePoint time, |
| 9329 | VsyncId vsyncId) { |
| 9330 | if (!mLayerTracing.isActiveTracingStarted()) { |
| 9331 | return; |
| 9332 | } |
| 9333 | if (isCompositionComputed != |
| 9334 | mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_COMPOSITION)) { |
| 9335 | return; |
| 9336 | } |
| 9337 | if (!visibleRegionDirty && |
| 9338 | !mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_BUFFERS)) { |
| 9339 | return; |
| 9340 | } |
| 9341 | auto snapshot = takeLayersSnapshotProto(mLayerTracing.getActiveTracingFlags(), time, vsyncId, |
| 9342 | visibleRegionDirty); |
| 9343 | mLayerTracing.addProtoSnapshotToOstream(std::move(snapshot), LayerTracing::Mode::MODE_ACTIVE); |
| 9344 | } |
| 9345 | |
| 9346 | perfetto::protos::LayersSnapshotProto SurfaceFlinger::takeLayersSnapshotProto( |
| 9347 | uint32_t traceFlags, TimePoint time, VsyncId vsyncId, bool visibleRegionDirty) { |
| 9348 | ATRACE_CALL(); |
| 9349 | perfetto::protos::LayersSnapshotProto snapshot; |
| 9350 | snapshot.set_elapsed_realtime_nanos(time.ns()); |
| 9351 | snapshot.set_vsync_id(ftl::to_underlying(vsyncId)); |
| 9352 | snapshot.set_where(visibleRegionDirty ? "visibleRegionsDirty" : "bufferLatched"); |
| 9353 | snapshot.set_excludes_composition_state((traceFlags & LayerTracing::Flag::TRACE_COMPOSITION) == |
| 9354 | 0); |
| 9355 | |
| 9356 | auto layers = dumpDrawingStateProto(traceFlags); |
| 9357 | if (traceFlags & LayerTracing::Flag::TRACE_EXTRA) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9358 | dumpOffscreenLayersProto(layers); |
| 9359 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9360 | *snapshot.mutable_layers() = std::move(layers); |
| 9361 | |
| 9362 | if (traceFlags & LayerTracing::Flag::TRACE_HWC) { |
| 9363 | std::string hwcDump; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9364 | dumpHwc(hwcDump); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9365 | snapshot.set_hwc_blob(std::move(hwcDump)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9366 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9367 | |
| 9368 | *snapshot.mutable_displays() = dumpDisplayProto(); |
| 9369 | |
| 9370 | return snapshot; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9371 | } |
| 9372 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 9373 | // sfdo functions |
| 9374 | |
| 9375 | void SurfaceFlinger::sfdo_enableRefreshRateOverlay(bool active) { |
| 9376 | auto future = mScheduler->schedule( |
| 9377 | [&]() FTL_FAKE_GUARD(mStateLock) |
| 9378 | FTL_FAKE_GUARD(kMainThreadContext) { enableRefreshRateOverlay(active); }); |
| 9379 | future.wait(); |
| 9380 | } |
| 9381 | |
| 9382 | void SurfaceFlinger::sfdo_setDebugFlash(int delay) { |
| 9383 | if (delay > 0) { |
| 9384 | mDebugFlashDelay = delay; |
| 9385 | } else { |
| 9386 | mDebugFlashDelay = mDebugFlashDelay ? 0 : 1; |
| 9387 | } |
| 9388 | scheduleRepaint(); |
| 9389 | } |
| 9390 | |
| 9391 | void SurfaceFlinger::sfdo_scheduleComposite() { |
| 9392 | scheduleComposite(SurfaceFlinger::FrameHint::kActive); |
| 9393 | } |
| 9394 | |
| 9395 | void SurfaceFlinger::sfdo_scheduleCommit() { |
| 9396 | Mutex::Autolock lock(mStateLock); |
| 9397 | setTransactionFlags(eTransactionNeeded | eDisplayTransactionNeeded | eTraversalNeeded); |
| 9398 | } |
| 9399 | |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 9400 | void SurfaceFlinger::sfdo_forceClientComposition(bool enabled) { |
| 9401 | mDebugDisableHWC = enabled; |
| 9402 | scheduleRepaint(); |
| 9403 | } |
| 9404 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9405 | // gui::ISurfaceComposer |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9406 | |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9407 | binder::Status SurfaceComposerAIDL::bootFinished() { |
| 9408 | status_t status = checkAccessPermission(); |
| 9409 | if (status != OK) { |
| 9410 | return binderStatusFromStatusT(status); |
| 9411 | } |
| 9412 | mFlinger->bootFinished(); |
| 9413 | return binder::Status::ok(); |
| 9414 | } |
| 9415 | |
| 9416 | binder::Status SurfaceComposerAIDL::createDisplayEventConnection( |
| 9417 | VsyncSource vsyncSource, EventRegistration eventRegistration, |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 9418 | const sp<IBinder>& layerHandle, sp<IDisplayEventConnection>* outConnection) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9419 | sp<IDisplayEventConnection> conn = |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 9420 | mFlinger->createDisplayEventConnection(vsyncSource, eventRegistration, layerHandle); |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9421 | if (conn == nullptr) { |
| 9422 | *outConnection = nullptr; |
| 9423 | return binderStatusFromStatusT(BAD_VALUE); |
| 9424 | } else { |
| 9425 | *outConnection = conn; |
| 9426 | return binder::Status::ok(); |
| 9427 | } |
| 9428 | } |
| 9429 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9430 | binder::Status SurfaceComposerAIDL::createConnection(sp<gui::ISurfaceComposerClient>* outClient) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 9431 | const sp<Client> client = sp<Client>::make(mFlinger); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9432 | if (client->initCheck() == NO_ERROR) { |
| 9433 | *outClient = client; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 9434 | if (FlagManager::getInstance().misc1()) { |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 9435 | const int policy = SCHED_FIFO; |
| 9436 | client->setMinSchedulerPolicy(policy, sched_get_priority_min(policy)); |
| 9437 | } |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9438 | return binder::Status::ok(); |
| 9439 | } else { |
| 9440 | *outClient = nullptr; |
| 9441 | return binderStatusFromStatusT(BAD_VALUE); |
| 9442 | } |
| 9443 | } |
| 9444 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9445 | binder::Status SurfaceComposerAIDL::createDisplay(const std::string& displayName, bool secure, |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 9446 | float requestedRefreshRate, |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9447 | sp<IBinder>* outDisplay) { |
| 9448 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9449 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9450 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9451 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9452 | String8 displayName8 = String8::format("%s", displayName.c_str()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 9453 | *outDisplay = mFlinger->createDisplay(displayName8, secure, requestedRefreshRate); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9454 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9455 | } |
| 9456 | |
| 9457 | binder::Status SurfaceComposerAIDL::destroyDisplay(const sp<IBinder>& display) { |
| 9458 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9459 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9460 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9461 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9462 | mFlinger->destroyDisplay(display); |
| 9463 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9464 | } |
| 9465 | |
| 9466 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) { |
| 9467 | std::vector<PhysicalDisplayId> physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); |
| 9468 | std::vector<int64_t> displayIds; |
| 9469 | displayIds.reserve(physicalDisplayIds.size()); |
| 9470 | for (auto item : physicalDisplayIds) { |
| 9471 | displayIds.push_back(static_cast<int64_t>(item.value)); |
| 9472 | } |
| 9473 | *outDisplayIds = displayIds; |
| 9474 | return binder::Status::ok(); |
| 9475 | } |
| 9476 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9477 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, |
| 9478 | sp<IBinder>* outDisplay) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9479 | status_t status = checkAccessPermission(); |
| 9480 | if (status != OK) { |
| 9481 | return binderStatusFromStatusT(status); |
| 9482 | } |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9483 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 9484 | *outDisplay = mFlinger->getPhysicalDisplayToken(*id); |
| 9485 | return binder::Status::ok(); |
| 9486 | } |
| 9487 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9488 | binder::Status SurfaceComposerAIDL::setPowerMode(const sp<IBinder>& display, int mode) { |
| 9489 | status_t status = checkAccessPermission(); |
| 9490 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9491 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9492 | } |
| 9493 | mFlinger->setPowerMode(display, mode); |
| 9494 | return binder::Status::ok(); |
| 9495 | } |
| 9496 | |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 9497 | binder::Status SurfaceComposerAIDL::getSupportedFrameTimestamps( |
| 9498 | std::vector<FrameEvent>* outSupported) { |
| 9499 | status_t status; |
| 9500 | if (!outSupported) { |
| 9501 | status = UNEXPECTED_NULL; |
| 9502 | } else { |
| 9503 | outSupported->clear(); |
| 9504 | status = mFlinger->getSupportedFrameTimestamps(outSupported); |
| 9505 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9506 | return binderStatusFromStatusT(status); |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 9507 | } |
| 9508 | |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9509 | binder::Status SurfaceComposerAIDL::getDisplayStats(const sp<IBinder>& display, |
| 9510 | gui::DisplayStatInfo* outStatInfo) { |
| 9511 | DisplayStatInfo statInfo; |
| 9512 | status_t status = mFlinger->getDisplayStats(display, &statInfo); |
| 9513 | if (status == NO_ERROR) { |
| 9514 | outStatInfo->vsyncTime = static_cast<long>(statInfo.vsyncTime); |
| 9515 | outStatInfo->vsyncPeriod = static_cast<long>(statInfo.vsyncPeriod); |
| 9516 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9517 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9518 | } |
| 9519 | |
| 9520 | binder::Status SurfaceComposerAIDL::getDisplayState(const sp<IBinder>& display, |
| 9521 | gui::DisplayState* outState) { |
| 9522 | ui::DisplayState state; |
| 9523 | status_t status = mFlinger->getDisplayState(display, &state); |
| 9524 | if (status == NO_ERROR) { |
| 9525 | outState->layerStack = state.layerStack.id; |
| 9526 | outState->orientation = static_cast<gui::Rotation>(state.orientation); |
| 9527 | outState->layerStackSpaceRect.width = state.layerStackSpaceRect.width; |
| 9528 | outState->layerStackSpaceRect.height = state.layerStackSpaceRect.height; |
| 9529 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9530 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9531 | } |
| 9532 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9533 | binder::Status SurfaceComposerAIDL::getStaticDisplayInfo(int64_t displayId, |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9534 | gui::StaticDisplayInfo* outInfo) { |
| 9535 | using Tag = gui::DeviceProductInfo::ManufactureOrModelDate::Tag; |
| 9536 | ui::StaticDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9537 | |
| 9538 | status_t status = mFlinger->getStaticDisplayInfo(displayId, &info); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9539 | if (status == NO_ERROR) { |
| 9540 | // convert ui::StaticDisplayInfo to gui::StaticDisplayInfo |
| 9541 | outInfo->connectionType = static_cast<gui::DisplayConnectionType>(info.connectionType); |
| 9542 | outInfo->density = info.density; |
| 9543 | outInfo->secure = info.secure; |
| 9544 | outInfo->installOrientation = static_cast<gui::Rotation>(info.installOrientation); |
| 9545 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9546 | if (const std::optional<DeviceProductInfo> dpi = info.deviceProductInfo) { |
| 9547 | gui::DeviceProductInfo dinfo; |
| 9548 | dinfo.name = std::move(dpi->name); |
| 9549 | dinfo.manufacturerPnpId = std::vector<uint8_t>(dpi->manufacturerPnpId.begin(), |
| 9550 | dpi->manufacturerPnpId.end()); |
| 9551 | dinfo.productId = dpi->productId; |
| 9552 | dinfo.relativeAddress = |
| 9553 | std::vector<uint8_t>(dpi->relativeAddress.begin(), dpi->relativeAddress.end()); |
| 9554 | if (const auto* model = |
| 9555 | std::get_if<DeviceProductInfo::ModelYear>(&dpi->manufactureOrModelDate)) { |
| 9556 | gui::DeviceProductInfo::ModelYear modelYear; |
| 9557 | modelYear.year = model->year; |
| 9558 | dinfo.manufactureOrModelDate.set<Tag::modelYear>(modelYear); |
| 9559 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureYear>( |
| 9560 | &dpi->manufactureOrModelDate)) { |
| 9561 | gui::DeviceProductInfo::ManufactureYear date; |
| 9562 | date.modelYear.year = manufacture->year; |
| 9563 | dinfo.manufactureOrModelDate.set<Tag::manufactureYear>(date); |
| 9564 | } else if (const auto* manufacture = |
| 9565 | std::get_if<DeviceProductInfo::ManufactureWeekAndYear>( |
| 9566 | &dpi->manufactureOrModelDate)) { |
| 9567 | gui::DeviceProductInfo::ManufactureWeekAndYear date; |
| 9568 | date.manufactureYear.modelYear.year = manufacture->year; |
| 9569 | date.week = manufacture->week; |
| 9570 | dinfo.manufactureOrModelDate.set<Tag::manufactureWeekAndYear>(date); |
| 9571 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9572 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9573 | outInfo->deviceProductInfo = dinfo; |
| 9574 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9575 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9576 | return binderStatusFromStatusT(status); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9577 | } |
| 9578 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9579 | void SurfaceComposerAIDL::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo& info, |
| 9580 | gui::DynamicDisplayInfo*& outInfo) { |
| 9581 | // convert ui::DynamicDisplayInfo to gui::DynamicDisplayInfo |
| 9582 | outInfo->supportedDisplayModes.clear(); |
| 9583 | outInfo->supportedDisplayModes.reserve(info.supportedDisplayModes.size()); |
| 9584 | for (const auto& mode : info.supportedDisplayModes) { |
| 9585 | gui::DisplayMode outMode; |
| 9586 | outMode.id = mode.id; |
| 9587 | outMode.resolution.width = mode.resolution.width; |
| 9588 | outMode.resolution.height = mode.resolution.height; |
| 9589 | outMode.xDpi = mode.xDpi; |
| 9590 | outMode.yDpi = mode.yDpi; |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 9591 | outMode.peakRefreshRate = mode.peakRefreshRate; |
Alec Mouri | d122a1c | 2023-09-30 01:36:33 +0000 | [diff] [blame] | 9592 | outMode.vsyncRate = mode.vsyncRate; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9593 | outMode.appVsyncOffset = mode.appVsyncOffset; |
| 9594 | outMode.sfVsyncOffset = mode.sfVsyncOffset; |
| 9595 | outMode.presentationDeadline = mode.presentationDeadline; |
| 9596 | outMode.group = mode.group; |
| 9597 | std::transform(mode.supportedHdrTypes.begin(), mode.supportedHdrTypes.end(), |
| 9598 | std::back_inserter(outMode.supportedHdrTypes), |
| 9599 | [](const ui::Hdr& value) { return static_cast<int32_t>(value); }); |
| 9600 | outInfo->supportedDisplayModes.push_back(outMode); |
| 9601 | } |
| 9602 | |
| 9603 | outInfo->activeDisplayModeId = info.activeDisplayModeId; |
| 9604 | outInfo->renderFrameRate = info.renderFrameRate; |
| 9605 | |
| 9606 | outInfo->supportedColorModes.clear(); |
| 9607 | outInfo->supportedColorModes.reserve(info.supportedColorModes.size()); |
| 9608 | for (const auto& cmode : info.supportedColorModes) { |
| 9609 | outInfo->supportedColorModes.push_back(static_cast<int32_t>(cmode)); |
| 9610 | } |
| 9611 | |
| 9612 | outInfo->activeColorMode = static_cast<int32_t>(info.activeColorMode); |
| 9613 | |
| 9614 | gui::HdrCapabilities& hdrCapabilities = outInfo->hdrCapabilities; |
| 9615 | hdrCapabilities.supportedHdrTypes.clear(); |
| 9616 | hdrCapabilities.supportedHdrTypes.reserve(info.hdrCapabilities.getSupportedHdrTypes().size()); |
| 9617 | for (const auto& hdr : info.hdrCapabilities.getSupportedHdrTypes()) { |
| 9618 | hdrCapabilities.supportedHdrTypes.push_back(static_cast<int32_t>(hdr)); |
| 9619 | } |
| 9620 | hdrCapabilities.maxLuminance = info.hdrCapabilities.getDesiredMaxLuminance(); |
| 9621 | hdrCapabilities.maxAverageLuminance = info.hdrCapabilities.getDesiredMaxAverageLuminance(); |
| 9622 | hdrCapabilities.minLuminance = info.hdrCapabilities.getDesiredMinLuminance(); |
| 9623 | |
| 9624 | outInfo->autoLowLatencyModeSupported = info.autoLowLatencyModeSupported; |
| 9625 | outInfo->gameContentTypeSupported = info.gameContentTypeSupported; |
| 9626 | outInfo->preferredBootDisplayMode = info.preferredBootDisplayMode; |
| 9627 | } |
| 9628 | |
| 9629 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromToken( |
| 9630 | const sp<IBinder>& display, gui::DynamicDisplayInfo* outInfo) { |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9631 | ui::DynamicDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9632 | status_t status = mFlinger->getDynamicDisplayInfoFromToken(display, &info); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9633 | if (status == NO_ERROR) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9634 | getDynamicDisplayInfoInternal(info, outInfo); |
| 9635 | } |
| 9636 | return binderStatusFromStatusT(status); |
| 9637 | } |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 9638 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9639 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromId(int64_t displayId, |
| 9640 | gui::DynamicDisplayInfo* outInfo) { |
| 9641 | ui::DynamicDisplayInfo info; |
| 9642 | status_t status = mFlinger->getDynamicDisplayInfoFromId(displayId, &info); |
| 9643 | if (status == NO_ERROR) { |
| 9644 | getDynamicDisplayInfoInternal(info, outInfo); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9645 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9646 | return binderStatusFromStatusT(status); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9647 | } |
| 9648 | |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9649 | binder::Status SurfaceComposerAIDL::getDisplayNativePrimaries(const sp<IBinder>& display, |
| 9650 | gui::DisplayPrimaries* outPrimaries) { |
| 9651 | ui::DisplayPrimaries primaries; |
| 9652 | status_t status = mFlinger->getDisplayNativePrimaries(display, primaries); |
| 9653 | if (status == NO_ERROR) { |
| 9654 | outPrimaries->red.X = primaries.red.X; |
| 9655 | outPrimaries->red.Y = primaries.red.Y; |
| 9656 | outPrimaries->red.Z = primaries.red.Z; |
| 9657 | |
| 9658 | outPrimaries->green.X = primaries.green.X; |
| 9659 | outPrimaries->green.Y = primaries.green.Y; |
| 9660 | outPrimaries->green.Z = primaries.green.Z; |
| 9661 | |
| 9662 | outPrimaries->blue.X = primaries.blue.X; |
| 9663 | outPrimaries->blue.Y = primaries.blue.Y; |
| 9664 | outPrimaries->blue.Z = primaries.blue.Z; |
| 9665 | |
| 9666 | outPrimaries->white.X = primaries.white.X; |
| 9667 | outPrimaries->white.Y = primaries.white.Y; |
| 9668 | outPrimaries->white.Z = primaries.white.Z; |
| 9669 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9670 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9671 | } |
| 9672 | |
| 9673 | binder::Status SurfaceComposerAIDL::setActiveColorMode(const sp<IBinder>& display, int colorMode) { |
| 9674 | status_t status = checkAccessPermission(); |
| 9675 | if (status == OK) { |
| 9676 | status = mFlinger->setActiveColorMode(display, static_cast<ui::ColorMode>(colorMode)); |
| 9677 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9678 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9679 | } |
| 9680 | |
| 9681 | binder::Status SurfaceComposerAIDL::setBootDisplayMode(const sp<IBinder>& display, |
| 9682 | int displayModeId) { |
| 9683 | status_t status = checkAccessPermission(); |
| 9684 | if (status == OK) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 9685 | status = mFlinger->setBootDisplayMode(display, DisplayModeId{displayModeId}); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9686 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9687 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9688 | } |
| 9689 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9690 | binder::Status SurfaceComposerAIDL::clearBootDisplayMode(const sp<IBinder>& display) { |
| 9691 | status_t status = checkAccessPermission(); |
| 9692 | if (status == OK) { |
| 9693 | status = mFlinger->clearBootDisplayMode(display); |
| 9694 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9695 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9696 | } |
| 9697 | |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 9698 | binder::Status SurfaceComposerAIDL::getOverlaySupport(gui::OverlayProperties* outProperties) { |
| 9699 | status_t status = checkAccessPermission(); |
| 9700 | if (status == OK) { |
| 9701 | status = mFlinger->getOverlaySupport(outProperties); |
| 9702 | } |
| 9703 | return binderStatusFromStatusT(status); |
| 9704 | } |
| 9705 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9706 | binder::Status SurfaceComposerAIDL::getBootDisplayModeSupport(bool* outMode) { |
| 9707 | status_t status = checkAccessPermission(); |
| 9708 | if (status == OK) { |
| 9709 | status = mFlinger->getBootDisplayModeSupport(outMode); |
| 9710 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9711 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9712 | } |
| 9713 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9714 | binder::Status SurfaceComposerAIDL::getHdrConversionCapabilities( |
| 9715 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) { |
| 9716 | status_t status = checkAccessPermission(); |
| 9717 | if (status == OK) { |
| 9718 | status = mFlinger->getHdrConversionCapabilities(hdrConversionCapabilities); |
| 9719 | } |
| 9720 | return binderStatusFromStatusT(status); |
| 9721 | } |
| 9722 | |
| 9723 | binder::Status SurfaceComposerAIDL::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 9724 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 9725 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9726 | status_t status = checkAccessPermission(); |
| 9727 | if (status == OK) { |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 9728 | status = mFlinger->setHdrConversionStrategy(hdrConversionStrategy, |
| 9729 | outPreferredHdrOutputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9730 | } |
| 9731 | return binderStatusFromStatusT(status); |
| 9732 | } |
| 9733 | |
| 9734 | binder::Status SurfaceComposerAIDL::getHdrOutputConversionSupport(bool* outMode) { |
| 9735 | status_t status = checkAccessPermission(); |
| 9736 | if (status == OK) { |
| 9737 | status = mFlinger->getHdrOutputConversionSupport(outMode); |
| 9738 | } |
| 9739 | return binderStatusFromStatusT(status); |
| 9740 | } |
| 9741 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9742 | binder::Status SurfaceComposerAIDL::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) { |
| 9743 | status_t status = checkAccessPermission(); |
| 9744 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9745 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9746 | } |
| 9747 | mFlinger->setAutoLowLatencyMode(display, on); |
| 9748 | return binder::Status::ok(); |
| 9749 | } |
| 9750 | |
| 9751 | binder::Status SurfaceComposerAIDL::setGameContentType(const sp<IBinder>& display, bool on) { |
| 9752 | status_t status = checkAccessPermission(); |
| 9753 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9754 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9755 | } |
| 9756 | mFlinger->setGameContentType(display, on); |
| 9757 | return binder::Status::ok(); |
| 9758 | } |
| 9759 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9760 | binder::Status SurfaceComposerAIDL::captureDisplay( |
| 9761 | const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9762 | mFlinger->captureDisplay(args, captureListener); |
| 9763 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9764 | } |
| 9765 | |
| 9766 | binder::Status SurfaceComposerAIDL::captureDisplayById( |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 9767 | int64_t displayId, const CaptureArgs& args, |
| 9768 | const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9769 | // status_t status; |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9770 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9771 | const int uid = ipc->getCallingUid(); |
| 9772 | if (uid == AID_ROOT || uid == AID_GRAPHICS || uid == AID_SYSTEM || uid == AID_SHELL) { |
| 9773 | std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId)); |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 9774 | mFlinger->captureDisplay(*id, args, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9775 | } else { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9776 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9777 | } |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9778 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9779 | } |
| 9780 | |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 9781 | binder::Status SurfaceComposerAIDL::captureLayersSync(const LayerCaptureArgs& args, |
| 9782 | ScreenCaptureResults* outResults) { |
| 9783 | *outResults = mFlinger->captureLayersSync(args); |
| 9784 | return binderStatusFromStatusT(NO_ERROR); |
| 9785 | } |
| 9786 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9787 | binder::Status SurfaceComposerAIDL::captureLayers( |
| 9788 | const LayerCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9789 | mFlinger->captureLayers(args, captureListener); |
| 9790 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9791 | } |
| 9792 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9793 | binder::Status SurfaceComposerAIDL::overrideHdrTypes(const sp<IBinder>& display, |
| 9794 | const std::vector<int32_t>& hdrTypes) { |
| 9795 | // overrideHdrTypes is used by CTS tests, which acquire the necessary |
| 9796 | // permission dynamically. Don't use the permission cache for this check. |
| 9797 | status_t status = checkAccessPermission(false); |
| 9798 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9799 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9800 | } |
| 9801 | |
| 9802 | std::vector<ui::Hdr> hdrTypesVector; |
| 9803 | for (int32_t i : hdrTypes) { |
| 9804 | hdrTypesVector.push_back(static_cast<ui::Hdr>(i)); |
| 9805 | } |
| 9806 | status = mFlinger->overrideHdrTypes(display, hdrTypesVector); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9807 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9808 | } |
| 9809 | |
| 9810 | binder::Status SurfaceComposerAIDL::onPullAtom(int32_t atomId, gui::PullAtomData* outPullData) { |
| 9811 | status_t status; |
| 9812 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 9813 | if (uid != AID_SYSTEM) { |
| 9814 | status = PERMISSION_DENIED; |
| 9815 | } else { |
| 9816 | status = mFlinger->onPullAtom(atomId, &outPullData->data, &outPullData->success); |
| 9817 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9818 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9819 | } |
| 9820 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9821 | binder::Status SurfaceComposerAIDL::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
| 9822 | if (!outLayers) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9823 | return binderStatusFromStatusT(UNEXPECTED_NULL); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9824 | } |
| 9825 | |
| 9826 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9827 | const int pid = ipc->getCallingPid(); |
| 9828 | const int uid = ipc->getCallingUid(); |
| 9829 | if ((uid != AID_SHELL) && !PermissionCache::checkPermission(sDump, pid, uid)) { |
| 9830 | ALOGE("Layer debug info permission denied for pid=%d, uid=%d", pid, uid); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9831 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9832 | } |
| 9833 | status_t status = mFlinger->getLayerDebugInfo(outLayers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9834 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9835 | } |
| 9836 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9837 | binder::Status SurfaceComposerAIDL::getCompositionPreference(gui::CompositionPreference* outPref) { |
| 9838 | ui::Dataspace dataspace; |
| 9839 | ui::PixelFormat pixelFormat; |
| 9840 | ui::Dataspace wideColorGamutDataspace; |
| 9841 | ui::PixelFormat wideColorGamutPixelFormat; |
| 9842 | status_t status = |
| 9843 | mFlinger->getCompositionPreference(&dataspace, &pixelFormat, &wideColorGamutDataspace, |
| 9844 | &wideColorGamutPixelFormat); |
| 9845 | if (status == NO_ERROR) { |
| 9846 | outPref->defaultDataspace = static_cast<int32_t>(dataspace); |
| 9847 | outPref->defaultPixelFormat = static_cast<int32_t>(pixelFormat); |
| 9848 | outPref->wideColorGamutDataspace = static_cast<int32_t>(wideColorGamutDataspace); |
| 9849 | outPref->wideColorGamutPixelFormat = static_cast<int32_t>(wideColorGamutPixelFormat); |
| 9850 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9851 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9852 | } |
| 9853 | |
| 9854 | binder::Status SurfaceComposerAIDL::getDisplayedContentSamplingAttributes( |
| 9855 | const sp<IBinder>& display, gui::ContentSamplingAttributes* outAttrs) { |
| 9856 | status_t status = checkAccessPermission(); |
| 9857 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9858 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9859 | } |
| 9860 | |
| 9861 | ui::PixelFormat format; |
| 9862 | ui::Dataspace dataspace; |
| 9863 | uint8_t componentMask; |
| 9864 | status = mFlinger->getDisplayedContentSamplingAttributes(display, &format, &dataspace, |
| 9865 | &componentMask); |
| 9866 | if (status == NO_ERROR) { |
| 9867 | outAttrs->format = static_cast<int32_t>(format); |
| 9868 | outAttrs->dataspace = static_cast<int32_t>(dataspace); |
| 9869 | outAttrs->componentMask = static_cast<int8_t>(componentMask); |
| 9870 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9871 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9872 | } |
| 9873 | |
| 9874 | binder::Status SurfaceComposerAIDL::setDisplayContentSamplingEnabled(const sp<IBinder>& display, |
| 9875 | bool enable, |
| 9876 | int8_t componentMask, |
| 9877 | int64_t maxFrames) { |
| 9878 | status_t status = checkAccessPermission(); |
| 9879 | if (status == OK) { |
| 9880 | status = mFlinger->setDisplayContentSamplingEnabled(display, enable, |
| 9881 | static_cast<uint8_t>(componentMask), |
| 9882 | static_cast<uint64_t>(maxFrames)); |
| 9883 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9884 | return binderStatusFromStatusT(status); |
| 9885 | } |
| 9886 | |
| 9887 | binder::Status SurfaceComposerAIDL::getDisplayedContentSample(const sp<IBinder>& display, |
| 9888 | int64_t maxFrames, int64_t timestamp, |
| 9889 | gui::DisplayedFrameStats* outStats) { |
| 9890 | if (!outStats) { |
| 9891 | return binderStatusFromStatusT(BAD_VALUE); |
| 9892 | } |
| 9893 | |
| 9894 | status_t status = checkAccessPermission(); |
| 9895 | if (status != OK) { |
| 9896 | return binderStatusFromStatusT(status); |
| 9897 | } |
| 9898 | |
| 9899 | DisplayedFrameStats stats; |
| 9900 | status = mFlinger->getDisplayedContentSample(display, static_cast<uint64_t>(maxFrames), |
| 9901 | static_cast<uint64_t>(timestamp), &stats); |
| 9902 | if (status == NO_ERROR) { |
| 9903 | // convert from ui::DisplayedFrameStats to gui::DisplayedFrameStats |
| 9904 | outStats->numFrames = static_cast<int64_t>(stats.numFrames); |
| 9905 | outStats->component_0_sample.reserve(stats.component_0_sample.size()); |
| 9906 | for (const auto& s : stats.component_0_sample) { |
| 9907 | outStats->component_0_sample.push_back(static_cast<int64_t>(s)); |
| 9908 | } |
| 9909 | outStats->component_1_sample.reserve(stats.component_1_sample.size()); |
| 9910 | for (const auto& s : stats.component_1_sample) { |
| 9911 | outStats->component_1_sample.push_back(static_cast<int64_t>(s)); |
| 9912 | } |
| 9913 | outStats->component_2_sample.reserve(stats.component_2_sample.size()); |
| 9914 | for (const auto& s : stats.component_2_sample) { |
| 9915 | outStats->component_2_sample.push_back(static_cast<int64_t>(s)); |
| 9916 | } |
| 9917 | outStats->component_3_sample.reserve(stats.component_3_sample.size()); |
| 9918 | for (const auto& s : stats.component_3_sample) { |
| 9919 | outStats->component_3_sample.push_back(static_cast<int64_t>(s)); |
| 9920 | } |
| 9921 | } |
| 9922 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9923 | } |
| 9924 | |
| 9925 | binder::Status SurfaceComposerAIDL::getProtectedContentSupport(bool* outSupported) { |
| 9926 | status_t status = mFlinger->getProtectedContentSupport(outSupported); |
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 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9930 | binder::Status SurfaceComposerAIDL::isWideColorDisplay(const sp<IBinder>& token, |
| 9931 | bool* outIsWideColorDisplay) { |
| 9932 | status_t status = mFlinger->isWideColorDisplay(token, outIsWideColorDisplay); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9933 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9934 | } |
| 9935 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9936 | binder::Status SurfaceComposerAIDL::addRegionSamplingListener( |
| 9937 | const gui::ARect& samplingArea, const sp<IBinder>& stopLayerHandle, |
| 9938 | const sp<gui::IRegionSamplingListener>& listener) { |
| 9939 | status_t status = checkReadFrameBufferPermission(); |
| 9940 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9941 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9942 | } |
| 9943 | android::Rect rect; |
| 9944 | rect.left = samplingArea.left; |
| 9945 | rect.top = samplingArea.top; |
| 9946 | rect.right = samplingArea.right; |
| 9947 | rect.bottom = samplingArea.bottom; |
| 9948 | status = mFlinger->addRegionSamplingListener(rect, stopLayerHandle, listener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9949 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9950 | } |
| 9951 | |
| 9952 | binder::Status SurfaceComposerAIDL::removeRegionSamplingListener( |
| 9953 | const sp<gui::IRegionSamplingListener>& listener) { |
| 9954 | status_t status = checkReadFrameBufferPermission(); |
| 9955 | if (status == OK) { |
| 9956 | status = mFlinger->removeRegionSamplingListener(listener); |
| 9957 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9958 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9959 | } |
| 9960 | |
| 9961 | binder::Status SurfaceComposerAIDL::addFpsListener(int32_t taskId, |
| 9962 | const sp<gui::IFpsListener>& listener) { |
| 9963 | status_t status = checkReadFrameBufferPermission(); |
| 9964 | if (status == OK) { |
| 9965 | status = mFlinger->addFpsListener(taskId, listener); |
| 9966 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9967 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9968 | } |
| 9969 | |
| 9970 | binder::Status SurfaceComposerAIDL::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 9971 | status_t status = checkReadFrameBufferPermission(); |
| 9972 | if (status == OK) { |
| 9973 | status = mFlinger->removeFpsListener(listener); |
| 9974 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9975 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9976 | } |
| 9977 | |
| 9978 | binder::Status SurfaceComposerAIDL::addTunnelModeEnabledListener( |
| 9979 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 9980 | status_t status = checkAccessPermission(); |
| 9981 | if (status == OK) { |
| 9982 | status = mFlinger->addTunnelModeEnabledListener(listener); |
| 9983 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9984 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9985 | } |
| 9986 | |
| 9987 | binder::Status SurfaceComposerAIDL::removeTunnelModeEnabledListener( |
| 9988 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 9989 | status_t status = checkAccessPermission(); |
| 9990 | if (status == OK) { |
| 9991 | status = mFlinger->removeTunnelModeEnabledListener(listener); |
| 9992 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9993 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9994 | } |
| 9995 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 9996 | binder::Status SurfaceComposerAIDL::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 9997 | const gui::DisplayModeSpecs& specs) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9998 | status_t status = checkAccessPermission(); |
| 9999 | if (status == OK) { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 10000 | status = mFlinger->setDesiredDisplayModeSpecs(displayToken, specs); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10001 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10002 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10003 | } |
| 10004 | |
| 10005 | binder::Status SurfaceComposerAIDL::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 10006 | gui::DisplayModeSpecs* outSpecs) { |
| 10007 | if (!outSpecs) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10008 | return binderStatusFromStatusT(BAD_VALUE); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10009 | } |
| 10010 | |
| 10011 | status_t status = checkAccessPermission(); |
| 10012 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10013 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10014 | } |
| 10015 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 10016 | status = mFlinger->getDesiredDisplayModeSpecs(displayToken, outSpecs); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10017 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10018 | } |
| 10019 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10020 | binder::Status SurfaceComposerAIDL::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 10021 | bool* outSupport) { |
| 10022 | status_t status = mFlinger->getDisplayBrightnessSupport(displayToken, outSupport); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10023 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10024 | } |
| 10025 | |
| 10026 | binder::Status SurfaceComposerAIDL::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 10027 | const gui::DisplayBrightness& brightness) { |
| 10028 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10029 | if (status == OK) { |
| 10030 | status = mFlinger->setDisplayBrightness(displayToken, brightness); |
| 10031 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10032 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10033 | } |
| 10034 | |
| 10035 | binder::Status SurfaceComposerAIDL::addHdrLayerInfoListener( |
| 10036 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 10037 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10038 | if (status == OK) { |
| 10039 | status = mFlinger->addHdrLayerInfoListener(displayToken, listener); |
| 10040 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10041 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10042 | } |
| 10043 | |
| 10044 | binder::Status SurfaceComposerAIDL::removeHdrLayerInfoListener( |
| 10045 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 10046 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10047 | if (status == OK) { |
| 10048 | status = mFlinger->removeHdrLayerInfoListener(displayToken, listener); |
| 10049 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10050 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10051 | } |
| 10052 | |
| 10053 | binder::Status SurfaceComposerAIDL::notifyPowerBoost(int boostId) { |
| 10054 | status_t status = checkAccessPermission(); |
| 10055 | if (status == OK) { |
| 10056 | status = mFlinger->notifyPowerBoost(boostId); |
| 10057 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10058 | return binderStatusFromStatusT(status); |
| 10059 | } |
| 10060 | |
| 10061 | binder::Status SurfaceComposerAIDL::setGlobalShadowSettings(const gui::Color& ambientColor, |
| 10062 | const gui::Color& spotColor, |
| 10063 | float lightPosY, float lightPosZ, |
| 10064 | float lightRadius) { |
| 10065 | status_t status = checkAccessPermission(); |
| 10066 | if (status != OK) { |
| 10067 | return binderStatusFromStatusT(status); |
| 10068 | } |
| 10069 | |
| 10070 | half4 ambientColorHalf = {ambientColor.r, ambientColor.g, ambientColor.b, ambientColor.a}; |
| 10071 | half4 spotColorHalf = {spotColor.r, spotColor.g, spotColor.b, spotColor.a}; |
| 10072 | status = mFlinger->setGlobalShadowSettings(ambientColorHalf, spotColorHalf, lightPosY, |
| 10073 | lightPosZ, lightRadius); |
| 10074 | return binderStatusFromStatusT(status); |
| 10075 | } |
| 10076 | |
| 10077 | binder::Status SurfaceComposerAIDL::getDisplayDecorationSupport( |
| 10078 | const sp<IBinder>& displayToken, std::optional<gui::DisplayDecorationSupport>* outSupport) { |
| 10079 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport> support; |
| 10080 | status_t status = mFlinger->getDisplayDecorationSupport(displayToken, &support); |
| 10081 | if (status != NO_ERROR) { |
| 10082 | ALOGE("getDisplayDecorationSupport failed with error %d", status); |
| 10083 | return binderStatusFromStatusT(status); |
| 10084 | } |
| 10085 | |
| 10086 | if (!support || !support.has_value()) { |
| 10087 | outSupport->reset(); |
| 10088 | } else { |
| 10089 | outSupport->emplace(); |
| 10090 | outSupport->value().format = static_cast<int32_t>(support->format); |
| 10091 | outSupport->value().alphaInterpretation = |
| 10092 | static_cast<int32_t>(support->alphaInterpretation); |
| 10093 | } |
| 10094 | |
| 10095 | return binder::Status::ok(); |
| 10096 | } |
| 10097 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10098 | binder::Status SurfaceComposerAIDL::setGameModeFrameRateOverride(int32_t uid, float frameRate) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10099 | status_t status; |
| 10100 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10101 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10102 | status = mFlinger->setGameModeFrameRateOverride(uid, frameRate); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10103 | } else { |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10104 | ALOGE("setGameModeFrameRateOverride() permission denied for uid: %d", c_uid); |
| 10105 | status = PERMISSION_DENIED; |
| 10106 | } |
| 10107 | return binderStatusFromStatusT(status); |
| 10108 | } |
| 10109 | |
| 10110 | binder::Status SurfaceComposerAIDL::setGameDefaultFrameRateOverride(int32_t uid, float frameRate) { |
| 10111 | status_t status; |
| 10112 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10113 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 10114 | status = mFlinger->setGameDefaultFrameRateOverride(uid, frameRate); |
| 10115 | } else { |
| 10116 | ALOGE("setGameDefaultFrameRateOverride() permission denied for uid: %d", c_uid); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10117 | status = PERMISSION_DENIED; |
| 10118 | } |
| 10119 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10120 | } |
| 10121 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 10122 | binder::Status SurfaceComposerAIDL::enableRefreshRateOverlay(bool active) { |
| 10123 | mFlinger->sfdo_enableRefreshRateOverlay(active); |
| 10124 | return binder::Status::ok(); |
| 10125 | } |
| 10126 | |
| 10127 | binder::Status SurfaceComposerAIDL::setDebugFlash(int delay) { |
| 10128 | mFlinger->sfdo_setDebugFlash(delay); |
| 10129 | return binder::Status::ok(); |
| 10130 | } |
| 10131 | |
| 10132 | binder::Status SurfaceComposerAIDL::scheduleComposite() { |
| 10133 | mFlinger->sfdo_scheduleComposite(); |
| 10134 | return binder::Status::ok(); |
| 10135 | } |
| 10136 | |
| 10137 | binder::Status SurfaceComposerAIDL::scheduleCommit() { |
| 10138 | mFlinger->sfdo_scheduleCommit(); |
| 10139 | return binder::Status::ok(); |
| 10140 | } |
| 10141 | |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 10142 | binder::Status SurfaceComposerAIDL::forceClientComposition(bool enabled) { |
| 10143 | mFlinger->sfdo_forceClientComposition(enabled); |
| 10144 | return binder::Status::ok(); |
| 10145 | } |
| 10146 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10147 | binder::Status SurfaceComposerAIDL::updateSmallAreaDetection(const std::vector<int32_t>& appIds, |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10148 | const std::vector<float>& thresholds) { |
| 10149 | status_t status; |
| 10150 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10151 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10152 | if (appIds.size() != thresholds.size()) return binderStatusFromStatusT(BAD_VALUE); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10153 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10154 | std::vector<std::pair<int32_t, float>> mappings; |
| 10155 | const size_t size = appIds.size(); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10156 | mappings.reserve(size); |
| 10157 | for (int i = 0; i < size; i++) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10158 | auto row = std::make_pair(appIds[i], thresholds[i]); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10159 | mappings.push_back(row); |
| 10160 | } |
| 10161 | status = mFlinger->updateSmallAreaDetection(mappings); |
| 10162 | } else { |
| 10163 | ALOGE("updateSmallAreaDetection() permission denied for uid: %d", c_uid); |
| 10164 | status = PERMISSION_DENIED; |
| 10165 | } |
| 10166 | return binderStatusFromStatusT(status); |
| 10167 | } |
| 10168 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10169 | binder::Status SurfaceComposerAIDL::setSmallAreaDetectionThreshold(int32_t appId, float threshold) { |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10170 | status_t status; |
| 10171 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10172 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10173 | status = mFlinger->setSmallAreaDetectionThreshold(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10174 | } else { |
| 10175 | ALOGE("setSmallAreaDetectionThreshold() permission denied for uid: %d", c_uid); |
| 10176 | status = PERMISSION_DENIED; |
| 10177 | } |
| 10178 | return binderStatusFromStatusT(status); |
| 10179 | } |
| 10180 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10181 | binder::Status SurfaceComposerAIDL::getGpuContextPriority(int32_t* outPriority) { |
| 10182 | *outPriority = mFlinger->getGpuContextPriority(); |
| 10183 | return binder::Status::ok(); |
| 10184 | } |
| 10185 | |
| 10186 | binder::Status SurfaceComposerAIDL::getMaxAcquiredBufferCount(int32_t* buffers) { |
| 10187 | status_t status = mFlinger->getMaxAcquiredBufferCount(buffers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10188 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10189 | } |
| 10190 | |
| 10191 | binder::Status SurfaceComposerAIDL::addWindowInfosListener( |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 10192 | const sp<gui::IWindowInfosListener>& windowInfosListener, |
| 10193 | gui::WindowInfosListenerInfo* outInfo) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10194 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10195 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10196 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10197 | // TODO(b/270566761) update permissions check so that only system_server and shell can add |
| 10198 | // WindowInfosListeners |
| 10199 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 10200 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 10201 | status = mFlinger->addWindowInfosListener(windowInfosListener, outInfo); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10202 | } else { |
| 10203 | status = PERMISSION_DENIED; |
| 10204 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10205 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10206 | } |
| 10207 | |
| 10208 | binder::Status SurfaceComposerAIDL::removeWindowInfosListener( |
| 10209 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 10210 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10211 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10212 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10213 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 10214 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10215 | status = mFlinger->removeWindowInfosListener(windowInfosListener); |
| 10216 | } else { |
| 10217 | status = PERMISSION_DENIED; |
| 10218 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10219 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10220 | } |
| 10221 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 10222 | binder::Status SurfaceComposerAIDL::getStalledTransactionInfo( |
| 10223 | int pid, std::optional<gui::StalledTransactionInfo>* outInfo) { |
| 10224 | const int callingPid = IPCThreadState::self()->getCallingPid(); |
| 10225 | const int callingUid = IPCThreadState::self()->getCallingUid(); |
| 10226 | if (!checkPermission(sAccessSurfaceFlinger, callingPid, callingUid)) { |
| 10227 | return binderStatusFromStatusT(PERMISSION_DENIED); |
| 10228 | } |
| 10229 | |
| 10230 | std::optional<TransactionHandler::StalledTransactionInfo> stalledTransactionInfo; |
| 10231 | status_t status = mFlinger->getStalledTransactionInfo(pid, stalledTransactionInfo); |
| 10232 | if (stalledTransactionInfo) { |
| 10233 | gui::StalledTransactionInfo result; |
| 10234 | result.layerName = String16{stalledTransactionInfo->layerName.c_str()}, |
| 10235 | result.bufferId = stalledTransactionInfo->bufferId, |
| 10236 | result.frameNumber = stalledTransactionInfo->frameNumber, |
| 10237 | outInfo->emplace(std::move(result)); |
| 10238 | } else { |
| 10239 | outInfo->reset(); |
| 10240 | } |
| 10241 | return binderStatusFromStatusT(status); |
| 10242 | } |
| 10243 | |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 10244 | binder::Status SurfaceComposerAIDL::getSchedulingPolicy(gui::SchedulingPolicy* outPolicy) { |
| 10245 | return gui::getSchedulingPolicy(outPolicy); |
| 10246 | } |
| 10247 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 10248 | status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { |
| 10249 | if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
| 10250 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10251 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", ipc->getCallingPid(), |
| 10252 | ipc->getCallingUid()); |
| 10253 | return PERMISSION_DENIED; |
| 10254 | } |
| 10255 | return OK; |
| 10256 | } |
| 10257 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10258 | status_t SurfaceComposerAIDL::checkControlDisplayBrightnessPermission() { |
| 10259 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10260 | const int pid = ipc->getCallingPid(); |
| 10261 | const int uid = ipc->getCallingUid(); |
Rheygine Medel | 9e9281e | 2022-09-22 10:13:56 -0700 | [diff] [blame] | 10262 | if ((uid != AID_GRAPHICS) && (uid != AID_SYSTEM) && |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10263 | !PermissionCache::checkPermission(sControlDisplayBrightness, pid, uid)) { |
| 10264 | ALOGE("Permission Denial: can't control brightness pid=%d, uid=%d", pid, uid); |
| 10265 | return PERMISSION_DENIED; |
| 10266 | } |
| 10267 | return OK; |
| 10268 | } |
| 10269 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10270 | status_t SurfaceComposerAIDL::checkReadFrameBufferPermission() { |
| 10271 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10272 | const int pid = ipc->getCallingPid(); |
| 10273 | const int uid = ipc->getCallingUid(); |
| 10274 | if ((uid != AID_GRAPHICS) && !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 10275 | ALOGE("Permission Denial: can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 10276 | return PERMISSION_DENIED; |
| 10277 | } |
| 10278 | return OK; |
| 10279 | } |
| 10280 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 10281 | void SurfaceFlinger::forceFutureUpdate(int delayInMs) { |
| 10282 | static_cast<void>(mScheduler->scheduleDelayed([&]() { scheduleRepaint(); }, ms2ns(delayInMs))); |
| 10283 | } |
| 10284 | |
Vishnu Nair | 2f65e97 | 2023-04-04 16:36:28 +0000 | [diff] [blame] | 10285 | const DisplayDevice* SurfaceFlinger::getDisplayFromLayerStack(ui::LayerStack layerStack) { |
| 10286 | for (const auto& [_, display] : mDisplays) { |
| 10287 | if (display->getLayerStack() == layerStack) { |
| 10288 | return display.get(); |
| 10289 | } |
| 10290 | } |
| 10291 | return nullptr; |
| 10292 | } |
| 10293 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 10294 | } // namespace android |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 10295 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 10296 | #if defined(__gl_h_) |
| 10297 | #error "don't include gl/gl.h in this file" |
| 10298 | #endif |
| 10299 | |
| 10300 | #if defined(__gl2_h_) |
| 10301 | #error "don't include gl2/gl2.h in this file" |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 10302 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 10303 | |
| 10304 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 10305 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |