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 "SurfaceFlingerProperties.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 157 | #include "TimeStats/TimeStats.h" |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 158 | #include "TunnelModeEnabledReporter.h" |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 159 | #include "Utils/Dumper.h" |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 160 | #include "WindowInfosListenerInvoker.h" |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 161 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 162 | #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 163 | #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 164 | #include <aidl/android/hardware/graphics/composer3/RenderIntent.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 165 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 166 | #undef NO_THREAD_SAFETY_ANALYSIS |
| 167 | #define NO_THREAD_SAFETY_ANALYSIS \ |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 168 | _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] | 169 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 170 | // To enable layer borders in the system, change the below flag to true. |
| 171 | #undef DOES_CONTAIN_BORDER |
| 172 | #define DOES_CONTAIN_BORDER false |
| 173 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | namespace android { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 175 | using namespace std::chrono_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 176 | using namespace std::string_literals; |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 177 | using namespace std::string_view_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 178 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 179 | using namespace hardware::configstore; |
| 180 | using namespace hardware::configstore::V1_0; |
| 181 | using namespace sysprop; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 182 | using ftl::Flags; |
| 183 | using namespace ftl::flag_operators; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 184 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 185 | using aidl::android::hardware::graphics::common::DisplayDecorationSupport; |
| 186 | using aidl::android::hardware::graphics::composer3::Capability; |
| 187 | using aidl::android::hardware::graphics::composer3::DisplayCapability; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 188 | using CompositionStrategyPredictionState = android::compositionengine::impl:: |
| 189 | OutputCompositionState::CompositionStrategyPredictionState; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 190 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 191 | using base::StringAppendF; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 192 | using display::PhysicalDisplay; |
| 193 | using display::PhysicalDisplays; |
Vishnu Nair | af6d297 | 2022-11-18 06:26:38 +0000 | [diff] [blame] | 194 | using frontend::TransactionHandler; |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 195 | using gui::DisplayInfo; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 196 | using gui::GameMode; |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 197 | using gui::IDisplayEventConnection; |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 198 | using gui::IWindowInfosListener; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 199 | using gui::LayerMetadata; |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 200 | using gui::WindowInfo; |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 201 | using gui::aidl_utils::binderStatusFromStatusT; |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 202 | using scheduler::VsyncModulator; |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 203 | using ui::Dataspace; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 204 | using ui::DisplayPrimaries; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 205 | using ui::RenderIntent; |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 206 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 207 | using KernelIdleTimerController = scheduler::RefreshRateSelector::KernelIdleTimerController; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 208 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 209 | namespace hal = android::hardware::graphics::composer::hal; |
| 210 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 211 | namespace { |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 212 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 213 | static constexpr int FOUR_K_WIDTH = 3840; |
| 214 | static constexpr int FOUR_K_HEIGHT = 2160; |
| 215 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 216 | // TODO(b/141333600): Consolidate with DisplayMode::Builder::getDefaultDensity. |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 217 | constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 218 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 219 | float getDensityFromProperty(const char* property, bool required) { |
| 220 | char value[PROPERTY_VALUE_MAX]; |
| 221 | const float density = property_get(property, value, nullptr) > 0 ? std::atof(value) : 0.f; |
| 222 | if (!density && required) { |
| 223 | ALOGE("%s must be defined as a build property", property); |
| 224 | return FALLBACK_DENSITY; |
| 225 | } |
| 226 | return density; |
| 227 | } |
| 228 | |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 229 | // Currently we only support V0_SRGB and DISPLAY_P3 as composition preference. |
| 230 | bool validateCompositionDataspace(Dataspace dataspace) { |
| 231 | return dataspace == Dataspace::V0_SRGB || dataspace == Dataspace::DISPLAY_P3; |
| 232 | } |
| 233 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 234 | std::chrono::milliseconds getIdleTimerTimeout(DisplayId displayId) { |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 235 | if (const int32_t displayIdleTimerMs = |
| 236 | base::GetIntProperty("debug.sf.set_idle_timer_ms_"s + |
| 237 | std::to_string(displayId.value), |
| 238 | 0); |
| 239 | displayIdleTimerMs > 0) { |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 240 | return std::chrono::milliseconds(displayIdleTimerMs); |
| 241 | } |
| 242 | |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 243 | 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] | 244 | const int32_t millis = setIdleTimerMs ? setIdleTimerMs : sysprop::set_idle_timer_ms(0); |
| 245 | return std::chrono::milliseconds(millis); |
| 246 | } |
| 247 | |
| 248 | bool getKernelIdleTimerSyspropConfig(DisplayId displayId) { |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 249 | const bool displaySupportKernelIdleTimer = |
| 250 | base::GetBoolProperty("debug.sf.support_kernel_idle_timer_"s + |
| 251 | std::to_string(displayId.value), |
| 252 | false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 253 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 254 | return displaySupportKernelIdleTimer || sysprop::support_kernel_idle_timer(false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 257 | bool isAbove4k30(const ui::DisplayMode& outMode) { |
| 258 | using fps_approx_ops::operator>; |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 259 | Fps refreshRate = Fps::fromValue(outMode.peakRefreshRate); |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 260 | return outMode.resolution.getWidth() >= FOUR_K_WIDTH && |
| 261 | outMode.resolution.getHeight() >= FOUR_K_HEIGHT && refreshRate > 30_Hz; |
| 262 | } |
| 263 | |
| 264 | void excludeDolbyVisionIf4k30Present(const std::vector<ui::Hdr>& displayHdrTypes, |
| 265 | ui::DisplayMode& outMode) { |
| 266 | if (isAbove4k30(outMode) && |
| 267 | std::any_of(displayHdrTypes.begin(), displayHdrTypes.end(), |
| 268 | [](ui::Hdr type) { return type == ui::Hdr::DOLBY_VISION_4K30; })) { |
| 269 | for (ui::Hdr type : displayHdrTypes) { |
| 270 | if (type != ui::Hdr::DOLBY_VISION_4K30 && type != ui::Hdr::DOLBY_VISION) { |
| 271 | outMode.supportedHdrTypes.push_back(type); |
| 272 | } |
| 273 | } |
| 274 | } else { |
| 275 | for (ui::Hdr type : displayHdrTypes) { |
| 276 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 277 | outMode.supportedHdrTypes.push_back(type); |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | HdrCapabilities filterOut4k30(const HdrCapabilities& displayHdrCapabilities) { |
| 284 | std::vector<ui::Hdr> hdrTypes; |
| 285 | for (ui::Hdr type : displayHdrCapabilities.getSupportedHdrTypes()) { |
| 286 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 287 | hdrTypes.push_back(type); |
| 288 | } |
| 289 | } |
| 290 | return {hdrTypes, displayHdrCapabilities.getDesiredMaxLuminance(), |
| 291 | displayHdrCapabilities.getDesiredMaxAverageLuminance(), |
| 292 | displayHdrCapabilities.getDesiredMinLuminance()}; |
| 293 | } |
| 294 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 295 | uint32_t getLayerIdFromSurfaceControl(sp<SurfaceControl> surfaceControl) { |
| 296 | if (!surfaceControl) { |
| 297 | return UNASSIGNED_LAYER_ID; |
| 298 | } |
| 299 | return LayerHandle::getLayerId(surfaceControl->getHandle()); |
| 300 | } |
| 301 | |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 302 | /** |
| 303 | * Returns true if the file at path exists and is newer than duration. |
| 304 | */ |
| 305 | bool fileNewerThan(const std::string& path, std::chrono::minutes duration) { |
| 306 | using Clock = std::filesystem::file_time_type::clock; |
| 307 | std::error_code error; |
| 308 | std::filesystem::file_time_type updateTime = std::filesystem::last_write_time(path, error); |
| 309 | if (error) { |
| 310 | return false; |
| 311 | } |
| 312 | return duration > (Clock::now() - updateTime); |
| 313 | } |
| 314 | |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 315 | bool isFrameIntervalOnCadence(TimePoint expectedPresentTime, TimePoint lastExpectedPresentTimestamp, |
| 316 | Fps lastFrameInterval, Period timeout, Duration threshold) { |
| 317 | if (lastFrameInterval.getPeriodNsecs() == 0) { |
| 318 | return false; |
| 319 | } |
| 320 | |
| 321 | const auto expectedPresentTimeDeltaNs = |
| 322 | expectedPresentTime.ns() - lastExpectedPresentTimestamp.ns(); |
| 323 | |
| 324 | if (expectedPresentTimeDeltaNs > timeout.ns()) { |
| 325 | return false; |
| 326 | } |
| 327 | |
| 328 | const auto expectedPresentPeriods = static_cast<nsecs_t>( |
| 329 | std::round(static_cast<float>(expectedPresentTimeDeltaNs) / |
| 330 | static_cast<float>(lastFrameInterval.getPeriodNsecs()))); |
| 331 | const auto calculatedPeriodsOutNs = lastFrameInterval.getPeriodNsecs() * expectedPresentPeriods; |
| 332 | const auto calculatedExpectedPresentTimeNs = |
| 333 | lastExpectedPresentTimestamp.ns() + calculatedPeriodsOutNs; |
| 334 | const auto presentTimeDelta = |
| 335 | std::abs(expectedPresentTime.ns() - calculatedExpectedPresentTimeNs); |
| 336 | return presentTimeDelta < threshold.ns(); |
| 337 | } |
| 338 | |
| 339 | bool isExpectedPresentWithinTimeout(TimePoint expectedPresentTime, |
| 340 | TimePoint lastExpectedPresentTimestamp, |
| 341 | std::optional<Period> timeoutOpt, Duration threshold) { |
| 342 | if (!timeoutOpt) { |
| 343 | // Always within timeout if timeoutOpt is absent and don't send hint |
| 344 | // for the timeout |
| 345 | return true; |
| 346 | } |
| 347 | |
| 348 | if (timeoutOpt->ns() == 0) { |
| 349 | // Always outside timeout if timeoutOpt is 0 and always send |
| 350 | // the hint for the timeout. |
| 351 | return false; |
| 352 | } |
| 353 | |
| 354 | if (expectedPresentTime.ns() < lastExpectedPresentTimestamp.ns() + timeoutOpt->ns()) { |
| 355 | return true; |
| 356 | } |
| 357 | |
| 358 | // Check if within the threshold as it can be just outside the timeout |
| 359 | return std::abs(expectedPresentTime.ns() - |
| 360 | (lastExpectedPresentTimestamp.ns() + timeoutOpt->ns())) < threshold.ns(); |
| 361 | } |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 362 | } // namespace anonymous |
| 363 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | // --------------------------------------------------------------------------- |
| 365 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 366 | const String16 sHardwareTest("android.permission.HARDWARE_TEST"); |
| 367 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 368 | const String16 sRotateSurfaceFlinger("android.permission.ROTATE_SURFACE_FLINGER"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 369 | const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER"); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 370 | const String16 sControlDisplayBrightness("android.permission.CONTROL_DISPLAY_BRIGHTNESS"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 371 | const String16 sDump("android.permission.DUMP"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 372 | const String16 sCaptureBlackoutContent("android.permission.CAPTURE_BLACKOUT_CONTENT"); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 373 | const String16 sInternalSystemWindow("android.permission.INTERNAL_SYSTEM_WINDOW"); |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 374 | const String16 sWakeupSurfaceFlinger("android.permission.WAKEUP_SURFACE_FLINGER"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 375 | |
Amy Hsu | c8cdfef | 2020-05-07 13:06:25 +0800 | [diff] [blame] | 376 | const char* KERNEL_IDLE_TIMER_PROP = "graphics.display.kernel_idle_timer.enabled"; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 377 | |
| 378 | // --------------------------------------------------------------------------- |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 379 | int64_t SurfaceFlinger::dispSyncPresentTimeOffset; |
| 380 | bool SurfaceFlinger::useHwcForRgbToYuv; |
| 381 | bool SurfaceFlinger::hasSyncFramework; |
| 382 | int64_t SurfaceFlinger::maxFrameBufferAcquiredBuffers; |
| 383 | int64_t SurfaceFlinger::minAcquiredBuffers = 1; |
| 384 | uint32_t SurfaceFlinger::maxGraphicsWidth; |
| 385 | uint32_t SurfaceFlinger::maxGraphicsHeight; |
| 386 | bool SurfaceFlinger::useContextPriority; |
| 387 | Dataspace SurfaceFlinger::defaultCompositionDataspace = Dataspace::V0_SRGB; |
| 388 | ui::PixelFormat SurfaceFlinger::defaultCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
| 389 | Dataspace SurfaceFlinger::wideColorGamutCompositionDataspace = Dataspace::V0_SRGB; |
| 390 | ui::PixelFormat SurfaceFlinger::wideColorGamutCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 391 | LatchUnsignaledConfig SurfaceFlinger::enableLatchUnsignaledConfig; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 392 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 393 | std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) { |
| 394 | switch(displayColorSetting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 395 | case DisplayColorSetting::kManaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 396 | return std::string("Managed"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 397 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 398 | return std::string("Unmanaged"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 399 | case DisplayColorSetting::kEnhanced: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 400 | return std::string("Enhanced"); |
| 401 | default: |
| 402 | return std::string("Unknown ") + |
| 403 | std::to_string(static_cast<int>(displayColorSetting)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 404 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 407 | bool callingThreadHasPermission(const String16& permission) { |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 408 | IPCThreadState* ipc = IPCThreadState::self(); |
| 409 | const int pid = ipc->getCallingPid(); |
| 410 | const int uid = ipc->getCallingUid(); |
| 411 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 412 | PermissionCache::checkPermission(permission, pid, uid); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 415 | ui::Transform::RotationFlags SurfaceFlinger::sActiveDisplayRotationFlags = ui::Transform::ROT_0; |
| 416 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 417 | SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag) |
| 418 | : mFactory(factory), |
| 419 | mPid(getpid()), |
Yiwei Zhang | f0229a7 | 2019-09-09 19:28:02 -0700 | [diff] [blame] | 420 | mTimeStats(std::make_shared<impl::TimeStats>()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 421 | mFrameTracer(mFactory.createFrameTracer()), |
| 422 | mFrameTimeline(mFactory.createFrameTimeline(mTimeStats, mPid)), |
| 423 | mCompositionEngine(mFactory.createCompositionEngine()), |
| 424 | mHwcServiceName(base::GetProperty("debug.sf.hwc_service_name"s, "default"s)), |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 425 | mTunnelModeEnabledReporter(sp<TunnelModeEnabledReporter>::make()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 426 | mEmulatedDisplayDensity(getDensityFromProperty("qemu.sf.lcd_density", false)), |
| 427 | mInternalDisplayDensity( |
| 428 | getDensityFromProperty("ro.sf.lcd_density", !mEmulatedDisplayDensity)), |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 429 | mPowerAdvisor(std::make_unique<Hwc2::impl::PowerAdvisor>(*this)), |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 430 | mWindowInfosListenerInvoker(sp<WindowInfosListenerInvoker>::make()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 431 | ALOGI("Using HWComposer service: %s", mHwcServiceName.c_str()); |
| 432 | } |
Fabien Sanglard | 0cc1938 | 2017-03-06 11:54:40 -0800 | [diff] [blame] | 433 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 434 | SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { |
| 435 | ATRACE_CALL(); |
| 436 | ALOGI("SurfaceFlinger is starting"); |
| 437 | |
| 438 | hasSyncFramework = running_without_sync_framework(true); |
| 439 | |
| 440 | dispSyncPresentTimeOffset = present_time_offset_from_vsync_ns(0); |
| 441 | |
| 442 | useHwcForRgbToYuv = force_hwc_copy_for_virtual_displays(false); |
| 443 | |
| 444 | maxFrameBufferAcquiredBuffers = max_frame_buffer_acquired_buffers(2); |
| 445 | minAcquiredBuffers = |
| 446 | SurfaceFlingerProperties::min_acquired_buffers().value_or(minAcquiredBuffers); |
| 447 | |
| 448 | maxGraphicsWidth = std::max(max_graphics_width(0), 0); |
| 449 | maxGraphicsHeight = std::max(max_graphics_height(0), 0); |
| 450 | |
| 451 | mSupportsWideColor = has_wide_color_display(false); |
| 452 | mDefaultCompositionDataspace = |
| 453 | static_cast<ui::Dataspace>(default_composition_dataspace(Dataspace::V0_SRGB)); |
| 454 | mWideColorGamutCompositionDataspace = static_cast<ui::Dataspace>(wcg_composition_dataspace( |
| 455 | mSupportsWideColor ? Dataspace::DISPLAY_P3 : Dataspace::V0_SRGB)); |
| 456 | defaultCompositionDataspace = mDefaultCompositionDataspace; |
| 457 | wideColorGamutCompositionDataspace = mWideColorGamutCompositionDataspace; |
| 458 | defaultCompositionPixelFormat = static_cast<ui::PixelFormat>( |
| 459 | default_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 460 | wideColorGamutCompositionPixelFormat = |
| 461 | static_cast<ui::PixelFormat>(wcg_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 462 | |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 463 | mLayerCachingEnabled = |
| 464 | base::GetBoolProperty("debug.sf.enable_layer_caching"s, |
| 465 | sysprop::SurfaceFlingerProperties::enable_layer_caching() |
| 466 | .value_or(false)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 467 | |
| 468 | useContextPriority = use_context_priority(true); |
| 469 | |
| 470 | mInternalDisplayPrimaries = sysprop::getDisplayNativePrimaries(); |
| 471 | |
| 472 | // debugging stuff... |
| 473 | char value[PROPERTY_VALUE_MAX]; |
| 474 | |
| 475 | property_get("ro.build.type", value, "user"); |
| 476 | mIsUserBuild = strcmp(value, "user") == 0; |
| 477 | |
| 478 | mDebugFlashDelay = base::GetUintProperty("debug.sf.showupdates"s, 0u); |
| 479 | |
| 480 | mBackpressureGpuComposition = base::GetBoolProperty("debug.sf.enable_gl_backpressure"s, true); |
| 481 | ALOGI_IF(mBackpressureGpuComposition, "Enabling backpressure for GPU composition"); |
| 482 | |
| 483 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 484 | bool supportsBlurs = atoi(value); |
| 485 | mSupportsBlur = supportsBlurs; |
| 486 | ALOGI_IF(!mSupportsBlur, "Disabling blur effects, they are not supported."); |
| 487 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 488 | property_get("debug.sf.luma_sampling", value, "1"); |
| 489 | mLumaSampling = atoi(value); |
| 490 | |
| 491 | property_get("debug.sf.disable_client_composition_cache", value, "0"); |
| 492 | mDisableClientCompositionCache = atoi(value); |
| 493 | |
| 494 | property_get("debug.sf.predict_hwc_composition_strategy", value, "1"); |
| 495 | mPredictCompositionStrategy = atoi(value); |
| 496 | |
| 497 | property_get("debug.sf.treat_170m_as_sRGB", value, "0"); |
| 498 | mTreat170mAsSrgb = atoi(value); |
| 499 | |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 500 | property_get("debug.sf.dim_in_gamma_in_enhanced_screenshots", value, 0); |
| 501 | mDimInGammaSpaceForEnhancedScreenshots = atoi(value); |
| 502 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 503 | mIgnoreHwcPhysicalDisplayOrientation = |
| 504 | base::GetBoolProperty("debug.sf.ignore_hwc_physical_display_orientation"s, false); |
| 505 | |
| 506 | // We should be reading 'persist.sys.sf.color_saturation' here |
| 507 | // but since /data may be encrypted, we need to wait until after vold |
| 508 | // comes online to attempt to read the property. The property is |
| 509 | // instead read after the boot animation |
| 510 | |
| 511 | if (base::GetBoolProperty("debug.sf.treble_testing_override"s, false)) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 512 | // Without the override SurfaceFlinger cannot connect to HIDL |
| 513 | // services that are not listed in the manifests. Considered |
| 514 | // deriving the setting from the set service name, but it |
| 515 | // would be brittle if the name that's not 'default' is used |
| 516 | // for production purposes later on. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 517 | ALOGI("Enabling Treble testing override"); |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 518 | android::hardware::details::setTrebleTestingOverride(true); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 519 | } |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 520 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 521 | // TODO (b/270966065) Update the HWC based refresh rate overlay to support spinner |
| 522 | mRefreshRateOverlaySpinner = property_get_bool("debug.sf.show_refresh_rate_overlay_spinner", 0); |
| 523 | mRefreshRateOverlayRenderRate = |
| 524 | property_get_bool("debug.sf.show_refresh_rate_overlay_render_rate", 0); |
| 525 | mRefreshRateOverlayShowInMiddle = |
| 526 | property_get_bool("debug.sf.show_refresh_rate_overlay_in_middle", 0); |
| 527 | |
| 528 | if (!mIsUserBuild && base::GetBoolProperty("debug.sf.enable_transaction_tracing"s, true)) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 529 | mTransactionTracing.emplace(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 530 | mLayerTracing.setTransactionTracing(*mTransactionTracing); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 531 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 532 | |
| 533 | mIgnoreHdrCameraLayers = ignore_hdr_camera_layers(false); |
| 534 | |
| 535 | mLayerLifecycleManagerEnabled = |
Vishnu Nair | f42d9bd | 2023-08-23 21:35:33 +0000 | [diff] [blame] | 536 | base::GetBoolProperty("persist.debug.sf.enable_layer_lifecycle_manager"s, true); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 537 | mLegacyFrontEndEnabled = !mLayerLifecycleManagerEnabled || |
| 538 | base::GetBoolProperty("persist.debug.sf.enable_legacy_frontend"s, false); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 539 | |
| 540 | // These are set by the HWC implementation to indicate that they will use the workarounds. |
| 541 | mIsHotplugErrViaNegVsync = |
| 542 | base::GetBoolProperty("debug.sf.hwc_hotplug_error_via_neg_vsync"s, false); |
| 543 | |
| 544 | mIsHdcpViaNegVsync = base::GetBoolProperty("debug.sf.hwc_hdcp_via_neg_vsync"s, false); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | LatchUnsignaledConfig SurfaceFlinger::getLatchUnsignaledConfig() { |
Ady Abraham | d9e8d1b | 2022-02-25 00:36:10 +0000 | [diff] [blame] | 548 | if (base::GetBoolProperty("debug.sf.auto_latch_unsignaled"s, true)) { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 549 | return LatchUnsignaledConfig::AutoSingleLayer; |
| 550 | } |
| 551 | |
| 552 | return LatchUnsignaledConfig::Disabled; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | } |
| 554 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 555 | SurfaceFlinger::~SurfaceFlinger() = default; |
| 556 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 557 | void SurfaceFlinger::binderDied(const wp<IBinder>&) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 558 | // the window manager died on us. prepare its eulogy. |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 559 | mBootFinished = false; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 560 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 561 | static_cast<void>(mScheduler->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 562 | // Sever the link to inputflinger since it's gone as well. |
| 563 | mInputFlinger.clear(); |
Vishnu Nair | b9df470 | 2021-03-01 11:53:15 -0800 | [diff] [blame] | 564 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 565 | initializeDisplays(); |
| 566 | })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 567 | |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 568 | mInitBootPropsFuture.callOnce([this] { |
| 569 | return std::async(std::launch::async, &SurfaceFlinger::initBootProperties, this); |
| 570 | }); |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 571 | |
| 572 | mInitBootPropsFuture.wait(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 573 | } |
| 574 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 575 | void SurfaceFlinger::run() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 576 | mScheduler->run(); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 577 | } |
| 578 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 579 | sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName, bool secure, |
| 580 | float requestedRefreshRate) { |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 581 | // onTransact already checks for some permissions, but adding an additional check here. |
| 582 | // This is to ensure that only system and graphics can request to create a secure |
| 583 | // display. Secure displays can show secure content so we add an additional restriction on it. |
| 584 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 585 | if (secure && uid != AID_GRAPHICS && uid != AID_SYSTEM) { |
| 586 | ALOGE("Only privileged processes can create a secure display"); |
| 587 | return nullptr; |
| 588 | } |
| 589 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 590 | class DisplayToken : public BBinder { |
| 591 | sp<SurfaceFlinger> flinger; |
| 592 | virtual ~DisplayToken() { |
| 593 | // no more references, this display must be terminated |
| 594 | Mutex::Autolock _l(flinger->mStateLock); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 595 | flinger->mCurrentState.displays.removeItem(wp<IBinder>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 596 | flinger->setTransactionFlags(eDisplayTransactionNeeded); |
| 597 | } |
| 598 | public: |
Chih-Hung Hsieh | c406791 | 2016-05-03 14:03:27 -0700 | [diff] [blame] | 599 | explicit DisplayToken(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 600 | : flinger(flinger) { |
| 601 | } |
| 602 | }; |
| 603 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 604 | sp<BBinder> token = sp<DisplayToken>::make(sp<SurfaceFlinger>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 605 | |
| 606 | Mutex::Autolock _l(mStateLock); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 607 | // Display ID is assigned when virtual display is allocated by HWC. |
| 608 | DisplayDeviceState state; |
| 609 | state.isSecure = secure; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 610 | // Set display as protected when marked as secure to ensure no behavior change |
| 611 | // TODO (b/314820005): separate as a different arg when creating the display. |
| 612 | state.isProtected = secure; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 613 | state.displayName = displayName; |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 614 | state.requestedRefreshRate = Fps::fromValue(requestedRefreshRate); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 615 | mCurrentState.displays.add(token, state); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 616 | return token; |
| 617 | } |
| 618 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 619 | void SurfaceFlinger::destroyDisplay(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 620 | Mutex::Autolock lock(mStateLock); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 621 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 622 | const ssize_t index = mCurrentState.displays.indexOfKey(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 623 | if (index < 0) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 624 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 625 | return; |
| 626 | } |
| 627 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 628 | const DisplayDeviceState& state = mCurrentState.displays.valueAt(index); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 629 | if (state.physical) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 630 | ALOGE("%s: Invalid operation on physical display", __func__); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 631 | return; |
| 632 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 633 | mCurrentState.displays.removeItemsAt(index); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 634 | setTransactionFlags(eDisplayTransactionNeeded); |
| 635 | } |
| 636 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 637 | void SurfaceFlinger::enableHalVirtualDisplays(bool enable) { |
| 638 | auto& generator = mVirtualDisplayIdGenerators.hal; |
| 639 | if (!generator && enable) { |
| 640 | ALOGI("Enabling HAL virtual displays"); |
| 641 | generator.emplace(getHwComposer().getMaxVirtualDisplayCount()); |
| 642 | } else if (generator && !enable) { |
| 643 | ALOGW_IF(generator->inUse(), "Disabling HAL virtual displays while in use"); |
| 644 | generator.reset(); |
| 645 | } |
| 646 | } |
| 647 | |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 648 | VirtualDisplayId SurfaceFlinger::acquireVirtualDisplay(ui::Size resolution, |
| 649 | ui::PixelFormat format) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 650 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 651 | if (const auto id = generator->generateId()) { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 652 | if (getHwComposer().allocateVirtualDisplay(*id, resolution, &format)) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 653 | return *id; |
| 654 | } |
| 655 | |
| 656 | generator->releaseId(*id); |
| 657 | } else { |
| 658 | ALOGW("%s: Exhausted HAL virtual displays", __func__); |
| 659 | } |
| 660 | |
| 661 | ALOGW("%s: Falling back to GPU virtual display", __func__); |
| 662 | } |
| 663 | |
| 664 | const auto id = mVirtualDisplayIdGenerators.gpu.generateId(); |
| 665 | LOG_ALWAYS_FATAL_IF(!id, "Failed to generate ID for GPU virtual display"); |
| 666 | return *id; |
| 667 | } |
| 668 | |
| 669 | void SurfaceFlinger::releaseVirtualDisplay(VirtualDisplayId displayId) { |
| 670 | if (const auto id = HalVirtualDisplayId::tryCast(displayId)) { |
| 671 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 672 | generator->releaseId(*id); |
| 673 | } |
| 674 | return; |
| 675 | } |
| 676 | |
| 677 | const auto id = GpuVirtualDisplayId::tryCast(displayId); |
| 678 | LOG_ALWAYS_FATAL_IF(!id); |
| 679 | mVirtualDisplayIdGenerators.gpu.releaseId(*id); |
| 680 | } |
| 681 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 682 | std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdsLocked() const { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 683 | std::vector<PhysicalDisplayId> displayIds; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 684 | displayIds.reserve(mPhysicalDisplays.size()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 685 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 686 | const auto defaultDisplayId = getDefaultDisplayDeviceLocked()->getPhysicalId(); |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 687 | displayIds.push_back(defaultDisplayId); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 688 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 689 | for (const auto& [id, display] : mPhysicalDisplays) { |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 690 | if (id != defaultDisplayId) { |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 691 | displayIds.push_back(id); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 692 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 693 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 694 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 695 | return displayIds; |
| 696 | } |
| 697 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 698 | std::optional<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdLocked( |
| 699 | const sp<display::DisplayToken>& displayToken) const { |
| 700 | return ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 701 | .transform(&ftl::to_key<PhysicalDisplays>); |
| 702 | } |
| 703 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 704 | sp<IBinder> SurfaceFlinger::getPhysicalDisplayToken(PhysicalDisplayId displayId) const { |
| 705 | Mutex::Autolock lock(mStateLock); |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 706 | return getPhysicalDisplayTokenLocked(displayId); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 709 | HWComposer& SurfaceFlinger::getHwComposer() const { |
| 710 | return mCompositionEngine->getHwComposer(); |
| 711 | } |
| 712 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 713 | renderengine::RenderEngine& SurfaceFlinger::getRenderEngine() const { |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 714 | return *mRenderEngine; |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 717 | compositionengine::CompositionEngine& SurfaceFlinger::getCompositionEngine() const { |
| 718 | return *mCompositionEngine.get(); |
| 719 | } |
| 720 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 721 | void SurfaceFlinger::bootFinished() { |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 722 | if (mBootFinished == true) { |
| 723 | ALOGE("Extra call to bootFinished"); |
| 724 | return; |
| 725 | } |
| 726 | mBootFinished = true; |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame] | 727 | FlagManager::getMutableInstance().markBootCompleted(); |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 728 | |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 729 | mInitBootPropsFuture.wait(); |
| 730 | mRenderEnginePrimeCacheFuture.wait(); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 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 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 819 | void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) { |
Parth Sane | 343626c | 2023-04-06 16:17:04 +0000 | [diff] [blame] | 820 | ATRACE_CALL(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 821 | ALOGI( "SurfaceFlinger's main thread ready to run. " |
| 822 | "Initializing graphics H/W..."); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 823 | addTransactionReadyFilters(); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 824 | Mutex::Autolock lock(mStateLock); |
Kevin DuBois | 413287f | 2019-02-25 08:46:47 -0800 | [diff] [blame] | 825 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 826 | // Get a RenderEngine for the given display / config (can't fail) |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 827 | // 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] | 828 | // Sending maxFrameBufferAcquiredBuffers as the cache size is tightly tuned to single-display. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 829 | auto builder = renderengine::RenderEngineCreationArgs::Builder() |
| 830 | .setPixelFormat(static_cast<int32_t>(defaultCompositionPixelFormat)) |
| 831 | .setImageCacheSize(maxFrameBufferAcquiredBuffers) |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 832 | .setEnableProtectedContext(enable_protected_contents(false)) |
| 833 | .setPrecacheToneMapperShaderOnly(false) |
| 834 | .setSupportsBackgroundBlur(mSupportsBlur) |
| 835 | .setContextPriority( |
| 836 | useContextPriority |
| 837 | ? renderengine::RenderEngine::ContextPriority::REALTIME |
| 838 | : renderengine::RenderEngine::ContextPriority::MEDIUM); |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 839 | chooseRenderEngineType(builder); |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 840 | mRenderEngine = renderengine::RenderEngine::create(builder.build()); |
| 841 | mCompositionEngine->setRenderEngine(mRenderEngine.get()); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 842 | mMaxRenderTargetSize = |
| 843 | std::min(getRenderEngine().getMaxTextureSize(), getRenderEngine().getMaxViewportDims()); |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 844 | |
| 845 | // Set SF main policy after initializing RenderEngine which has its own policy. |
| 846 | if (!SetTaskProfiles(0, {"SFMainPolicy"})) { |
| 847 | ALOGW("Failed to set main task profile"); |
| 848 | } |
| 849 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 850 | mCompositionEngine->setTimeStats(mTimeStats); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 851 | mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName)); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 852 | mCompositionEngine->getHwComposer().setCallback(*this); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 853 | ClientCache::getInstance().setRenderEngine(&getRenderEngine()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 854 | |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 855 | mHasReliablePresentFences = |
| 856 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE); |
| 857 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 858 | enableLatchUnsignaledConfig = getLatchUnsignaledConfig(); |
| 859 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 860 | if (base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false)) { |
| 861 | enableHalVirtualDisplays(true); |
| 862 | } |
| 863 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 864 | // Process hotplug for displays connected at boot. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 865 | LOG_ALWAYS_FATAL_IF(!configureLocked(), |
| 866 | "Initial display configuration failed: HWC did not hotplug"); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 867 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 868 | // Commit primary display. |
| 869 | sp<const DisplayDevice> display; |
| 870 | if (const auto indexOpt = mCurrentState.getDisplayIndex(getPrimaryDisplayIdLocked())) { |
| 871 | const auto& displays = mCurrentState.displays; |
| 872 | |
| 873 | const auto& token = displays.keyAt(*indexOpt); |
| 874 | const auto& state = displays.valueAt(*indexOpt); |
| 875 | |
| 876 | processDisplayAdded(token, state); |
| 877 | mDrawingState.displays.add(token, state); |
| 878 | |
| 879 | display = getDefaultDisplayDeviceLocked(); |
| 880 | } |
| 881 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 882 | LOG_ALWAYS_FATAL_IF(!display, "Failed to configure the primary display"); |
| 883 | LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(display->getPhysicalId()), |
| 884 | "Primary display is disconnected"); |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 885 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 886 | // TODO(b/241285876): The Scheduler needlessly depends on creating the CompositionEngine part of |
| 887 | // the DisplayDevice, hence the above commit of the primary display. Remove that special case by |
| 888 | // initializing the Scheduler after configureLocked, once decoupled from DisplayDevice. |
| 889 | initScheduler(display); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 890 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 891 | mLayerTracing.setTakeLayersSnapshotProtoFunction([&](uint32_t traceFlags) { |
| 892 | auto snapshot = perfetto::protos::LayersSnapshotProto{}; |
| 893 | mScheduler |
| 894 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 895 | snapshot = takeLayersSnapshotProto(traceFlags, TimePoint::now(), |
| 896 | mLastCommittedVsyncId, true); |
| 897 | }) |
| 898 | .wait(); |
| 899 | return snapshot; |
| 900 | }); |
| 901 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 902 | // Commit secondary display(s). |
| 903 | processDisplayChangesLocked(); |
| 904 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 905 | // initialize our drawing state |
| 906 | mDrawingState = mCurrentState; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 907 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 908 | onActiveDisplayChangedLocked(nullptr, *display); |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 909 | |
| 910 | static_cast<void>(mScheduler->schedule( |
| 911 | [this]() FTL_FAKE_GUARD(kMainThreadContext) { initializeDisplays(); })); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 912 | |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 913 | mPowerAdvisor->init(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 914 | |
Bruno BELANYI | fd02878 | 2023-10-13 14:39:53 +0000 | [diff] [blame] | 915 | if (base::GetBoolProperty("service.sf.prime_shader_cache"s, true)) { |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 916 | if (setSchedFifo(false) != NO_ERROR) { |
| 917 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 918 | } |
| 919 | |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 920 | mRenderEnginePrimeCacheFuture.callOnce([this] { |
| 921 | const bool shouldPrimeUltraHDR = |
| 922 | base::GetBoolProperty("ro.surface_flinger.prime_shader_cache.ultrahdr"s, false); |
| 923 | return getRenderEngine().primeCache(shouldPrimeUltraHDR); |
| 924 | }); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 925 | |
| 926 | if (setSchedFifo(true) != NO_ERROR) { |
linkai | d696a4f | 2023-11-14 10:13:36 +0800 | [diff] [blame] | 927 | ALOGW("Can't set SCHED_FIFO after primeCache"); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 928 | } |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 929 | } |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 930 | |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 931 | // Avoid blocking the main thread on `init` to set properties. |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 932 | mInitBootPropsFuture.callOnce([this] { |
| 933 | return std::async(std::launch::async, &SurfaceFlinger::initBootProperties, this); |
| 934 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 936 | initTransactionTraceWriter(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 937 | ALOGV("Done initializing"); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 940 | // During boot, offload `initBootProperties` to another thread. `property_set` depends on |
| 941 | // `property_service`, which may be delayed by slow operations like `mount_all --late` in |
| 942 | // the `init` process. See b/34499826 and b/63844978. |
| 943 | void SurfaceFlinger::initBootProperties() { |
| 944 | property_set("service.sf.present_timestamp", mHasReliablePresentFences ? "1" : "0"); |
| 945 | |
Dominik Laskowski | b0fdfe7 | 2024-02-21 10:42:23 -0500 | [diff] [blame] | 946 | if (base::GetBoolProperty("debug.sf.boot_animation"s, true)) { |
| 947 | // Reset and (if needed) start BootAnimation. |
| 948 | property_set("service.bootanim.exit", "0"); |
| 949 | property_set("service.bootanim.progress", "0"); |
| 950 | property_set("ctl.start", "bootanim"); |
| 951 | } |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 952 | } |
| 953 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 954 | void SurfaceFlinger::initTransactionTraceWriter() { |
| 955 | if (!mTransactionTracing) { |
| 956 | return; |
| 957 | } |
| 958 | TransactionTraceWriter::getInstance().setWriterFunction( |
| 959 | [&](const std::string& filename, bool overwrite) { |
| 960 | auto writeFn = [&]() { |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 961 | if (!overwrite && fileNewerThan(filename, std::chrono::minutes{10})) { |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 962 | ALOGD("TransactionTraceWriter: file=%s already exists", filename.c_str()); |
| 963 | return; |
| 964 | } |
| 965 | mTransactionTracing->flush(); |
| 966 | mTransactionTracing->writeToFile(filename); |
| 967 | }; |
| 968 | if (std::this_thread::get_id() == mMainThreadId) { |
| 969 | writeFn(); |
| 970 | } else { |
| 971 | mScheduler->schedule(writeFn).get(); |
| 972 | } |
| 973 | }); |
| 974 | } |
| 975 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 976 | void SurfaceFlinger::readPersistentProperties() { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 977 | Mutex::Autolock _l(mStateLock); |
| 978 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 979 | char value[PROPERTY_VALUE_MAX]; |
| 980 | |
| 981 | property_get("persist.sys.sf.color_saturation", value, "1.0"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 982 | mGlobalSaturationFactor = atof(value); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 983 | updateColorMatrixLocked(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 984 | ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 985 | |
| 986 | property_get("persist.sys.sf.native_mode", value, "0"); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 987 | mDisplayColorSetting = static_cast<DisplayColorSetting>(atoi(value)); |
Peiyong Lin | a3ea559 | 2019-02-10 14:45:00 -0800 | [diff] [blame] | 988 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 989 | mForceColorMode = |
| 990 | 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] | 991 | } |
| 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 | |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 1006 | if (mHasReliablePresentFences) { |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 1007 | outSupported->push_back(FrameEvent::DISPLAY_PRESENT); |
| 1008 | } |
| 1009 | return NO_ERROR; |
| 1010 | } |
| 1011 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1012 | status_t SurfaceFlinger::getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState* state) { |
| 1013 | if (!displayToken || !state) { |
| 1014 | return BAD_VALUE; |
| 1015 | } |
| 1016 | |
| 1017 | Mutex::Autolock lock(mStateLock); |
| 1018 | |
| 1019 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1020 | if (!display) { |
| 1021 | return NAME_NOT_FOUND; |
| 1022 | } |
| 1023 | |
| 1024 | state->layerStack = display->getLayerStack(); |
| 1025 | state->orientation = display->getOrientation(); |
| 1026 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 1027 | const Rect layerStackRect = display->getLayerStackSpaceRect(); |
| 1028 | state->layerStackSpaceRect = |
| 1029 | layerStackRect.isValid() ? layerStackRect.getSize() : display->getSize(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1030 | |
| 1031 | return NO_ERROR; |
| 1032 | } |
| 1033 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1034 | status_t SurfaceFlinger::getStaticDisplayInfo(int64_t displayId, ui::StaticDisplayInfo* info) { |
| 1035 | if (!info) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1036 | return BAD_VALUE; |
| 1037 | } |
| 1038 | |
| 1039 | Mutex::Autolock lock(mStateLock); |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1040 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 1041 | const auto displayOpt = mPhysicalDisplays.get(*id).and_then(getDisplayDeviceAndSnapshot()); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1042 | |
| 1043 | if (!displayOpt) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1044 | return NAME_NOT_FOUND; |
| 1045 | } |
| 1046 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1047 | const auto& [display, snapshotRef] = *displayOpt; |
| 1048 | const auto& snapshot = snapshotRef.get(); |
| 1049 | |
| 1050 | info->connectionType = snapshot.connectionType(); |
| 1051 | info->deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1052 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1053 | if (mEmulatedDisplayDensity) { |
| 1054 | info->density = mEmulatedDisplayDensity; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1055 | } else { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1056 | info->density = info->connectionType == ui::DisplayConnectionType::Internal |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1057 | ? mInternalDisplayDensity |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1058 | : FALLBACK_DENSITY; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1059 | } |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 1060 | info->density /= ACONFIGURATION_DENSITY_MEDIUM; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1061 | |
| 1062 | info->secure = display->isSecure(); |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1063 | info->installOrientation = display->getPhysicalOrientation(); |
Vishnu Nair | d0a8965 | 2022-01-13 12:05:54 -0800 | [diff] [blame] | 1064 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1065 | return NO_ERROR; |
| 1066 | } |
| 1067 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1068 | void SurfaceFlinger::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo*& info, |
| 1069 | const sp<DisplayDevice>& display, |
| 1070 | const display::DisplaySnapshot& snapshot) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1071 | const auto& displayModes = snapshot.displayModes(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1072 | info->supportedDisplayModes.clear(); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1073 | info->supportedDisplayModes.reserve(displayModes.size()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1074 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1075 | for (const auto& [id, mode] : displayModes) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1076 | ui::DisplayMode outMode; |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1077 | outMode.id = ftl::to_underlying(id); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1078 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1079 | auto [width, height] = mode->getResolution(); |
| 1080 | auto [xDpi, yDpi] = mode->getDpi(); |
Yiwei Zhang | 27de5df | 2018-08-23 17:04:51 -0700 | [diff] [blame] | 1081 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1082 | if (const auto physicalOrientation = display->getPhysicalOrientation(); |
| 1083 | physicalOrientation == ui::ROTATION_90 || physicalOrientation == ui::ROTATION_270) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1084 | std::swap(width, height); |
| 1085 | std::swap(xDpi, yDpi); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1086 | } |
| 1087 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1088 | outMode.resolution = ui::Size(width, height); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1089 | |
Huan Song | f7eeb10 | 2022-03-28 11:02:38 -0700 | [diff] [blame] | 1090 | outMode.xDpi = xDpi; |
| 1091 | outMode.yDpi = yDpi; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1092 | |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1093 | const auto peakFps = mode->getPeakFps(); |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 1094 | outMode.peakRefreshRate = peakFps.getValue(); |
Alec Mouri | d122a1c | 2023-09-30 01:36:33 +0000 | [diff] [blame] | 1095 | outMode.vsyncRate = mode->getVsyncRate().getValue(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1096 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1097 | const auto vsyncConfigSet = mScheduler->getVsyncConfiguration().getConfigsForRefreshRate( |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 1098 | Fps::fromValue(outMode.peakRefreshRate)); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1099 | outMode.appVsyncOffset = vsyncConfigSet.late.appOffset; |
| 1100 | outMode.sfVsyncOffset = vsyncConfigSet.late.sfOffset; |
| 1101 | outMode.group = mode->getGroup(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1102 | |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1103 | // This is how far in advance a buffer must be queued for |
| 1104 | // presentation at a given time. If you want a buffer to appear |
| 1105 | // on the screen at time N, you must submit the buffer before |
| 1106 | // (N - presentationDeadline). |
| 1107 | // |
| 1108 | // Normally it's one full refresh period (to give SF a chance to |
| 1109 | // latch the buffer), but this can be reduced by configuring a |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 1110 | // VsyncController offset. Any additional delays introduced by the hardware |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1111 | // composer or panel must be accounted for here. |
| 1112 | // |
| 1113 | // We add an additional 1ms to allow for processing time and |
| 1114 | // differences between the ideal and actual refresh rate. |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1115 | outMode.presentationDeadline = peakFps.getPeriodNsecs() - outMode.sfVsyncOffset + 1000000; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1116 | excludeDolbyVisionIf4k30Present(display->getHdrCapabilities().getSupportedHdrTypes(), |
| 1117 | outMode); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1118 | info->supportedDisplayModes.push_back(outMode); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1121 | info->supportedColorModes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1122 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1123 | const PhysicalDisplayId displayId = snapshot.displayId(); |
| 1124 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1125 | const auto mode = display->refreshRateSelector().getActiveMode(); |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1126 | info->activeDisplayModeId = ftl::to_underlying(mode.modePtr->getId()); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1127 | info->renderFrameRate = mode.fps.getValue(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1128 | info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1129 | info->hdrCapabilities = filterOut4k30(display->getHdrCapabilities()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1130 | |
Marin Shalamanov | b173f75 | 2021-02-16 19:38:36 +0100 | [diff] [blame] | 1131 | info->autoLowLatencyModeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1132 | getHwComposer().hasDisplayCapability(displayId, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1133 | DisplayCapability::AUTO_LOW_LATENCY_MODE); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1134 | info->gameContentTypeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1135 | getHwComposer().supportsContentType(displayId, hal::ContentType::GAME); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1136 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1137 | info->preferredBootDisplayMode = static_cast<ui::DisplayModeId>(-1); |
Kriti Dang | ac0a74d | 2022-03-16 11:52:35 +0100 | [diff] [blame] | 1138 | |
| 1139 | if (getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG)) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1140 | if (const auto hwcId = getHwComposer().getPreferredBootDisplayMode(displayId)) { |
| 1141 | if (const auto modeId = snapshot.translateModeId(*hwcId)) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1142 | info->preferredBootDisplayMode = ftl::to_underlying(*modeId); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1143 | } |
| 1144 | } |
| 1145 | } |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1146 | } |
Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame] | 1147 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1148 | status_t SurfaceFlinger::getDynamicDisplayInfoFromId(int64_t physicalDisplayId, |
| 1149 | ui::DynamicDisplayInfo* info) { |
| 1150 | if (!info) { |
| 1151 | return BAD_VALUE; |
| 1152 | } |
| 1153 | |
| 1154 | Mutex::Autolock lock(mStateLock); |
| 1155 | |
| 1156 | const auto id_ = |
| 1157 | DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(physicalDisplayId)); |
| 1158 | const auto displayOpt = mPhysicalDisplays.get(*id_).and_then(getDisplayDeviceAndSnapshot()); |
| 1159 | |
| 1160 | if (!displayOpt) { |
| 1161 | return NAME_NOT_FOUND; |
| 1162 | } |
| 1163 | |
| 1164 | const auto& [display, snapshotRef] = *displayOpt; |
| 1165 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
| 1166 | return NO_ERROR; |
| 1167 | } |
| 1168 | |
| 1169 | status_t SurfaceFlinger::getDynamicDisplayInfoFromToken(const sp<IBinder>& displayToken, |
| 1170 | ui::DynamicDisplayInfo* info) { |
| 1171 | if (!displayToken || !info) { |
| 1172 | return BAD_VALUE; |
| 1173 | } |
| 1174 | |
| 1175 | Mutex::Autolock lock(mStateLock); |
| 1176 | |
| 1177 | const auto displayOpt = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1178 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1179 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1180 | |
| 1181 | if (!displayOpt) { |
| 1182 | return NAME_NOT_FOUND; |
| 1183 | } |
| 1184 | |
| 1185 | const auto& [display, snapshotRef] = *displayOpt; |
| 1186 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1187 | return NO_ERROR; |
| 1188 | } |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 1189 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1190 | status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>& displayToken, |
| 1191 | DisplayStatInfo* outStats) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1192 | if (!outStats) { |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1193 | return BAD_VALUE; |
| 1194 | } |
| 1195 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1196 | std::optional<PhysicalDisplayId> displayIdOpt; |
| 1197 | { |
| 1198 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1199 | if (displayToken) { |
| 1200 | displayIdOpt = getPhysicalDisplayIdLocked(displayToken); |
| 1201 | if (!displayIdOpt) { |
| 1202 | ALOGW("%s: Invalid physical display token %p", __func__, displayToken.get()); |
| 1203 | return NAME_NOT_FOUND; |
| 1204 | } |
| 1205 | } else { |
| 1206 | // TODO (b/277364366): Clients should be updated to pass in the display they |
| 1207 | // want, rather than us picking an arbitrary one (the active display, in this |
| 1208 | // case). |
| 1209 | displayIdOpt = mActiveDisplayId; |
| 1210 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1211 | } |
| 1212 | |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1213 | const auto schedule = mScheduler->getVsyncSchedule(displayIdOpt); |
| 1214 | if (!schedule) { |
| 1215 | ALOGE("%s: Missing VSYNC schedule for display %s!", __func__, |
| 1216 | to_string(*displayIdOpt).c_str()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1217 | return NAME_NOT_FOUND; |
| 1218 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1219 | outStats->vsyncTime = schedule->vsyncDeadlineAfter(TimePoint::now()).ns(); |
| 1220 | outStats->vsyncPeriod = schedule->period().ns(); |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1221 | return NO_ERROR; |
| 1222 | } |
| 1223 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1224 | void SurfaceFlinger::setDesiredMode(display::DisplayModeRequest&& desiredMode) { |
| 1225 | const auto mode = desiredMode.mode; |
| 1226 | const auto displayId = mode.modePtr->getPhysicalDisplayId(); |
| 1227 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1228 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
| 1229 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1230 | const auto display = getDisplayDeviceLocked(displayId); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1231 | if (!display) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1232 | ALOGW("%s: display is no longer valid", __func__); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1233 | return; |
| 1234 | } |
| 1235 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1236 | const bool emitEvent = desiredMode.emitEvent; |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 1237 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1238 | switch (display->setDesiredMode(std::move(desiredMode))) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1239 | case DisplayDevice::DesiredModeAction::InitiateDisplayModeSwitch: |
| 1240 | // DisplayDevice::setDesiredMode updated the render rate, so inform Scheduler. |
Ady Abraham | ee6365b | 2024-03-06 14:31:45 -0800 | [diff] [blame] | 1241 | mScheduler->setRenderRate(displayId, display->refreshRateSelector().getActiveMode().fps, |
| 1242 | /*applyImmediately*/ true); |
Ady Abraham | 95a37e2 | 2023-01-18 22:57:28 -0800 | [diff] [blame] | 1243 | |
| 1244 | // Schedule a new frame to initiate the display mode switch. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1245 | scheduleComposite(FrameHint::kNone); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1246 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1247 | // Start receiving vsync samples now, so that we can detect a period |
| 1248 | // switch. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1249 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 1250 | mode.modePtr.get()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1251 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1252 | // As we called to set period, we will call to onRefreshRateChangeCompleted once |
| 1253 | // VsyncController model is locked. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1254 | mScheduler->modulateVsync(displayId, &VsyncModulator::onRefreshRateChangeInitiated); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1255 | |
| 1256 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1257 | mScheduler->updatePhaseConfiguration(mode.fps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1258 | } |
| 1259 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1260 | mScheduler->setModeChangePending(true); |
| 1261 | break; |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1262 | case DisplayDevice::DesiredModeAction::InitiateRenderRateSwitch: |
Ady Abraham | ee6365b | 2024-03-06 14:31:45 -0800 | [diff] [blame] | 1263 | mScheduler->setRenderRate(displayId, mode.fps, /*applyImmediately*/ false); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1264 | |
| 1265 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1266 | mScheduler->updatePhaseConfiguration(mode.fps); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1267 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1268 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1269 | if (emitEvent) { |
| 1270 | dispatchDisplayModeChangeEvent(displayId, mode); |
| 1271 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1272 | break; |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1273 | case DisplayDevice::DesiredModeAction::None: |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1274 | break; |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1275 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1276 | } |
| 1277 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1278 | status_t SurfaceFlinger::setActiveModeFromBackdoor(const sp<display::DisplayToken>& displayToken, |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1279 | DisplayModeId modeId, Fps minFps, Fps maxFps) { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1280 | ATRACE_CALL(); |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1281 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 1282 | if (!displayToken) { |
| 1283 | return BAD_VALUE; |
| 1284 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1285 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1286 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1287 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1288 | const auto displayOpt = |
| 1289 | FTL_FAKE_GUARD(mStateLock, |
| 1290 | ftl::find_if(mPhysicalDisplays, |
| 1291 | PhysicalDisplay::hasToken(displayToken)) |
| 1292 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1293 | .and_then(getDisplayDeviceAndSnapshot())); |
| 1294 | if (!displayOpt) { |
| 1295 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1296 | return NAME_NOT_FOUND; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1297 | } |
| 1298 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1299 | const auto& [display, snapshotRef] = *displayOpt; |
| 1300 | const auto& snapshot = snapshotRef.get(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1301 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1302 | const auto fpsOpt = snapshot.displayModes().get(modeId).transform( |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1303 | [](const DisplayModePtr& mode) { return mode->getPeakFps(); }); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1304 | |
| 1305 | if (!fpsOpt) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1306 | 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] | 1307 | to_string(snapshot.displayId()).c_str()); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1308 | return BAD_VALUE; |
| 1309 | } |
| 1310 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1311 | const Fps fps = *fpsOpt; |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1312 | const FpsRange physical = {fps, fps}; |
| 1313 | const FpsRange render = {minFps.isValid() ? minFps : fps, maxFps.isValid() ? maxFps : fps}; |
| 1314 | const FpsRanges ranges = {physical, render}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1315 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1316 | // Keep the old switching type. |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1317 | const bool allowGroupSwitching = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1318 | display->refreshRateSelector().getCurrentPolicy().allowGroupSwitching; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1319 | |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1320 | const scheduler::RefreshRateSelector::DisplayManagerPolicy policy{modeId, ranges, ranges, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 1321 | allowGroupSwitching}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1322 | |
| 1323 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1324 | }); |
| 1325 | |
| 1326 | return future.get(); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1327 | } |
| 1328 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1329 | void SurfaceFlinger::finalizeDisplayModeChange(DisplayDevice& display) { |
| 1330 | const auto displayId = display.getPhysicalId(); |
| 1331 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1332 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1333 | const auto pendingModeOpt = display.getPendingMode(); |
| 1334 | if (!pendingModeOpt) { |
| 1335 | // There is no pending mode change. This can happen if the active |
| 1336 | // display changed and the mode change happened on a different display. |
| 1337 | return; |
| 1338 | } |
Ady Abraham | faac6da | 2021-07-15 10:04:40 -0700 | [diff] [blame] | 1339 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1340 | const auto& activeMode = pendingModeOpt->mode; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1341 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1342 | if (display.getActiveMode().modePtr->getResolution() != activeMode.modePtr->getResolution()) { |
| 1343 | auto& state = mCurrentState.displays.editValueFor(display.getDisplayToken()); |
| 1344 | // We need to generate new sequenceId in order to recreate the display (and this |
| 1345 | // way the framebuffer). |
| 1346 | state.sequenceId = DisplayDeviceState{}.sequenceId; |
| 1347 | state.physical->activeMode = activeMode.modePtr.get(); |
| 1348 | processDisplayChangesLocked(); |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1349 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1350 | // processDisplayChangesLocked will update all necessary components so we're done here. |
| 1351 | return; |
| 1352 | } |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 1353 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1354 | display.finalizeModeChange(activeMode.modePtr->getId(), activeMode.modePtr->getVsyncRate(), |
| 1355 | activeMode.fps); |
| 1356 | |
| 1357 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1358 | mScheduler->updatePhaseConfiguration(activeMode.fps); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | if (pendingModeOpt->emitEvent) { |
| 1362 | dispatchDisplayModeChangeEvent(displayId, activeMode); |
| 1363 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1364 | } |
| 1365 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1366 | void SurfaceFlinger::dropModeRequest(const sp<DisplayDevice>& display) { |
| 1367 | display->clearDesiredMode(); |
| 1368 | if (display->getPhysicalId() == mActiveDisplayId) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1369 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1370 | mScheduler->setModeChangePending(false); |
| 1371 | } |
Ady Abraham | 53852a5 | 2019-05-28 18:07:44 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1374 | void SurfaceFlinger::applyActiveMode(const sp<DisplayDevice>& display) { |
| 1375 | const auto activeModeOpt = display->getDesiredMode(); |
| 1376 | auto activeModePtr = activeModeOpt->mode.modePtr; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1377 | const auto displayId = activeModePtr->getPhysicalDisplayId(); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1378 | const auto renderFps = activeModeOpt->mode.fps; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1379 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1380 | dropModeRequest(display); |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1381 | |
| 1382 | constexpr bool kAllowToEnable = true; |
| 1383 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, std::move(activeModePtr).take()); |
Ady Abraham | ee6365b | 2024-03-06 14:31:45 -0800 | [diff] [blame] | 1384 | mScheduler->setRenderRate(displayId, renderFps, /*applyImmediately*/ true); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1385 | |
| 1386 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1387 | mScheduler->updatePhaseConfiguration(renderFps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1388 | } |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1389 | } |
| 1390 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1391 | void SurfaceFlinger::initiateDisplayModeChanges() { |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1392 | ATRACE_CALL(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1393 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1394 | std::optional<PhysicalDisplayId> displayToUpdateImmediately; |
| 1395 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1396 | for (const auto& [id, physical] : mPhysicalDisplays) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1397 | const auto display = getDisplayDeviceLocked(id); |
| 1398 | if (!display) continue; |
| 1399 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1400 | auto desiredModeOpt = display->getDesiredMode(); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1401 | if (!desiredModeOpt) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1402 | continue; |
| 1403 | } |
| 1404 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 1405 | if (!shouldApplyRefreshRateSelectorPolicy(*display)) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1406 | dropModeRequest(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1407 | continue; |
| 1408 | } |
| 1409 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1410 | const auto desiredModeId = desiredModeOpt->mode.modePtr->getId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1411 | const auto displayModePtrOpt = physical.snapshot().displayModes().get(desiredModeId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1412 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1413 | if (!displayModePtrOpt) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1414 | ALOGW("Desired display mode is no longer supported. Mode ID = %d", |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1415 | ftl::to_underlying(desiredModeId)); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1416 | continue; |
| 1417 | } |
| 1418 | |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1419 | ALOGV("%s changing active mode to %d(%s) for display %s", __func__, |
| 1420 | ftl::to_underlying(desiredModeId), |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1421 | to_string(displayModePtrOpt->get()->getVsyncRate()).c_str(), |
| 1422 | to_string(display->getId()).c_str()); |
| 1423 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1424 | if ((!FlagManager::getInstance().connected_display() || !desiredModeOpt->force) && |
| 1425 | display->getActiveMode() == desiredModeOpt->mode) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1426 | applyActiveMode(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1427 | continue; |
| 1428 | } |
| 1429 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1430 | // Desired active mode was set, it is different than the mode currently in use, however |
| 1431 | // allowed modes might have changed by the time we process the refresh. |
| 1432 | // Make sure the desired mode is still allowed |
| 1433 | if (!display->refreshRateSelector().isModeAllowed(desiredModeOpt->mode)) { |
| 1434 | dropModeRequest(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1435 | continue; |
| 1436 | } |
| 1437 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1438 | // TODO(b/142753666) use constrains |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1439 | hal::VsyncPeriodChangeConstraints constraints; |
| 1440 | constraints.desiredTimeNanos = systemTime(); |
| 1441 | constraints.seamlessRequired = false; |
| 1442 | hal::VsyncPeriodChangeTimeline outTimeline; |
| 1443 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1444 | if (!display->initiateModeChange(std::move(*desiredModeOpt), constraints, outTimeline)) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1445 | continue; |
| 1446 | } |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1447 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1448 | display->refreshRateSelector().onModeChangeInitiated(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1449 | mScheduler->onNewVsyncPeriodChangeTimeline(outTimeline); |
| 1450 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1451 | if (outTimeline.refreshRequired) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 1452 | scheduleComposite(FrameHint::kNone); |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1453 | } else { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1454 | // TODO(b/255635711): Remove `displayToUpdateImmediately` to `finalizeDisplayModeChange` |
| 1455 | // for all displays. This was only needed when the loop iterated over `mDisplays` rather |
| 1456 | // than `mPhysicalDisplays`. |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1457 | displayToUpdateImmediately = display->getPhysicalId(); |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | if (displayToUpdateImmediately) { |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1462 | const auto display = getDisplayDeviceLocked(*displayToUpdateImmediately); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1463 | finalizeDisplayModeChange(*display); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1464 | |
| 1465 | const auto desiredModeOpt = display->getDesiredMode(); |
| 1466 | if (desiredModeOpt && display->getActiveMode() == desiredModeOpt->mode) { |
| 1467 | applyActiveMode(display); |
| 1468 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1469 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1470 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1471 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1472 | void SurfaceFlinger::disableExpensiveRendering() { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1473 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1474 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1475 | ATRACE_NAME(whence); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1476 | if (mPowerAdvisor->isUsingExpensiveRendering()) { |
Dominik Laskowski | bc6c860 | 2022-01-11 08:53:24 -0800 | [diff] [blame] | 1477 | for (const auto& [_, display] : mDisplays) { |
| 1478 | constexpr bool kDisable = false; |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1479 | mPowerAdvisor->setExpensiveRenderingExpected(display->getId(), kDisable); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1480 | } |
| 1481 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1482 | }); |
| 1483 | |
| 1484 | future.wait(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1487 | status_t SurfaceFlinger::getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1488 | ui::DisplayPrimaries& primaries) { |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1489 | if (!displayToken) { |
| 1490 | return BAD_VALUE; |
| 1491 | } |
| 1492 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1493 | Mutex::Autolock lock(mStateLock); |
| 1494 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1495 | const auto display = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1496 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>); |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1497 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1498 | return NAME_NOT_FOUND; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1499 | } |
| 1500 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1501 | if (!display.transform(&PhysicalDisplay::isInternal).value()) { |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1502 | return INVALID_OPERATION; |
| 1503 | } |
| 1504 | |
| 1505 | // 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] | 1506 | primaries = mInternalDisplayPrimaries; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1507 | return NO_ERROR; |
| 1508 | } |
| 1509 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1510 | status_t SurfaceFlinger::setActiveColorMode(const sp<IBinder>& displayToken, ui::ColorMode mode) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1511 | if (!displayToken) { |
| 1512 | return BAD_VALUE; |
| 1513 | } |
| 1514 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1515 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1516 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1517 | const auto displayOpt = |
| 1518 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1519 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1520 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1521 | |
| 1522 | if (!displayOpt) { |
| 1523 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1524 | return NAME_NOT_FOUND; |
| 1525 | } |
| 1526 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1527 | const auto& [display, snapshotRef] = *displayOpt; |
| 1528 | const auto& snapshot = snapshotRef.get(); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1529 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1530 | const auto modes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1531 | const bool exists = std::find(modes.begin(), modes.end(), mode) != modes.end(); |
| 1532 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1533 | if (mode < ui::ColorMode::NATIVE || !exists) { |
| 1534 | ALOGE("%s: Invalid color mode %s (%d) for display %s", whence, |
| 1535 | decodeColorMode(mode).c_str(), mode, to_string(snapshot.displayId()).c_str()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1536 | return BAD_VALUE; |
| 1537 | } |
| 1538 | |
| 1539 | display->getCompositionDisplay()->setColorProfile( |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 1540 | {mode, Dataspace::UNKNOWN, RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1541 | |
| 1542 | return NO_ERROR; |
| 1543 | }); |
| 1544 | |
Dominik Laskowski | 0a5f921 | 2021-08-05 17:00:04 -0700 | [diff] [blame] | 1545 | // TODO(b/195698395): Propagate error. |
| 1546 | future.wait(); |
| 1547 | return NO_ERROR; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1548 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1549 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1550 | status_t SurfaceFlinger::getBootDisplayModeSupport(bool* outSupport) const { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1551 | auto future = mScheduler->schedule( |
| 1552 | [this] { return getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG); }); |
| 1553 | |
| 1554 | *outSupport = future.get(); |
| 1555 | return NO_ERROR; |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1556 | } |
| 1557 | |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1558 | status_t SurfaceFlinger::getOverlaySupport(gui::OverlayProperties* outProperties) const { |
| 1559 | const auto& aidlProperties = getHwComposer().getOverlaySupport(); |
| 1560 | // convert aidl OverlayProperties to gui::OverlayProperties |
| 1561 | outProperties->combinations.reserve(aidlProperties.combinations.size()); |
| 1562 | for (const auto& combination : aidlProperties.combinations) { |
| 1563 | std::vector<int32_t> pixelFormats; |
| 1564 | pixelFormats.reserve(combination.pixelFormats.size()); |
| 1565 | std::transform(combination.pixelFormats.cbegin(), combination.pixelFormats.cend(), |
| 1566 | std::back_inserter(pixelFormats), |
| 1567 | [](const auto& val) { return static_cast<int32_t>(val); }); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1568 | std::vector<int32_t> standards; |
| 1569 | standards.reserve(combination.standards.size()); |
| 1570 | std::transform(combination.standards.cbegin(), combination.standards.cend(), |
| 1571 | std::back_inserter(standards), |
| 1572 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1573 | std::vector<int32_t> transfers; |
| 1574 | transfers.reserve(combination.transfers.size()); |
| 1575 | std::transform(combination.transfers.cbegin(), combination.transfers.cend(), |
| 1576 | std::back_inserter(transfers), |
| 1577 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1578 | std::vector<int32_t> ranges; |
| 1579 | ranges.reserve(combination.ranges.size()); |
| 1580 | std::transform(combination.ranges.cbegin(), combination.ranges.cend(), |
| 1581 | std::back_inserter(ranges), |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1582 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1583 | gui::OverlayProperties::SupportedBufferCombinations outCombination; |
| 1584 | outCombination.pixelFormats = std::move(pixelFormats); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1585 | outCombination.standards = std::move(standards); |
| 1586 | outCombination.transfers = std::move(transfers); |
| 1587 | outCombination.ranges = std::move(ranges); |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1588 | outProperties->combinations.emplace_back(outCombination); |
| 1589 | } |
Sally Qi | 8b4cb55 | 2022-12-14 16:24:31 -0800 | [diff] [blame] | 1590 | outProperties->supportMixedColorSpaces = aidlProperties.supportMixedColorSpaces; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 1591 | return NO_ERROR; |
| 1592 | } |
| 1593 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1594 | status_t SurfaceFlinger::setBootDisplayMode(const sp<display::DisplayToken>& displayToken, |
| 1595 | DisplayModeId modeId) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1596 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1597 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1598 | const auto snapshotOpt = |
| 1599 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1600 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1601 | .transform(&PhysicalDisplay::snapshotRef); |
| 1602 | |
| 1603 | if (!snapshotOpt) { |
| 1604 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1605 | return NAME_NOT_FOUND; |
| 1606 | } |
Kriti Dang | f50d677 | 2022-02-18 15:09:12 +0100 | [diff] [blame] | 1607 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1608 | const auto& snapshot = snapshotOpt->get(); |
| 1609 | const auto hwcIdOpt = snapshot.displayModes().get(modeId).transform( |
| 1610 | [](const DisplayModePtr& mode) { return mode->getHwcId(); }); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1611 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1612 | if (!hwcIdOpt) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1613 | 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] | 1614 | to_string(snapshot.displayId()).c_str()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1615 | return BAD_VALUE; |
| 1616 | } |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1617 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1618 | return getHwComposer().setBootDisplayMode(snapshot.displayId(), *hwcIdOpt); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1619 | }); |
| 1620 | return future.get(); |
| 1621 | } |
| 1622 | |
| 1623 | status_t SurfaceFlinger::clearBootDisplayMode(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1624 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1625 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1626 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1627 | return getHwComposer().clearBootDisplayMode(*displayId); |
| 1628 | } else { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1629 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1630 | return BAD_VALUE; |
| 1631 | } |
| 1632 | }); |
| 1633 | return future.get(); |
| 1634 | } |
| 1635 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1636 | status_t SurfaceFlinger::getHdrConversionCapabilities( |
| 1637 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) const { |
| 1638 | bool hdrOutputConversionSupport; |
| 1639 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1640 | if (hdrOutputConversionSupport == false) { |
| 1641 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1642 | return INVALID_OPERATION; |
| 1643 | } |
| 1644 | const auto aidlConversionCapability = getHwComposer().getHdrConversionCapabilities(); |
| 1645 | for (auto capability : aidlConversionCapability) { |
| 1646 | gui::HdrConversionCapability tempCapability; |
Kriti Dang | 3c243dc | 2023-03-07 15:00:13 +0100 | [diff] [blame] | 1647 | tempCapability.sourceType = static_cast<int>(capability.sourceType); |
| 1648 | tempCapability.outputType = static_cast<int>(capability.outputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1649 | tempCapability.addsLatency = capability.addsLatency; |
| 1650 | hdrConversionCapabilities->push_back(tempCapability); |
| 1651 | } |
| 1652 | return NO_ERROR; |
| 1653 | } |
| 1654 | |
| 1655 | status_t SurfaceFlinger::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1656 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 1657 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1658 | bool hdrOutputConversionSupport; |
| 1659 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1660 | if (hdrOutputConversionSupport == false) { |
| 1661 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1662 | return INVALID_OPERATION; |
| 1663 | } |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1664 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) mutable -> status_t { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1665 | using AidlHdrConversionStrategy = |
| 1666 | aidl::android::hardware::graphics::common::HdrConversionStrategy; |
| 1667 | using GuiHdrConversionStrategyTag = gui::HdrConversionStrategy::Tag; |
| 1668 | AidlHdrConversionStrategy aidlConversionStrategy; |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1669 | status_t status; |
| 1670 | aidl::android::hardware::graphics::common::Hdr aidlPreferredHdrOutputType; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1671 | switch (hdrConversionStrategy.getTag()) { |
| 1672 | case GuiHdrConversionStrategyTag::passthrough: { |
| 1673 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::passthrough>( |
| 1674 | hdrConversionStrategy.get<GuiHdrConversionStrategyTag::passthrough>()); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1675 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1676 | &aidlPreferredHdrOutputType); |
| 1677 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1678 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1679 | } |
| 1680 | case GuiHdrConversionStrategyTag::autoAllowedHdrTypes: { |
| 1681 | auto autoHdrTypes = |
| 1682 | hdrConversionStrategy |
| 1683 | .get<GuiHdrConversionStrategyTag::autoAllowedHdrTypes>(); |
| 1684 | std::vector<aidl::android::hardware::graphics::common::Hdr> aidlAutoHdrTypes; |
| 1685 | for (auto type : autoHdrTypes) { |
| 1686 | aidlAutoHdrTypes.push_back( |
| 1687 | static_cast<aidl::android::hardware::graphics::common::Hdr>(type)); |
| 1688 | } |
| 1689 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::autoAllowedHdrTypes>( |
| 1690 | aidlAutoHdrTypes); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1691 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1692 | &aidlPreferredHdrOutputType); |
| 1693 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1694 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1695 | } |
| 1696 | case GuiHdrConversionStrategyTag::forceHdrConversion: { |
| 1697 | auto forceHdrConversion = |
| 1698 | hdrConversionStrategy |
| 1699 | .get<GuiHdrConversionStrategyTag::forceHdrConversion>(); |
| 1700 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::forceHdrConversion>( |
| 1701 | static_cast<aidl::android::hardware::graphics::common::Hdr>( |
| 1702 | forceHdrConversion)); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1703 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1704 | &aidlPreferredHdrOutputType); |
| 1705 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1706 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1707 | } |
| 1708 | } |
| 1709 | }); |
| 1710 | return future.get(); |
| 1711 | } |
| 1712 | |
| 1713 | status_t SurfaceFlinger::getHdrOutputConversionSupport(bool* outSupport) const { |
| 1714 | auto future = mScheduler->schedule([this] { |
| 1715 | return getHwComposer().hasCapability(Capability::HDR_OUTPUT_CONVERSION_CONFIG); |
| 1716 | }); |
| 1717 | |
| 1718 | *outSupport = future.get(); |
| 1719 | return NO_ERROR; |
| 1720 | } |
| 1721 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1722 | void SurfaceFlinger::setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1723 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1724 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1725 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1726 | getHwComposer().setAutoLowLatencyMode(*displayId, on); |
| 1727 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1728 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1729 | } |
| 1730 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1731 | } |
| 1732 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1733 | void SurfaceFlinger::setGameContentType(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1734 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1735 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1736 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1737 | const auto type = on ? hal::ContentType::GAME : hal::ContentType::NONE; |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1738 | getHwComposer().setContentType(*displayId, type); |
| 1739 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1740 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1741 | } |
| 1742 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1743 | } |
| 1744 | |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1745 | status_t SurfaceFlinger::overrideHdrTypes(const sp<IBinder>& displayToken, |
| 1746 | const std::vector<ui::Hdr>& hdrTypes) { |
| 1747 | Mutex::Autolock lock(mStateLock); |
| 1748 | |
| 1749 | auto display = getDisplayDeviceLocked(displayToken); |
| 1750 | if (!display) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1751 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1752 | return NAME_NOT_FOUND; |
| 1753 | } |
| 1754 | |
| 1755 | display->overrideHdrTypes(hdrTypes); |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 1756 | mScheduler->dispatchHotplug(display->getPhysicalId(), scheduler::Scheduler::Hotplug::Connected); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1757 | return NO_ERROR; |
| 1758 | } |
| 1759 | |
Huihong Luo | 30aa437 | 2022-10-03 14:54:12 -0700 | [diff] [blame] | 1760 | status_t SurfaceFlinger::onPullAtom(const int32_t atomId, std::vector<uint8_t>* pulledData, |
| 1761 | bool* success) { |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 1762 | *success = mTimeStats->onPullAtom(atomId, pulledData); |
| 1763 | return NO_ERROR; |
| 1764 | } |
| 1765 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1766 | status_t SurfaceFlinger::getDisplayedContentSamplingAttributes(const sp<IBinder>& displayToken, |
| 1767 | ui::PixelFormat* outFormat, |
| 1768 | ui::Dataspace* outDataspace, |
| 1769 | uint8_t* outComponentMask) const { |
| 1770 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 1771 | return BAD_VALUE; |
| 1772 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1773 | |
| 1774 | Mutex::Autolock lock(mStateLock); |
| 1775 | |
| 1776 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1777 | if (!displayId) { |
| 1778 | return NAME_NOT_FOUND; |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1779 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1780 | |
| 1781 | return getHwComposer().getDisplayedContentSamplingAttributes(*displayId, outFormat, |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1782 | outDataspace, outComponentMask); |
| 1783 | } |
| 1784 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1785 | status_t SurfaceFlinger::setDisplayContentSamplingEnabled(const sp<IBinder>& displayToken, |
| 1786 | bool enable, uint8_t componentMask, |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1787 | uint64_t maxFrames) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1788 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1789 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1790 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1791 | return getHwComposer().setDisplayContentSamplingEnabled(*displayId, enable, |
| 1792 | componentMask, maxFrames); |
| 1793 | } else { |
| 1794 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
| 1795 | return NAME_NOT_FOUND; |
| 1796 | } |
| 1797 | }); |
| 1798 | |
| 1799 | return future.get(); |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1800 | } |
| 1801 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1802 | status_t SurfaceFlinger::getDisplayedContentSample(const sp<IBinder>& displayToken, |
| 1803 | uint64_t maxFrames, uint64_t timestamp, |
| 1804 | DisplayedFrameStats* outStats) const { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1805 | Mutex::Autolock lock(mStateLock); |
| 1806 | |
| 1807 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1808 | if (!displayId) { |
| 1809 | return NAME_NOT_FOUND; |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1812 | return getHwComposer().getDisplayedContentSample(*displayId, maxFrames, timestamp, outStats); |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
Peiyong Lin | 3c2791e | 2019-01-14 17:05:18 -0800 | [diff] [blame] | 1815 | status_t SurfaceFlinger::getProtectedContentSupport(bool* outSupported) const { |
| 1816 | if (!outSupported) { |
| 1817 | return BAD_VALUE; |
| 1818 | } |
| 1819 | *outSupported = getRenderEngine().supportsProtectedContent(); |
| 1820 | return NO_ERROR; |
| 1821 | } |
| 1822 | |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1823 | status_t SurfaceFlinger::isWideColorDisplay(const sp<IBinder>& displayToken, |
| 1824 | bool* outIsWideColorDisplay) const { |
| 1825 | if (!displayToken || !outIsWideColorDisplay) { |
| 1826 | return BAD_VALUE; |
| 1827 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1828 | |
| 1829 | Mutex::Autolock lock(mStateLock); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1830 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1831 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1832 | return NAME_NOT_FOUND; |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1833 | } |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 1834 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1835 | *outIsWideColorDisplay = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1836 | display->isPrimary() ? mSupportsWideColor : display->hasWideColorGamut(); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1837 | return NO_ERROR; |
| 1838 | } |
| 1839 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 1840 | status_t SurfaceFlinger::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1841 | outLayers->clear(); |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1842 | auto future = mScheduler->schedule([=, this] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1843 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Vishnu Nair | 43bccf8 | 2020-06-05 10:53:37 -0700 | [diff] [blame] | 1844 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 1845 | outLayers->push_back(layer->getLayerDebugInfo(display.get())); |
| 1846 | }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1847 | }); |
| 1848 | |
| 1849 | future.wait(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1850 | return NO_ERROR; |
| 1851 | } |
| 1852 | |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1853 | status_t SurfaceFlinger::getCompositionPreference( |
| 1854 | Dataspace* outDataspace, ui::PixelFormat* outPixelFormat, |
| 1855 | Dataspace* outWideColorGamutDataspace, |
| 1856 | ui::PixelFormat* outWideColorGamutPixelFormat) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1857 | *outDataspace = mDefaultCompositionDataspace; |
| 1858 | *outPixelFormat = defaultCompositionPixelFormat; |
| 1859 | *outWideColorGamutDataspace = mWideColorGamutCompositionDataspace; |
| 1860 | *outWideColorGamutPixelFormat = wideColorGamutCompositionPixelFormat; |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 1861 | return NO_ERROR; |
| 1862 | } |
| 1863 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1864 | status_t SurfaceFlinger::addRegionSamplingListener(const Rect& samplingArea, |
| 1865 | const sp<IBinder>& stopLayerHandle, |
| 1866 | const sp<IRegionSamplingListener>& listener) { |
Leon Scroggins III | ae16b80 | 2022-01-12 11:42:05 -0500 | [diff] [blame] | 1867 | if (!listener || samplingArea == Rect::INVALID_RECT || samplingArea.isEmpty()) { |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1868 | return BAD_VALUE; |
| 1869 | } |
Alec Mouri | 9a02eda | 2020-04-21 17:39:34 -0700 | [diff] [blame] | 1870 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 1871 | // LayerHandle::getLayer promotes the layer object in a binder thread but we will not destroy |
| 1872 | // 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] | 1873 | const sp<Layer> stopLayer = LayerHandle::getLayer(stopLayerHandle); |
| 1874 | mRegionSamplingThread->addListener(samplingArea, |
| 1875 | stopLayer ? stopLayer->getSequence() : UNASSIGNED_LAYER_ID, |
| 1876 | listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1877 | return NO_ERROR; |
| 1878 | } |
| 1879 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1880 | status_t SurfaceFlinger::removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) { |
tangrobin | af45f01 | 2019-02-26 18:10:10 +0800 | [diff] [blame] | 1881 | if (!listener) { |
| 1882 | return BAD_VALUE; |
| 1883 | } |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1884 | mRegionSamplingThread->removeListener(listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1885 | return NO_ERROR; |
| 1886 | } |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1887 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1888 | status_t SurfaceFlinger::addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) { |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1889 | if (!listener) { |
| 1890 | return BAD_VALUE; |
| 1891 | } |
| 1892 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1893 | mFpsReporter->addListener(listener, taskId); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1894 | return NO_ERROR; |
| 1895 | } |
| 1896 | |
| 1897 | status_t SurfaceFlinger::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 1898 | if (!listener) { |
| 1899 | return BAD_VALUE; |
| 1900 | } |
| 1901 | mFpsReporter->removeListener(listener); |
| 1902 | return NO_ERROR; |
| 1903 | } |
| 1904 | |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 1905 | status_t SurfaceFlinger::addTunnelModeEnabledListener( |
| 1906 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1907 | if (!listener) { |
| 1908 | return BAD_VALUE; |
| 1909 | } |
| 1910 | |
| 1911 | mTunnelModeEnabledReporter->addListener(listener); |
| 1912 | return NO_ERROR; |
| 1913 | } |
| 1914 | |
| 1915 | status_t SurfaceFlinger::removeTunnelModeEnabledListener( |
| 1916 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1917 | if (!listener) { |
| 1918 | return BAD_VALUE; |
| 1919 | } |
| 1920 | |
| 1921 | mTunnelModeEnabledReporter->removeListener(listener); |
| 1922 | return NO_ERROR; |
| 1923 | } |
| 1924 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1925 | status_t SurfaceFlinger::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 1926 | bool* outSupport) const { |
| 1927 | if (!displayToken || !outSupport) { |
| 1928 | return BAD_VALUE; |
| 1929 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1930 | |
| 1931 | Mutex::Autolock lock(mStateLock); |
| 1932 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1933 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1934 | if (!displayId) { |
| 1935 | return NAME_NOT_FOUND; |
| 1936 | } |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1937 | *outSupport = getHwComposer().hasDisplayCapability(*displayId, DisplayCapability::BRIGHTNESS); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1938 | return NO_ERROR; |
| 1939 | } |
| 1940 | |
John Reck | 22be696 | 2021-03-10 12:59:54 -0500 | [diff] [blame] | 1941 | status_t SurfaceFlinger::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 1942 | const gui::DisplayBrightness& brightness) { |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1943 | if (!displayToken) { |
| 1944 | return BAD_VALUE; |
| 1945 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1946 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1947 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1948 | return ftl::Future(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 1949 | // 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] | 1950 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1951 | const bool supportsDisplayBrightnessCommand = |
| 1952 | getHwComposer().getComposer()->isSupported( |
| 1953 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 1954 | // If we support applying display brightness as a command, then we also support |
| 1955 | // dimming SDR layers. |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1956 | if (supportsDisplayBrightnessCommand) { |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1957 | auto compositionDisplay = display->getCompositionDisplay(); |
| 1958 | float currentDimmingRatio = |
| 1959 | compositionDisplay->editState().sdrWhitePointNits / |
| 1960 | compositionDisplay->editState().displayBrightnessNits; |
Sally Qi | 0ea47b5 | 2023-06-22 13:27:20 -0700 | [diff] [blame] | 1961 | static constexpr float kDimmingThreshold = 0.02f; |
| 1962 | if (brightness.sdrWhitePointNits == 0.f || |
| 1963 | abs(brightness.sdrWhitePointNits - brightness.displayBrightnessNits) / |
| 1964 | brightness.sdrWhitePointNits >= |
| 1965 | kDimmingThreshold) { |
| 1966 | // to optimize, skip brightness setter if the brightness difference ratio |
| 1967 | // is lower than threshold |
| 1968 | compositionDisplay |
| 1969 | ->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 1970 | brightness.displayBrightnessNits); |
| 1971 | } else { |
| 1972 | compositionDisplay->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 1973 | brightness.sdrWhitePointNits); |
| 1974 | } |
| 1975 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1976 | FTL_FAKE_GUARD(kMainThreadContext, |
| 1977 | display->stageBrightness(brightness.displayBrightness)); |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 1978 | float currentHdrSdrRatio = |
| 1979 | compositionDisplay->editState().displayBrightnessNits / |
| 1980 | compositionDisplay->editState().sdrWhitePointNits; |
| 1981 | FTL_FAKE_GUARD(kMainThreadContext, |
| 1982 | display->updateHdrSdrRatioOverlayRatio(currentHdrSdrRatio)); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1983 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1984 | if (brightness.sdrWhitePointNits / brightness.displayBrightnessNits != |
| 1985 | currentDimmingRatio) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1986 | scheduleComposite(FrameHint::kNone); |
| 1987 | } else { |
| 1988 | scheduleCommit(FrameHint::kNone); |
| 1989 | } |
| 1990 | return ftl::yield<status_t>(OK); |
| 1991 | } else { |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1992 | return getHwComposer() |
| 1993 | .setDisplayBrightness(display->getPhysicalId(), |
| 1994 | brightness.displayBrightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 1995 | brightness.displayBrightnessNits, |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1996 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 1997 | .applyImmediately = true}); |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 1998 | } |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1999 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2000 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 2001 | return ftl::yield<status_t>(NAME_NOT_FOUND); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2002 | } |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 2003 | })) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 2004 | .then([](ftl::Future<status_t> task) { return task; }) |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2005 | .get(); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2006 | } |
| 2007 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2008 | status_t SurfaceFlinger::addHdrLayerInfoListener(const sp<IBinder>& displayToken, |
| 2009 | const sp<gui::IHdrLayerInfoListener>& listener) { |
| 2010 | if (!displayToken) { |
| 2011 | return BAD_VALUE; |
| 2012 | } |
| 2013 | |
| 2014 | Mutex::Autolock lock(mStateLock); |
| 2015 | |
| 2016 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2017 | if (!display) { |
| 2018 | return NAME_NOT_FOUND; |
| 2019 | } |
| 2020 | const auto displayId = display->getId(); |
| 2021 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2022 | if (!hdrInfoReporter) { |
| 2023 | hdrInfoReporter = sp<HdrLayerInfoReporter>::make(); |
| 2024 | } |
| 2025 | hdrInfoReporter->addListener(listener); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2026 | |
| 2027 | |
| 2028 | mAddingHDRLayerInfoListener = true; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2029 | return OK; |
| 2030 | } |
| 2031 | |
| 2032 | status_t SurfaceFlinger::removeHdrLayerInfoListener( |
| 2033 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 2034 | if (!displayToken) { |
| 2035 | return BAD_VALUE; |
| 2036 | } |
| 2037 | |
| 2038 | Mutex::Autolock lock(mStateLock); |
| 2039 | |
| 2040 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2041 | if (!display) { |
| 2042 | return NAME_NOT_FOUND; |
| 2043 | } |
| 2044 | const auto displayId = display->getId(); |
| 2045 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2046 | if (hdrInfoReporter) { |
| 2047 | hdrInfoReporter->removeListener(listener); |
| 2048 | } |
| 2049 | return OK; |
| 2050 | } |
| 2051 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2052 | status_t SurfaceFlinger::notifyPowerBoost(int32_t boostId) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 2053 | using aidl::android::hardware::power::Boost; |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2054 | Boost powerBoost = static_cast<Boost>(boostId); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2055 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2056 | if (powerBoost == Boost::INTERACTION) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2057 | mScheduler->onTouchHint(); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | return NO_ERROR; |
| 2061 | } |
| 2062 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2063 | status_t SurfaceFlinger::getDisplayDecorationSupport( |
| 2064 | const sp<IBinder>& displayToken, |
| 2065 | std::optional<DisplayDecorationSupport>* outSupport) const { |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2066 | if (!displayToken || !outSupport) { |
| 2067 | return BAD_VALUE; |
| 2068 | } |
| 2069 | |
| 2070 | Mutex::Autolock lock(mStateLock); |
| 2071 | |
| 2072 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 2073 | if (!displayId) { |
| 2074 | return NAME_NOT_FOUND; |
| 2075 | } |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2076 | getHwComposer().getDisplayDecorationSupport(*displayId, outSupport); |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2077 | return NO_ERROR; |
| 2078 | } |
| 2079 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 2080 | // ---------------------------------------------------------------------------- |
| 2081 | |
Jorim Jaggi | b1e2f8d | 2017-06-08 15:43:59 -0700 | [diff] [blame] | 2082 | sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection( |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 2083 | gui::ISurfaceComposer::VsyncSource vsyncSource, EventRegistrationFlags eventRegistration, |
| 2084 | const sp<IBinder>& layerHandle) { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 2085 | const auto cycle = vsyncSource == gui::ISurfaceComposer::VsyncSource::eVsyncSourceSurfaceFlinger |
| 2086 | ? scheduler::Cycle::LastComposite |
| 2087 | : scheduler::Cycle::Render; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 2088 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 2089 | return mScheduler->createDisplayEventConnection(cycle, eventRegistration, layerHandle); |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 2090 | } |
| 2091 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2092 | void SurfaceFlinger::scheduleCommit(FrameHint hint) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2093 | if (hint == FrameHint::kActive) { |
| 2094 | mScheduler->resetIdleTimer(); |
| 2095 | } |
Matt Buckley | 15ecd1c | 2022-11-01 21:57:16 +0000 | [diff] [blame] | 2096 | mPowerAdvisor->notifyDisplayUpdateImminentAndCpuReset(); |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 2097 | mScheduler->scheduleFrame(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2098 | } |
| 2099 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2100 | void SurfaceFlinger::scheduleComposite(FrameHint hint) { |
| 2101 | mMustComposite = true; |
| 2102 | scheduleCommit(hint); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | void SurfaceFlinger::scheduleRepaint() { |
| 2106 | mGeometryDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2107 | scheduleComposite(FrameHint::kActive); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2110 | void SurfaceFlinger::scheduleSample() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2111 | static_cast<void>(mScheduler->schedule([this] { sample(); })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2112 | } |
| 2113 | |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 2114 | nsecs_t SurfaceFlinger::getVsyncPeriodFromHWC() const { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2115 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
| 2116 | return display->getVsyncPeriodFromHWC(); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2117 | } |
| 2118 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2119 | return 0; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2120 | } |
| 2121 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2122 | void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp, |
| 2123 | std::optional<hal::VsyncPeriodNanos> vsyncPeriod) { |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2124 | if (FlagManager::getInstance().connected_display() && timestamp < 0 && |
| 2125 | vsyncPeriod.has_value()) { |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2126 | // 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] | 2127 | if (mIsHotplugErrViaNegVsync && vsyncPeriod.value() == ~0) { |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2128 | const auto errorCode = static_cast<int32_t>(-timestamp); |
| 2129 | ALOGD("%s: Hotplug error %d for display %" PRIu64, __func__, errorCode, hwcDisplayId); |
| 2130 | mScheduler->dispatchHotplugError(errorCode); |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2131 | return; |
| 2132 | } |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2133 | |
| 2134 | if (mIsHdcpViaNegVsync && vsyncPeriod.value() == ~1) { |
| 2135 | const int32_t value = static_cast<int32_t>(-timestamp); |
| 2136 | // one byte is good enough to encode android.hardware.drm.HdcpLevel |
| 2137 | const int32_t maxLevel = (value >> 8) & 0xFF; |
| 2138 | const int32_t connectedLevel = value & 0xFF; |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2139 | 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] | 2140 | connectedLevel, maxLevel, hwcDisplayId); |
| 2141 | updateHdcpLevels(hwcDisplayId, connectedLevel, maxLevel); |
| 2142 | return; |
| 2143 | } |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
Dominik Laskowski | 3d48304 | 2023-02-22 17:58:56 -0500 | [diff] [blame] | 2146 | ATRACE_NAME(vsyncPeriod |
| 2147 | ? ftl::Concat(__func__, ' ', hwcDisplayId, ' ', *vsyncPeriod, "ns").c_str() |
| 2148 | : ftl::Concat(__func__, ' ', hwcDisplayId).c_str()); |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 2149 | |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2150 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2151 | if (const auto displayIdOpt = getHwComposer().onVsync(hwcDisplayId, timestamp)) { |
| 2152 | if (mScheduler->addResyncSample(*displayIdOpt, timestamp, vsyncPeriod)) { |
| 2153 | // period flushed |
| 2154 | mScheduler->modulateVsync(displayIdOpt, &VsyncModulator::onRefreshRateChangeCompleted); |
| 2155 | } |
Alec Mouri | 754c98a | 2019-03-18 18:53:42 -0700 | [diff] [blame] | 2156 | } |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 2157 | } |
| 2158 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2159 | void SurfaceFlinger::onComposerHalHotplugEvent(hal::HWDisplayId hwcDisplayId, |
| 2160 | DisplayHotplugEvent event) { |
| 2161 | if (event == DisplayHotplugEvent::CONNECTED || event == DisplayHotplugEvent::DISCONNECTED) { |
| 2162 | hal::Connection connection = (event == DisplayHotplugEvent::CONNECTED) |
| 2163 | ? hal::Connection::CONNECTED |
| 2164 | : hal::Connection::DISCONNECTED; |
| 2165 | { |
| 2166 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 2167 | mPendingHotplugEvents.push_back(HotplugEvent{hwcDisplayId, connection}); |
| 2168 | } |
| 2169 | |
| 2170 | if (mScheduler) { |
| 2171 | mScheduler->scheduleConfigure(); |
| 2172 | } |
| 2173 | |
| 2174 | return; |
Jiwen 'Steve' Cai | ccfd682 | 2018-02-21 16:15:58 -0800 | [diff] [blame] | 2175 | } |
| 2176 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2177 | if (FlagManager::getInstance().hotplug2()) { |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2178 | // TODO(b/311403559): use enum type instead of int |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2179 | const auto errorCode = static_cast<int32_t>(event); |
| 2180 | ALOGD("%s: Hotplug error %d for display %" PRIu64, __func__, errorCode, hwcDisplayId); |
| 2181 | mScheduler->dispatchHotplugError(errorCode); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2182 | } |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 2183 | } |
| 2184 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2185 | void SurfaceFlinger::onComposerHalVsyncPeriodTimingChanged( |
| 2186 | hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline& timeline) { |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2187 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2188 | mScheduler->onNewVsyncPeriodChangeTimeline(timeline); |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2189 | |
| 2190 | if (timeline.refreshRequired) { |
| 2191 | scheduleComposite(FrameHint::kNone); |
| 2192 | } |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2195 | void SurfaceFlinger::onComposerHalSeamlessPossible(hal::HWDisplayId) { |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 2196 | // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and |
Ady Abraham | b0433bc | 2020-01-08 17:31:06 -0800 | [diff] [blame] | 2197 | // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE. |
| 2198 | } |
| 2199 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2200 | void SurfaceFlinger::onComposerHalRefresh(hal::HWDisplayId) { |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2201 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2202 | scheduleComposite(FrameHint::kNone); |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2203 | } |
| 2204 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2205 | void SurfaceFlinger::onComposerHalVsyncIdle(hal::HWDisplayId) { |
Ady Abraham | e9befd7 | 2022-02-24 17:24:44 -0800 | [diff] [blame] | 2206 | ATRACE_CALL(); |
| 2207 | mScheduler->forceNextResync(); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2208 | } |
| 2209 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 2210 | void SurfaceFlinger::onRefreshRateChangedDebug(const RefreshRateChangedDebugData& data) { |
| 2211 | ATRACE_CALL(); |
| 2212 | if (const auto displayId = getHwComposer().toPhysicalDisplayId(data.display); displayId) { |
ramindani | 19919ff | 2023-12-07 11:27:06 -0800 | [diff] [blame] | 2213 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 2214 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
ramindani | 19919ff | 2023-12-07 11:27:06 -0800 | [diff] [blame] | 2215 | const Fps fps = Fps::fromPeriodNsecs(getHwComposer().getComposer()->isVrrSupported() |
| 2216 | ? data.refreshPeriodNanos |
| 2217 | : data.vsyncPeriodNanos); |
| 2218 | ATRACE_FORMAT("%s Fps %d", whence, fps.getIntValue()); |
| 2219 | const auto display = getDisplayDeviceLocked(*displayId); |
| 2220 | FTL_FAKE_GUARD(kMainThreadContext, |
| 2221 | display->updateRefreshRateOverlayRate(fps, display->getActiveMode().fps, |
| 2222 | /* setByHwc */ true)); |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 2223 | })); |
| 2224 | } |
ramindani | 12bfe6b | 2023-02-03 13:29:19 -0800 | [diff] [blame] | 2225 | } |
| 2226 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2227 | void SurfaceFlinger::configure() { |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2228 | Mutex::Autolock lock(mStateLock); |
| 2229 | if (configureLocked()) { |
| 2230 | setTransactionFlags(eDisplayTransactionNeeded); |
| 2231 | } |
| 2232 | } |
| 2233 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2234 | bool SurfaceFlinger::updateLayerSnapshotsLegacy(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2235 | bool flushTransactions, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2236 | bool& outTransactionsAreEmpty) { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2237 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2238 | frontend::Update update; |
| 2239 | if (flushTransactions) { |
| 2240 | update = flushLifecycleUpdates(); |
| 2241 | if (mTransactionTracing) { |
| 2242 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2243 | update, mFrontEndDisplayInfos, |
| 2244 | mFrontEndDisplayInfosChanged); |
| 2245 | } |
| 2246 | } |
| 2247 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2248 | bool needsTraversal = false; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2249 | if (flushTransactions) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2250 | needsTraversal |= commitMirrorDisplays(vsyncId); |
| 2251 | needsTraversal |= commitCreatedLayers(vsyncId, update.layerCreatedStates); |
| 2252 | needsTraversal |= applyTransactions(update.transactions, vsyncId); |
| 2253 | } |
| 2254 | outTransactionsAreEmpty = !needsTraversal; |
| 2255 | const bool shouldCommit = (getTransactionFlags() & ~eTransactionFlushNeeded) || needsTraversal; |
| 2256 | if (shouldCommit) { |
| 2257 | commitTransactions(); |
| 2258 | } |
| 2259 | |
| 2260 | bool mustComposite = latchBuffers() || shouldCommit; |
| 2261 | updateLayerGeometry(); |
| 2262 | return mustComposite; |
| 2263 | } |
| 2264 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2265 | void SurfaceFlinger::updateLayerHistory(nsecs_t now) { |
| 2266 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 2267 | using Changes = frontend::RequestedLayerState::Changes; |
| 2268 | if (snapshot->path.isClone()) { |
| 2269 | continue; |
| 2270 | } |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 2271 | |
Jerry Chang | 3667800 | 2023-11-29 16:56:17 +0000 | [diff] [blame] | 2272 | const bool updateSmallDirty = FlagManager::getInstance().enable_small_area_detection() && |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2273 | ((snapshot->clientChanges & layer_state_t::eSurfaceDamageRegionChanged) || |
| 2274 | snapshot->changes.any(Changes::Geometry)); |
| 2275 | |
| 2276 | const bool hasChanges = |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 2277 | snapshot->changes.any(Changes::FrameRate | Changes::Buffer | Changes::Animation | |
| 2278 | Changes::Geometry | Changes::Visibility) || |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2279 | (snapshot->clientChanges & layer_state_t::eDefaultFrameRateCompatibilityChanged) != |
| 2280 | 0; |
| 2281 | |
| 2282 | if (!updateSmallDirty && !hasChanges) { |
| 2283 | continue; |
| 2284 | } |
| 2285 | |
| 2286 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 2287 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 2288 | "Couldn't find layer object for %s", |
| 2289 | snapshot->getDebugString().c_str()); |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2290 | |
| 2291 | if (updateSmallDirty) { |
| 2292 | // Update small dirty flag while surface damage region or geometry changed |
| 2293 | it->second->setIsSmallDirty(snapshot.get()); |
| 2294 | } |
| 2295 | |
| 2296 | if (!hasChanges) { |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2297 | continue; |
| 2298 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2299 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2300 | const auto layerProps = scheduler::LayerProps{ |
| 2301 | .visible = snapshot->isVisible, |
| 2302 | .bounds = snapshot->geomLayerBounds, |
| 2303 | .transform = snapshot->geomLayerTransform, |
| 2304 | .setFrameRateVote = snapshot->frameRate, |
| 2305 | .frameRateSelectionPriority = snapshot->frameRateSelectionPriority, |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2306 | .isSmallDirty = snapshot->isSmallDirty, |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 2307 | .isFrontBuffered = snapshot->isFrontBuffered(), |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2308 | }; |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2309 | |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 2310 | if (snapshot->changes.any(Changes::Geometry | Changes::Visibility)) { |
| 2311 | mScheduler->setLayerProperties(snapshot->sequence, layerProps); |
| 2312 | } |
| 2313 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2314 | if (snapshot->clientChanges & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 2315 | mScheduler->setDefaultFrameRateCompatibility(snapshot->sequence, |
| 2316 | snapshot->defaultFrameRateCompatibility); |
| 2317 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2318 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2319 | if (snapshot->changes.test(Changes::Animation)) { |
| 2320 | it->second->recordLayerHistoryAnimationTx(layerProps, now); |
| 2321 | } |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 2322 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2323 | if (snapshot->changes.test(Changes::FrameRate)) { |
| 2324 | it->second->setFrameRateForLayerTree(snapshot->frameRate, layerProps, now); |
| 2325 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2326 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2327 | if (snapshot->changes.test(Changes::Buffer)) { |
| 2328 | it->second->recordLayerHistoryBufferUpdate(layerProps, now); |
| 2329 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2330 | } |
| 2331 | } |
| 2332 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2333 | bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2334 | bool flushTransactions, bool& outTransactionsAreEmpty) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2335 | using Changes = frontend::RequestedLayerState::Changes; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2336 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2337 | frontend::Update update; |
| 2338 | if (flushTransactions) { |
| 2339 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 2340 | // Locking: |
| 2341 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 2342 | // we must keep a copy of the transactions (specifically the composer |
| 2343 | // states) around outside the scope of the lock. |
| 2344 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 2345 | // transactions with layers still in the createdLayer queue, collect the transactions |
| 2346 | // before committing the created layers. |
| 2347 | // 3. Transactions can only be flushed after adding layers, since the layer can be a newly |
| 2348 | // created one |
| 2349 | mTransactionHandler.collectTransactions(); |
| 2350 | { |
| 2351 | // TODO(b/238781169) lockless queue this and keep order. |
| 2352 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 2353 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 2354 | mCreatedLayers.clear(); |
| 2355 | update.newLayers = std::move(mNewLayers); |
| 2356 | mNewLayers.clear(); |
| 2357 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 2358 | mNewLayerArgs.clear(); |
| 2359 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 2360 | mDestroyedHandles.clear(); |
| 2361 | } |
| 2362 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2363 | mLayerLifecycleManager.addLayers(std::move(update.newLayers)); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2364 | update.transactions = mTransactionHandler.flushTransactions(); |
| 2365 | if (mTransactionTracing) { |
| 2366 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2367 | update, mFrontEndDisplayInfos, |
| 2368 | mFrontEndDisplayInfosChanged); |
| 2369 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2370 | mLayerLifecycleManager.applyTransactions(update.transactions); |
| 2371 | mLayerLifecycleManager.onHandlesDestroyed(update.destroyedHandles); |
| 2372 | for (auto& legacyLayer : update.layerCreatedStates) { |
| 2373 | sp<Layer> layer = legacyLayer.layer.promote(); |
| 2374 | if (layer) { |
| 2375 | mLegacyLayers[layer->sequence] = layer; |
| 2376 | } |
| 2377 | } |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 2378 | mLayerHierarchyBuilder.update(mLayerLifecycleManager); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2379 | } |
| 2380 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2381 | bool mustComposite = false; |
| 2382 | mustComposite |= applyAndCommitDisplayTransactionStates(update.transactions); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2383 | |
| 2384 | { |
| 2385 | ATRACE_NAME("LayerSnapshotBuilder:update"); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2386 | frontend::LayerSnapshotBuilder::Args |
| 2387 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 2388 | .layerLifecycleManager = mLayerLifecycleManager, |
| 2389 | .displays = mFrontEndDisplayInfos, |
| 2390 | .displayChanges = mFrontEndDisplayInfosChanged, |
| 2391 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2392 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2393 | .forceFullDamage = mForceFullDamage, |
| 2394 | .supportedLayerGenericMetadata = |
| 2395 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 2396 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 2397 | .skipRoundCornersWhenProtected = |
| 2398 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2399 | mLayerSnapshotBuilder.update(args); |
| 2400 | } |
| 2401 | |
| 2402 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Geometry | Changes::Input | |
Vishnu Nair | 40d0228 | 2023-02-28 21:11:40 +0000 | [diff] [blame] | 2403 | Changes::Hierarchy | Changes::Visibility)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2404 | mUpdateInputInfo = true; |
| 2405 | } |
| 2406 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::VisibleRegion | Changes::Hierarchy | |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2407 | Changes::Visibility | Changes::Geometry)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2408 | mVisibleRegionsDirty = true; |
| 2409 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2410 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Hierarchy | Changes::FrameRate)) { |
| 2411 | // The frame rate of attached choreographers can only change as a result of a |
| 2412 | // FrameRate change (including when Hierarchy changes). |
| 2413 | mUpdateAttachedChoreographer = true; |
| 2414 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2415 | outTransactionsAreEmpty = mLayerLifecycleManager.getGlobalChanges().get() == 0; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2416 | mustComposite |= mLayerLifecycleManager.getGlobalChanges().get() != 0; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2417 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2418 | bool newDataLatched = false; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2419 | if (!mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2420 | ATRACE_NAME("DisplayCallbackAndStatsUpdates"); |
Vishnu Nair | d2a38f9 | 2023-08-23 18:43:01 -0700 | [diff] [blame] | 2421 | mustComposite |= applyTransactions(update.transactions, vsyncId); |
Vishnu Nair | c1d19d7 | 2023-08-10 12:35:11 -0700 | [diff] [blame] | 2422 | traverseLegacyLayers([&](Layer* layer) { layer->commitTransaction(); }); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2423 | const nsecs_t latchTime = systemTime(); |
| 2424 | bool unused = false; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2425 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2426 | for (auto& layer : mLayerLifecycleManager.getLayers()) { |
| 2427 | if (layer->changes.test(frontend::RequestedLayerState::Changes::Created) && |
| 2428 | layer->bgColorLayer) { |
| 2429 | sp<Layer> bgColorLayer = getFactory().createEffectLayer( |
| 2430 | LayerCreationArgs(this, nullptr, layer->name, |
| 2431 | ISurfaceComposerClient::eFXSurfaceEffect, LayerMetadata(), |
Vishnu Nair | e4af095 | 2023-05-01 09:11:33 -0700 | [diff] [blame] | 2432 | std::make_optional(layer->id), true)); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2433 | mLegacyLayers[bgColorLayer->sequence] = bgColorLayer; |
| 2434 | } |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2435 | const bool willReleaseBufferOnLatch = layer->willReleaseBufferOnLatch(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2436 | |
| 2437 | auto it = mLegacyLayers.find(layer->id); |
Vishnu Nair | 1009dbd | 2024-01-17 10:42:29 -0800 | [diff] [blame] | 2438 | if (it == mLegacyLayers.end() && |
| 2439 | layer->changes.test(frontend::RequestedLayerState::Changes::Destroyed)) { |
| 2440 | // Layer handle was created and immediately destroyed. It was destroyed before it |
| 2441 | // was added to the map. |
| 2442 | continue; |
| 2443 | } |
| 2444 | |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 2445 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 2446 | "Couldnt find layer object for %s", |
| 2447 | layer->getDebugString().c_str()); |
Vishnu Nair | f32ff9b | 2023-08-23 14:32:30 -0700 | [diff] [blame] | 2448 | if (!layer->hasReadyFrame() && !willReleaseBufferOnLatch) { |
| 2449 | if (!it->second->hasBuffer()) { |
| 2450 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 2451 | // instead of a missed frame. This is used to identify scenarios where we |
| 2452 | // could not latch a buffer or apply a transaction due to backpressure. |
| 2453 | // We only update the latch time for buffer less layers here, the latch time |
| 2454 | // is updated for buffer layers when the buffer is latched. |
| 2455 | it->second->updateLastLatchTime(latchTime); |
| 2456 | } |
| 2457 | continue; |
| 2458 | } |
| 2459 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2460 | const bool bgColorOnly = |
| 2461 | !layer->externalTexture && (layer->bgColorLayerId != UNASSIGNED_LAYER_ID); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2462 | if (willReleaseBufferOnLatch) { |
| 2463 | mLayersWithBuffersRemoved.emplace(it->second); |
| 2464 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2465 | it->second->latchBufferImpl(unused, latchTime, bgColorOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2466 | newDataLatched = true; |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2467 | |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2468 | mLayersWithQueuedFrames.emplace(it->second); |
| 2469 | mLayersIdsWithQueuedFrames.emplace(it->second->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2470 | } |
| 2471 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2472 | updateLayerHistory(latchTime); |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2473 | mLayerSnapshotBuilder.forEachVisibleSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2474 | if (mLayersIdsWithQueuedFrames.find(snapshot.path.id) == |
| 2475 | mLayersIdsWithQueuedFrames.end()) |
| 2476 | return; |
| 2477 | Region visibleReg; |
| 2478 | visibleReg.set(snapshot.transformedBoundsWithoutTransparentRegion); |
| 2479 | invalidateLayerStack(snapshot.outputFilter, visibleReg); |
| 2480 | }); |
| 2481 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2482 | for (auto& destroyedLayer : mLayerLifecycleManager.getDestroyedLayers()) { |
| 2483 | mLegacyLayers.erase(destroyedLayer->id); |
| 2484 | } |
| 2485 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2486 | { |
| 2487 | ATRACE_NAME("LLM:commitChanges"); |
| 2488 | mLayerLifecycleManager.commitChanges(); |
| 2489 | } |
| 2490 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2491 | // enter boot animation on first buffer latch |
| 2492 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 2493 | ALOGI("Enter boot animation"); |
| 2494 | mBootStage = BootStage::BOOTANIMATION; |
| 2495 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2496 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2497 | mustComposite |= (getTransactionFlags() & ~eTransactionFlushNeeded) || newDataLatched; |
Vishnu Nair | 8134c1a | 2023-10-17 22:55:49 -0700 | [diff] [blame] | 2498 | if (mustComposite && !mLegacyFrontEndEnabled) { |
| 2499 | commitTransactions(); |
| 2500 | } |
| 2501 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2502 | return mustComposite; |
| 2503 | } |
| 2504 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2505 | bool SurfaceFlinger::commit(PhysicalDisplayId pacesetterId, |
| 2506 | const scheduler::FrameTargets& frameTargets) { |
| 2507 | const scheduler::FrameTarget& pacesetterFrameTarget = *frameTargets.get(pacesetterId)->get(); |
| 2508 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2509 | const VsyncId vsyncId = pacesetterFrameTarget.vsyncId(); |
| 2510 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2511 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2512 | if (pacesetterFrameTarget.didMissFrame()) { |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2513 | mTimeStats->incrementMissedFrames(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2514 | } |
| 2515 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2516 | // If a mode set is pending and the fence hasn't fired yet, wait for the next commit. |
| 2517 | if (std::any_of(frameTargets.begin(), frameTargets.end(), |
| 2518 | [this](const auto& pair) FTL_FAKE_GUARD(mStateLock) |
| 2519 | FTL_FAKE_GUARD(kMainThreadContext) { |
| 2520 | if (!pair.second->isFramePending()) return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2521 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2522 | if (const auto display = getDisplayDeviceLocked(pair.first)) { |
| 2523 | return display->isModeSetPending(); |
| 2524 | } |
| 2525 | |
| 2526 | return false; |
| 2527 | })) { |
| 2528 | mScheduler->scheduleFrame(); |
| 2529 | return false; |
| 2530 | } |
| 2531 | |
| 2532 | { |
| 2533 | Mutex::Autolock lock(mStateLock); |
| 2534 | |
| 2535 | for (const auto [id, target] : frameTargets) { |
| 2536 | // TODO(b/241285876): This is `nullptr` when the DisplayDevice is about to be removed in |
| 2537 | // this commit, since the PhysicalDisplay has already been removed. Rather than checking |
| 2538 | // for `nullptr` below, change Scheduler::onFrameSignal to filter out the FrameTarget of |
| 2539 | // the removed display. |
| 2540 | const auto display = getDisplayDeviceLocked(id); |
| 2541 | |
| 2542 | if (display && display->isModeSetPending()) { |
| 2543 | finalizeDisplayModeChange(*display); |
| 2544 | } |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2545 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2546 | } |
| 2547 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2548 | if (pacesetterFrameTarget.isFramePending()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2549 | if (mBackpressureGpuComposition || pacesetterFrameTarget.didMissHwcFrame()) { |
Ady Abraham | e988303 | 2023-11-20 17:54:54 -0800 | [diff] [blame] | 2550 | if (FlagManager::getInstance().vrr_config()) { |
| 2551 | mScheduler->getVsyncSchedule()->getTracker().onFrameMissed( |
| 2552 | pacesetterFrameTarget.expectedPresentTime()); |
| 2553 | } |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2554 | scheduleCommit(FrameHint::kNone); |
| 2555 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2556 | } |
| 2557 | } |
| 2558 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2559 | const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); |
| 2560 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2561 | // Save this once per commit + composite to ensure consistency |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2562 | // TODO (b/240619471): consider removing active display check once AOD is fixed |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 2563 | const auto activeDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(mActiveDisplayId)); |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2564 | mPowerHintSessionEnabled = mPowerAdvisor->usePowerHintSession() && activeDisplay && |
| 2565 | activeDisplay->getPowerMode() == hal::PowerMode::ON; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2566 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2567 | mPowerAdvisor->setCommitStart(pacesetterFrameTarget.frameBeginTime()); |
| 2568 | mPowerAdvisor->setExpectedPresentTime(pacesetterFrameTarget.expectedPresentTime()); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2569 | |
| 2570 | // 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] | 2571 | const Duration idealSfWorkDuration = |
| 2572 | mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2573 | const Duration frameDelay = |
| 2574 | idealSfWorkDuration - pacesetterFrameTarget.expectedFrameDuration(); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2575 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2576 | mPowerAdvisor->setFrameDelay(frameDelay); |
| 2577 | mPowerAdvisor->setTotalFrameTargetWorkDuration(idealSfWorkDuration); |
Matt Buckley | 676e439 | 2023-05-25 22:09:26 +0000 | [diff] [blame] | 2578 | |
| 2579 | const auto& display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get(); |
| 2580 | const Period idealVsyncPeriod = display->getActiveMode().fps.getPeriod(); |
| 2581 | mPowerAdvisor->updateTargetWorkDuration(idealVsyncPeriod); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2582 | } |
| 2583 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2584 | if (mRefreshRateOverlaySpinner || mHdrSdrRatioOverlay) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 2585 | Mutex::Autolock lock(mStateLock); |
| 2586 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2587 | display->animateOverlay(); |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2588 | } |
| 2589 | } |
| 2590 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2591 | // Composite if transactions were committed, or if requested by HWC. |
| 2592 | bool mustComposite = mMustComposite.exchange(false); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2593 | { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2594 | mFrameTimeline->setSfWakeUp(ftl::to_underlying(vsyncId), |
| 2595 | pacesetterFrameTarget.frameBeginTime().ns(), |
Pascal Muetschard | ac7bcd9 | 2023-10-03 15:05:36 +0200 | [diff] [blame] | 2596 | Fps::fromPeriodNsecs(vsyncPeriod.ns()), |
| 2597 | mScheduler->getPacesetterRefreshRate()); |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 2598 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2599 | const bool flushTransactions = clearTransactionFlags(eTransactionFlushNeeded); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2600 | bool transactionsAreEmpty; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2601 | if (mLegacyFrontEndEnabled) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2602 | mustComposite |= |
| 2603 | updateLayerSnapshotsLegacy(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2604 | flushTransactions, transactionsAreEmpty); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2605 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2606 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2607 | mustComposite |= |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2608 | updateLayerSnapshots(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2609 | flushTransactions, transactionsAreEmpty); |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | if (transactionFlushNeeded()) { |
| 2613 | setTransactionFlags(eTransactionFlushNeeded); |
| 2614 | } |
| 2615 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2616 | // This has to be called after latchBuffers because we want to include the layers that have |
| 2617 | // been latched in the commit callback |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2618 | if (transactionsAreEmpty) { |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2619 | // Invoke empty transaction callbacks early. |
| 2620 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 2621 | } else { |
| 2622 | // Invoke OnCommit callbacks. |
| 2623 | mTransactionCallbackInvoker.sendCallbacks(true /* onCommitOnly */); |
| 2624 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | // Layers need to get updated (in the previous line) before we can use them for |
| 2628 | // choosing the refresh rate. |
| 2629 | // Hold mStateLock as chooseRefreshRateForContent promotes wp<Layer> to sp<Layer> |
| 2630 | // and may eventually call to ~Layer() if it holds the last reference |
| 2631 | { |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2632 | bool updateAttachedChoreographer = mUpdateAttachedChoreographer; |
| 2633 | mUpdateAttachedChoreographer = false; |
| 2634 | |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 2635 | Mutex::Autolock lock(mStateLock); |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2636 | mScheduler->chooseRefreshRateForContent(mLayerLifecycleManagerEnabled |
| 2637 | ? &mLayerHierarchyBuilder.getHierarchy() |
| 2638 | : nullptr, |
| 2639 | updateAttachedChoreographer); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2640 | initiateDisplayModeChanges(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2641 | } |
| 2642 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2643 | updateCursorAsync(); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2644 | if (!mustComposite) { |
| 2645 | updateInputFlinger(vsyncId, pacesetterFrameTarget.frameBeginTime()); |
| 2646 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2647 | doActiveLayersTracingIfNeeded(false, mVisibleRegionsDirty, |
| 2648 | pacesetterFrameTarget.frameBeginTime(), vsyncId); |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 2649 | |
Pablo Gamito | 6be8244 | 2022-06-13 11:04:34 +0000 | [diff] [blame] | 2650 | mLastCommittedVsyncId = vsyncId; |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2651 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2652 | persistDisplayBrightness(mustComposite); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2653 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2654 | return mustComposite && CC_LIKELY(mBootStage != BootStage::BOOTLOADER); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2657 | CompositeResultsPerDisplay SurfaceFlinger::composite( |
| 2658 | PhysicalDisplayId pacesetterId, const scheduler::FrameTargeters& frameTargeters) { |
| 2659 | const scheduler::FrameTarget& pacesetterTarget = |
| 2660 | frameTargeters.get(pacesetterId)->get()->target(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2661 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2662 | const VsyncId vsyncId = pacesetterTarget.vsyncId(); |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2663 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2664 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2665 | compositionengine::CompositionRefreshArgs refreshArgs; |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 2666 | refreshArgs.powerCallback = this; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2667 | const auto& displays = FTL_FAKE_GUARD(mStateLock, mDisplays); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2668 | refreshArgs.outputs.reserve(displays.size()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2669 | |
| 2670 | // Add outputs for physical displays. |
| 2671 | for (const auto& [id, targeter] : frameTargeters) { |
| 2672 | ftl::FakeGuard guard(mStateLock); |
| 2673 | |
| 2674 | if (const auto display = getCompositionDisplayLocked(id)) { |
| 2675 | refreshArgs.outputs.push_back(display); |
| 2676 | } |
Leon Scroggins III | 370b8b5 | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 2677 | |
| 2678 | refreshArgs.frameTargets.try_emplace(id, &targeter->target()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2679 | } |
| 2680 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2681 | std::vector<DisplayId> displayIds; |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2682 | for (const auto& [_, display] : displays) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2683 | displayIds.push_back(display->getId()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2684 | display->tracePowerMode(); |
| 2685 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2686 | // Add outputs for virtual displays. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2687 | if (display->isVirtual()) { |
| 2688 | const Fps refreshRate = display->getAdjustedRefreshRate(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2689 | |
| 2690 | if (!refreshRate.isValid() || |
| 2691 | mScheduler->isVsyncInPhase(pacesetterTarget.frameBeginTime(), refreshRate)) { |
| 2692 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2693 | } |
| 2694 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2695 | } |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2696 | mPowerAdvisor->setDisplays(displayIds); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2697 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 2698 | const bool updateTaskMetadata = mCompositionEngine->getFeatureFlags().test( |
| 2699 | compositionengine::Feature::kSnapshotLayerMetadata); |
| 2700 | if (updateTaskMetadata && (mVisibleRegionsDirty || mLayerMetadataSnapshotNeeded)) { |
| 2701 | updateLayerMetadataSnapshot(); |
| 2702 | mLayerMetadataSnapshotNeeded = false; |
| 2703 | } |
| 2704 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2705 | if (DOES_CONTAIN_BORDER) { |
| 2706 | refreshArgs.borderInfoList.clear(); |
| 2707 | mDrawingState.traverse([&refreshArgs](Layer* layer) { |
| 2708 | if (layer->isBorderEnabled()) { |
| 2709 | compositionengine::BorderRenderInfo info; |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 2710 | info.width = layer->getBorderWidth(); |
| 2711 | info.color = layer->getBorderColor(); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2712 | layer->traverse(LayerVector::StateSet::Drawing, [&info](Layer* ilayer) { |
| 2713 | info.layerIds.push_back(ilayer->getSequence()); |
| 2714 | }); |
| 2715 | refreshArgs.borderInfoList.emplace_back(std::move(info)); |
| 2716 | } |
| 2717 | }); |
| 2718 | } |
| 2719 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 2720 | refreshArgs.bufferIdsToUncache = std::move(mBufferIdsToUncache); |
| 2721 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2722 | refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); |
Alec Mouri | 5c9c960 | 2020-09-01 15:10:40 -0700 | [diff] [blame] | 2723 | for (auto layer : mLayersWithQueuedFrames) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 2724 | if (auto layerFE = layer->getCompositionEngineLayerFE()) |
| 2725 | refreshArgs.layersWithQueuedFrames.push_back(layerFE); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2726 | } |
| 2727 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 2728 | refreshArgs.outputColorSetting = mDisplayColorSetting; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 2729 | refreshArgs.forceOutputColorMode = mForceColorMode; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2730 | |
| 2731 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
Vishnu Nair | 995f4cf | 2024-03-07 19:40:03 -0800 | [diff] [blame] | 2732 | refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || |
| 2733 | mVisibleRegionsDirty || mDrawingState.colorMatrixChanged; |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 2734 | refreshArgs.internalDisplayRotationFlags = getActiveDisplayRotationFlags(); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2735 | |
| 2736 | if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) { |
| 2737 | refreshArgs.colorTransformMatrix = mDrawingState.colorMatrix; |
| 2738 | mDrawingState.colorMatrixChanged = false; |
| 2739 | } |
| 2740 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2741 | refreshArgs.devOptForceClientComposition = mDebugDisableHWC; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2742 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2743 | if (mDebugFlashDelay != 0) { |
| 2744 | refreshArgs.devOptForceClientComposition = true; |
| 2745 | refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay); |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 2746 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2747 | |
ramindani | 0491e64 | 2023-11-16 17:42:14 -0800 | [diff] [blame] | 2748 | // TODO(b/255601557) Update frameInterval per display |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 2749 | refreshArgs.frameInterval = |
| 2750 | mScheduler->getNextFrameInterval(pacesetterId, pacesetterTarget.expectedPresentTime()); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 2751 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 2752 | const auto scheduledFrameTimeOpt = scheduledFrameResultOpt |
| 2753 | ? std::optional{scheduledFrameResultOpt->callbackTime} |
| 2754 | : std::nullopt; |
| 2755 | refreshArgs.scheduledFrameTime = scheduledFrameTimeOpt; |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 2756 | refreshArgs.hasTrustedPresentationListener = mNumTrustedPresentationListeners > 0; |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2757 | // Store the present time just before calling to the composition engine so we could notify |
| 2758 | // the scheduler. |
| 2759 | const auto presentTime = systemTime(); |
| 2760 | |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2761 | constexpr bool kCursorOnly = false; |
| 2762 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
| 2763 | |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2764 | if (mLayerLifecycleManagerEnabled && !mVisibleRegionsDirty) { |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2765 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 2766 | auto compositionDisplay = display->getCompositionDisplay(); |
| 2767 | if (!compositionDisplay->getState().isEnabled) continue; |
| 2768 | for (auto outputLayer : compositionDisplay->getOutputLayersOrderedByZ()) { |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2769 | if (outputLayer->getLayerFE().getCompositionState() == nullptr) { |
| 2770 | // This is unexpected but instead of crashing, capture traces to disk |
| 2771 | // and recover gracefully by forcing CE to rebuild layer stack. |
| 2772 | ALOGE("Output layer %s for display %s %" PRIu64 " has a null " |
| 2773 | "snapshot. Forcing mVisibleRegionsDirty", |
| 2774 | outputLayer->getLayerFE().getDebugName(), |
| 2775 | compositionDisplay->getName().c_str(), compositionDisplay->getId().value); |
| 2776 | |
| 2777 | TransactionTraceWriter::getInstance().invoke(__func__, /* overwrite= */ false); |
| 2778 | mVisibleRegionsDirty = true; |
| 2779 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
| 2780 | refreshArgs.updatingGeometryThisFrame = mVisibleRegionsDirty; |
| 2781 | } |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2782 | } |
| 2783 | } |
| 2784 | } |
| 2785 | |
Melody Hsu | c949cde | 2024-03-12 01:43:34 +0000 | [diff] [blame^] | 2786 | refreshArgs.refreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 2787 | for (auto [layer, layerFE] : layers) { |
| 2788 | layer->onPreComposition(refreshArgs.refreshStartTime); |
| 2789 | } |
| 2790 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2791 | mCompositionEngine->present(refreshArgs); |
| 2792 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2793 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2794 | for (auto [layer, layerFE] : layers) { |
| 2795 | CompositionResult compositionResult{layerFE->stealCompositionResult()}; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2796 | for (auto& [releaseFence, layerStack] : compositionResult.releaseFences) { |
Vishnu Nair | 332e6ba | 2023-01-25 17:16:19 -0800 | [diff] [blame] | 2797 | Layer* clonedFrom = layer->getClonedFrom().get(); |
| 2798 | auto owningLayer = clonedFrom ? clonedFrom : layer; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2799 | owningLayer->onLayerDisplayed(std::move(releaseFence), layerStack); |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2800 | } |
| 2801 | if (compositionResult.lastClientCompositionFence) { |
| 2802 | layer->setWasClientComposed(compositionResult.lastClientCompositionFence); |
| 2803 | } |
| 2804 | } |
| 2805 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2806 | mTimeStats->recordFrameDuration(pacesetterTarget.frameBeginTime().ns(), systemTime()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2807 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2808 | // Send a power hint after presentation is finished. |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2809 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2810 | // Now that the current frame has been presented above, PowerAdvisor needs the present time |
| 2811 | // of the previous frame (whose fence is signaled by now) to determine how long the HWC had |
| 2812 | // waited on that fence to retire before presenting. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2813 | const auto& previousPresentFence = pacesetterTarget.presentFenceForPreviousFrame(); |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2814 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2815 | mPowerAdvisor->setSfPresentTiming(TimePoint::fromNs(previousPresentFence->getSignalTime()), |
| 2816 | TimePoint::now()); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 2817 | mPowerAdvisor->reportActualWorkDuration(); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2818 | } |
| 2819 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2820 | if (mScheduler->onCompositionPresented(presentTime)) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2821 | scheduleComposite(FrameHint::kNone); |
| 2822 | } |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2823 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 2824 | mNotifyExpectedPresentMap[pacesetterId].hintStatus = NotifyExpectedPresentHintStatus::Start; |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2825 | onCompositionPresented(pacesetterId, frameTargeters, presentTime); |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 2826 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2827 | const bool hadGpuComposited = |
| 2828 | multiDisplayUnion(mCompositionCoverage).test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2829 | mCompositionCoverage.clear(); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2830 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2831 | TimeStats::ClientCompositionRecord clientCompositionRecord; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2832 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2833 | for (const auto& [_, display] : displays) { |
| 2834 | const auto& state = display->getCompositionDisplay()->getState(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2835 | CompositionCoverageFlags& flags = |
| 2836 | mCompositionCoverage.try_emplace(display->getId()).first->second; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2837 | |
| 2838 | if (state.usesDeviceComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2839 | flags |= CompositionCoverage::Hwc; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | if (state.reusedClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2843 | flags |= CompositionCoverage::GpuReuse; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2844 | } else if (state.usesClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2845 | flags |= CompositionCoverage::Gpu; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2846 | } |
| 2847 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2848 | clientCompositionRecord.predicted |= |
| 2849 | (state.strategyPrediction != CompositionStrategyPredictionState::DISABLED); |
| 2850 | clientCompositionRecord.predictionSucceeded |= |
| 2851 | (state.strategyPrediction == CompositionStrategyPredictionState::SUCCESS); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2852 | } |
| 2853 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2854 | const auto coverage = multiDisplayUnion(mCompositionCoverage); |
| 2855 | const bool hasGpuComposited = coverage.test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2856 | |
| 2857 | clientCompositionRecord.hadClientComposition = hasGpuComposited; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2858 | clientCompositionRecord.reused = coverage.test(CompositionCoverage::GpuReuse); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2859 | clientCompositionRecord.changed = hadGpuComposited != hasGpuComposited; |
| 2860 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2861 | mTimeStats->pushCompositionStrategyState(clientCompositionRecord); |
| 2862 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2863 | using namespace ftl::flag_operators; |
| 2864 | |
| 2865 | // TODO(b/160583065): Enable skip validation when SF caches all client composition layers. |
| 2866 | const bool hasGpuUseOrReuse = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2867 | coverage.any(CompositionCoverage::Gpu | CompositionCoverage::GpuReuse); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2868 | mScheduler->modulateVsync({}, &VsyncModulator::onDisplayRefresh, hasGpuUseOrReuse); |
Dan Stoza | 14cd37c | 2015-07-09 12:43:33 -0700 | [diff] [blame] | 2869 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 2870 | mLayersWithQueuedFrames.clear(); |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2871 | mLayersIdsWithQueuedFrames.clear(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2872 | doActiveLayersTracingIfNeeded(true, mVisibleRegionsDirty, pacesetterTarget.frameBeginTime(), |
| 2873 | vsyncId); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2874 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2875 | updateInputFlinger(vsyncId, pacesetterTarget.frameBeginTime()); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2876 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2877 | if (mVisibleRegionsDirty) mHdrLayerInfoChanged = true; |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 2878 | mVisibleRegionsDirty = false; |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2879 | |
| 2880 | if (mCompositionEngine->needsAnotherUpdate()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2881 | scheduleCommit(FrameHint::kNone); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2882 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2883 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2884 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2885 | mPowerAdvisor->setCompositeEnd(TimePoint::now()); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2886 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2887 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2888 | CompositeResultsPerDisplay resultsPerDisplay; |
| 2889 | |
| 2890 | // Filter out virtual displays. |
| 2891 | for (const auto& [id, coverage] : mCompositionCoverage) { |
| 2892 | if (const auto idOpt = PhysicalDisplayId::tryCast(id)) { |
| 2893 | resultsPerDisplay.try_emplace(*idOpt, CompositeResult{coverage}); |
| 2894 | } |
| 2895 | } |
| 2896 | |
| 2897 | return resultsPerDisplay; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2898 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2899 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2900 | void SurfaceFlinger::updateLayerGeometry() { |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2901 | ATRACE_CALL(); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 2902 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2903 | if (mVisibleRegionsDirty) { |
| 2904 | computeLayerBounds(); |
| 2905 | } |
| 2906 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2907 | for (auto& layer : mLayersPendingRefresh) { |
| 2908 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2909 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2910 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2911 | } |
| 2912 | mLayersPendingRefresh.clear(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2913 | } |
| 2914 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2915 | bool SurfaceFlinger::isHdrLayer(const frontend::LayerSnapshot& snapshot) const { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2916 | // Even though the camera layer may be using an HDR transfer function or otherwise be "HDR" |
| 2917 | // the device may need to avoid boosting the brightness as a result of these layers to |
| 2918 | // reduce power consumption during camera recording |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2919 | if (mIgnoreHdrCameraLayers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2920 | if (snapshot.externalTexture && |
| 2921 | (snapshot.externalTexture->getUsage() & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) { |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2922 | return false; |
| 2923 | } |
| 2924 | } |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 2925 | // RANGE_EXTENDED layer may identify themselves as being "HDR" |
| 2926 | // via a desired hdr/sdr ratio |
| 2927 | auto pixelFormat = snapshot.buffer |
| 2928 | ? std::make_optional(static_cast<ui::PixelFormat>(snapshot.buffer->getPixelFormat())) |
| 2929 | : std::nullopt; |
| 2930 | |
| 2931 | if (getHdrRenderType(snapshot.dataspace, pixelFormat, snapshot.desiredHdrSdrRatio) != |
| 2932 | HdrRenderType::SDR) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2933 | return true; |
| 2934 | } |
| 2935 | // If the layer is not allowed to be dimmed, treat it as HDR. WindowManager may disable |
| 2936 | // dimming in order to keep animations invoking SDR screenshots of HDR layers seamless. |
| 2937 | // Treat such tagged layers as HDR so that DisplayManagerService does not try to change |
| 2938 | // the screen brightness |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2939 | if (!snapshot.dimmingEnabled) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2940 | return true; |
| 2941 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2942 | return false; |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2943 | } |
| 2944 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2945 | ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId, |
| 2946 | bool isPrimary) const { |
| 2947 | const auto id = PhysicalDisplayId::tryCast(displayId); |
| 2948 | if (!id) { |
| 2949 | return ui::ROTATION_0; |
| 2950 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2951 | if (!mIgnoreHwcPhysicalDisplayOrientation && |
Neha Jain | 7b31cca | 2023-01-09 23:10:42 +0000 | [diff] [blame] | 2952 | getHwComposer().getComposer()->isSupported( |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2953 | Hwc2::Composer::OptionalFeature::PhysicalDisplayOrientation)) { |
| 2954 | switch (getHwComposer().getPhysicalDisplayOrientation(*id)) { |
| 2955 | case Hwc2::AidlTransform::ROT_90: |
| 2956 | return ui::ROTATION_90; |
| 2957 | case Hwc2::AidlTransform::ROT_180: |
| 2958 | return ui::ROTATION_180; |
| 2959 | case Hwc2::AidlTransform::ROT_270: |
| 2960 | return ui::ROTATION_270; |
| 2961 | default: |
| 2962 | return ui::ROTATION_0; |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | if (isPrimary) { |
| 2967 | using Values = SurfaceFlingerProperties::primary_display_orientation_values; |
| 2968 | switch (primary_display_orientation(Values::ORIENTATION_0)) { |
| 2969 | case Values::ORIENTATION_90: |
| 2970 | return ui::ROTATION_90; |
| 2971 | case Values::ORIENTATION_180: |
| 2972 | return ui::ROTATION_180; |
| 2973 | case Values::ORIENTATION_270: |
| 2974 | return ui::ROTATION_270; |
| 2975 | default: |
| 2976 | break; |
| 2977 | } |
| 2978 | } |
| 2979 | return ui::ROTATION_0; |
| 2980 | } |
| 2981 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2982 | void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId, |
| 2983 | const scheduler::FrameTargeters& frameTargeters, |
| 2984 | nsecs_t presentStartTime) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2985 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2986 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2987 | ui::PhysicalDisplayMap<PhysicalDisplayId, std::shared_ptr<FenceTime>> presentFences; |
| 2988 | ui::PhysicalDisplayMap<PhysicalDisplayId, const sp<Fence>> gpuCompositionDoneFences; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2989 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2990 | for (const auto& [id, targeter] : frameTargeters) { |
| 2991 | auto presentFence = getHwComposer().getPresentFence(id); |
| 2992 | |
| 2993 | if (id == pacesetterId) { |
| 2994 | mTransactionCallbackInvoker.addPresentFence(presentFence); |
| 2995 | } |
| 2996 | |
| 2997 | if (auto fenceTime = targeter->setPresentFence(std::move(presentFence)); |
| 2998 | fenceTime->isValid()) { |
| 2999 | presentFences.try_emplace(id, std::move(fenceTime)); |
| 3000 | } |
| 3001 | |
| 3002 | ftl::FakeGuard guard(mStateLock); |
| 3003 | if (const auto display = getCompositionDisplayLocked(id); |
| 3004 | display && display->getState().usesClientComposition) { |
| 3005 | gpuCompositionDoneFences |
| 3006 | .try_emplace(id, display->getRenderSurface()->getClientTargetAcquireFence()); |
| 3007 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3008 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3009 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3010 | const auto pacesetterDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(pacesetterId)); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3011 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3012 | std::shared_ptr<FenceTime> pacesetterPresentFenceTime = |
| 3013 | presentFences.get(pacesetterId) |
| 3014 | .transform([](const FenceTimePtr& ptr) { return ptr; }) |
| 3015 | .value_or(FenceTime::NO_FENCE); |
| 3016 | |
| 3017 | std::shared_ptr<FenceTime> pacesetterGpuCompositionDoneFenceTime = |
| 3018 | gpuCompositionDoneFences.get(pacesetterId) |
| 3019 | .transform([](sp<Fence> fence) { |
| 3020 | return std::make_shared<FenceTime>(std::move(fence)); |
| 3021 | }) |
| 3022 | .value_or(FenceTime::NO_FENCE); |
| 3023 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 3024 | const TimePoint presentTime = TimePoint::now(); |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 3025 | |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 3026 | // Set presentation information before calling Layer::releasePendingBuffer, such that jank |
| 3027 | // information from previous' frame classification is already available when sending jank info |
| 3028 | // to clients, so they get jank classification as early as possible. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3029 | mFrameTimeline->setSfPresent(presentTime.ns(), pacesetterPresentFenceTime, |
| 3030 | pacesetterGpuCompositionDoneFenceTime); |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 3031 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 3032 | // We use the CompositionEngine::getLastFrameRefreshTimestamp() which might |
| 3033 | // 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] | 3034 | // but that should be okay since CompositorTiming has snapping logic. |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 3035 | const TimePoint compositeTime = |
| 3036 | TimePoint::fromNs(mCompositionEngine->getLastFrameRefreshTimestamp()); |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 3037 | const Duration presentLatency = mHasReliablePresentFences |
| 3038 | ? mPresentLatencyTracker.trackPendingFrame(compositeTime, pacesetterPresentFenceTime) |
| 3039 | : Duration::zero(); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3040 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3041 | const auto schedule = mScheduler->getVsyncSchedule(); |
| 3042 | const TimePoint vsyncDeadline = schedule->vsyncDeadlineAfter(presentTime); |
| 3043 | const Period vsyncPeriod = schedule->period(); |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 3044 | const nsecs_t vsyncPhase = |
| 3045 | mScheduler->getVsyncConfiguration().getCurrentConfigs().late.sfOffset; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3046 | |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 3047 | const CompositorTiming compositorTiming(vsyncDeadline.ns(), vsyncPeriod.ns(), vsyncPhase, |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 3048 | presentLatency.ns()); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 3049 | |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 3050 | ui::DisplayMap<ui::LayerStack, const DisplayDevice*> layerStackToDisplay; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3051 | { |
| 3052 | if (!mLayersWithBuffersRemoved.empty() || mNumTrustedPresentationListeners > 0) { |
| 3053 | Mutex::Autolock lock(mStateLock); |
| 3054 | for (const auto& [token, display] : mDisplays) { |
| 3055 | layerStackToDisplay.emplace_or_replace(display->getLayerStack(), display.get()); |
| 3056 | } |
| 3057 | } |
| 3058 | } |
| 3059 | |
| 3060 | for (auto layer : mLayersWithBuffersRemoved) { |
Vishnu Nair | f10a87b | 2023-05-01 14:02:51 -0700 | [diff] [blame] | 3061 | std::vector<ui::LayerStack> previouslyPresentedLayerStacks = |
| 3062 | std::move(layer->mPreviouslyPresentedLayerStacks); |
| 3063 | layer->mPreviouslyPresentedLayerStacks.clear(); |
| 3064 | for (auto layerStack : previouslyPresentedLayerStacks) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3065 | auto optDisplay = layerStackToDisplay.get(layerStack); |
| 3066 | if (optDisplay && !optDisplay->get()->isVirtual()) { |
| 3067 | auto fence = getHwComposer().getPresentFence(optDisplay->get()->getPhysicalId()); |
| 3068 | layer->onLayerDisplayed(ftl::yield<FenceResult>(fence).share(), |
| 3069 | ui::INVALID_LAYER_STACK); |
| 3070 | } |
| 3071 | } |
| 3072 | layer->releasePendingBuffer(presentTime.ns()); |
| 3073 | } |
| 3074 | mLayersWithBuffersRemoved.clear(); |
| 3075 | |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 3076 | for (const auto& layer: mLayersWithQueuedFrames) { |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 3077 | layer->onCompositionPresented(pacesetterDisplay.get(), |
| 3078 | pacesetterGpuCompositionDoneFenceTime, |
| 3079 | pacesetterPresentFenceTime, compositorTiming); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3080 | layer->releasePendingBuffer(presentTime.ns()); |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 3081 | } |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 3082 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3083 | std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>> |
| 3084 | hdrInfoListeners; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3085 | bool haveNewListeners = false; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3086 | { |
| 3087 | Mutex::Autolock lock(mStateLock); |
| 3088 | if (mFpsReporter) { |
Andy Yu | aef688b | 2024-01-23 17:14:23 -0800 | [diff] [blame] | 3089 | mFpsReporter->dispatchLayerFps(mLayerHierarchyBuilder.getHierarchy()); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3090 | } |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 3091 | |
| 3092 | if (mTunnelModeEnabledReporter) { |
| 3093 | mTunnelModeEnabledReporter->updateTunnelModeStatus(); |
| 3094 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3095 | hdrInfoListeners.reserve(mHdrLayerInfoListeners.size()); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 3096 | for (const auto& [displayId, reporter] : mHdrLayerInfoListeners) { |
| 3097 | if (reporter && reporter->hasListeners()) { |
| 3098 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 3099 | hdrInfoListeners.emplace_back(display->getCompositionDisplay(), reporter); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3100 | } |
| 3101 | } |
| 3102 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3103 | haveNewListeners = mAddingHDRLayerInfoListener; // grab this with state lock |
| 3104 | mAddingHDRLayerInfoListener = false; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3105 | } |
| 3106 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3107 | if (haveNewListeners || mHdrLayerInfoChanged) { |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3108 | for (auto& [compositionDisplay, listener] : hdrInfoListeners) { |
| 3109 | HdrLayerInfoReporter::HdrLayerInfo info; |
| 3110 | int32_t maxArea = 0; |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 3111 | |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3112 | auto updateInfoFn = |
| 3113 | [&](const std::shared_ptr<compositionengine::Display>& compositionDisplay, |
| 3114 | const frontend::LayerSnapshot& snapshot, const sp<LayerFE>& layerFe) { |
| 3115 | if (snapshot.isVisible && |
| 3116 | compositionDisplay->includesLayer(snapshot.outputFilter)) { |
| 3117 | if (isHdrLayer(snapshot)) { |
| 3118 | const auto* outputLayer = |
| 3119 | compositionDisplay->getOutputLayerForLayer(layerFe); |
| 3120 | if (outputLayer) { |
| 3121 | const float desiredHdrSdrRatio = |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 3122 | snapshot.desiredHdrSdrRatio < 1.f |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3123 | ? std::numeric_limits<float>::infinity() |
| 3124 | : snapshot.desiredHdrSdrRatio; |
| 3125 | info.mergeDesiredRatio(desiredHdrSdrRatio); |
| 3126 | info.numberOfHdrLayers++; |
| 3127 | const auto displayFrame = outputLayer->getState().displayFrame; |
| 3128 | const int32_t area = |
| 3129 | displayFrame.width() * displayFrame.height(); |
| 3130 | if (area > maxArea) { |
| 3131 | maxArea = area; |
| 3132 | info.maxW = displayFrame.width(); |
| 3133 | info.maxH = displayFrame.height(); |
| 3134 | } |
| 3135 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3136 | } |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 3137 | } |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3138 | }; |
| 3139 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3140 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3141 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 3142 | [&, compositionDisplay = compositionDisplay]( |
| 3143 | std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 3144 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 3145 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 3146 | "Couldnt find layer object for %s", |
| 3147 | snapshot->getDebugString().c_str()); |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3148 | auto& legacyLayer = it->second; |
| 3149 | sp<LayerFE> layerFe = |
| 3150 | legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
| 3151 | |
| 3152 | updateInfoFn(compositionDisplay, *snapshot, layerFe); |
| 3153 | }); |
| 3154 | } else { |
| 3155 | mDrawingState.traverse([&, compositionDisplay = compositionDisplay](Layer* layer) { |
| 3156 | const auto layerFe = layer->getCompositionEngineLayerFE(); |
| 3157 | const frontend::LayerSnapshot& snapshot = *layer->getLayerSnapshot(); |
| 3158 | updateInfoFn(compositionDisplay, snapshot, layerFe); |
| 3159 | }); |
| 3160 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3161 | listener->dispatchHdrLayerInfo(info); |
| 3162 | } |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3163 | } |
| 3164 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3165 | mHdrLayerInfoChanged = false; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3166 | |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 3167 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 3168 | mTransactionCallbackInvoker.clearCompletedTransactions(); |
| 3169 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3170 | mTimeStats->incrementTotalFrames(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3171 | mTimeStats->setPresentFenceGlobal(pacesetterPresentFenceTime); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3172 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3173 | for (auto&& [id, presentFence] : presentFences) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3174 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3175 | const bool isInternalDisplay = |
| 3176 | mPhysicalDisplays.get(id).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 3177 | |
| 3178 | if (isInternalDisplay) { |
| 3179 | mScheduler->addPresentFence(id, std::move(presentFence)); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3180 | } |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3181 | } |
| 3182 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3183 | const bool hasPacesetterDisplay = |
| 3184 | pacesetterDisplay && getHwComposer().isConnected(pacesetterId); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3185 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3186 | if (!hasSyncFramework) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3187 | if (hasPacesetterDisplay && pacesetterDisplay->isPoweredOn()) { |
| 3188 | mScheduler->enableHardwareVsync(pacesetterId); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3189 | } |
| 3190 | } |
| 3191 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3192 | if (hasPacesetterDisplay && !pacesetterDisplay->isPoweredOn()) { |
Lars Svensson | d9e5469 | 2021-12-21 07:41:57 +0100 | [diff] [blame] | 3193 | getRenderEngine().cleanupPostRender(); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 3194 | return; |
| 3195 | } |
| 3196 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 3197 | // Cleanup any outstanding resources due to rendering a prior frame. |
| 3198 | getRenderEngine().cleanupPostRender(); |
| 3199 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3200 | if (mNumTrustedPresentationListeners > 0) { |
| 3201 | // 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] | 3202 | traverseLegacyLayers([&](Layer* layer) { |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3203 | if (!layer->hasTrustedPresentationListener()) { |
| 3204 | return; |
| 3205 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3206 | const frontend::LayerSnapshot* snapshot = mLayerLifecycleManagerEnabled |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3207 | ? mLayerSnapshotBuilder.getSnapshot(layer->sequence) |
| 3208 | : layer->getLayerSnapshot(); |
| 3209 | std::optional<const DisplayDevice*> displayOpt = std::nullopt; |
| 3210 | if (snapshot) { |
| 3211 | displayOpt = layerStackToDisplay.get(snapshot->outputFilter.layerStack); |
| 3212 | } |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 3213 | const DisplayDevice* display = displayOpt.value_or(nullptr); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3214 | layer->updateTrustedPresentationState(display, snapshot, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 3215 | nanoseconds_to_milliseconds(presentStartTime), |
| 3216 | false); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3217 | }); |
| 3218 | } |
| 3219 | |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3220 | // Even though ATRACE_INT64 already checks if tracing is enabled, it doesn't prevent the |
| 3221 | // side-effect of getTotalSize(), so we check that again here |
| 3222 | if (ATRACE_ENABLED()) { |
Marissa Wall | 22b2de1 | 2019-12-02 18:11:43 -0800 | [diff] [blame] | 3223 | // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3224 | ATRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize()); |
| 3225 | } |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3226 | |
| 3227 | logFrameStats(presentTime); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 3228 | } |
| 3229 | |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3230 | FloatRect SurfaceFlinger::getMaxDisplayBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3231 | const ui::Size maxSize = [this] { |
| 3232 | ftl::FakeGuard guard(mStateLock); |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3233 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3234 | // The LayerTraceGenerator tool runs without displays. |
| 3235 | if (mDisplays.empty()) return ui::Size{5000, 5000}; |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3236 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3237 | return std::accumulate(mDisplays.begin(), mDisplays.end(), ui::kEmptySize, |
| 3238 | [](ui::Size size, const auto& pair) -> ui::Size { |
| 3239 | const auto& display = pair.second; |
| 3240 | return {std::max(size.getWidth(), display->getWidth()), |
| 3241 | std::max(size.getHeight(), display->getHeight())}; |
| 3242 | }); |
| 3243 | }(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3244 | |
| 3245 | // Ignore display bounds for now since they will be computed later. Use a large Rect bound |
| 3246 | // to ensure it's bigger than an actual display will be. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3247 | const float xMax = maxSize.getWidth() * 10.f; |
| 3248 | const float yMax = maxSize.getHeight() * 10.f; |
| 3249 | |
| 3250 | return {-xMax, -yMax, xMax, yMax}; |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | void SurfaceFlinger::computeLayerBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3254 | const FloatRect maxBounds = getMaxDisplayBounds(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3255 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 3256 | layer->computeBounds(maxBounds, ui::Transform(), 0.f /* shadowRadius */); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3257 | } |
| 3258 | } |
| 3259 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3260 | void SurfaceFlinger::commitTransactions() { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 3261 | ATRACE_CALL(); |
| 3262 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3263 | // Keep a copy of the drawing state (that is going to be overwritten |
| 3264 | // by commitTransactionsLocked) outside of mStateLock so that the side |
| 3265 | // effects of the State assignment don't happen with mStateLock held, |
| 3266 | // which can cause deadlocks. |
Mathias Agopian | 7cc6df5 | 2013-06-05 14:30:54 -0700 | [diff] [blame] | 3267 | State drawingState(mDrawingState); |
| 3268 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3269 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 3270 | mDebugInTransaction = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3271 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3272 | // Here we're guaranteed that some transaction flags are set |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3273 | // so we can call commitTransactionsLocked unconditionally. |
| 3274 | // We clear the flags with mStateLock held to guarantee that |
| 3275 | // mCurrentState won't change until the transaction is committed. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3276 | mScheduler->modulateVsync({}, &VsyncModulator::onTransactionCommit); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3277 | commitTransactionsLocked(clearTransactionFlags(eTransactionMask)); |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 3278 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3279 | mDebugInTransaction = 0; |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3282 | std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes( |
| 3283 | PhysicalDisplayId displayId) const { |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3284 | std::vector<HWComposer::HWCDisplayMode> hwcModes; |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3285 | std::optional<hal::HWConfigId> activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3286 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3287 | const bool isExternalDisplay = FlagManager::getInstance().connected_display() && |
| 3288 | getHwComposer().getDisplayConnectionType(displayId) == |
| 3289 | ui::DisplayConnectionType::External; |
| 3290 | |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3291 | int attempt = 0; |
| 3292 | constexpr int kMaxAttempts = 3; |
| 3293 | do { |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 3294 | hwcModes = getHwComposer().getModes(displayId, |
| 3295 | scheduler::RefreshRateSelector::kMinSupportedFrameRate |
| 3296 | .getPeriodNsecs()); |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3297 | const auto activeModeHwcIdExp = getHwComposer().getActiveMode(displayId); |
| 3298 | activeModeHwcIdOpt = activeModeHwcIdExp.value_opt(); |
| 3299 | |
| 3300 | if (isExternalDisplay && |
| 3301 | activeModeHwcIdExp.has_error([](status_t error) { return error == NO_INIT; })) { |
| 3302 | constexpr nsecs_t k59HzVsyncPeriod = 16949153; |
| 3303 | constexpr nsecs_t k60HzVsyncPeriod = 16666667; |
| 3304 | |
| 3305 | // DM sets the initial mode for an external display to 1080p@60, but |
| 3306 | // this comes after SF creates its own state (including the |
| 3307 | // DisplayDevice). For now, pick the same mode in order to avoid |
| 3308 | // inconsistent state and unnecessary mode switching. |
| 3309 | // TODO (b/318534874): Let DM decide the initial mode. |
| 3310 | // |
| 3311 | // Try to find 1920x1080 @ 60 Hz |
| 3312 | if (const auto iter = std::find_if(hwcModes.begin(), hwcModes.end(), |
| 3313 | [](const auto& mode) { |
| 3314 | return mode.width == 1920 && |
| 3315 | mode.height == 1080 && |
| 3316 | mode.vsyncPeriod == k60HzVsyncPeriod; |
| 3317 | }); |
| 3318 | iter != hwcModes.end()) { |
| 3319 | activeModeHwcIdOpt = iter->hwcId; |
| 3320 | break; |
| 3321 | } |
| 3322 | |
| 3323 | // Try to find 1920x1080 @ 59-60 Hz |
| 3324 | if (const auto iter = std::find_if(hwcModes.begin(), hwcModes.end(), |
| 3325 | [](const auto& mode) { |
| 3326 | return mode.width == 1920 && |
| 3327 | mode.height == 1080 && |
| 3328 | mode.vsyncPeriod >= k60HzVsyncPeriod && |
| 3329 | mode.vsyncPeriod <= k59HzVsyncPeriod; |
| 3330 | }); |
| 3331 | iter != hwcModes.end()) { |
| 3332 | activeModeHwcIdOpt = iter->hwcId; |
| 3333 | break; |
| 3334 | } |
| 3335 | |
| 3336 | // The display does not support 1080p@60, and this is the last attempt to pick a display |
| 3337 | // mode. Prefer 60 Hz if available, with the closest resolution to 1080p. |
| 3338 | if (attempt + 1 == kMaxAttempts) { |
| 3339 | std::vector<HWComposer::HWCDisplayMode> hwcModeOpts; |
| 3340 | |
| 3341 | for (const auto& mode : hwcModes) { |
| 3342 | if (mode.width <= 1920 && mode.height <= 1080 && |
| 3343 | mode.vsyncPeriod >= k60HzVsyncPeriod && |
| 3344 | mode.vsyncPeriod <= k59HzVsyncPeriod) { |
| 3345 | hwcModeOpts.push_back(mode); |
| 3346 | } |
| 3347 | } |
| 3348 | |
| 3349 | if (const auto iter = std::max_element(hwcModeOpts.begin(), hwcModeOpts.end(), |
| 3350 | [](const auto& a, const auto& b) { |
| 3351 | const auto aSize = a.width * a.height; |
| 3352 | const auto bSize = b.width * b.height; |
| 3353 | if (aSize < bSize) |
| 3354 | return true; |
| 3355 | else if (aSize == bSize) |
| 3356 | return a.vsyncPeriod > b.vsyncPeriod; |
| 3357 | else |
| 3358 | return false; |
| 3359 | }); |
| 3360 | iter != hwcModeOpts.end()) { |
| 3361 | activeModeHwcIdOpt = iter->hwcId; |
| 3362 | break; |
| 3363 | } |
| 3364 | |
| 3365 | // hwcModeOpts was empty, use hwcModes[0] as the last resort |
| 3366 | activeModeHwcIdOpt = hwcModes[0].hwcId; |
| 3367 | } |
| 3368 | } |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3369 | |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3370 | const auto isActiveMode = [activeModeHwcIdOpt](const HWComposer::HWCDisplayMode& mode) { |
| 3371 | return mode.hwcId == activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3372 | }; |
| 3373 | |
| 3374 | if (std::any_of(hwcModes.begin(), hwcModes.end(), isActiveMode)) { |
| 3375 | break; |
| 3376 | } |
| 3377 | } while (++attempt < kMaxAttempts); |
| 3378 | |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3379 | if (attempt == kMaxAttempts) { |
| 3380 | const std::string activeMode = |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3381 | activeModeHwcIdOpt ? std::to_string(*activeModeHwcIdOpt) : "unknown"s; |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3382 | ALOGE("HWC failed to report an active mode that is supported: activeModeHwcId=%s, " |
| 3383 | "hwcModes={%s}", |
| 3384 | activeMode.c_str(), base::Join(hwcModes, ", ").c_str()); |
| 3385 | return {}; |
| 3386 | } |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3387 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3388 | const DisplayModes oldModes = mPhysicalDisplays.get(displayId) |
| 3389 | .transform([](const PhysicalDisplay& display) { |
| 3390 | return display.snapshot().displayModes(); |
| 3391 | }) |
| 3392 | .value_or(DisplayModes{}); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3393 | |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 3394 | DisplayModeId nextModeId = std::accumulate(oldModes.begin(), oldModes.end(), DisplayModeId(-1), |
| 3395 | [](DisplayModeId max, const auto& pair) { |
| 3396 | return std::max(max, pair.first); |
| 3397 | }); |
| 3398 | ++nextModeId; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3399 | |
| 3400 | DisplayModes newModes; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3401 | for (const auto& hwcMode : hwcModes) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 3402 | const auto id = nextModeId++; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3403 | newModes.try_emplace(id, |
| 3404 | DisplayMode::Builder(hwcMode.hwcId) |
| 3405 | .setId(id) |
| 3406 | .setPhysicalDisplayId(displayId) |
| 3407 | .setResolution({hwcMode.width, hwcMode.height}) |
| 3408 | .setVsyncPeriod(hwcMode.vsyncPeriod) |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 3409 | .setVrrConfig(hwcMode.vrrConfig) |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3410 | .setDpiX(hwcMode.dpiX) |
| 3411 | .setDpiY(hwcMode.dpiY) |
| 3412 | .setGroup(hwcMode.configGroup) |
| 3413 | .build()); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3414 | } |
| 3415 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3416 | const bool sameModes = |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3417 | std::equal(newModes.begin(), newModes.end(), oldModes.begin(), oldModes.end(), |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3418 | [](const auto& lhs, const auto& rhs) { |
| 3419 | return equalsExceptDisplayModeId(*lhs.second, *rhs.second); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3420 | }); |
| 3421 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3422 | // Keep IDs if modes have not changed. |
| 3423 | const auto& modes = sameModes ? oldModes : newModes; |
| 3424 | const DisplayModePtr activeMode = |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3425 | std::find_if(modes.begin(), modes.end(), [activeModeHwcIdOpt](const auto& pair) { |
| 3426 | return pair.second->getHwcId() == activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3427 | })->second; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3428 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3429 | if (isExternalDisplay) { |
| 3430 | ALOGI("External display %s initial mode: {%s}", to_string(displayId).c_str(), |
| 3431 | to_string(*activeMode).c_str()); |
| 3432 | } |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3433 | return {modes, activeMode}; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3434 | } |
| 3435 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3436 | bool SurfaceFlinger::configureLocked() { |
| 3437 | std::vector<HotplugEvent> events; |
| 3438 | { |
| 3439 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 3440 | events = std::move(mPendingHotplugEvents); |
| 3441 | } |
| 3442 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3443 | for (const auto [hwcDisplayId, connection] : events) { |
| 3444 | if (auto info = getHwComposer().onHotplug(hwcDisplayId, connection)) { |
| 3445 | const auto displayId = info->id; |
| 3446 | const bool connected = connection == hal::Connection::CONNECTED; |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3447 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3448 | if (const char* const log = |
| 3449 | processHotplug(displayId, hwcDisplayId, connected, std::move(*info))) { |
| 3450 | ALOGI("%s display %s (HAL ID %" PRIu64 ")", log, to_string(displayId).c_str(), |
| 3451 | hwcDisplayId); |
| 3452 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3453 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3454 | } |
| 3455 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3456 | return !events.empty(); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3457 | } |
| 3458 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3459 | const char* SurfaceFlinger::processHotplug(PhysicalDisplayId displayId, |
| 3460 | hal::HWDisplayId hwcDisplayId, bool connected, |
| 3461 | DisplayIdentificationInfo&& info) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3462 | const auto displayOpt = mPhysicalDisplays.get(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3463 | if (!connected) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3464 | LOG_ALWAYS_FATAL_IF(!displayOpt); |
| 3465 | const auto& display = displayOpt->get(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3466 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3467 | if (const ssize_t index = mCurrentState.displays.indexOfKey(display.token()); index >= 0) { |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3468 | mCurrentState.displays.removeItemsAt(index); |
| 3469 | } |
| 3470 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3471 | mPhysicalDisplays.erase(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3472 | return "Disconnecting"; |
| 3473 | } |
| 3474 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3475 | auto [displayModes, activeMode] = loadDisplayModes(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3476 | if (!activeMode) { |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3477 | ALOGE("Failed to hotplug display %s", to_string(displayId).c_str()); |
Huihong Luo | 9f0fc59 | 2024-01-17 12:29:26 -0800 | [diff] [blame] | 3478 | if (FlagManager::getInstance().hotplug2()) { |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3479 | mScheduler->dispatchHotplugError( |
| 3480 | static_cast<int32_t>(DisplayHotplugEvent::ERROR_UNKNOWN)); |
Huihong Luo | 9f0fc59 | 2024-01-17 12:29:26 -0800 | [diff] [blame] | 3481 | } |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3482 | getHwComposer().disconnectDisplay(displayId); |
| 3483 | return nullptr; |
| 3484 | } |
| 3485 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3486 | ui::ColorModes colorModes = getHwComposer().getColorModes(displayId); |
| 3487 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3488 | if (displayOpt) { |
| 3489 | const auto& display = displayOpt->get(); |
| 3490 | const auto& snapshot = display.snapshot(); |
| 3491 | |
| 3492 | std::optional<DeviceProductInfo> deviceProductInfo; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3493 | if (getHwComposer().updatesDeviceProductInfoOnHotplugReconnect()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3494 | deviceProductInfo = std::move(info.deviceProductInfo); |
| 3495 | } else { |
| 3496 | deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3497 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3498 | |
| 3499 | const auto it = |
| 3500 | mPhysicalDisplays.try_replace(displayId, display.token(), displayId, |
| 3501 | snapshot.connectionType(), std::move(displayModes), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3502 | std::move(colorModes), std::move(deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3503 | |
| 3504 | auto& state = mCurrentState.displays.editValueFor(it->second.token()); |
| 3505 | state.sequenceId = DisplayDeviceState{}.sequenceId; // Generate new sequenceId. |
| 3506 | state.physical->activeMode = std::move(activeMode); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3507 | return "Reconnecting"; |
| 3508 | } |
| 3509 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3510 | const sp<IBinder> token = sp<BBinder>::make(); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3511 | const ui::DisplayConnectionType connectionType = |
| 3512 | getHwComposer().getDisplayConnectionType(displayId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3513 | |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3514 | mPhysicalDisplays.try_emplace(displayId, token, displayId, connectionType, |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3515 | std::move(displayModes), std::move(colorModes), |
| 3516 | std::move(info.deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3517 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3518 | DisplayDeviceState state; |
| 3519 | state.physical = {.id = displayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3520 | .hwcDisplayId = hwcDisplayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3521 | .activeMode = std::move(activeMode)}; |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3522 | state.isSecure = connectionType == ui::DisplayConnectionType::Internal; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3523 | state.isProtected = true; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3524 | state.displayName = std::move(info.name); |
| 3525 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3526 | mCurrentState.displays.add(token, state); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3527 | return "Connecting"; |
| 3528 | } |
| 3529 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3530 | void SurfaceFlinger::dispatchDisplayModeChangeEvent(PhysicalDisplayId displayId, |
| 3531 | const scheduler::FrameRateMode& mode) { |
| 3532 | // TODO(b/255635821): Merge code paths and move to Scheduler. |
| 3533 | const auto onDisplayModeChanged = displayId == mActiveDisplayId |
| 3534 | ? &scheduler::Scheduler::onPrimaryDisplayModeChanged |
| 3535 | : &scheduler::Scheduler::onNonPrimaryDisplayModeChanged; |
| 3536 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 3537 | ((*mScheduler).*onDisplayModeChanged)(scheduler::Cycle::Render, mode); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3538 | } |
| 3539 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3540 | sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3541 | const wp<IBinder>& displayToken, |
| 3542 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3543 | const DisplayDeviceState& state, |
| 3544 | const sp<compositionengine::DisplaySurface>& displaySurface, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3545 | const sp<IGraphicBufferProducer>& producer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3546 | DisplayDeviceCreationArgs creationArgs(sp<SurfaceFlinger>::fromExisting(this), getHwComposer(), |
| 3547 | displayToken, compositionDisplay); |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 3548 | creationArgs.sequenceId = state.sequenceId; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3549 | creationArgs.isSecure = state.isSecure; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3550 | creationArgs.isProtected = state.isProtected; |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3551 | creationArgs.displaySurface = displaySurface; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3552 | creationArgs.hasWideColorGamut = false; |
| 3553 | creationArgs.supportedPerFrameMetadata = 0; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 3554 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3555 | if (const auto& physical = state.physical) { |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3556 | creationArgs.activeModeId = physical->activeMode->getId(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3557 | const auto [kernelIdleTimerController, idleTimerTimeoutMs] = |
| 3558 | getKernelIdleTimerProperties(compositionDisplay->getId()); |
| 3559 | |
Ady Abraham | 0c8b723 | 2023-01-27 21:12:16 -0800 | [diff] [blame] | 3560 | using Config = scheduler::RefreshRateSelector::Config; |
| 3561 | const auto enableFrameRateOverride = sysprop::enable_frame_rate_override(true) |
| 3562 | ? Config::FrameRateOverride::Enabled |
| 3563 | : Config::FrameRateOverride::Disabled; |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 3564 | const Config config = |
Ady Abraham | 8ca643a | 2022-10-18 18:26:47 -0700 | [diff] [blame] | 3565 | {.enableFrameRateOverride = enableFrameRateOverride, |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3566 | .frameRateMultipleThreshold = |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 3567 | base::GetIntProperty("debug.sf.frame_rate_multiple_threshold"s, 0), |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3568 | .idleTimerTimeout = idleTimerTimeoutMs, |
| 3569 | .kernelIdleTimerController = kernelIdleTimerController}; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3570 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3571 | creationArgs.refreshRateSelector = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3572 | mPhysicalDisplays.get(physical->id) |
| 3573 | .transform(&PhysicalDisplay::snapshotRef) |
| 3574 | .transform([&](const display::DisplaySnapshot& snapshot) { |
| 3575 | return std::make_shared< |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3576 | scheduler::RefreshRateSelector>(snapshot.displayModes(), |
| 3577 | creationArgs.activeModeId, |
| 3578 | config); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3579 | }) |
| 3580 | .value_or(nullptr); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3581 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3582 | creationArgs.isPrimary = physical->id == getPrimaryDisplayIdLocked(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3583 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 3584 | mPhysicalDisplays.get(physical->id) |
| 3585 | .transform(&PhysicalDisplay::snapshotRef) |
| 3586 | .transform(ftl::unit_fn([&](const display::DisplaySnapshot& snapshot) { |
| 3587 | for (const auto mode : snapshot.colorModes()) { |
| 3588 | creationArgs.hasWideColorGamut |= ui::isWideColorMode(mode); |
| 3589 | creationArgs.hwcColorModes |
| 3590 | .emplace(mode, |
| 3591 | getHwComposer().getRenderIntents(physical->id, mode)); |
| 3592 | } |
| 3593 | })); |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 3594 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3595 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3596 | if (const auto id = HalDisplayId::tryCast(compositionDisplay->getId())) { |
| 3597 | getHwComposer().getHdrCapabilities(*id, &creationArgs.hdrCapabilities); |
| 3598 | creationArgs.supportedPerFrameMetadata = getHwComposer().getSupportedPerFrameMetadata(*id); |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 3599 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3600 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 3601 | auto nativeWindowSurface = getFactory().createNativeWindowSurface(producer); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3602 | auto nativeWindow = nativeWindowSurface->getNativeWindow(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3603 | creationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3604 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3605 | // Make sure that composition can never be stalled by a virtual display |
| 3606 | // 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] | 3607 | // here, in case the display is composed entirely by HWC. |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 3608 | if (state.isVirtual()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3609 | nativeWindow->setSwapInterval(nativeWindow.get(), 0); |
| 3610 | } |
| 3611 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 3612 | creationArgs.physicalOrientation = |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3613 | getPhysicalDisplayOrientation(compositionDisplay->getId(), creationArgs.isPrimary); |
| 3614 | ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 3615 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 3616 | creationArgs.initialPowerMode = state.isVirtual() ? hal::PowerMode::ON : hal::PowerMode::OFF; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3617 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3618 | creationArgs.requestedRefreshRate = state.requestedRefreshRate; |
| 3619 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3620 | sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3621 | |
Ady Abraham | 8565ad2 | 2021-06-22 17:45:44 -0700 | [diff] [blame] | 3622 | nativeWindowSurface->preallocateBuffers(); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3623 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3624 | ui::ColorMode defaultColorMode = ui::ColorMode::NATIVE; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 3625 | Dataspace defaultDataSpace = Dataspace::UNKNOWN; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3626 | if (display->hasWideColorGamut()) { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3627 | defaultColorMode = ui::ColorMode::SRGB; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 3628 | defaultDataSpace = Dataspace::V0_SRGB; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3629 | } |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 3630 | display->getCompositionDisplay()->setColorProfile( |
| 3631 | compositionengine::Output::ColorProfile{defaultColorMode, defaultDataSpace, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 3632 | RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3633 | |
| 3634 | if (const auto& physical = state.physical) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3635 | const auto& mode = *physical->activeMode; |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 3636 | display->setActiveMode(mode.getId(), mode.getVsyncRate(), mode.getVsyncRate()); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 3637 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3638 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3639 | display->setLayerFilter(makeLayerFilterForDisplay(display->getId(), state.layerStack)); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3640 | display->setProjection(state.orientation, state.layerStackSpaceRect, |
| 3641 | state.orientedDisplaySpaceRect); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3642 | display->setDisplayName(state.displayName); |
Vishnu Nair | a119aaa | 2021-09-24 07:19:35 -0700 | [diff] [blame] | 3643 | display->setFlags(state.flags); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3644 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3645 | return display; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3646 | } |
| 3647 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3648 | void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, |
| 3649 | const DisplayDeviceState& state) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3650 | ui::Size resolution(0, 0); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3651 | ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN); |
| 3652 | if (state.physical) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3653 | resolution = state.physical->activeMode->getResolution(); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3654 | pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888); |
| 3655 | } else if (state.surface != nullptr) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3656 | int status = state.surface->query(NATIVE_WINDOW_WIDTH, &resolution.width); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3657 | ALOGE_IF(status != NO_ERROR, "Unable to query width (%d)", status); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3658 | status = state.surface->query(NATIVE_WINDOW_HEIGHT, &resolution.height); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3659 | ALOGE_IF(status != NO_ERROR, "Unable to query height (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3660 | int format; |
| 3661 | status = state.surface->query(NATIVE_WINDOW_FORMAT, &format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3662 | ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3663 | pixelFormat = static_cast<ui::PixelFormat>(format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3664 | } else { |
| 3665 | // Virtual displays without a surface are dormant: |
| 3666 | // they have external state (layer stack, projection, |
| 3667 | // etc.) but no internal state (i.e. a DisplayDevice). |
| 3668 | return; |
| 3669 | } |
| 3670 | |
| 3671 | compositionengine::DisplayCreationArgsBuilder builder; |
| 3672 | if (const auto& physical = state.physical) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3673 | builder.setId(physical->id); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3674 | } else { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 3675 | builder.setId(acquireVirtualDisplay(resolution, pixelFormat)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3676 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3677 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3678 | builder.setPixels(resolution); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3679 | builder.setIsSecure(state.isSecure); |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3680 | builder.setIsProtected(state.isProtected); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 3681 | builder.setPowerAdvisor(mPowerAdvisor.get()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3682 | builder.setName(state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3683 | auto compositionDisplay = getCompositionEngine().createDisplay(builder.build()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3684 | compositionDisplay->setLayerCachingEnabled(mLayerCachingEnabled); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3685 | |
| 3686 | sp<compositionengine::DisplaySurface> displaySurface; |
| 3687 | sp<IGraphicBufferProducer> producer; |
| 3688 | sp<IGraphicBufferProducer> bqProducer; |
| 3689 | sp<IGraphicBufferConsumer> bqConsumer; |
| 3690 | getFactory().createBufferQueue(&bqProducer, &bqConsumer, /*consumerIsSurfaceFlinger =*/false); |
| 3691 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3692 | if (state.isVirtual()) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3693 | const auto displayId = VirtualDisplayId::tryCast(compositionDisplay->getId()); |
| 3694 | LOG_FATAL_IF(!displayId); |
| 3695 | auto surface = sp<VirtualDisplaySurface>::make(getHwComposer(), *displayId, state.surface, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3696 | bqProducer, bqConsumer, state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3697 | displaySurface = surface; |
| 3698 | producer = std::move(surface); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3699 | } else { |
| 3700 | ALOGE_IF(state.surface != nullptr, |
| 3701 | "adding a supported display, but rendering " |
| 3702 | "surface is provided (%p), ignoring it", |
| 3703 | state.surface.get()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3704 | const auto displayId = PhysicalDisplayId::tryCast(compositionDisplay->getId()); |
| 3705 | LOG_FATAL_IF(!displayId); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3706 | displaySurface = |
| 3707 | sp<FramebufferSurface>::make(getHwComposer(), *displayId, bqConsumer, |
| 3708 | state.physical->activeMode->getResolution(), |
| 3709 | ui::Size(maxGraphicsWidth, maxGraphicsHeight)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3710 | producer = bqProducer; |
| 3711 | } |
| 3712 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3713 | LOG_FATAL_IF(!displaySurface); |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3714 | auto display = setupNewDisplayDeviceInternal(displayToken, std::move(compositionDisplay), state, |
| 3715 | displaySurface, producer); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3716 | |
| 3717 | if (mScheduler && !display->isVirtual()) { |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3718 | // TODO(b/241285876): Annotate `processDisplayAdded` instead. |
| 3719 | ftl::FakeGuard guard(kMainThreadContext); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3720 | |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3721 | // For hotplug reconnect, renew the registration since display modes have been reloaded. |
| 3722 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector()); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3723 | } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3724 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3725 | if (display->isVirtual()) { |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 3726 | display->adjustRefreshRate(mScheduler->getPacesetterRefreshRate()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3727 | } |
| 3728 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3729 | mDisplays.try_emplace(displayToken, std::move(display)); |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3730 | |
| 3731 | // For an external display, loadDisplayModes already attempted to select the same mode |
| 3732 | // as DM, but SF still needs to be updated to match. |
| 3733 | // TODO (b/318534874): Let DM decide the initial mode. |
| 3734 | if (const auto& physical = state.physical; |
| 3735 | mScheduler && physical && FlagManager::getInstance().connected_display()) { |
| 3736 | const bool isInternalDisplay = mPhysicalDisplays.get(physical->id) |
| 3737 | .transform(&PhysicalDisplay::isInternal) |
| 3738 | .value_or(false); |
| 3739 | |
| 3740 | if (!isInternalDisplay) { |
| 3741 | auto activeModePtr = physical->activeMode; |
| 3742 | const auto fps = activeModePtr->getPeakFps(); |
| 3743 | |
| 3744 | setDesiredMode( |
| 3745 | {.mode = scheduler::FrameRateMode{fps, |
| 3746 | ftl::as_non_null(std::move(activeModePtr))}, |
| 3747 | .emitEvent = false, |
| 3748 | .force = true}); |
| 3749 | } |
| 3750 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3751 | } |
| 3752 | |
| 3753 | void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3754 | auto display = getDisplayDeviceLocked(displayToken); |
| 3755 | if (display) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3756 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3757 | |
| 3758 | if (display->isVirtual()) { |
| 3759 | releaseVirtualDisplay(display->getVirtualId()); |
| 3760 | } else { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 3761 | mScheduler->unregisterDisplay(display->getPhysicalId()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3762 | } |
| 3763 | } |
| 3764 | |
| 3765 | mDisplays.erase(displayToken); |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3766 | |
| 3767 | if (display && display->isVirtual()) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 3768 | static_cast<void>(mScheduler->schedule([display = std::move(display)] { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3769 | // Destroy the display without holding the mStateLock. |
| 3770 | // This is a temporary solution until we can manage transaction queues without |
| 3771 | // holding the mStateLock. |
| 3772 | // With blast, the IGBP that is passed to the VirtualDisplaySurface is owned by the |
| 3773 | // client. When the IGBP is disconnected, its buffer cache in SF will be cleared |
| 3774 | // via SurfaceComposerClient::doUncacheBufferTransaction. This call from the client |
| 3775 | // ends up running on the main thread causing a deadlock since setTransactionstate |
| 3776 | // will try to acquire the mStateLock. Instead we extend the lifetime of |
| 3777 | // DisplayDevice and destroy it in the main thread without holding the mStateLock. |
| 3778 | // The display will be disconnected and removed from the mDisplays list so it will |
| 3779 | // not be accessible. |
| 3780 | })); |
| 3781 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, |
| 3785 | const DisplayDeviceState& currentState, |
| 3786 | const DisplayDeviceState& drawingState) { |
| 3787 | const sp<IBinder> currentBinder = IInterface::asBinder(currentState.surface); |
| 3788 | const sp<IBinder> drawingBinder = IInterface::asBinder(drawingState.surface); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3789 | |
| 3790 | // Recreate the DisplayDevice if the surface or sequence ID changed. |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3791 | if (currentBinder != drawingBinder || currentState.sequenceId != drawingState.sequenceId) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3792 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3793 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3794 | if (display->isVirtual()) { |
| 3795 | releaseVirtualDisplay(display->getVirtualId()); |
| 3796 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3797 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3798 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3799 | mDisplays.erase(displayToken); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3800 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3801 | if (const auto& physical = currentState.physical) { |
| 3802 | getHwComposer().allocatePhysicalDisplay(physical->hwcDisplayId, physical->id); |
| 3803 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3804 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3805 | processDisplayAdded(displayToken, currentState); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3806 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3807 | if (currentState.physical) { |
Marin Shalamanov | 4c5e301 | 2020-06-04 21:41:42 +0200 | [diff] [blame] | 3808 | const auto display = getDisplayDeviceLocked(displayToken); |
| 3809 | setPowerModeInternal(display, hal::PowerMode::ON); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3810 | |
| 3811 | // TODO(b/175678251) Call a listener instead. |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 3812 | if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 3813 | mScheduler->resetPhaseConfiguration(display->getActiveMode().fps); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3814 | } |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3815 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3816 | return; |
| 3817 | } |
| 3818 | |
| 3819 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3820 | if (currentState.layerStack != drawingState.layerStack) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3821 | display->setLayerFilter( |
| 3822 | makeLayerFilterForDisplay(display->getId(), currentState.layerStack)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3823 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 3824 | if (currentState.flags != drawingState.flags) { |
| 3825 | display->setFlags(currentState.flags); |
| 3826 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3827 | if ((currentState.orientation != drawingState.orientation) || |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3828 | (currentState.layerStackSpaceRect != drawingState.layerStackSpaceRect) || |
| 3829 | (currentState.orientedDisplaySpaceRect != drawingState.orientedDisplaySpaceRect)) { |
| 3830 | display->setProjection(currentState.orientation, currentState.layerStackSpaceRect, |
| 3831 | currentState.orientedDisplaySpaceRect); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3832 | if (display->getId() == mActiveDisplayId) { |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 3833 | mActiveDisplayTransformHint = display->getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 3834 | sActiveDisplayRotationFlags = |
| 3835 | ui::Transform::toRotationFlags(display->getOrientation()); |
Arthur Hung | b6aa9a0 | 2021-06-09 14:23:01 +0800 | [diff] [blame] | 3836 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3837 | } |
| 3838 | if (currentState.width != drawingState.width || |
| 3839 | currentState.height != drawingState.height) { |
| 3840 | display->setDisplaySize(currentState.width, currentState.height); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 3841 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3842 | if (display->getId() == mActiveDisplayId) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 3843 | onActiveDisplaySizeChanged(*display); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3844 | } |
| 3845 | } |
| 3846 | } |
| 3847 | } |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 3848 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3849 | void SurfaceFlinger::processDisplayChangesLocked() { |
| 3850 | // here we take advantage of Vector's copy-on-write semantics to |
| 3851 | // improve performance by skipping the transaction entirely when |
| 3852 | // know that the lists are identical |
| 3853 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays); |
| 3854 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays); |
| 3855 | if (!curr.isIdenticalTo(draw)) { |
| 3856 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3857 | mUpdateInputInfo = true; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3858 | |
Dominik Laskowski | 01f191c | 2024-01-29 11:51:23 -0500 | [diff] [blame] | 3859 | // Apply the current color matrix to any added or changed display. |
| 3860 | mCurrentState.colorMatrixChanged = true; |
| 3861 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3862 | // find the displays that were removed |
| 3863 | // (ie: in drawing state but not in current state) |
| 3864 | // also handle displays that changed |
| 3865 | // (ie: displays that are in both lists) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3866 | for (size_t i = 0; i < draw.size(); i++) { |
| 3867 | const wp<IBinder>& displayToken = draw.keyAt(i); |
| 3868 | const ssize_t j = curr.indexOfKey(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3869 | if (j < 0) { |
| 3870 | // in drawing state but not in current state |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3871 | processDisplayRemoved(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3872 | } else { |
| 3873 | // this display is in both lists. see if something changed. |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3874 | const DisplayDeviceState& currentState = curr[j]; |
| 3875 | const DisplayDeviceState& drawingState = draw[i]; |
| 3876 | processDisplayChanged(displayToken, currentState, drawingState); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3877 | } |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | // find displays that were added |
| 3881 | // (ie: in current state but not in drawing state) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3882 | for (size_t i = 0; i < curr.size(); i++) { |
| 3883 | const wp<IBinder>& displayToken = curr.keyAt(i); |
| 3884 | if (draw.indexOfKey(displayToken) < 0) { |
| 3885 | processDisplayAdded(displayToken, curr[i]); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3886 | } |
| 3887 | } |
| 3888 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3889 | |
| 3890 | mDrawingState.displays = mCurrentState.displays; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3891 | } |
| 3892 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3893 | void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { |
| 3894 | // Commit display transactions. |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3895 | const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3896 | mFrontEndDisplayInfosChanged = displayTransactionNeeded; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3897 | if (displayTransactionNeeded && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3898 | processDisplayChangesLocked(); |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 3899 | mFrontEndDisplayInfos.clear(); |
| 3900 | for (const auto& [_, display] : mDisplays) { |
| 3901 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 3902 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3903 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 3904 | mForceTransactionDisplayChange = displayTransactionNeeded; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3905 | |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3906 | if (mSomeChildrenChanged) { |
| 3907 | mVisibleRegionsDirty = true; |
| 3908 | mSomeChildrenChanged = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3909 | mUpdateInputInfo = true; |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3910 | } |
| 3911 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3912 | // Update transform hint. |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 3913 | if (transactionFlags & (eTransformHintUpdateNeeded | eDisplayTransactionNeeded)) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3914 | // 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] | 3915 | // |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 3916 | // 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] | 3917 | // the hint is set before we acquire a buffer from the surface texture. |
| 3918 | // |
| 3919 | // NOTE: layer transactions have taken place already, so we use their |
| 3920 | // drawing state. However, SurfaceFlinger's own transaction has not |
| 3921 | // happened yet, so we must use the current state layer list |
| 3922 | // (soon to become the drawing state list). |
| 3923 | // |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3924 | sp<const DisplayDevice> hintDisplay; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3925 | ui::LayerStack layerStack; |
| 3926 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3927 | mCurrentState.traverse([&](Layer* layer) REQUIRES(mStateLock) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3928 | // NOTE: we rely on the fact that layers are sorted by |
| 3929 | // layerStack first (so we don't have to traverse the list |
| 3930 | // of displays for every layer). |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3931 | if (const auto filter = layer->getOutputFilter(); layerStack != filter.layerStack) { |
| 3932 | layerStack = filter.layerStack; |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3933 | hintDisplay = nullptr; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3934 | |
| 3935 | // Find the display that includes the layer. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3936 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3937 | if (!display->getCompositionDisplay()->includesLayer(filter)) { |
| 3938 | continue; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3939 | } |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3940 | |
| 3941 | // Pick the primary display if another display mirrors the layer. |
| 3942 | if (hintDisplay) { |
| 3943 | hintDisplay = nullptr; |
| 3944 | break; |
| 3945 | } |
| 3946 | |
| 3947 | hintDisplay = display; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3948 | } |
| 3949 | } |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 3950 | |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3951 | if (!hintDisplay) { |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3952 | // NOTE: TEMPORARY FIX ONLY. Real fix should cause layers to |
| 3953 | // redraw after transform hint changes. See bug 8508397. |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3954 | // could be null when this layer is using a layerStack |
| 3955 | // that is not visible on any display. Also can occur at |
| 3956 | // screen off/on times. |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3957 | // U Update: Don't provide stale hints to the clients. For |
| 3958 | // special cases where we want the app to draw its |
| 3959 | // first frame before the display is available, we rely |
| 3960 | // on WMS and DMS to provide the right information |
| 3961 | // so the client can calculate the hint. |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3962 | layer->skipReportingTransformHint(); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3963 | } else { |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3964 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3965 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3966 | }); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3967 | } |
| 3968 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3969 | if (mLayersAdded) { |
| 3970 | mLayersAdded = false; |
| 3971 | // Layers have been added. |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3972 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3973 | mUpdateInputInfo = true; |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3974 | } |
| 3975 | |
| 3976 | // some layers might have been removed, so |
| 3977 | // we need to update the regions they're exposing. |
| 3978 | if (mLayersRemoved) { |
| 3979 | mLayersRemoved = false; |
| 3980 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3981 | mUpdateInputInfo = true; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3982 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3983 | if (mLayersPendingRemoval.indexOf(sp<Layer>::fromExisting(layer)) >= 0) { |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3984 | // this layer is not visible anymore |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3985 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3986 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3987 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 3988 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3989 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3990 | } |
| 3991 | |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 3992 | if (transactionFlags & eInputInfoUpdateNeeded) { |
| 3993 | mUpdateInputInfo = true; |
| 3994 | } |
| 3995 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3996 | doCommitTransactions(); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 3997 | } |
| 3998 | |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3999 | void SurfaceFlinger::updateInputFlinger(VsyncId vsyncId, TimePoint frameTime) { |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4000 | if (!mInputFlinger || (!mUpdateInputInfo && mInputWindowCommands.empty())) { |
Vishnu Nair | 42a27b5 | 2021-11-18 15:35:22 -0800 | [diff] [blame] | 4001 | return; |
| 4002 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4003 | ATRACE_CALL(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4004 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4005 | std::vector<WindowInfo> windowInfos; |
| 4006 | std::vector<DisplayInfo> displayInfos; |
| 4007 | bool updateWindowInfo = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4008 | if (mUpdateInputInfo) { |
| 4009 | mUpdateInputInfo = false; |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4010 | updateWindowInfo = true; |
| 4011 | buildWindowInfos(windowInfos, displayInfos); |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4012 | } |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4013 | |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4014 | std::unordered_set<int32_t> visibleWindowIds; |
| 4015 | for (WindowInfo& windowInfo : windowInfos) { |
| 4016 | if (!windowInfo.inputConfig.test(WindowInfo::InputConfig::NOT_VISIBLE)) { |
| 4017 | visibleWindowIds.insert(windowInfo.id); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4018 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4019 | } |
| 4020 | bool visibleWindowsChanged = false; |
| 4021 | if (visibleWindowIds != mVisibleWindowIds) { |
| 4022 | visibleWindowsChanged = true; |
| 4023 | mVisibleWindowIds = std::move(visibleWindowIds); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4024 | } |
| 4025 | |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 4026 | BackgroundExecutor::getInstance().sendCallbacks({[updateWindowInfo, |
| 4027 | windowInfos = std::move(windowInfos), |
| 4028 | displayInfos = std::move(displayInfos), |
| 4029 | inputWindowCommands = |
| 4030 | std::move(mInputWindowCommands), |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4031 | inputFlinger = mInputFlinger, this, |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4032 | visibleWindowsChanged, vsyncId, frameTime]() { |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4033 | ATRACE_NAME("BackgroundExecutor::updateInputFlinger"); |
| 4034 | if (updateWindowInfo) { |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 4035 | mWindowInfosListenerInvoker |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4036 | ->windowInfosChanged(gui::WindowInfosUpdate{std::move(windowInfos), |
| 4037 | std::move(displayInfos), |
| 4038 | ftl::to_underlying(vsyncId), |
| 4039 | frameTime.ns()}, |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4040 | std::move( |
| 4041 | inputWindowCommands.windowInfosReportedListeners), |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4042 | /* forceImmediateCall= */ visibleWindowsChanged || |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4043 | !inputWindowCommands.focusRequests.empty()); |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 4044 | } else { |
| 4045 | // If there are listeners but no changes to input windows, call the listeners |
| 4046 | // immediately. |
| 4047 | for (const auto& listener : inputWindowCommands.windowInfosReportedListeners) { |
| 4048 | if (IInterface::asBinder(listener)->isBinderAlive()) { |
| 4049 | listener->onWindowInfosReported(); |
| 4050 | } |
| 4051 | } |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4052 | } |
| 4053 | for (const auto& focusRequest : inputWindowCommands.focusRequests) { |
| 4054 | inputFlinger->setFocusedWindow(focusRequest); |
| 4055 | } |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 4056 | }}); |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 4057 | |
Arthur Hung | 6cbb975 | 2019-09-05 16:38:18 +0800 | [diff] [blame] | 4058 | mInputWindowCommands.clear(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4059 | } |
| 4060 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4061 | void SurfaceFlinger::persistDisplayBrightness(bool needsComposite) { |
| 4062 | const bool supportsDisplayBrightnessCommand = getHwComposer().getComposer()->isSupported( |
| 4063 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 4064 | if (!supportsDisplayBrightnessCommand) { |
| 4065 | return; |
| 4066 | } |
| 4067 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4068 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4069 | if (const auto brightness = display->getStagedBrightness(); brightness) { |
| 4070 | if (!needsComposite) { |
| 4071 | const status_t error = |
| 4072 | getHwComposer() |
| 4073 | .setDisplayBrightness(display->getPhysicalId(), *brightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 4074 | display->getCompositionDisplay() |
| 4075 | ->getState() |
| 4076 | .displayBrightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4077 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 4078 | .applyImmediately = true}) |
| 4079 | .get(); |
| 4080 | |
| 4081 | ALOGE_IF(error != NO_ERROR, |
| 4082 | "Error setting display brightness for display %s: %d (%s)", |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 4083 | to_string(display->getId()).c_str(), error, strerror(error)); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4084 | } |
| 4085 | display->persistBrightness(needsComposite); |
| 4086 | } |
| 4087 | } |
| 4088 | } |
| 4089 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4090 | void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, |
| 4091 | std::vector<DisplayInfo>& outDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4092 | static size_t sNumWindowInfos = 0; |
| 4093 | outWindowInfos.reserve(sNumWindowInfos); |
| 4094 | sNumWindowInfos = 0; |
| 4095 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4096 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4097 | mLayerSnapshotBuilder.forEachInputSnapshot( |
| 4098 | [&outWindowInfos](const frontend::LayerSnapshot& snapshot) { |
| 4099 | outWindowInfos.push_back(snapshot.inputInfo); |
| 4100 | }); |
| 4101 | } else { |
| 4102 | mDrawingState.traverseInReverseZOrder([&](Layer* layer) { |
| 4103 | if (!layer->needsInputInfo()) return; |
| 4104 | const auto opt = |
| 4105 | mFrontEndDisplayInfos.get(layer->getLayerStack()) |
| 4106 | .transform([](const frontend::DisplayInfo& info) { |
| 4107 | return Layer::InputDisplayArgs{&info.transform, info.isSecure}; |
| 4108 | }); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4109 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4110 | outWindowInfos.push_back(layer->fillInputInfo(opt.value_or(Layer::InputDisplayArgs{}))); |
| 4111 | }); |
| 4112 | } |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 4113 | |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4114 | sNumWindowInfos = outWindowInfos.size(); |
| 4115 | |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 4116 | outDisplayInfos.reserve(mFrontEndDisplayInfos.size()); |
| 4117 | for (const auto& [_, info] : mFrontEndDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4118 | outDisplayInfos.push_back(info.info); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 4119 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 4120 | } |
| 4121 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 4122 | void SurfaceFlinger::updateCursorAsync() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4123 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4124 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 4125 | if (HalDisplayId::tryCast(display->getId())) { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4126 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 4127 | } |
| 4128 | } |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 4129 | |
| 4130 | constexpr bool kCursorOnly = true; |
| 4131 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4132 | mCompositionEngine->updateCursorAsync(refreshArgs); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4133 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4134 | } |
| 4135 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 4136 | void SurfaceFlinger::requestHardwareVsync(PhysicalDisplayId displayId, bool enable) { |
| 4137 | getHwComposer().setVsyncEnabled(displayId, enable ? hal::Vsync::ENABLE : hal::Vsync::DISABLE); |
| 4138 | } |
| 4139 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4140 | void SurfaceFlinger::requestDisplayModes(std::vector<display::DisplayModeRequest> modeRequests) { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 4141 | if (mBootStage != BootStage::FINISHED) { |
| 4142 | ALOGV("Currently in the boot stage, skipping display mode changes"); |
| 4143 | return; |
| 4144 | } |
| 4145 | |
| 4146 | ATRACE_CALL(); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4147 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 4148 | // If this is called from the main thread mStateLock must be locked before |
| 4149 | // 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] | 4150 | // Scheduler::chooseRefreshRateForContent |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 4151 | |
| 4152 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
Marin Shalamanov | a63f9ae | 2021-11-03 15:05:16 +0100 | [diff] [blame] | 4153 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4154 | for (auto& request : modeRequests) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4155 | const auto& modePtr = request.mode.modePtr; |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 4156 | |
| 4157 | const auto displayId = modePtr->getPhysicalDisplayId(); |
| 4158 | const auto display = getDisplayDeviceLocked(displayId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4159 | |
| 4160 | if (!display) continue; |
| 4161 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 4162 | if (ftl::FakeGuard guard(kMainThreadContext); |
| 4163 | !shouldApplyRefreshRateSelectorPolicy(*display)) { |
| 4164 | ALOGV("%s(%s): Skipped applying policy", __func__, to_string(displayId).c_str()); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 4165 | continue; |
| 4166 | } |
| 4167 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4168 | if (display->refreshRateSelector().isModeAllowed(request.mode)) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 4169 | setDesiredMode(std::move(request)); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4170 | } else { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 4171 | ALOGV("%s: Mode %d is disallowed for display %s", __func__, |
| 4172 | ftl::to_underlying(modePtr->getId()), to_string(displayId).c_str()); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4173 | } |
| 4174 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 4175 | } |
| 4176 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 4177 | void SurfaceFlinger::triggerOnFrameRateOverridesChanged() { |
| 4178 | PhysicalDisplayId displayId = [&]() { |
| 4179 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 4180 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 4181 | }(); |
| 4182 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4183 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 4184 | } |
| 4185 | |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 4186 | void SurfaceFlinger::notifyCpuLoadUp() { |
| 4187 | mPowerAdvisor->notifyCpuLoadUp(); |
| 4188 | } |
| 4189 | |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 4190 | void SurfaceFlinger::onChoreographerAttached() { |
| 4191 | ATRACE_CALL(); |
| 4192 | if (mLayerLifecycleManagerEnabled) { |
| 4193 | mUpdateAttachedChoreographer = true; |
| 4194 | scheduleCommit(FrameHint::kNone); |
| 4195 | } |
| 4196 | } |
| 4197 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4198 | void SurfaceFlinger::onExpectedPresentTimePosted(TimePoint expectedPresentTime, |
| 4199 | ftl::NonNull<DisplayModePtr> modePtr, |
| 4200 | Fps renderRate) { |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4201 | const auto vsyncPeriod = modePtr->getVsyncRate().getPeriod(); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4202 | const auto timeoutOpt = [&]() -> std::optional<Period> { |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4203 | const auto vrrConfig = modePtr->getVrrConfig(); |
| 4204 | if (!vrrConfig) return std::nullopt; |
| 4205 | |
| 4206 | const auto notifyExpectedPresentConfig = |
| 4207 | modePtr->getVrrConfig()->notifyExpectedPresentConfig; |
| 4208 | if (!notifyExpectedPresentConfig) return std::nullopt; |
ramindani | cbd7a6d | 2023-12-19 16:00:30 -0800 | [diff] [blame] | 4209 | return Period::fromNs(notifyExpectedPresentConfig->timeoutNs); |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4210 | }(); |
| 4211 | |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4212 | notifyExpectedPresentIfRequired(modePtr->getPhysicalDisplayId(), vsyncPeriod, |
| 4213 | expectedPresentTime, renderRate, timeoutOpt); |
| 4214 | } |
| 4215 | |
| 4216 | void SurfaceFlinger::notifyExpectedPresentIfRequired(PhysicalDisplayId displayId, |
| 4217 | Period vsyncPeriod, |
| 4218 | TimePoint expectedPresentTime, |
| 4219 | Fps frameInterval, |
| 4220 | std::optional<Period> timeoutOpt) { |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4221 | auto& data = mNotifyExpectedPresentMap[displayId]; |
| 4222 | const auto lastExpectedPresentTimestamp = data.lastExpectedPresentTimestamp; |
| 4223 | const auto lastFrameInterval = data.lastFrameInterval; |
| 4224 | data.lastFrameInterval = frameInterval; |
| 4225 | data.lastExpectedPresentTimestamp = expectedPresentTime; |
| 4226 | const auto threshold = Duration::fromNs(vsyncPeriod.ns() / 2); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4227 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4228 | const constexpr nsecs_t kOneSecondNs = |
| 4229 | std::chrono::duration_cast<std::chrono::nanoseconds>(1s).count(); |
| 4230 | const auto timeout = |
| 4231 | Period::fromNs(timeoutOpt && timeoutOpt->ns() > 0 ? timeoutOpt->ns() : kOneSecondNs); |
| 4232 | const bool frameIntervalIsOnCadence = |
| 4233 | isFrameIntervalOnCadence(expectedPresentTime, lastExpectedPresentTimestamp, |
| 4234 | lastFrameInterval, timeout, threshold); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4235 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4236 | const bool expectedPresentWithinTimeout = |
| 4237 | isExpectedPresentWithinTimeout(expectedPresentTime, lastExpectedPresentTimestamp, |
| 4238 | timeoutOpt, threshold); |
| 4239 | if (expectedPresentWithinTimeout && frameIntervalIsOnCadence) { |
| 4240 | return; |
| 4241 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4242 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4243 | auto hintStatus = data.hintStatus.load(); |
| 4244 | if (!expectedPresentWithinTimeout) { |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4245 | if ((hintStatus != NotifyExpectedPresentHintStatus::Sent && |
| 4246 | hintStatus != NotifyExpectedPresentHintStatus::ScheduleOnTx) || |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4247 | (timeoutOpt && timeoutOpt->ns() == 0)) { |
| 4248 | // Send the hint immediately if timeout, as the hint gets |
| 4249 | // delayed otherwise, as the frame is scheduled close |
| 4250 | // to the actual present. |
| 4251 | if (data.hintStatus |
| 4252 | .compare_exchange_strong(hintStatus, |
| 4253 | NotifyExpectedPresentHintStatus::ScheduleOnTx)) { |
| 4254 | scheduleNotifyExpectedPresentHint(displayId); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4255 | return; |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4256 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4257 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4258 | } |
| 4259 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4260 | if (hintStatus == NotifyExpectedPresentHintStatus::Sent && |
| 4261 | data.hintStatus.compare_exchange_strong(hintStatus, |
| 4262 | NotifyExpectedPresentHintStatus::ScheduleOnTx)) { |
| 4263 | return; |
| 4264 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4265 | if (hintStatus != NotifyExpectedPresentHintStatus::Start) { |
| 4266 | return; |
| 4267 | } |
| 4268 | data.hintStatus.store(NotifyExpectedPresentHintStatus::ScheduleOnPresent); |
| 4269 | mScheduler->scheduleFrame(); |
| 4270 | } |
| 4271 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4272 | void SurfaceFlinger::scheduleNotifyExpectedPresentHint(PhysicalDisplayId displayId, |
| 4273 | VsyncId vsyncId) { |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4274 | auto itr = mNotifyExpectedPresentMap.find(displayId); |
| 4275 | if (itr == mNotifyExpectedPresentMap.end()) { |
| 4276 | return; |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4277 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4278 | |
| 4279 | const char* const whence = __func__; |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4280 | const auto sendHint = [=, this]() { |
| 4281 | auto& data = mNotifyExpectedPresentMap.at(displayId); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4282 | TimePoint expectedPresentTime = data.lastExpectedPresentTimestamp; |
| 4283 | if (ftl::to_underlying(vsyncId) != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 4284 | const auto predictionOpt = mFrameTimeline->getTokenManager()->getPredictionsForToken( |
| 4285 | ftl::to_underlying(vsyncId)); |
| 4286 | const auto expectedPresentTimeOnPredictor = TimePoint::fromNs( |
| 4287 | predictionOpt ? predictionOpt->presentTime : expectedPresentTime.ns()); |
| 4288 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 4289 | const auto expectedPresentTimeOnScheduler = scheduledFrameResultOpt.has_value() |
| 4290 | ? scheduledFrameResultOpt->vsyncTime |
| 4291 | : TimePoint::fromNs(0); |
| 4292 | expectedPresentTime = |
| 4293 | std::max(expectedPresentTimeOnPredictor, expectedPresentTimeOnScheduler); |
| 4294 | } |
| 4295 | |
| 4296 | if (expectedPresentTime < TimePoint::now()) { |
| 4297 | expectedPresentTime = |
| 4298 | mScheduler->getVsyncSchedule()->vsyncDeadlineAfter(TimePoint::now()); |
| 4299 | if (mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration > |
| 4300 | mScheduler->getVsyncSchedule(displayId)->period()) { |
| 4301 | expectedPresentTime += mScheduler->getVsyncSchedule(displayId)->period(); |
| 4302 | } |
| 4303 | } |
| 4304 | const auto status = getHwComposer().notifyExpectedPresent(displayId, expectedPresentTime, |
| 4305 | data.lastFrameInterval); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4306 | if (status != NO_ERROR) { |
| 4307 | ALOGE("%s failed to notifyExpectedPresentHint for display %" PRId64, whence, |
| 4308 | displayId.value); |
| 4309 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4310 | }; |
| 4311 | |
| 4312 | if (itr->second.hintStatus == NotifyExpectedPresentHintStatus::ScheduleOnTx) { |
| 4313 | return static_cast<void>(mScheduler->schedule([=, |
| 4314 | this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 4315 | auto& data = mNotifyExpectedPresentMap.at(displayId); |
| 4316 | auto scheduleHintOnTx = NotifyExpectedPresentHintStatus::ScheduleOnTx; |
| 4317 | if (data.hintStatus.compare_exchange_strong(scheduleHintOnTx, |
| 4318 | NotifyExpectedPresentHintStatus::Sent)) { |
| 4319 | sendHint(); |
| 4320 | } |
| 4321 | })); |
| 4322 | } |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4323 | auto scheduleHintOnPresent = NotifyExpectedPresentHintStatus::ScheduleOnPresent; |
| 4324 | if (itr->second.hintStatus.compare_exchange_strong(scheduleHintOnPresent, |
| 4325 | NotifyExpectedPresentHintStatus::Sent)) { |
| 4326 | sendHint(); |
| 4327 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | void SurfaceFlinger::sendNotifyExpectedPresentHint(PhysicalDisplayId displayId) { |
| 4331 | if (auto itr = mNotifyExpectedPresentMap.find(displayId); |
| 4332 | itr == mNotifyExpectedPresentMap.end() || |
| 4333 | itr->second.hintStatus != NotifyExpectedPresentHintStatus::ScheduleOnPresent) { |
| 4334 | return; |
| 4335 | } |
| 4336 | scheduleNotifyExpectedPresentHint(displayId); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4337 | } |
| 4338 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 4339 | void SurfaceFlinger::initScheduler(const sp<const DisplayDevice>& display) { |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4340 | using namespace scheduler; |
| 4341 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 4342 | LOG_ALWAYS_FATAL_IF(mScheduler); |
| 4343 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4344 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 4345 | const Fps activeRefreshRate = activeMode.fps; |
Ady Abraham | 9e16a48 | 2019-12-03 17:19:41 -0800 | [diff] [blame] | 4346 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4347 | FeatureFlags features; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4348 | |
Ady Abraham | 3f84c50 | 2023-11-30 18:18:06 -0800 | [diff] [blame] | 4349 | const auto defaultContentDetectionValue = |
| 4350 | FlagManager::getInstance().enable_fro_dependent_features() && |
| 4351 | sysprop::enable_frame_rate_override(true); |
| 4352 | if (sysprop::use_content_detection_for_refresh_rate(defaultContentDetectionValue)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4353 | features |= Feature::kContentDetection; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 4354 | if (FlagManager::getInstance().enable_small_area_detection()) { |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 4355 | features |= Feature::kSmallDirtyContentDetection; |
| 4356 | } |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4357 | } |
| 4358 | if (base::GetBoolProperty("debug.sf.show_predicted_vsync"s, false)) { |
| 4359 | features |= Feature::kTracePredictedVsync; |
| 4360 | } |
| 4361 | if (!base::GetBoolProperty("debug.sf.vsync_reactor_ignore_present_fences"s, false) && |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 4362 | mHasReliablePresentFences) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4363 | features |= Feature::kPresentFences; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4364 | } |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4365 | if (display->refreshRateSelector().kernelIdleTimerController()) { |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4366 | features |= Feature::kKernelIdleTimer; |
| 4367 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4368 | if (mBackpressureGpuComposition) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4369 | features |= Feature::kBackpressureGpuComposition; |
| 4370 | } |
Leon Scroggins III | 0bd0d4c | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 4371 | if (getHwComposer().getComposer()->isSupported( |
| 4372 | Hwc2::Composer::OptionalFeature::ExpectedPresentTime)) { |
| 4373 | features |= Feature::kExpectedPresentTime; |
| 4374 | } |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4375 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4376 | mScheduler = std::make_unique<Scheduler>(static_cast<ICompositor&>(*this), |
| 4377 | static_cast<ISchedulerCallback&>(*this), features, |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4378 | getFactory(), activeRefreshRate, *mTimeStats); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4379 | |
| 4380 | // The pacesetter must be registered before EventThread creation below. |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4381 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector()); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4382 | if (FlagManager::getInstance().vrr_config()) { |
Ady Abraham | ee6365b | 2024-03-06 14:31:45 -0800 | [diff] [blame] | 4383 | mScheduler->setRenderRate(display->getPhysicalId(), activeMode.fps, |
| 4384 | /*applyImmediately*/ true); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4385 | } |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4386 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 4387 | const auto configs = mScheduler->getVsyncConfiguration().getCurrentConfigs(); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4388 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4389 | mScheduler->createEventThread(scheduler::Cycle::Render, mFrameTimeline->getTokenManager(), |
| 4390 | /* workDuration */ configs.late.appWorkDuration, |
| 4391 | /* readyDuration */ configs.late.sfWorkDuration); |
| 4392 | mScheduler->createEventThread(scheduler::Cycle::LastComposite, |
| 4393 | mFrameTimeline->getTokenManager(), |
| 4394 | /* workDuration */ activeRefreshRate.getPeriod(), |
| 4395 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4396 | |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 4397 | // Dispatch after EventThread creation, since registerDisplay above skipped dispatch. |
| 4398 | mScheduler->dispatchHotplug(display->getPhysicalId(), scheduler::Scheduler::Hotplug::Connected); |
| 4399 | |
Leon Scroggins III | a7be94e | 2024-01-23 12:24:30 -0500 | [diff] [blame] | 4400 | mScheduler->initVsync(*mFrameTimeline->getTokenManager(), configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4401 | |
| 4402 | mRegionSamplingThread = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4403 | sp<RegionSamplingThread>::make(*this, |
| 4404 | RegionSamplingThread::EnvironmentTimingTunables()); |
Andy Yu | aef688b | 2024-01-23 17:14:23 -0800 | [diff] [blame] | 4405 | mFpsReporter = sp<FpsReporter>::make(*mFrameTimeline); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4406 | |
| 4407 | // Timer callbacks may fire, so do this last. |
| 4408 | mScheduler->startTimers(); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4409 | } |
| 4410 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4411 | void SurfaceFlinger::doCommitTransactions() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 4412 | ATRACE_CALL(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4413 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4414 | if (!mLayersPendingRemoval.isEmpty()) { |
| 4415 | // Notify removed layers now that they can't be drawn from |
| 4416 | for (const auto& l : mLayersPendingRemoval) { |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4417 | // Ensure any buffers set to display on any children are released. |
| 4418 | if (l->isRemovedFromCurrentState()) { |
| 4419 | l->latchAndReleaseBuffer(); |
| 4420 | } |
| 4421 | |
chaviw | 6852bff | 2022-04-19 17:35:11 -0500 | [diff] [blame] | 4422 | // If a layer has a parent, we allow it to out-live it's handle |
| 4423 | // with the idea that the parent holds a reference and will eventually |
| 4424 | // be cleaned up. However no one cleans up the top-level so we do so |
| 4425 | // here. |
| 4426 | if (l->isAtRoot()) { |
| 4427 | l->setIsAtRoot(false); |
| 4428 | mCurrentState.layersSortedByZ.remove(l); |
| 4429 | } |
| 4430 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4431 | // If the layer has been removed and has no parent, then it will not be reachable |
| 4432 | // when traversing layers on screen. Add the layer to the offscreenLayers set to |
| 4433 | // ensure we can copy its current to drawing state. |
| 4434 | if (!l->getParent()) { |
| 4435 | mOffscreenLayers.emplace(l.get()); |
| 4436 | } |
| 4437 | } |
| 4438 | mLayersPendingRemoval.clear(); |
| 4439 | } |
| 4440 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4441 | mDrawingState = mCurrentState; |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4442 | mCurrentState.colorMatrixChanged = false; |
| 4443 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4444 | if (mVisibleRegionsDirty) { |
| 4445 | for (const auto& rootLayer : mDrawingState.layersSortedByZ) { |
| 4446 | rootLayer->commitChildList(); |
| 4447 | } |
Andrei Stanciu | dadac5a | 2020-08-05 17:02:34 +0300 | [diff] [blame] | 4448 | } |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4449 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4450 | commitOffscreenLayers(); |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4451 | if (mLayerMirrorRoots.size() > 0) { |
| 4452 | std::deque<Layer*> pendingUpdates; |
| 4453 | pendingUpdates.insert(pendingUpdates.end(), mLayerMirrorRoots.begin(), |
| 4454 | mLayerMirrorRoots.end()); |
| 4455 | std::vector<Layer*> needsUpdating; |
| 4456 | for (Layer* cloneRoot : mLayerMirrorRoots) { |
| 4457 | pendingUpdates.pop_front(); |
| 4458 | if (cloneRoot->isRemovedFromCurrentState()) { |
| 4459 | continue; |
| 4460 | } |
| 4461 | if (cloneRoot->updateMirrorInfo(pendingUpdates)) { |
| 4462 | } else { |
| 4463 | needsUpdating.push_back(cloneRoot); |
| 4464 | } |
| 4465 | } |
| 4466 | for (Layer* cloneRoot : needsUpdating) { |
| 4467 | cloneRoot->updateMirrorInfo({}); |
| 4468 | } |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4469 | } |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4470 | } |
| 4471 | |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4472 | void SurfaceFlinger::commitOffscreenLayers() { |
| 4473 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4474 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, [](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4475 | if (layer->clearTransactionFlags(eTransactionNeeded)) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4476 | layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4477 | layer->commitChildList(); |
| 4478 | } |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4479 | }); |
| 4480 | } |
| 4481 | } |
| 4482 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4483 | void SurfaceFlinger::invalidateLayerStack(const ui::LayerFilter& layerFilter, const Region& dirty) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4484 | for (const auto& [token, displayDevice] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4485 | auto display = displayDevice->getCompositionDisplay(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4486 | if (display->includesLayer(layerFilter)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4487 | display->editState().dirtyRegion.orSelf(dirty); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 4488 | } |
| 4489 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 4490 | } |
| 4491 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4492 | bool SurfaceFlinger::latchBuffers() { |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 4493 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 4494 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4495 | const nsecs_t latchTime = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4496 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4497 | bool visibleRegions = false; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4498 | bool frameQueued = false; |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4499 | bool newDataLatched = false; |
Eric Penner | 51c59cd | 2014-07-28 19:51:58 -0700 | [diff] [blame] | 4500 | |
| 4501 | // Store the set of layers that need updates. This set must not change as |
| 4502 | // buffers are being latched, as this could result in a deadlock. |
| 4503 | // Example: Two producers share the same command stream and: |
| 4504 | // 1.) Layer 0 is latched |
| 4505 | // 2.) Layer 0 gets a new frame |
| 4506 | // 2.) Layer 1 gets a new frame |
| 4507 | // 3.) Layer 1 is latched. |
| 4508 | // Display is now waiting on Layer 1's frame, which is behind layer 0's |
| 4509 | // 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] | 4510 | mDrawingState.traverse([&](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4511 | if (layer->clearTransactionFlags(eTransactionNeeded) || mForceTransactionDisplayChange) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4512 | const uint32_t flags = layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4513 | if (flags & Layer::eVisibleRegion) { |
| 4514 | mVisibleRegionsDirty = true; |
| 4515 | } |
| 4516 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4517 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4518 | if (layer->hasReadyFrame() || layer->willReleaseBufferOnLatch()) { |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4519 | frameQueued = true; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4520 | mLayersWithQueuedFrames.emplace(sp<Layer>::fromExisting(layer)); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4521 | } else { |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 4522 | layer->useEmptyDamage(); |
Vishnu Nair | c09c023 | 2023-03-02 03:22:35 +0000 | [diff] [blame] | 4523 | if (!layer->hasBuffer()) { |
| 4524 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 4525 | // instead of a missed frame. This is used to identify scenarios where we |
| 4526 | // could not latch a buffer or apply a transaction due to backpressure. |
| 4527 | // We only update the latch time for buffer less layers here, the latch time |
| 4528 | // is updated for buffer layers when the buffer is latched. |
| 4529 | layer->updateLastLatchTime(latchTime); |
| 4530 | } |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4531 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4532 | }); |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4533 | mForceTransactionDisplayChange = false; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4534 | |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4535 | // The client can continue submitting buffers for offscreen layers, but they will not |
| 4536 | // be shown on screen. Therefore, we need to latch and release buffers of offscreen |
| 4537 | // layers to ensure dequeueBuffer doesn't block indefinitely. |
| 4538 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4539 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4540 | [&](Layer* l) { l->latchAndReleaseBuffer(); }); |
| 4541 | } |
| 4542 | |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4543 | if (!mLayersWithQueuedFrames.empty()) { |
| 4544 | // mStateLock is needed for latchBuffer as LayerRejecter::reject() |
| 4545 | // writes to Layer current state. See also b/119481871 |
| 4546 | Mutex::Autolock lock(mStateLock); |
| 4547 | |
Alec Mouri | 2f7d9ae | 2020-11-30 19:32:33 -0800 | [diff] [blame] | 4548 | for (const auto& layer : mLayersWithQueuedFrames) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4549 | if (layer->willReleaseBufferOnLatch()) { |
| 4550 | mLayersWithBuffersRemoved.emplace(layer); |
| 4551 | } |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 4552 | if (layer->latchBuffer(visibleRegions, latchTime)) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4553 | mLayersPendingRefresh.push_back(layer); |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4554 | newDataLatched = true; |
| 4555 | } |
Vishnu Nair | 1b70019 | 2022-02-04 10:09:47 -0800 | [diff] [blame] | 4556 | layer->useSurfaceDamage(); |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4557 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4558 | } |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 4559 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 4560 | mVisibleRegionsDirty |= visibleRegions; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4561 | |
| 4562 | // If we will need to wake up at some time in the future to deal with a |
| 4563 | // queued frame that shouldn't be displayed during this vsync period, wake |
| 4564 | // up during the next vsync period to check again. |
Chia-I Wu | a36bf92 | 2017-06-30 12:51:05 -0700 | [diff] [blame] | 4565 | if (frameQueued && (mLayersWithQueuedFrames.empty() || !newDataLatched)) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4566 | scheduleCommit(FrameHint::kNone); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4567 | } |
| 4568 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 4569 | // enter boot animation on first buffer latch |
| 4570 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 4571 | ALOGI("Enter boot animation"); |
| 4572 | mBootStage = BootStage::BOOTANIMATION; |
| 4573 | } |
| 4574 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4575 | if (mLayerMirrorRoots.size() > 0) { |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4576 | mDrawingState.traverse([&](Layer* layer) { layer->updateCloneBufferInfo(); }); |
| 4577 | } |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 4578 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4579 | // 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] | 4580 | return !mLayersWithQueuedFrames.empty() && newDataLatched; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4581 | } |
| 4582 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4583 | status_t SurfaceFlinger::addClientLayer(LayerCreationArgs& args, const sp<IBinder>& handle, |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4584 | const sp<Layer>& layer, const wp<Layer>& parent, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4585 | uint32_t* outTransformHint) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4586 | if (mNumLayers >= MAX_LAYERS) { |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4587 | ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(), |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4588 | MAX_LAYERS); |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 4589 | static_cast<void>(mScheduler->schedule([=, this] { |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4590 | ALOGE("Dumping layer keeping > 20 children alive:"); |
| 4591 | bool leakingParentLayerFound = false; |
| 4592 | mDrawingState.traverse([&](Layer* layer) { |
| 4593 | if (leakingParentLayerFound) { |
| 4594 | return; |
| 4595 | } |
| 4596 | if (layer->getChildrenCount() > 20) { |
| 4597 | leakingParentLayerFound = true; |
| 4598 | sp<Layer> parent = sp<Layer>::fromExisting(layer); |
| 4599 | while (parent) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4600 | ALOGE("Parent Layer: %s%s", parent->getName().c_str(), |
| 4601 | (parent->isHandleAlive() ? "handleAlive" : "")); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4602 | parent = parent->getParent(); |
| 4603 | } |
| 4604 | // Sample up to 100 layers |
| 4605 | ALOGE("Dumping random sampling of child layers total(%zu): ", |
| 4606 | layer->getChildrenCount()); |
| 4607 | int sampleSize = (layer->getChildrenCount() / 100) + 1; |
| 4608 | layer->traverseChildren([&](Layer* layer) { |
| 4609 | if (rand() % sampleSize == 0) { |
jiayongqiang | c476a34 | 2023-12-06 17:04:54 +0800 | [diff] [blame] | 4610 | ALOGE("Child Layer: %s%s", layer->getName().c_str(), |
| 4611 | (layer->isHandleAlive() ? "handleAlive" : "")); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4612 | } |
| 4613 | }); |
| 4614 | } |
| 4615 | }); |
| 4616 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4617 | int numLayers = 0; |
| 4618 | mDrawingState.traverse([&](Layer* layer) { numLayers++; }); |
| 4619 | |
| 4620 | ALOGE("Dumping random sampling of on-screen layers total(%u):", numLayers); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4621 | mDrawingState.traverse([&](Layer* layer) { |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4622 | // Aim to dump about 200 layers to avoid totally trashing |
| 4623 | // logcat. On the other hand, if there really are 4096 layers |
| 4624 | // something has gone totally wrong its probably the most |
| 4625 | // useful information in logcat. |
| 4626 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4627 | ALOGE("Layer: %s%s", layer->getName().c_str(), |
| 4628 | (layer->isHandleAlive() ? "handleAlive" : "")); |
| 4629 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4630 | } |
| 4631 | }); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4632 | ALOGE("Dumping random sampling of off-screen layers total(%zu): ", |
| 4633 | mOffscreenLayers.size()); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4634 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 4635 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4636 | ALOGE("Offscreen-layer: %s%s", offscreenLayer->getName().c_str(), |
| 4637 | (offscreenLayer->isHandleAlive() ? "handleAlive" : "")); |
| 4638 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4639 | } |
| 4640 | } |
| 4641 | })); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4642 | return NO_MEMORY; |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4643 | } |
| 4644 | |
Vishnu Nair | 86e1190 | 2022-09-06 16:03:27 +0000 | [diff] [blame] | 4645 | layer->updateTransformHint(mActiveDisplayTransformHint); |
| 4646 | if (outTransformHint) { |
| 4647 | *outTransformHint = mActiveDisplayTransformHint; |
| 4648 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4649 | args.parentId = LayerHandle::getLayerId(args.parentHandle.promote()); |
| 4650 | args.layerIdToMirror = LayerHandle::getLayerId(args.mirrorLayerHandle.promote()); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4651 | { |
| 4652 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4653 | mCreatedLayers.emplace_back(layer, parent, args.addToRoot); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4654 | mNewLayers.emplace_back(std::make_unique<frontend::RequestedLayerState>(args)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 4655 | args.mirrorLayerHandle.clear(); |
| 4656 | args.parentHandle.clear(); |
| 4657 | mNewLayerArgs.emplace_back(std::move(args)); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4658 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4659 | |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4660 | setTransactionFlags(eTransactionNeeded); |
| 4661 | return NO_ERROR; |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 4662 | } |
| 4663 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4664 | uint32_t SurfaceFlinger::getTransactionFlags() const { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 4665 | return mTransactionFlags; |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 4666 | } |
| 4667 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4668 | uint32_t SurfaceFlinger::clearTransactionFlags(uint32_t mask) { |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4669 | uint32_t transactionFlags = mTransactionFlags.fetch_and(~mask); |
| 4670 | ATRACE_INT("mTransactionFlags", transactionFlags); |
| 4671 | return transactionFlags & mask; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4672 | } |
| 4673 | |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4674 | void SurfaceFlinger::setTransactionFlags(uint32_t mask, TransactionSchedule schedule, |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4675 | const sp<IBinder>& applyToken, FrameHint frameHint) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4676 | mScheduler->modulateVsync({}, &VsyncModulator::setTransactionSchedule, schedule, applyToken); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4677 | uint32_t transactionFlags = mTransactionFlags.fetch_or(mask); |
| 4678 | ATRACE_INT("mTransactionFlags", transactionFlags); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4679 | |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4680 | if (const bool scheduled = transactionFlags & mask; !scheduled) { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4681 | scheduleCommit(frameHint); |
Ady Abraham | 27bcb55 | 2023-01-21 04:34:22 +0000 | [diff] [blame] | 4682 | } else if (frameHint == FrameHint::kActive) { |
| 4683 | // Even if the next frame is already scheduled, we should reset the idle timer |
| 4684 | // as a new activity just happened. |
| 4685 | mScheduler->resetIdleTimer(); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4686 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4687 | } |
| 4688 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4689 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyTimelineCheck( |
| 4690 | const TransactionHandler::TransactionFlushState& flushState) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 4691 | const auto& transaction = *flushState.transaction; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4692 | |
| 4693 | const TimePoint desiredPresentTime = TimePoint::fromNs(transaction.desiredPresentTime); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 4694 | const TimePoint expectedPresentTime = mScheduler->expectedPresentTimeForPacesetter(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4695 | |
| 4696 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4697 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4698 | // Do not present if the desiredPresentTime has not passed unless it is more than |
| 4699 | // one second in the future. We ignore timestamps more than 1 second in the future |
| 4700 | // for stability reasons. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4701 | if (!transaction.isAutoTimestamp && desiredPresentTime >= expectedPresentTime && |
| 4702 | desiredPresentTime < expectedPresentTime + 1s) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4703 | ATRACE_FORMAT("not current desiredPresentTime: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4704 | desiredPresentTime, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4705 | return TransactionReadiness::NotReady; |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4706 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4707 | |
Ady Abraham | 20024aa | 2024-03-05 01:32:49 +0000 | [diff] [blame] | 4708 | const auto vsyncId = VsyncId{transaction.frameTimelineInfo.vsyncId}; |
| 4709 | |
| 4710 | // Transactions with VsyncId are already throttled by the vsyncId (i.e. Choreographer issued |
| 4711 | // the vsyncId according to the frame rate override cadence) so we shouldn't throttle again |
| 4712 | // when applying the transaction. Otherwise we might throttle older transactions |
| 4713 | // incorrectly as the frame rate of SF changed before it drained the older transactions. |
| 4714 | if (ftl::to_underlying(vsyncId) == FrameTimelineInfo::INVALID_VSYNC_ID && |
| 4715 | !mScheduler->isVsyncValid(expectedPresentTime, transaction.originUid)) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4716 | ATRACE_FORMAT("!isVsyncValid expectedPresentTime: %" PRId64 " uid: %d", expectedPresentTime, |
| 4717 | transaction.originUid); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4718 | return TransactionReadiness::NotReady; |
| 4719 | } |
| 4720 | |
| 4721 | // If the client didn't specify desiredPresentTime, use the vsyncId to determine the |
| 4722 | // expected present time of this transaction. |
Ady Abraham | 20024aa | 2024-03-05 01:32:49 +0000 | [diff] [blame] | 4723 | if (transaction.isAutoTimestamp && frameIsEarly(expectedPresentTime, vsyncId)) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4724 | ATRACE_FORMAT("frameIsEarly vsyncId: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4725 | transaction.frameTimelineInfo.vsyncId, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4726 | return TransactionReadiness::NotReady; |
| 4727 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4728 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4729 | return TransactionReadiness::Ready; |
| 4730 | } |
| 4731 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4732 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheckLegacy( |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4733 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4734 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4735 | auto ready = TransactionReadiness::Ready; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4736 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const ResolvedComposerState& |
| 4737 | resolvedState) -> bool { |
| 4738 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 4739 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4740 | const auto& transaction = *flushState.transaction; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4741 | const auto& s = resolvedState.state; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4742 | // check for barrier frames |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4743 | if (s.bufferData->hasBarrier) { |
| 4744 | // The current producerId is already a newer producer than the buffer that has a |
| 4745 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4746 | // 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] | 4747 | if (layer->getDrawingState().barrierProducerId > s.bufferData->producerId) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4748 | layer->callReleaseBufferCallback(s.bufferData->releaseBufferListener, |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4749 | resolvedState.externalTexture->getBuffer(), |
Chavi Weingarten | c8bcb68 | 2023-03-06 22:20:42 +0000 | [diff] [blame] | 4750 | s.bufferData->frameNumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4751 | s.bufferData->acquireFence); |
| 4752 | // Delete the entire state at this point and not just release the buffer because |
| 4753 | // 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] | 4754 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", |
| 4755 | layer->getDebugName(), layer->getDrawingState().barrierProducerId, |
| 4756 | s.bufferData->producerId); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4757 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4758 | } |
| 4759 | |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 4760 | if (layer->getDrawingState().barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4761 | const bool willApplyBarrierFrame = |
| 4762 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4763 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4764 | s.bufferData->barrierFrameNumber)); |
| 4765 | if (!willApplyBarrierFrame) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4766 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4767 | layer->getDebugName(), |
| 4768 | layer->getDrawingState().barrierFrameNumber, |
| 4769 | s.bufferData->barrierFrameNumber); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4770 | ready = TransactionReadiness::NotReadyBarrier; |
| 4771 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4772 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4773 | } |
| 4774 | } |
| 4775 | |
| 4776 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4777 | // the transaction in the queue. |
| 4778 | const bool hasPendingBuffer = |
| 4779 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4780 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4781 | ATRACE_FORMAT("hasPendingBuffer %s", layer->getDebugName()); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4782 | ready = TransactionReadiness::NotReady; |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4783 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4784 | } |
| 4785 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4786 | const bool acquireFenceAvailable = s.bufferData && |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4787 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4788 | s.bufferData->acquireFence; |
Ying Wei | 1fd9bfc | 2023-06-29 16:47:00 +0000 | [diff] [blame] | 4789 | const bool fenceSignaled = !acquireFenceAvailable || |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4790 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4791 | if (!fenceSignaled) { |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4792 | // check fence status |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4793 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(s, transaction.states.size(), |
| 4794 | flushState.firstTransaction) && |
| 4795 | layer->isSimpleBufferUpdate(s); |
| 4796 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4797 | if (allowLatchUnsignaled) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4798 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", |
| 4799 | layer->getDebugName()); |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4800 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4801 | } else { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4802 | ready = TransactionReadiness::NotReady; |
| 4803 | auto& listener = s.bufferData->releaseBufferListener; |
| 4804 | if (listener && |
| 4805 | (flushState.queueProcessTime - transaction.postTime) > |
| 4806 | std::chrono::nanoseconds(4s).count()) { |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 4807 | mTransactionHandler |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 4808 | .onTransactionQueueStalled(transaction.id, |
| 4809 | {.pid = layer->getOwnerPid(), |
| 4810 | .layerId = static_cast<uint32_t>( |
| 4811 | layer->getSequence()), |
| 4812 | .layerName = layer->getDebugName(), |
| 4813 | .bufferId = s.bufferData->getId(), |
| 4814 | .frameNumber = s.bufferData->frameNumber}); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4815 | } |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4816 | ATRACE_FORMAT("fence unsignaled %s", layer->getDebugName()); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4817 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4818 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4819 | } |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4820 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4821 | }); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4822 | return ready; |
| 4823 | } |
| 4824 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4825 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheck( |
| 4826 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4827 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4828 | auto ready = TransactionReadiness::Ready; |
| 4829 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const ResolvedComposerState& |
| 4830 | resolvedState) -> bool { |
| 4831 | const frontend::RequestedLayerState* layer = |
| 4832 | mLayerLifecycleManager.getLayerFromId(resolvedState.layerId); |
| 4833 | const auto& transaction = *flushState.transaction; |
| 4834 | const auto& s = resolvedState.state; |
| 4835 | // check for barrier frames |
| 4836 | if (s.bufferData->hasBarrier) { |
| 4837 | // The current producerId is already a newer producer than the buffer that has a |
| 4838 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4839 | // don't wait on the barrier since we know that's stale information. |
| 4840 | if (layer->barrierProducerId > s.bufferData->producerId) { |
| 4841 | if (s.bufferData->releaseBufferListener) { |
| 4842 | uint32_t currentMaxAcquiredBufferCount = |
| 4843 | getMaxAcquiredBufferCountForCurrentRefreshRate(layer->ownerUid.val()); |
| 4844 | ATRACE_FORMAT_INSTANT("callReleaseBufferCallback %s - %" PRIu64, |
| 4845 | layer->name.c_str(), s.bufferData->frameNumber); |
| 4846 | s.bufferData->releaseBufferListener |
| 4847 | ->onReleaseBuffer({resolvedState.externalTexture->getBuffer()->getId(), |
| 4848 | s.bufferData->frameNumber}, |
| 4849 | s.bufferData->acquireFence |
| 4850 | ? s.bufferData->acquireFence |
| 4851 | : Fence::NO_FENCE, |
| 4852 | currentMaxAcquiredBufferCount); |
| 4853 | } |
| 4854 | |
| 4855 | // Delete the entire state at this point and not just release the buffer because |
| 4856 | // everything associated with the Layer in this Transaction is now out of date. |
| 4857 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", layer->name.c_str(), |
| 4858 | layer->barrierProducerId, s.bufferData->producerId); |
| 4859 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4860 | } |
| 4861 | |
| 4862 | if (layer->barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
| 4863 | const bool willApplyBarrierFrame = |
| 4864 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4865 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4866 | s.bufferData->barrierFrameNumber)); |
| 4867 | if (!willApplyBarrierFrame) { |
| 4868 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4869 | layer->name.c_str(), layer->barrierFrameNumber, |
| 4870 | s.bufferData->barrierFrameNumber); |
| 4871 | ready = TransactionReadiness::NotReadyBarrier; |
| 4872 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4873 | } |
| 4874 | } |
| 4875 | } |
| 4876 | |
| 4877 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4878 | // the transaction in the queue. |
| 4879 | const bool hasPendingBuffer = |
| 4880 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4881 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
| 4882 | ATRACE_FORMAT("hasPendingBuffer %s", layer->name.c_str()); |
| 4883 | ready = TransactionReadiness::NotReady; |
| 4884 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4885 | } |
| 4886 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4887 | const bool acquireFenceAvailable = s.bufferData && |
| 4888 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4889 | s.bufferData->acquireFence; |
Ying Wei | 1fd9bfc | 2023-06-29 16:47:00 +0000 | [diff] [blame] | 4890 | const bool fenceSignaled = !acquireFenceAvailable || |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4891 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
| 4892 | if (!fenceSignaled) { |
| 4893 | // check fence status |
| 4894 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(s, transaction.states.size(), |
| 4895 | flushState.firstTransaction) && |
| 4896 | layer->isSimpleBufferUpdate(s); |
| 4897 | if (allowLatchUnsignaled) { |
| 4898 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", layer->name.c_str()); |
| 4899 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4900 | } else { |
| 4901 | ready = TransactionReadiness::NotReady; |
| 4902 | auto& listener = s.bufferData->releaseBufferListener; |
| 4903 | if (listener && |
| 4904 | (flushState.queueProcessTime - transaction.postTime) > |
| 4905 | std::chrono::nanoseconds(4s).count()) { |
| 4906 | mTransactionHandler |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 4907 | .onTransactionQueueStalled(transaction.id, |
| 4908 | {.pid = layer->ownerPid.val(), |
| 4909 | .layerId = layer->id, |
| 4910 | .layerName = layer->name, |
| 4911 | .bufferId = s.bufferData->getId(), |
| 4912 | .frameNumber = s.bufferData->frameNumber}); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4913 | } |
| 4914 | ATRACE_FORMAT("fence unsignaled %s", layer->name.c_str()); |
| 4915 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4916 | } |
| 4917 | } |
| 4918 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
| 4919 | }); |
| 4920 | return ready; |
| 4921 | } |
| 4922 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4923 | void SurfaceFlinger::addTransactionReadyFilters() { |
| 4924 | mTransactionHandler.addTransactionReadyFilter( |
| 4925 | std::bind(&SurfaceFlinger::transactionReadyTimelineCheck, this, std::placeholders::_1)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4926 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4927 | mTransactionHandler.addTransactionReadyFilter( |
| 4928 | std::bind(&SurfaceFlinger::transactionReadyBufferCheck, this, |
| 4929 | std::placeholders::_1)); |
| 4930 | } else { |
| 4931 | mTransactionHandler.addTransactionReadyFilter( |
| 4932 | std::bind(&SurfaceFlinger::transactionReadyBufferCheckLegacy, this, |
| 4933 | std::placeholders::_1)); |
| 4934 | } |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4935 | } |
| 4936 | |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4937 | // For tests only |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4938 | bool SurfaceFlinger::flushTransactionQueues(VsyncId vsyncId) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4939 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4940 | std::vector<TransactionState> transactions = mTransactionHandler.flushTransactions(); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4941 | return applyTransactions(transactions, vsyncId); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4942 | } |
| 4943 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4944 | bool SurfaceFlinger::applyTransactions(std::vector<TransactionState>& transactions, |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4945 | VsyncId vsyncId) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 4946 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4947 | return applyTransactionsLocked(transactions, vsyncId); |
| 4948 | } |
| 4949 | |
| 4950 | bool SurfaceFlinger::applyTransactionsLocked(std::vector<TransactionState>& transactions, |
| 4951 | VsyncId vsyncId) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4952 | bool needsTraversal = false; |
| 4953 | // Now apply all transactions. |
Robert Carr | ff7663b | 2022-02-08 12:46:49 -0800 | [diff] [blame] | 4954 | for (auto& transaction : transactions) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4955 | needsTraversal |= |
| 4956 | applyTransactionState(transaction.frameTimelineInfo, transaction.states, |
| 4957 | transaction.displays, transaction.flags, |
| 4958 | transaction.inputWindowCommands, |
| 4959 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4960 | std::move(transaction.uncacheBufferIds), transaction.postTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4961 | transaction.hasListenerCallbacks, |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4962 | transaction.listenerCallbacks, transaction.originPid, |
| 4963 | transaction.originUid, transaction.id); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4964 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4965 | return needsTraversal; |
Marissa Wall | e6e3c0d | 2019-03-29 10:28:30 -0700 | [diff] [blame] | 4966 | } |
| 4967 | |
| 4968 | bool SurfaceFlinger::transactionFlushNeeded() { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4969 | return mTransactionHandler.hasPendingTransactions(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4970 | } |
| 4971 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4972 | bool SurfaceFlinger::frameIsEarly(TimePoint expectedPresentTime, VsyncId vsyncId) const { |
| 4973 | const auto prediction = |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 4974 | mFrameTimeline->getTokenManager()->getPredictionsForToken(ftl::to_underlying(vsyncId)); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4975 | if (!prediction) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4976 | return false; |
| 4977 | } |
| 4978 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4979 | const auto predictedPresentTime = TimePoint::fromNs(prediction->presentTime); |
| 4980 | |
Rachel Lee | 0655a91 | 2023-04-20 19:54:18 -0700 | [diff] [blame] | 4981 | if (std::chrono::abs(predictedPresentTime - expectedPresentTime) >= |
| 4982 | scheduler::VsyncConfig::kEarlyLatchMaxThreshold) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4983 | return false; |
| 4984 | } |
| 4985 | |
Ady Abraham | 3db8a3c | 2023-11-20 17:53:47 -0800 | [diff] [blame] | 4986 | const Duration earlyLatchVsyncThreshold = mScheduler->getVsyncSchedule()->minFramePeriod() / 2; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4987 | |
| 4988 | return predictedPresentTime >= expectedPresentTime && |
| 4989 | predictedPresentTime - expectedPresentTime >= earlyLatchVsyncThreshold; |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4990 | } |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4991 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4992 | bool SurfaceFlinger::shouldLatchUnsignaled(const layer_state_t& state, size_t numStates, |
| 4993 | bool firstTransaction) const { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4994 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Disabled) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4995 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::Disabled)", __func__); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4996 | return false; |
| 4997 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4998 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4999 | // We only want to latch unsignaled when a single layer is updated in this |
| 5000 | // transaction (i.e. not a blast sync transaction). |
| 5001 | if (numStates != 1) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 5002 | ATRACE_FORMAT_INSTANT("%s: false (numStates=%zu)", __func__, numStates); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5003 | return false; |
| 5004 | } |
| 5005 | |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 5006 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::AutoSingleLayer) { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5007 | if (!firstTransaction) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 5008 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; not first " |
| 5009 | "transaction)", |
| 5010 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 5011 | return false; |
| 5012 | } |
| 5013 | |
| 5014 | // We don't want to latch unsignaled if are in early / client composition |
| 5015 | // as it leads to jank due to RenderEngine waiting for unsignaled buffer |
| 5016 | // or window animations being slow. |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 5017 | if (mScheduler->vsyncModulator().isVsyncConfigEarly()) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 5018 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; " |
| 5019 | "isVsyncConfigEarly)", |
| 5020 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 5021 | return false; |
| 5022 | } |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5023 | } |
| 5024 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5025 | return true; |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5026 | } |
| 5027 | |
chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 5028 | status_t SurfaceFlinger::setTransactionState( |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5029 | const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 5030 | const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5031 | InputWindowCommands inputWindowCommands, int64_t desiredPresentTime, bool isAutoTimestamp, |
| 5032 | const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 5033 | const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId, |
| 5034 | const std::vector<uint64_t>& mergedTransactionIds) { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 5035 | ATRACE_CALL(); |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 5036 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5037 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5038 | const int originPid = ipc->getCallingPid(); |
| 5039 | const int originUid = ipc->getCallingUid(); |
| 5040 | uint32_t permissions = LayerStatePermissions::getTransactionPermissions(originPid, originUid); |
| 5041 | for (auto composerState : states) { |
| 5042 | composerState.state.sanitize(permissions); |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 5043 | } |
| 5044 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5045 | for (DisplayState display : displays) { |
| 5046 | display.sanitize(permissions); |
| 5047 | } |
| 5048 | |
| 5049 | if (!inputWindowCommands.empty() && |
| 5050 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) == 0) { |
| 5051 | ALOGE("Only privileged callers are allowed to send input commands."); |
| 5052 | inputWindowCommands.clear(); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 5053 | } |
| 5054 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 5055 | if (flags & (eEarlyWakeupStart | eEarlyWakeupEnd)) { |
| 5056 | const bool hasPermission = |
| 5057 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) || |
| 5058 | callingThreadHasPermission(sWakeupSurfaceFlinger); |
| 5059 | if (!hasPermission) { |
| 5060 | ALOGE("Caller needs permission android.permission.WAKEUP_SURFACE_FLINGER to use " |
| 5061 | "eEarlyWakeup[Start|End] flags"); |
| 5062 | flags &= ~(eEarlyWakeupStart | eEarlyWakeupEnd); |
| 5063 | } |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 5064 | } |
| 5065 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 5066 | const int64_t postTime = systemTime(); |
| 5067 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5068 | std::vector<uint64_t> uncacheBufferIds; |
| 5069 | uncacheBufferIds.reserve(uncacheBuffers.size()); |
| 5070 | for (const auto& uncacheBuffer : uncacheBuffers) { |
| 5071 | sp<GraphicBuffer> buffer = ClientCache::getInstance().erase(uncacheBuffer); |
| 5072 | if (buffer != nullptr) { |
| 5073 | uncacheBufferIds.push_back(buffer->getId()); |
| 5074 | } |
| 5075 | } |
| 5076 | |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5077 | std::vector<ResolvedComposerState> resolvedStates; |
| 5078 | resolvedStates.reserve(states.size()); |
| 5079 | for (auto& state : states) { |
| 5080 | resolvedStates.emplace_back(std::move(state)); |
| 5081 | auto& resolvedState = resolvedStates.back(); |
| 5082 | if (resolvedState.state.hasBufferChanges() && resolvedState.state.hasValidBuffer() && |
| 5083 | resolvedState.state.surface) { |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 5084 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 5085 | std::string layerName = (layer) ? |
| 5086 | layer->getDebugName() : std::to_string(resolvedState.state.layerId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5087 | resolvedState.externalTexture = |
| 5088 | getExternalTextureFromBufferData(*resolvedState.state.bufferData, |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 5089 | layerName.c_str(), transactionId); |
Patrick Williams | 38d920e | 2023-08-31 17:31:18 -0500 | [diff] [blame] | 5090 | if (resolvedState.externalTexture) { |
| 5091 | resolvedState.state.bufferData->buffer = resolvedState.externalTexture->getBuffer(); |
| 5092 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5093 | mBufferCountTracker.increment(resolvedState.state.surface->localBinder()); |
| 5094 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 5095 | resolvedState.layerId = LayerHandle::getLayerId(resolvedState.state.surface); |
| 5096 | if (resolvedState.state.what & layer_state_t::eReparent) { |
| 5097 | resolvedState.parentId = |
| 5098 | getLayerIdFromSurfaceControl(resolvedState.state.parentSurfaceControlForChild); |
| 5099 | } |
| 5100 | if (resolvedState.state.what & layer_state_t::eRelativeLayerChanged) { |
| 5101 | resolvedState.relativeParentId = |
| 5102 | getLayerIdFromSurfaceControl(resolvedState.state.relativeLayerSurfaceControl); |
| 5103 | } |
| 5104 | if (resolvedState.state.what & layer_state_t::eInputInfoChanged) { |
| 5105 | wp<IBinder>& touchableRegionCropHandle = |
| 5106 | resolvedState.state.windowInfoHandle->editInfo()->touchableRegionCropHandle; |
| 5107 | resolvedState.touchCropId = |
| 5108 | LayerHandle::getLayerId(touchableRegionCropHandle.promote()); |
| 5109 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5110 | } |
| 5111 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5112 | TransactionState state{frameTimelineInfo, |
| 5113 | resolvedStates, |
| 5114 | displays, |
| 5115 | flags, |
| 5116 | applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5117 | std::move(inputWindowCommands), |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5118 | desiredPresentTime, |
| 5119 | isAutoTimestamp, |
| 5120 | std::move(uncacheBufferIds), |
| 5121 | postTime, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5122 | hasListenerCallbacks, |
| 5123 | listenerCallbacks, |
| 5124 | originPid, |
| 5125 | originUid, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 5126 | transactionId, |
| 5127 | mergedTransactionIds}; |
Vishnu Nair | 83df034 | 2021-03-30 11:50:44 -0700 | [diff] [blame] | 5128 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 5129 | if (mTransactionTracing) { |
| 5130 | mTransactionTracing->addQueuedTransaction(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5131 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5132 | |
| 5133 | const auto schedule = [](uint32_t flags) { |
| 5134 | if (flags & eEarlyWakeupEnd) return TransactionSchedule::EarlyEnd; |
| 5135 | if (flags & eEarlyWakeupStart) return TransactionSchedule::EarlyStart; |
| 5136 | return TransactionSchedule::Late; |
| 5137 | }(state.flags); |
| 5138 | |
| 5139 | const auto frameHint = state.isFrameActive() ? FrameHint::kActive : FrameHint::kNone; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5140 | mTransactionHandler.queueTransaction(std::move(state)); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 5141 | for (const auto& [displayId, data] : mNotifyExpectedPresentMap) { |
| 5142 | if (data.hintStatus.load() == NotifyExpectedPresentHintStatus::ScheduleOnTx) { |
| 5143 | scheduleNotifyExpectedPresentHint(displayId, VsyncId{frameTimelineInfo.vsyncId}); |
| 5144 | } |
| 5145 | } |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 5146 | setTransactionFlags(eTransactionFlushNeeded, schedule, applyToken, frameHint); |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 5147 | return NO_ERROR; |
| 5148 | } |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 5149 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5150 | bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5151 | std::vector<ResolvedComposerState>& states, |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 5152 | Vector<DisplayState>& displays, uint32_t flags, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5153 | const InputWindowCommands& inputWindowCommands, |
| 5154 | const int64_t desiredPresentTime, bool isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5155 | const std::vector<uint64_t>& uncacheBufferIds, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5156 | const int64_t postTime, bool hasListenerCallbacks, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5157 | const std::vector<ListenerCallbacks>& listenerCallbacks, |
| 5158 | int originPid, int originUid, uint64_t transactionId) { |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 5159 | uint32_t transactionFlags = 0; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5160 | if (!mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5161 | for (DisplayState& display : displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5162 | transactionFlags |= setDisplayStateLocked(display); |
| 5163 | } |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 5164 | } |
| 5165 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5166 | // start and end registration for listeners w/ no surface so they can get their callback. Note |
| 5167 | // that listeners with SurfaceControls will start registration during setClientStateLocked |
| 5168 | // below. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5169 | for (const auto& listener : listenerCallbacks) { |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5170 | mTransactionCallbackInvoker.addEmptyTransaction(listener); |
Marissa Wall | d600d57 | 2019-03-26 15:38:50 -0700 | [diff] [blame] | 5171 | } |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 5172 | nsecs_t now = systemTime(); |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5173 | uint32_t clientStateFlags = 0; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5174 | for (auto& resolvedState : states) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5175 | if (mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5176 | clientStateFlags |= |
| 5177 | setClientStateLocked(frameTimelineInfo, resolvedState, desiredPresentTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5178 | isAutoTimestamp, postTime, transactionId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5179 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5180 | } else /*mLayerLifecycleManagerEnabled*/ { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5181 | clientStateFlags |= updateLayerCallbacksAndStats(frameTimelineInfo, resolvedState, |
| 5182 | desiredPresentTime, isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5183 | postTime, transactionId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5184 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5185 | if ((flags & eAnimation) && resolvedState.state.surface) { |
| 5186 | if (const auto layer = LayerHandle::getLayer(resolvedState.state.surface)) { |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5187 | const auto layerProps = scheduler::LayerProps{ |
| 5188 | .visible = layer->isVisible(), |
| 5189 | .bounds = layer->getBounds(), |
| 5190 | .transform = layer->getTransform(), |
| 5191 | .setFrameRateVote = layer->getFrameRateForLayerTree(), |
| 5192 | .frameRateSelectionPriority = layer->getFrameRateSelectionPriority(), |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 5193 | .isFrontBuffered = layer->isFrontBuffered(), |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5194 | }; |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 5195 | layer->recordLayerHistoryAnimationTx(layerProps, now); |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 5196 | } |
| 5197 | } |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 5198 | } |
| 5199 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5200 | transactionFlags |= clientStateFlags; |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5201 | transactionFlags |= addInputWindowCommands(inputWindowCommands); |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5202 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5203 | for (uint64_t uncacheBufferId : uncacheBufferIds) { |
| 5204 | mBufferIdsToUncache.push_back(uncacheBufferId); |
Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 5205 | } |
| 5206 | |
Jorim Jaggi | bdcf09c | 2017-08-08 15:22:08 +0200 | [diff] [blame] | 5207 | // If a synchronous transaction is explicitly requested without any changes, force a transaction |
| 5208 | // anyway. This can be used as a flush mechanism for previous async transactions. |
| 5209 | // Empty animation transaction can be used to simulate back-pressure, so also force a |
| 5210 | // transaction for empty animation transactions. |
Vishnu Nair | 1523dad | 2022-09-29 16:05:18 -0700 | [diff] [blame] | 5211 | if (transactionFlags == 0 && (flags & eAnimation)) { |
Robert Carr | 2a7dbb4 | 2016-05-24 11:41:28 -0700 | [diff] [blame] | 5212 | transactionFlags = eTransactionNeeded; |
| 5213 | } |
| 5214 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5215 | bool needsTraversal = false; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 5216 | if (transactionFlags) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5217 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 5218 | // 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] | 5219 | if (transactionFlags & eTraversalNeeded) { |
| 5220 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5221 | needsTraversal = true; |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 5222 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5223 | if (transactionFlags) { |
| 5224 | setTransactionFlags(transactionFlags); |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 5225 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5226 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5227 | |
| 5228 | return needsTraversal; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5229 | } |
| 5230 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5231 | bool SurfaceFlinger::applyAndCommitDisplayTransactionStates( |
| 5232 | std::vector<TransactionState>& transactions) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5233 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5234 | bool needsTraversal = false; |
| 5235 | uint32_t transactionFlags = 0; |
| 5236 | for (auto& transaction : transactions) { |
| 5237 | for (DisplayState& display : transaction.displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5238 | transactionFlags |= setDisplayStateLocked(display); |
| 5239 | } |
| 5240 | } |
| 5241 | |
| 5242 | if (transactionFlags) { |
| 5243 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 5244 | // so we don't have to wake up again next frame to perform an unnecessary traversal. |
| 5245 | if (transactionFlags & eTraversalNeeded) { |
| 5246 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
| 5247 | needsTraversal = true; |
| 5248 | } |
| 5249 | if (transactionFlags) { |
| 5250 | setTransactionFlags(transactionFlags); |
| 5251 | } |
| 5252 | } |
| 5253 | |
| 5254 | mFrontEndDisplayInfosChanged = mTransactionFlags & eDisplayTransactionNeeded; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5255 | if (mFrontEndDisplayInfosChanged && !mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5256 | processDisplayChangesLocked(); |
| 5257 | mFrontEndDisplayInfos.clear(); |
| 5258 | for (const auto& [_, display] : mDisplays) { |
| 5259 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 5260 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5261 | needsTraversal = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5262 | } |
| 5263 | |
| 5264 | return needsTraversal; |
| 5265 | } |
| 5266 | |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5267 | uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s) { |
| 5268 | const ssize_t index = mCurrentState.displays.indexOfKey(s.token); |
| 5269 | if (index < 0) return 0; |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 5270 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5271 | uint32_t flags = 0; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5272 | DisplayDeviceState& state = mCurrentState.displays.editValueAt(index); |
| 5273 | |
| 5274 | const uint32_t what = s.what; |
| 5275 | if (what & DisplayState::eSurfaceChanged) { |
| 5276 | if (IInterface::asBinder(state.surface) != IInterface::asBinder(s.surface)) { |
| 5277 | state.surface = s.surface; |
| 5278 | flags |= eDisplayTransactionNeeded; |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 5279 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5280 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5281 | if (what & DisplayState::eLayerStackChanged) { |
| 5282 | if (state.layerStack != s.layerStack) { |
| 5283 | state.layerStack = s.layerStack; |
| 5284 | flags |= eDisplayTransactionNeeded; |
| 5285 | } |
| 5286 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 5287 | if (what & DisplayState::eFlagsChanged) { |
| 5288 | if (state.flags != s.flags) { |
| 5289 | state.flags = s.flags; |
| 5290 | flags |= eDisplayTransactionNeeded; |
| 5291 | } |
| 5292 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5293 | if (what & DisplayState::eDisplayProjectionChanged) { |
| 5294 | if (state.orientation != s.orientation) { |
| 5295 | state.orientation = s.orientation; |
| 5296 | flags |= eDisplayTransactionNeeded; |
| 5297 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5298 | if (state.orientedDisplaySpaceRect != s.orientedDisplaySpaceRect) { |
| 5299 | state.orientedDisplaySpaceRect = s.orientedDisplaySpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5300 | flags |= eDisplayTransactionNeeded; |
| 5301 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5302 | if (state.layerStackSpaceRect != s.layerStackSpaceRect) { |
| 5303 | state.layerStackSpaceRect = s.layerStackSpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5304 | flags |= eDisplayTransactionNeeded; |
| 5305 | } |
| 5306 | } |
| 5307 | if (what & DisplayState::eDisplaySizeChanged) { |
| 5308 | if (state.width != s.width) { |
| 5309 | state.width = s.width; |
| 5310 | flags |= eDisplayTransactionNeeded; |
| 5311 | } |
| 5312 | if (state.height != s.height) { |
| 5313 | state.height = s.height; |
| 5314 | flags |= eDisplayTransactionNeeded; |
| 5315 | } |
| 5316 | } |
| 5317 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5318 | return flags; |
| 5319 | } |
| 5320 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5321 | bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5322 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5323 | const int pid = ipc->getCallingPid(); |
| 5324 | const int uid = ipc->getCallingUid(); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5325 | if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) && |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5326 | (usePermissionCache ? !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid) |
| 5327 | : !checkPermission(sAccessSurfaceFlinger, pid, uid))) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5328 | return false; |
| 5329 | } |
| 5330 | return true; |
| 5331 | } |
| 5332 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5333 | uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5334 | ResolvedComposerState& composerState, |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5335 | int64_t desiredPresentTime, bool isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5336 | int64_t postTime, uint64_t transactionId) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5337 | layer_state_t& s = composerState.state; |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5338 | |
| 5339 | std::vector<ListenerCallbacks> filteredListeners; |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5340 | for (auto& listener : s.listeners) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5341 | // Starts a registration but separates the callback ids according to callback type. This |
| 5342 | // allows the callback invoker to send on latch callbacks earlier. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5343 | // note that startRegistration will not re-register if the listener has |
| 5344 | // already be registered for a prior surface control |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5345 | |
| 5346 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5347 | if (!onCommitCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5348 | filteredListeners.push_back(onCommitCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5349 | } |
| 5350 | |
| 5351 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5352 | if (!onCompleteCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5353 | filteredListeners.push_back(onCompleteCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5354 | } |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5355 | } |
| 5356 | |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 5357 | const uint64_t what = s.what; |
| 5358 | uint32_t flags = 0; |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 5359 | sp<Layer> layer = nullptr; |
| 5360 | if (s.surface) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5361 | layer = LayerHandle::getLayer(s.surface); |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 5362 | } else { |
| 5363 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5364 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5365 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5366 | if (layer == nullptr) { |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5367 | for (auto& [listener, callbackIds] : s.listeners) { |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 5368 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5369 | callbackIds, |
| 5370 | s.surface), |
| 5371 | std::vector<JankData>()); |
Marissa Wall | 88e2048 | 2019-06-24 10:49:42 -0700 | [diff] [blame] | 5372 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5373 | return 0; |
| 5374 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 5375 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5376 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 5377 | ui::LayerStack oldLayerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5378 | |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 5379 | // Only set by BLAST adapter layers |
| 5380 | if (what & layer_state_t::eProducerDisconnect) { |
| 5381 | layer->onDisconnect(); |
| 5382 | } |
| 5383 | |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5384 | if (what & layer_state_t::ePositionChanged) { |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 5385 | if (layer->setPosition(s.x, s.y)) { |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5386 | flags |= eTraversalNeeded; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5387 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5388 | } |
| 5389 | if (what & layer_state_t::eLayerChanged) { |
| 5390 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5391 | const auto& p = layer->getParent(); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5392 | if (p == nullptr) { |
chaviw | 64f7b42 | 2017-07-12 10:31:58 -0700 | [diff] [blame] | 5393 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5394 | if (layer->setLayer(s.z) && idx >= 0) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5395 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5396 | mCurrentState.layersSortedByZ.add(layer); |
| 5397 | // we need traversal (state changed) |
| 5398 | // AND transaction (list changed) |
| 5399 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5400 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5401 | } else { |
| 5402 | if (p->setChildLayer(layer, s.z)) { |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 5403 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5404 | } |
| 5405 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5406 | } |
| 5407 | if (what & layer_state_t::eRelativeLayerChanged) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5408 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5409 | const auto& p = layer->getParent(); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5410 | const auto& relativeHandle = s.relativeLayerSurfaceControl ? |
| 5411 | s.relativeLayerSurfaceControl->getHandle() : nullptr; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5412 | if (p == nullptr) { |
| 5413 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5414 | if (layer->setRelativeLayer(relativeHandle, s.z) && |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5415 | idx >= 0) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5416 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5417 | mCurrentState.layersSortedByZ.add(layer); |
| 5418 | // we need traversal (state changed) |
| 5419 | // AND transaction (list changed) |
| 5420 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5421 | } |
| 5422 | } else { |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5423 | if (p->setChildRelativeLayer(layer, relativeHandle, s.z)) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5424 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5425 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5426 | } |
| 5427 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5428 | if (what & layer_state_t::eAlphaChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5429 | if (layer->setAlpha(s.color.a)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5430 | } |
| 5431 | if (what & layer_state_t::eColorChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5432 | if (layer->setColor(s.color.rgb)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5433 | } |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 5434 | if (what & layer_state_t::eColorTransformChanged) { |
| 5435 | if (layer->setColorTransform(s.colorTransform)) { |
| 5436 | flags |= eTraversalNeeded; |
| 5437 | } |
| 5438 | } |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5439 | if (what & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5440 | if (layer->setBackgroundColor(s.bgColor.rgb, s.bgColor.a, s.bgColorDataspace)) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5441 | flags |= eTraversalNeeded; |
| 5442 | } |
| 5443 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5444 | if (what & layer_state_t::eMatrixChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5445 | if (layer->setMatrix(s.matrix)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5446 | } |
| 5447 | if (what & layer_state_t::eTransparentRegionChanged) { |
| 5448 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 5449 | flags |= eTraversalNeeded; |
| 5450 | } |
| 5451 | if (what & layer_state_t::eFlagsChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5452 | if (layer->setFlags(s.flags, s.mask)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5453 | } |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 5454 | if (what & layer_state_t::eCornerRadiusChanged) { |
| 5455 | if (layer->setCornerRadius(s.cornerRadius)) |
| 5456 | flags |= eTraversalNeeded; |
| 5457 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5458 | if (what & layer_state_t::eBackgroundBlurRadiusChanged && mSupportsBlur) { |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5459 | if (layer->setBackgroundBlurRadius(s.backgroundBlurRadius)) flags |= eTraversalNeeded; |
| 5460 | } |
Galia Peycheva | e11d575 | 2021-01-22 13:50:16 +0000 | [diff] [blame] | 5461 | if (what & layer_state_t::eBlurRegionsChanged) { |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5462 | if (layer->setBlurRegions(s.blurRegions)) flags |= eTraversalNeeded; |
| 5463 | } |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 5464 | if (what & layer_state_t::eRenderBorderChanged) { |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 5465 | if (layer->enableBorder(s.borderEnabled, s.borderWidth, s.borderColor)) { |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 5466 | flags |= eTraversalNeeded; |
| 5467 | } |
| 5468 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5469 | if (what & layer_state_t::eLayerStackChanged) { |
| 5470 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 5471 | // We only allow setting layer stacks for top level layers, |
| 5472 | // everything else inherits layer stack from its parent. |
| 5473 | if (layer->hasParent()) { |
| 5474 | 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] | 5475 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5476 | } else if (idx < 0) { |
| 5477 | ALOGE("Attempt to set layer stack on layer without parent (%s) that " |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5478 | "that also does not appear in the top level layer list. Something" |
| 5479 | " has gone wrong.", |
| 5480 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5481 | } else if (layer->setLayerStack(s.layerStack)) { |
| 5482 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5483 | mCurrentState.layersSortedByZ.add(layer); |
| 5484 | // we need traversal (state changed) |
| 5485 | // AND transaction (list changed) |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5486 | flags |= eTransactionNeeded | eTraversalNeeded | eTransformHintUpdateNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5487 | } |
| 5488 | } |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5489 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5490 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5491 | } |
| 5492 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5493 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5494 | flags |= eTraversalNeeded; |
| 5495 | } |
| 5496 | if (what & layer_state_t::eCropChanged) { |
| 5497 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5498 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5499 | if (what & layer_state_t::eDataspaceChanged) { |
| 5500 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5501 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5502 | if (what & layer_state_t::eSurfaceDamageRegionChanged) { |
| 5503 | if (layer->setSurfaceDamageRegion(s.surfaceDamageRegion)) flags |= eTraversalNeeded; |
| 5504 | } |
| 5505 | if (what & layer_state_t::eApiChanged) { |
| 5506 | if (layer->setApi(s.api)) flags |= eTraversalNeeded; |
| 5507 | } |
| 5508 | if (what & layer_state_t::eSidebandStreamChanged) { |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 5509 | if (layer->setSidebandStream(s.sidebandStream, frameTimelineInfo, postTime)) |
| 5510 | flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5511 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5512 | if (what & layer_state_t::eInputInfoChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5513 | layer->setInputInfo(*s.windowInfoHandle->getInfo()); |
| 5514 | flags |= eTraversalNeeded; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5515 | } |
Vishnu Nair | adf632b | 2021-01-07 14:05:08 -0800 | [diff] [blame] | 5516 | std::optional<nsecs_t> dequeueBufferTimestamp; |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5517 | if (what & layer_state_t::eMetadataChanged) { |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5518 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5519 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5520 | if (const int32_t gameMode = s.metadata.getInt32(gui::METADATA_GAME_MODE, -1); |
| 5521 | gameMode != -1) { |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5522 | // The transaction will be received on the Task layer and needs to be applied to all |
| 5523 | // child layers. Child layers that are added at a later point will obtain the game mode |
| 5524 | // info through addChild(). |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5525 | layer->setGameModeForTree(static_cast<GameMode>(gameMode)); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5526 | } |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5527 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 5528 | if (layer->setMetadata(s.metadata)) { |
| 5529 | flags |= eTraversalNeeded; |
| 5530 | mLayerMetadataSnapshotNeeded = true; |
| 5531 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5532 | } |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 5533 | if (what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 5534 | if (layer->setColorSpaceAgnostic(s.colorSpaceAgnostic)) { |
| 5535 | flags |= eTraversalNeeded; |
| 5536 | } |
| 5537 | } |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 5538 | if (what & layer_state_t::eShadowRadiusChanged) { |
| 5539 | if (layer->setShadowRadius(s.shadowRadius)) flags |= eTraversalNeeded; |
| 5540 | } |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 5541 | if (what & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 5542 | const auto compatibility = |
| 5543 | Layer::FrameRate::convertCompatibility(s.defaultFrameRateCompatibility); |
| 5544 | |
| 5545 | if (layer->setDefaultFrameRateCompatibility(compatibility)) { |
| 5546 | flags |= eTraversalNeeded; |
| 5547 | } |
| 5548 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5549 | if (what & layer_state_t::eFrameRateSelectionPriority) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5550 | if (layer->setFrameRateSelectionPriority(s.frameRateSelectionPriority)) { |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5551 | flags |= eTraversalNeeded; |
| 5552 | } |
| 5553 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5554 | if (what & layer_state_t::eFrameRateChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5555 | const auto compatibility = |
| 5556 | Layer::FrameRate::convertCompatibility(s.frameRateCompatibility); |
| 5557 | const auto strategy = |
| 5558 | Layer::FrameRate::convertChangeFrameRateStrategy(s.changeFrameRateStrategy); |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 5559 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 5560 | if (layer->setFrameRate(Layer::FrameRate::FrameRateVote(Fps::fromValue(s.frameRate), |
| 5561 | compatibility, strategy))) { |
| 5562 | flags |= eTraversalNeeded; |
| 5563 | } |
| 5564 | } |
| 5565 | if (what & layer_state_t::eFrameRateCategoryChanged) { |
| 5566 | const FrameRateCategory category = Layer::FrameRate::convertCategory(s.frameRateCategory); |
Rachel Lee | 67afbea | 2023-09-28 15:35:07 -0700 | [diff] [blame] | 5567 | if (layer->setFrameRateCategory(category, s.frameRateCategorySmoothSwitchOnly)) { |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 5568 | flags |= eTraversalNeeded; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 5569 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5570 | } |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 5571 | if (what & layer_state_t::eFrameRateSelectionStrategyChanged) { |
| 5572 | const scheduler::LayerInfo::FrameRateSelectionStrategy strategy = |
| 5573 | scheduler::LayerInfo::convertFrameRateSelectionStrategy( |
| 5574 | s.frameRateSelectionStrategy); |
| 5575 | if (layer->setFrameRateSelectionStrategy(strategy)) { |
| 5576 | flags |= eTraversalNeeded; |
| 5577 | } |
| 5578 | } |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5579 | if (what & layer_state_t::eFixedTransformHintChanged) { |
| 5580 | if (layer->setFixedTransformHint(s.fixedTransformHint)) { |
| 5581 | flags |= eTraversalNeeded | eTransformHintUpdateNeeded; |
| 5582 | } |
| 5583 | } |
Vishnu Nair | cf26a0a | 2020-11-13 12:56:20 -0800 | [diff] [blame] | 5584 | if (what & layer_state_t::eAutoRefreshChanged) { |
| 5585 | layer->setAutoRefresh(s.autoRefresh); |
| 5586 | } |
Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 5587 | if (what & layer_state_t::eDimmingEnabledChanged) { |
| 5588 | if (layer->setDimmingEnabled(s.dimmingEnabled)) flags |= eTraversalNeeded; |
| 5589 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5590 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 5591 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5592 | flags |= eTraversalNeeded; |
| 5593 | } |
| 5594 | } |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 5595 | if (what & layer_state_t::eDesiredHdrHeadroomChanged) { |
| 5596 | if (layer->setDesiredHdrHeadroom(s.desiredHdrSdrRatio)) { |
| 5597 | flags |= eTraversalNeeded; |
| 5598 | } |
| 5599 | } |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 5600 | if (what & layer_state_t::eCachingHintChanged) { |
| 5601 | if (layer->setCachingHint(s.cachingHint)) { |
| 5602 | flags |= eTraversalNeeded; |
| 5603 | } |
| 5604 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5605 | if (what & layer_state_t::eHdrMetadataChanged) { |
| 5606 | if (layer->setHdrMetadata(s.hdrMetadata)) flags |= eTraversalNeeded; |
| 5607 | } |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5608 | if (what & layer_state_t::eTrustedOverlayChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5609 | if (layer->setTrustedOverlay(s.isTrustedOverlay)) { |
| 5610 | flags |= eTraversalNeeded; |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5611 | } |
| 5612 | } |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 5613 | if (what & layer_state_t::eStretchChanged) { |
| 5614 | if (layer->setStretchEffect(s.stretchEffect)) { |
| 5615 | flags |= eTraversalNeeded; |
| 5616 | } |
| 5617 | } |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 5618 | if (what & layer_state_t::eBufferCropChanged) { |
| 5619 | if (layer->setBufferCrop(s.bufferCrop)) { |
| 5620 | flags |= eTraversalNeeded; |
| 5621 | } |
| 5622 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 5623 | if (what & layer_state_t::eDestinationFrameChanged) { |
| 5624 | if (layer->setDestinationFrame(s.destinationFrame)) { |
| 5625 | flags |= eTraversalNeeded; |
| 5626 | } |
| 5627 | } |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5628 | if (what & layer_state_t::eDropInputModeChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5629 | if (layer->setDropInputMode(s.dropInputMode)) { |
| 5630 | flags |= eTraversalNeeded; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 5631 | mUpdateInputInfo = true; |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5632 | } |
| 5633 | } |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5634 | // This has to happen after we reparent children because when we reparent to null we remove |
| 5635 | // child layers from current state and remove its relative z. If the children are reparented in |
| 5636 | // the same transaction, then we have to make sure we reparent the children first so we do not |
| 5637 | // lose its relative z order. |
| 5638 | if (what & layer_state_t::eReparent) { |
| 5639 | bool hadParent = layer->hasParent(); |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5640 | auto parentHandle = (s.parentSurfaceControlForChild) |
| 5641 | ? s.parentSurfaceControlForChild->getHandle() |
| 5642 | : nullptr; |
| 5643 | if (layer->reparent(parentHandle)) { |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5644 | if (!hadParent) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 5645 | layer->setIsAtRoot(false); |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5646 | mCurrentState.layersSortedByZ.remove(layer); |
| 5647 | } |
| 5648 | flags |= eTransactionNeeded | eTraversalNeeded; |
| 5649 | } |
| 5650 | } |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5651 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5652 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5653 | for (auto& [listener, callbackIds] : filteredListeners) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 5654 | callbackHandles.emplace_back( |
| 5655 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5656 | } |
| 5657 | } |
Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 5658 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5659 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5660 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5661 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 5662 | frameTimelineInfo)) { |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5663 | flags |= eTraversalNeeded; |
| 5664 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5665 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5666 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 5667 | } |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 5668 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5669 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5670 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5671 | } |
| 5672 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5673 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5674 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5675 | s.trustedPresentationListener)) { |
| 5676 | flags |= eTraversalNeeded; |
| 5677 | } |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5678 | } |
| 5679 | |
Pascal Muetschard | b39918f | 2023-01-27 11:36:11 +0100 | [diff] [blame] | 5680 | if (what & layer_state_t::eFlushJankData) { |
| 5681 | // Do nothing. Processing the transaction completed listeners currently cause the flush. |
| 5682 | } |
| 5683 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5684 | if (layer->setTransactionCompletedListeners(callbackHandles, |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5685 | layer->willPresentCurrentTransaction() || |
| 5686 | layer->willReleaseBufferOnLatch())) { |
Vishnu Nair | d691322 | 2023-02-01 22:56:21 +0000 | [diff] [blame] | 5687 | flags |= eTraversalNeeded; |
| 5688 | } |
| 5689 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5690 | // Do not put anything that updates layer state or modifies flags after |
| 5691 | // setTransactionCompletedListener |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5692 | |
| 5693 | // 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] | 5694 | if (((flags & eTransformHintUpdateNeeded) == 0) && |
| 5695 | oldLayerStack != layer->getLayerStack(LayerVector::StateSet::Current)) { |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5696 | flags |= eTransformHintUpdateNeeded; |
| 5697 | } |
| 5698 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5699 | return flags; |
| 5700 | } |
| 5701 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5702 | uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& frameTimelineInfo, |
| 5703 | ResolvedComposerState& composerState, |
| 5704 | int64_t desiredPresentTime, |
| 5705 | bool isAutoTimestamp, int64_t postTime, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5706 | uint64_t transactionId) { |
| 5707 | layer_state_t& s = composerState.state; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5708 | |
| 5709 | std::vector<ListenerCallbacks> filteredListeners; |
| 5710 | for (auto& listener : s.listeners) { |
| 5711 | // Starts a registration but separates the callback ids according to callback type. This |
| 5712 | // allows the callback invoker to send on latch callbacks earlier. |
| 5713 | // note that startRegistration will not re-register if the listener has |
| 5714 | // already be registered for a prior surface control |
| 5715 | |
| 5716 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5717 | if (!onCommitCallbacks.callbackIds.empty()) { |
| 5718 | filteredListeners.push_back(onCommitCallbacks); |
| 5719 | } |
| 5720 | |
| 5721 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5722 | if (!onCompleteCallbacks.callbackIds.empty()) { |
| 5723 | filteredListeners.push_back(onCompleteCallbacks); |
| 5724 | } |
| 5725 | } |
| 5726 | |
| 5727 | const uint64_t what = s.what; |
| 5728 | uint32_t flags = 0; |
| 5729 | sp<Layer> layer = nullptr; |
| 5730 | if (s.surface) { |
| 5731 | layer = LayerHandle::getLayer(s.surface); |
| 5732 | } else { |
| 5733 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5734 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5735 | } |
| 5736 | if (layer == nullptr) { |
| 5737 | for (auto& [listener, callbackIds] : s.listeners) { |
| 5738 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5739 | callbackIds, |
| 5740 | s.surface), |
| 5741 | std::vector<JankData>()); |
| 5742 | } |
| 5743 | return 0; |
| 5744 | } |
| 5745 | if (what & layer_state_t::eProducerDisconnect) { |
| 5746 | layer->onDisconnect(); |
| 5747 | } |
| 5748 | std::optional<nsecs_t> dequeueBufferTimestamp; |
| 5749 | if (what & layer_state_t::eMetadataChanged) { |
| 5750 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
| 5751 | } |
| 5752 | |
| 5753 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5754 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5755 | for (auto& [listener, callbackIds] : filteredListeners) { |
| 5756 | callbackHandles.emplace_back( |
| 5757 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
| 5758 | } |
| 5759 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5760 | // TODO(b/238781169) remove after screenshot refactor, currently screenshots |
| 5761 | // requires to read drawing state from binder thread. So we need to fix that |
| 5762 | // before removing this. |
Vishnu Nair | aeaf9d7 | 2023-09-12 15:47:41 -0700 | [diff] [blame] | 5763 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5764 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
| 5765 | } |
| 5766 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5767 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5768 | flags |= eTraversalNeeded; |
| 5769 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5770 | if (what & layer_state_t::eCropChanged) { |
| 5771 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5772 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5773 | if (what & layer_state_t::eSidebandStreamChanged) { |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 5774 | if (layer->setSidebandStream(s.sidebandStream, frameTimelineInfo, postTime)) |
| 5775 | flags |= eTraversalNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5776 | } |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 5777 | if (what & layer_state_t::eDataspaceChanged) { |
| 5778 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5779 | } |
Vishnu Nair | c5e3416 | 2023-08-22 13:21:20 -0700 | [diff] [blame] | 5780 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
| 5781 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
| 5782 | flags |= eTraversalNeeded; |
| 5783 | } |
| 5784 | } |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 5785 | if (what & layer_state_t::eDesiredHdrHeadroomChanged) { |
| 5786 | if (layer->setDesiredHdrHeadroom(s.desiredHdrSdrRatio)) { |
| 5787 | flags |= eTraversalNeeded; |
| 5788 | } |
| 5789 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5790 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 5791 | std::optional<ui::Transform::RotationFlags> transformHint = std::nullopt; |
| 5792 | frontend::LayerSnapshot* snapshot = mLayerSnapshotBuilder.getSnapshot(layer->sequence); |
| 5793 | if (snapshot) { |
| 5794 | transformHint = snapshot->transformHint; |
| 5795 | } |
| 5796 | layer->setTransformHint(transformHint); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5797 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5798 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
| 5799 | frameTimelineInfo)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5800 | flags |= eTraversalNeeded; |
| 5801 | } |
| 5802 | mLayersWithQueuedFrames.emplace(layer); |
| 5803 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5804 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
| 5805 | } |
| 5806 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5807 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5808 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5809 | } |
| 5810 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5811 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5812 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5813 | s.trustedPresentationListener)) { |
| 5814 | flags |= eTraversalNeeded; |
| 5815 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5816 | } |
| 5817 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5818 | const auto& requestedLayerState = mLayerLifecycleManager.getLayerFromId(layer->getSequence()); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5819 | bool willPresentCurrentTransaction = requestedLayerState && |
| 5820 | (requestedLayerState->hasReadyFrame() || |
| 5821 | requestedLayerState->willReleaseBufferOnLatch()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5822 | if (layer->setTransactionCompletedListeners(callbackHandles, willPresentCurrentTransaction)) |
| 5823 | flags |= eTraversalNeeded; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5824 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5825 | return flags; |
| 5826 | } |
| 5827 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5828 | uint32_t SurfaceFlinger::addInputWindowCommands(const InputWindowCommands& inputWindowCommands) { |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5829 | bool hasChanges = mInputWindowCommands.merge(inputWindowCommands); |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 5830 | return hasChanges ? eTraversalNeeded : 0; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5831 | } |
| 5832 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5833 | status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5834 | const sp<IBinder>& mirrorFromHandle, |
| 5835 | gui::CreateSurfaceResult& outResult) { |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5836 | if (!mirrorFromHandle) { |
| 5837 | return NAME_NOT_FOUND; |
| 5838 | } |
| 5839 | |
| 5840 | sp<Layer> mirrorLayer; |
| 5841 | sp<Layer> mirrorFrom; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5842 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5843 | { |
| 5844 | Mutex::Autolock _l(mStateLock); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5845 | mirrorFrom = LayerHandle::getLayer(mirrorFromHandle); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5846 | if (!mirrorFrom) { |
| 5847 | return NAME_NOT_FOUND; |
| 5848 | } |
Vishnu Nair | b21272e | 2022-07-01 22:47:33 +0000 | [diff] [blame] | 5849 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5850 | mirrorArgs.mirrorLayerHandle = mirrorFromHandle; |
| 5851 | mirrorArgs.addToRoot = false; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5852 | status_t result = createEffectLayer(mirrorArgs, &outResult.handle, &mirrorLayer); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5853 | if (result != NO_ERROR) { |
| 5854 | return result; |
| 5855 | } |
| 5856 | |
Vishnu Nair | de17725 | 2023-04-21 12:44:10 -0700 | [diff] [blame] | 5857 | mirrorLayer->setClonedChild(mirrorFrom->createClone(mirrorLayer->getSequence())); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5858 | } |
| 5859 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5860 | outResult.layerId = mirrorLayer->sequence; |
| 5861 | outResult.layerName = String16(mirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5862 | return addClientLayer(mirrorArgs, outResult.handle, mirrorLayer /* layer */, |
| 5863 | nullptr /* parent */, nullptr /* outTransformHint */); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5864 | } |
| 5865 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5866 | status_t SurfaceFlinger::mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5867 | gui::CreateSurfaceResult& outResult) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5868 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5869 | const int uid = ipc->getCallingUid(); |
| 5870 | if (uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM && uid != AID_SHELL) { |
| 5871 | ALOGE("Permission denied when trying to mirror display"); |
| 5872 | return PERMISSION_DENIED; |
| 5873 | } |
| 5874 | |
| 5875 | ui::LayerStack layerStack; |
| 5876 | sp<Layer> rootMirrorLayer; |
| 5877 | status_t result = 0; |
| 5878 | |
| 5879 | { |
| 5880 | Mutex::Autolock lock(mStateLock); |
| 5881 | |
| 5882 | const auto display = getDisplayDeviceLocked(displayId); |
| 5883 | if (!display) { |
| 5884 | return NAME_NOT_FOUND; |
| 5885 | } |
| 5886 | |
| 5887 | layerStack = display->getLayerStack(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5888 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5889 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5890 | mirrorArgs.addToRoot = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5891 | mirrorArgs.layerStackToMirror = layerStack; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5892 | result = createEffectLayer(mirrorArgs, &outResult.handle, &rootMirrorLayer); |
| 5893 | outResult.layerId = rootMirrorLayer->sequence; |
| 5894 | outResult.layerName = String16(rootMirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5895 | result |= addClientLayer(mirrorArgs, outResult.handle, rootMirrorLayer /* layer */, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5896 | nullptr /* parent */, nullptr /* outTransformHint */); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5897 | } |
| 5898 | |
| 5899 | if (result != NO_ERROR) { |
| 5900 | return result; |
| 5901 | } |
| 5902 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5903 | if (mLegacyFrontEndEnabled) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5904 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5905 | mMirrorDisplays.emplace_back(layerStack, outResult.handle, args.client); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | setTransactionFlags(eTransactionFlushNeeded); |
| 5909 | return NO_ERROR; |
| 5910 | } |
| 5911 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5912 | status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, gui::CreateSurfaceResult& outResult) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5913 | status_t result = NO_ERROR; |
| 5914 | |
| 5915 | sp<Layer> layer; |
| 5916 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5917 | switch (args.flags & ISurfaceComposerClient::eFXSurfaceMask) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5918 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 5919 | case ISurfaceComposerClient::eFXSurfaceContainer: |
| 5920 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 5921 | args.flags |= ISurfaceComposerClient::eNoColorFill; |
Siarhei Vishniakou | 8d66013 | 2024-01-11 16:48:44 -0800 | [diff] [blame] | 5922 | [[fallthrough]]; |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 5923 | case ISurfaceComposerClient::eFXSurfaceEffect: { |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5924 | result = createBufferStateLayer(args, &outResult.handle, &layer); |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5925 | std::atomic<int32_t>* pendingBufferCounter = layer->getPendingBufferCounter(); |
| 5926 | if (pendingBufferCounter) { |
| 5927 | std::string counterName = layer->getPendingBufferCounterName(); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5928 | mBufferCountTracker.add(outResult.handle->localBinder(), counterName, |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5929 | pendingBufferCounter); |
| 5930 | } |
| 5931 | } break; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5932 | default: |
| 5933 | result = BAD_VALUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5934 | break; |
| 5935 | } |
| 5936 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5937 | if (result != NO_ERROR) { |
| 5938 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5939 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5940 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5941 | args.addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess(); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5942 | // We can safely promote the parent layer in binder thread because we have a strong reference |
| 5943 | // to the layer's handle inside this scope. |
| 5944 | sp<Layer> parent = LayerHandle::getLayer(args.parentHandle.promote()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5945 | if (args.parentHandle != nullptr && parent == nullptr) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5946 | ALOGE("Invalid parent handle %p", args.parentHandle.promote().get()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5947 | args.addToRoot = false; |
Garfield Tan | dbc93d7 | 2021-10-26 18:28:57 -0700 | [diff] [blame] | 5948 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5949 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5950 | uint32_t outTransformHint; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5951 | result = addClientLayer(args, outResult.handle, layer, parent, &outTransformHint); |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 5952 | if (result != NO_ERROR) { |
| 5953 | return result; |
| 5954 | } |
| 5955 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5956 | outResult.transformHint = static_cast<int32_t>(outTransformHint); |
| 5957 | outResult.layerId = layer->sequence; |
| 5958 | outResult.layerName = String16(layer->getDebugName()); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5959 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5960 | } |
| 5961 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5962 | status_t SurfaceFlinger::createBufferStateLayer(LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5963 | sp<Layer>* outLayer) { |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5964 | *outLayer = getFactory().createBufferStateLayer(args); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5965 | *handle = (*outLayer)->getHandle(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5966 | return NO_ERROR; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 5967 | } |
| 5968 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5969 | status_t SurfaceFlinger::createEffectLayer(const LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5970 | sp<Layer>* outLayer) { |
| 5971 | *outLayer = getFactory().createEffectLayer(args); |
| 5972 | *handle = (*outLayer)->getHandle(); |
| 5973 | return NO_ERROR; |
| 5974 | } |
| 5975 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5976 | void SurfaceFlinger::markLayerPendingRemovalLocked(const sp<Layer>& layer) { |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5977 | mLayersPendingRemoval.add(layer); |
| 5978 | mLayersRemoved = true; |
| 5979 | setTransactionFlags(eTransactionNeeded); |
| 5980 | } |
| 5981 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5982 | void SurfaceFlinger::onHandleDestroyed(BBinder* handle, sp<Layer>& layer, uint32_t layerId) { |
| 5983 | { |
| 5984 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | 606d9d0 | 2023-08-19 14:20:18 -0700 | [diff] [blame] | 5985 | mDestroyedHandles.emplace_back(layerId, layer->getDebugName()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5986 | } |
| 5987 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 5988 | mTransactionHandler.onLayerDestroyed(layerId); |
| 5989 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5990 | Mutex::Autolock lock(mStateLock); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5991 | markLayerPendingRemovalLocked(layer); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 5992 | layer->onHandleDestroyed(); |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 5993 | mBufferCountTracker.remove(handle); |
Robert Carr | 695d528 | 2018-12-18 15:27:58 -0800 | [diff] [blame] | 5994 | layer.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5995 | |
| 5996 | setTransactionFlags(eTransactionFlushNeeded); |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 5997 | } |
| 5998 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 5999 | void SurfaceFlinger::initializeDisplays() { |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6000 | TransactionState state; |
| 6001 | state.inputWindowCommands = mInputWindowCommands; |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6002 | const nsecs_t now = systemTime(); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6003 | state.desiredPresentTime = now; |
| 6004 | state.postTime = now; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6005 | state.originPid = mPid; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6006 | state.originUid = static_cast<int>(getuid()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6007 | const uint64_t transactionId = (static_cast<uint64_t>(mPid) << 32) | mUniqueTransactionId++; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6008 | state.id = transactionId; |
| 6009 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6010 | auto layerStack = ui::DEFAULT_LAYER_STACK.id; |
| 6011 | for (const auto& [id, display] : FTL_FAKE_GUARD(mStateLock, mPhysicalDisplays)) { |
| 6012 | state.displays.push(DisplayState(display.token(), ui::LayerStack::fromValue(layerStack++))); |
| 6013 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 6014 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6015 | std::vector<TransactionState> transactions; |
| 6016 | transactions.emplace_back(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 6017 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6018 | if (mLegacyFrontEndEnabled) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6019 | applyTransactions(transactions, VsyncId{0}); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6020 | } else { |
| 6021 | applyAndCommitDisplayTransactionStates(transactions); |
| 6022 | } |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 6023 | |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6024 | { |
| 6025 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6026 | |
| 6027 | // In case of a restart, ensure all displays are off. |
| 6028 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6029 | setPowerModeInternal(getDisplayDeviceLocked(id), hal::PowerMode::OFF); |
| 6030 | } |
| 6031 | |
| 6032 | // Power on all displays. The primary display is first, so becomes the active display. Also, |
| 6033 | // the DisplayCapability set of a display is populated on its first powering on. Do this now |
| 6034 | // before responding to any Binder query from DisplayManager about display capabilities. |
| 6035 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6036 | setPowerModeInternal(getDisplayDeviceLocked(id), hal::PowerMode::ON); |
| 6037 | } |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6038 | } |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 6039 | } |
| 6040 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6041 | void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6042 | if (display->isVirtual()) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6043 | // TODO(b/241285876): This code path should not be reachable, so enforce this at compile |
| 6044 | // time. |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 6045 | ALOGE("%s: Invalid operation on virtual display", __func__); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6046 | return; |
| 6047 | } |
| 6048 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6049 | const auto displayId = display->getPhysicalId(); |
| 6050 | 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] | 6051 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6052 | const auto currentMode = display->getPowerMode(); |
| 6053 | if (currentMode == mode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6054 | return; |
| 6055 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6056 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6057 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 6058 | .transform(&PhysicalDisplay::isInternal) |
| 6059 | .value_or(false); |
| 6060 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 6061 | const auto activeDisplay = getDisplayDeviceLocked(mActiveDisplayId); |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 6062 | |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6063 | ALOGW_IF(display != activeDisplay && isInternalDisplay && activeDisplay && |
| 6064 | activeDisplay->isPoweredOn(), |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 6065 | "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] | 6066 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6067 | display->setPowerMode(mode); |
| 6068 | |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 6069 | const auto activeMode = display->refreshRateSelector().getActiveMode().modePtr; |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6070 | if (currentMode == hal::PowerMode::OFF) { |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 6071 | // Turn on the display |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6072 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 6073 | // Activate the display (which involves a modeset to the active mode) when the inner or |
| 6074 | // outer display of a foldable is powered on. This condition relies on the above |
| 6075 | // DisplayDevice::setPowerMode. If `display` and `activeDisplay` are the same display, |
| 6076 | // then the `activeDisplay->isPoweredOn()` below is true, such that the display is not |
| 6077 | // activated every time it is powered on. |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6078 | // |
| 6079 | // TODO(b/255635821): Remove the concept of active display. |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 6080 | if (isInternalDisplay && (!activeDisplay || !activeDisplay->isPoweredOn())) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 6081 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 6082 | } |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6083 | |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6084 | if (displayId == mActiveDisplayId) { |
| 6085 | // TODO(b/281692563): Merge the syscalls. For now, keep uclamp in a separate syscall and |
| 6086 | // set it before SCHED_FIFO due to b/190237315. |
| 6087 | if (setSchedAttr(true) != NO_ERROR) { |
| 6088 | ALOGW("Failed to set uclamp.min after powering on active display: %s", |
| 6089 | strerror(errno)); |
| 6090 | } |
| 6091 | if (setSchedFifo(true) != NO_ERROR) { |
| 6092 | ALOGW("Failed to set SCHED_FIFO after powering on active display: %s", |
| 6093 | strerror(errno)); |
| 6094 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 6095 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6096 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6097 | getHwComposer().setPowerMode(displayId, mode); |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6098 | if (mode != hal::PowerMode::DOZE_SUSPEND && |
| 6099 | (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present())) { |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6100 | const bool enable = |
| 6101 | mScheduler->getVsyncSchedule(displayId)->getPendingHardwareVsyncState(); |
| 6102 | requestHardwareVsync(displayId, enable); |
| 6103 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6104 | if (displayId == mActiveDisplayId) { |
| 6105 | mScheduler->enableSyntheticVsync(false); |
| 6106 | } |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6107 | |
| 6108 | constexpr bool kAllowToEnable = true; |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 6109 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, activeMode.get()); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6110 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6111 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6112 | mVisibleRegionsDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6113 | scheduleComposite(FrameHint::kActive); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6114 | } else if (mode == hal::PowerMode::OFF) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6115 | const bool currentModeNotDozeSuspend = (currentMode != hal::PowerMode::DOZE_SUSPEND); |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 6116 | // Turn off the display |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6117 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 6118 | if (const auto display = getActivatableDisplay()) { |
| 6119 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
| 6120 | } else { |
| 6121 | if (setSchedFifo(false) != NO_ERROR) { |
| 6122 | ALOGW("Failed to set SCHED_OTHER after powering off active display: %s", |
| 6123 | strerror(errno)); |
| 6124 | } |
| 6125 | if (setSchedAttr(false) != NO_ERROR) { |
| 6126 | ALOGW("Failed set uclamp.min after powering off active display: %s", |
| 6127 | strerror(errno)); |
| 6128 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6129 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6130 | if (currentModeNotDozeSuspend) { |
| 6131 | if (!FlagManager::getInstance().multithreaded_present()) { |
| 6132 | mScheduler->disableHardwareVsync(displayId, true); |
| 6133 | } |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 6134 | mScheduler->enableSyntheticVsync(); |
| 6135 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6136 | } |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 6137 | } |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6138 | if (currentModeNotDozeSuspend && FlagManager::getInstance().multithreaded_present()) { |
| 6139 | constexpr bool kDisallow = true; |
| 6140 | mScheduler->disableHardwareVsync(displayId, kDisallow); |
| 6141 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6142 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6143 | // We must disable VSYNC *before* turning off the display. The call to |
| 6144 | // disableHardwareVsync, above, schedules a task to turn it off after |
| 6145 | // this method returns. But by that point, the display is OFF, so the |
| 6146 | // call just updates the pending state, without actually disabling |
| 6147 | // VSYNC. |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6148 | requestHardwareVsync(displayId, false); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6149 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6150 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6151 | mVisibleRegionsDirty = true; |
| 6152 | // from this point on, SF will stop drawing on this display |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6153 | } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6154 | // Update display while dozing |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6155 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6156 | if (currentMode == hal::PowerMode::DOZE_SUSPEND && |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6157 | (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present())) { |
| 6158 | if (displayId == mActiveDisplayId) { |
| 6159 | ALOGI("Force repainting for DOZE_SUSPEND -> DOZE or ON."); |
| 6160 | mVisibleRegionsDirty = true; |
| 6161 | scheduleRepaint(); |
| 6162 | mScheduler->enableSyntheticVsync(false); |
| 6163 | } |
| 6164 | constexpr bool kAllowToEnable = true; |
| 6165 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, activeMode.get()); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6166 | } |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6167 | } else if (mode == hal::PowerMode::DOZE_SUSPEND) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6168 | // Leave display going to doze |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6169 | if (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present()) { |
| 6170 | constexpr bool kDisallow = true; |
| 6171 | mScheduler->disableHardwareVsync(displayId, kDisallow); |
| 6172 | } |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6173 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6174 | mScheduler->enableSyntheticVsync(); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6175 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6176 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6177 | } else { |
Matthew Bouyack | 38d4961 | 2017-05-12 12:49:32 -0700 | [diff] [blame] | 6178 | ALOGE("Attempting to set unknown power mode: %d\n", mode); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6179 | getHwComposer().setPowerMode(displayId, mode); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6180 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6181 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6182 | if (displayId == mActiveDisplayId) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 6183 | mTimeStats->setPowerMode(mode); |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 6184 | mScheduler->setActiveDisplayPowerModeForRefreshRateStats(mode); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 6185 | } |
| 6186 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6187 | mScheduler->setDisplayPowerMode(displayId, mode); |
| 6188 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6189 | 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] | 6190 | } |
| 6191 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6192 | void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) { |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 6193 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 6194 | kMainThreadContext) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 6195 | const auto display = getDisplayDeviceLocked(displayToken); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6196 | if (!display) { |
| 6197 | ALOGE("Attempt to set power mode %d for invalid display token %p", mode, |
| 6198 | displayToken.get()); |
| 6199 | } else if (display->isVirtual()) { |
| 6200 | ALOGW("Attempt to set power mode %d for virtual display", mode); |
| 6201 | } else { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6202 | setPowerModeInternal(display, static_cast<hal::PowerMode>(mode)); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6203 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6204 | }); |
| 6205 | |
| 6206 | future.wait(); |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 6207 | } |
| 6208 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 6209 | status_t SurfaceFlinger::doDump(int fd, const DumpArgs& args, bool asProto) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6210 | std::string result; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 6211 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 6212 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6213 | const int pid = ipc->getCallingPid(); |
| 6214 | const int uid = ipc->getCallingUid(); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 6215 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 6216 | if ((uid != AID_SHELL) && |
| 6217 | !PermissionCache::checkPermission(sDump, pid, uid)) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6218 | StringAppendF(&result, "Permission Denial: can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 6219 | pid, uid); |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6220 | write(fd, result.c_str(), result.size()); |
| 6221 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6222 | } |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 6223 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6224 | if (asProto && args.empty()) { |
| 6225 | perfetto::protos::LayersTraceFileProto traceFileProto = |
| 6226 | mLayerTracing.createTraceFileProto(); |
| 6227 | perfetto::protos::LayersSnapshotProto* layersTrace = traceFileProto.add_entry(); |
| 6228 | perfetto::protos::LayersProto layersProto = dumpProtoFromMainThread(); |
| 6229 | layersTrace->mutable_layers()->Swap(&layersProto); |
| 6230 | auto displayProtos = dumpDisplayProto(); |
| 6231 | layersTrace->mutable_displays()->Swap(&displayProtos); |
| 6232 | result.append(traceFileProto.SerializeAsString()); |
| 6233 | write(fd, result.c_str(), result.size()); |
| 6234 | return NO_ERROR; |
| 6235 | } |
| 6236 | |
| 6237 | static const std::unordered_map<std::string, Dumper> dumpers = { |
| 6238 | {"--comp-displays"s, dumper(&SurfaceFlinger::dumpCompositionDisplays)}, |
| 6239 | {"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)}, |
| 6240 | {"--displays"s, dumper(&SurfaceFlinger::dumpDisplays)}, |
| 6241 | {"--edid"s, argsDumper(&SurfaceFlinger::dumpRawDisplayIdentificationData)}, |
| 6242 | {"--events"s, dumper(&SurfaceFlinger::dumpEvents)}, |
| 6243 | {"--frametimeline"s, argsDumper(&SurfaceFlinger::dumpFrameTimeline)}, |
| 6244 | {"--frontend"s, mainThreadDumper(&SurfaceFlinger::dumpFrontEnd)}, |
| 6245 | {"--hdrinfo"s, dumper(&SurfaceFlinger::dumpHdrInfo)}, |
| 6246 | {"--hwclayers"s, mainThreadDumper(&SurfaceFlinger::dumpHwcLayersMinidump)}, |
| 6247 | {"--latency"s, argsDumper(&SurfaceFlinger::dumpStatsLocked)}, |
| 6248 | {"--latency-clear"s, argsDumper(&SurfaceFlinger::clearStatsLocked)}, |
| 6249 | {"--list"s, dumper(&SurfaceFlinger::listLayersLocked)}, |
| 6250 | {"--planner"s, argsDumper(&SurfaceFlinger::dumpPlannerInfo)}, |
| 6251 | {"--scheduler"s, dumper(&SurfaceFlinger::dumpScheduler)}, |
| 6252 | {"--timestats"s, protoDumper(&SurfaceFlinger::dumpTimeStats)}, |
| 6253 | {"--vsync"s, dumper(&SurfaceFlinger::dumpVsync)}, |
| 6254 | {"--wide-color"s, dumper(&SurfaceFlinger::dumpWideColorInfo)}, |
| 6255 | }; |
| 6256 | |
| 6257 | const auto flag = args.empty() ? ""s : std::string(String8(args[0])); |
| 6258 | if (const auto it = dumpers.find(flag); it != dumpers.end()) { |
| 6259 | (it->second)(args, asProto, result); |
| 6260 | write(fd, result.c_str(), result.size()); |
| 6261 | return NO_ERROR; |
| 6262 | } |
| 6263 | |
| 6264 | // Traversal of drawing state must happen on the main thread. |
| 6265 | // Otherwise, SortedVector may have shared ownership during concurrent |
| 6266 | // traversals, which can result in use-after-frees. |
| 6267 | std::string compositionLayers; |
| 6268 | mScheduler |
| 6269 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 6270 | dumpVisibleFrontEnd(compositionLayers); |
| 6271 | }) |
| 6272 | .get(); |
| 6273 | dumpAll(args, compositionLayers, result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6274 | write(fd, result.c_str(), result.size()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6275 | return NO_ERROR; |
| 6276 | } |
| 6277 | |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 6278 | status_t SurfaceFlinger::dumpCritical(int fd, const DumpArgs&, bool asProto) { |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 6279 | return doDump(fd, DumpArgs(), asProto); |
| 6280 | } |
| 6281 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6282 | void SurfaceFlinger::listLayersLocked(std::string& result) const { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6283 | mCurrentState.traverseInZOrder( |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 6284 | [&](Layer* layer) { StringAppendF(&result, "%s\n", layer->getDebugName()); }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6285 | } |
| 6286 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6287 | void SurfaceFlinger::dumpStatsLocked(const DumpArgs& args, std::string& result) const { |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 6288 | StringAppendF(&result, "%" PRId64 "\n", getVsyncPeriodFromHWC()); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6289 | if (args.size() < 2) return; |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 6290 | |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6291 | const auto name = String8(args[1]); |
| 6292 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 6293 | if (layer->getName() == name.c_str()) { |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6294 | layer->dumpFrameStats(result); |
| 6295 | } |
| 6296 | }); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6297 | } |
| 6298 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6299 | void SurfaceFlinger::clearStatsLocked(const DumpArgs& args, std::string&) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 6300 | const bool clearAll = args.size() < 2; |
| 6301 | const auto name = clearAll ? String8() : String8(args[1]); |
| 6302 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 6303 | mCurrentState.traverse([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 6304 | if (clearAll || layer->getName() == name.c_str()) { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 6305 | layer->clearFrameStats(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6306 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 6307 | }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6308 | } |
| 6309 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6310 | void SurfaceFlinger::dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const { |
| 6311 | mTimeStats->parseArgs(asProto, args, result); |
| 6312 | } |
| 6313 | |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 6314 | void SurfaceFlinger::dumpFrameTimeline(const DumpArgs& args, std::string& result) const { |
| 6315 | mFrameTimeline->parseArgs(args, result); |
| 6316 | } |
| 6317 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6318 | void SurfaceFlinger::logFrameStats(TimePoint now) { |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6319 | static TimePoint sTimestamp = now; |
| 6320 | if (now - sTimestamp < 30min) return; |
| 6321 | sTimestamp = now; |
| 6322 | |
| 6323 | ATRACE_CALL(); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6324 | mDrawingState.traverse([&](Layer* layer) { layer->logFrameStats(); }); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 6325 | } |
| 6326 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6327 | void SurfaceFlinger::appendSfConfigString(std::string& result) const { |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 6328 | result.append(" [sf"); |
Fabien Sanglard | c93afd5 | 2017-03-13 13:02:42 -0700 | [diff] [blame] | 6329 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6330 | StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); |
| 6331 | StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 6332 | StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%zu", |
| 6333 | getHwComposer().getMaxVirtualDisplayDimension()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6334 | StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6335 | StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6336 | maxFrameBufferAcquiredBuffers); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 6337 | result.append("]"); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6338 | } |
| 6339 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6340 | void SurfaceFlinger::dumpScheduler(std::string& result) const { |
| 6341 | utils::Dumper dumper{result}; |
| 6342 | |
| 6343 | mScheduler->dump(dumper); |
| 6344 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6345 | // TODO(b/241285876): Move to DisplayModeController. |
| 6346 | dumper.dump("debugDisplayModeSetByBackdoor"sv, mDebugDisplayModeSetByBackdoor); |
| 6347 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6348 | |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6349 | StringAppendF(&result, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6350 | " present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64 |
| 6351 | " ns\n\n", |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6352 | dispSyncPresentTimeOffset, getVsyncPeriodFromHWC()); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6353 | } |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6354 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6355 | void SurfaceFlinger::dumpEvents(std::string& result) const { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 6356 | mScheduler->dump(scheduler::Cycle::Render, result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6357 | } |
| 6358 | |
| 6359 | void SurfaceFlinger::dumpVsync(std::string& result) const { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 6360 | mScheduler->dumpVsync(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6361 | } |
| 6362 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 6363 | void SurfaceFlinger::dumpPlannerInfo(const DumpArgs& args, std::string& result) const { |
| 6364 | for (const auto& [token, display] : mDisplays) { |
| 6365 | const auto compositionDisplay = display->getCompositionDisplay(); |
| 6366 | compositionDisplay->dumpPlannerInfo(args, result); |
| 6367 | } |
| 6368 | } |
| 6369 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6370 | void SurfaceFlinger::dumpCompositionDisplays(std::string& result) const { |
| 6371 | for (const auto& [token, display] : mDisplays) { |
| 6372 | display->getCompositionDisplay()->dump(result); |
| 6373 | result += '\n'; |
| 6374 | } |
| 6375 | } |
| 6376 | |
| 6377 | void SurfaceFlinger::dumpDisplays(std::string& result) const { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6378 | utils::Dumper dumper{result}; |
| 6379 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6380 | for (const auto& [id, display] : mPhysicalDisplays) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6381 | utils::Dumper::Section section(dumper, ftl::Concat("Display ", id.value).str()); |
| 6382 | |
| 6383 | display.snapshot().dump(dumper); |
| 6384 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6385 | if (const auto device = getDisplayDeviceLocked(id)) { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6386 | device->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6387 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6388 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6389 | |
| 6390 | for (const auto& [token, display] : mDisplays) { |
| 6391 | if (display->isVirtual()) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6392 | const auto displayId = display->getId(); |
| 6393 | utils::Dumper::Section section(dumper, |
| 6394 | ftl::Concat("Virtual Display ", displayId.value).str()); |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6395 | display->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6396 | } |
| 6397 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6398 | } |
| 6399 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6400 | void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 6401 | for (const auto& [token, display] : mDisplays) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6402 | const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6403 | if (!displayId) { |
| 6404 | continue; |
| 6405 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6406 | const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId); |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6407 | if (!hwcDisplayId) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6408 | continue; |
| 6409 | } |
| 6410 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6411 | StringAppendF(&result, |
| 6412 | "Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), |
| 6413 | *hwcDisplayId); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6414 | uint8_t port; |
| 6415 | DisplayIdentificationData data; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6416 | if (!getHwComposer().getDisplayIdentificationData(*hwcDisplayId, &port, &data)) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6417 | result.append("no identification data\n"); |
| 6418 | continue; |
| 6419 | } |
| 6420 | |
| 6421 | if (!isEdid(data)) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6422 | result.append("unknown identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6423 | continue; |
| 6424 | } |
| 6425 | |
| 6426 | const auto edid = parseEdid(data); |
| 6427 | if (!edid) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6428 | result.append("invalid EDID\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6429 | continue; |
| 6430 | } |
| 6431 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6432 | StringAppendF(&result, "port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6433 | result.append(edid->displayName.data(), edid->displayName.length()); |
| 6434 | result.append("\"\n"); |
| 6435 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6436 | } |
| 6437 | |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6438 | void SurfaceFlinger::dumpRawDisplayIdentificationData(const DumpArgs& args, |
| 6439 | std::string& result) const { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 6440 | hal::HWDisplayId hwcDisplayId; |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6441 | uint8_t port; |
| 6442 | DisplayIdentificationData data; |
| 6443 | |
| 6444 | if (args.size() > 1 && base::ParseUint(String8(args[1]), &hwcDisplayId) && |
| 6445 | getHwComposer().getDisplayIdentificationData(hwcDisplayId, &port, &data)) { |
| 6446 | result.append(reinterpret_cast<const char*>(data.data()), data.size()); |
| 6447 | } |
| 6448 | } |
| 6449 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6450 | void SurfaceFlinger::dumpWideColorInfo(std::string& result) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6451 | StringAppendF(&result, "Device supports wide color: %d\n", mSupportsWideColor); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6452 | StringAppendF(&result, "DisplayColorSetting: %s\n", |
| 6453 | decodeDisplayColorSetting(mDisplayColorSetting).c_str()); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6454 | |
| 6455 | // TODO: print out if wide-color mode is active or not |
| 6456 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6457 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6458 | StringAppendF(&result, "Display %s color modes:\n", to_string(id).c_str()); |
| 6459 | for (const auto mode : display.snapshot().colorModes()) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6460 | StringAppendF(&result, " %s (%d)\n", decodeColorMode(mode).c_str(), mode); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6461 | } |
| 6462 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6463 | if (const auto display = getDisplayDeviceLocked(id)) { |
| 6464 | ui::ColorMode currentMode = display->getCompositionDisplay()->getState().colorMode; |
| 6465 | StringAppendF(&result, " Current color mode: %s (%d)\n", |
| 6466 | decodeColorMode(currentMode).c_str(), currentMode); |
| 6467 | } |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6468 | } |
| 6469 | result.append("\n"); |
| 6470 | } |
| 6471 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6472 | void SurfaceFlinger::dumpHdrInfo(std::string& result) const { |
| 6473 | for (const auto& [displayId, listener] : mHdrLayerInfoListeners) { |
| 6474 | StringAppendF(&result, "HDR events for display %" PRIu64 "\n", displayId.value); |
| 6475 | listener->dump(result); |
| 6476 | result.append("\n"); |
| 6477 | } |
| 6478 | } |
| 6479 | |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6480 | void SurfaceFlinger::dumpFrontEnd(std::string& result) { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6481 | std::ostringstream out; |
| 6482 | out << "\nComposition list\n"; |
| 6483 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6484 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 6485 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 6486 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 6487 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6488 | } |
| 6489 | out << " " << *snapshot << "\n"; |
| 6490 | } |
| 6491 | |
| 6492 | out << "\nInput list\n"; |
| 6493 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6494 | mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6495 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 6496 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 6497 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6498 | } |
| 6499 | out << " " << snapshot << "\n"; |
| 6500 | }); |
| 6501 | |
| 6502 | out << "\nLayer Hierarchy\n" |
| 6503 | << mLayerHierarchyBuilder.getHierarchy().dump() << "\nOffscreen Hierarchy\n" |
| 6504 | << mLayerHierarchyBuilder.getOffscreenHierarchy().dump() << "\n\n"; |
| 6505 | result.append(out.str()); |
| 6506 | } |
| 6507 | |
| 6508 | void SurfaceFlinger::dumpVisibleFrontEnd(std::string& result) { |
| 6509 | if (!mLayerLifecycleManagerEnabled) { |
| 6510 | StringAppendF(&result, "Composition layers\n"); |
| 6511 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 6512 | auto* compositionState = layer->getCompositionState(); |
| 6513 | if (!compositionState || !compositionState->isVisible) return; |
| 6514 | android::base::StringAppendF(&result, "* Layer %p (%s)\n", layer, |
| 6515 | layer->getDebugName() ? layer->getDebugName() |
| 6516 | : "<unknown>"); |
| 6517 | compositionState->dump(result); |
| 6518 | }); |
| 6519 | |
| 6520 | StringAppendF(&result, "Offscreen Layers\n"); |
| 6521 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6522 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
| 6523 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
| 6524 | } |
| 6525 | } else { |
| 6526 | std::ostringstream out; |
| 6527 | out << "\nComposition list\n"; |
| 6528 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6529 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 6530 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 6531 | if (snapshot->hasSomethingToDraw()) { |
| 6532 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 6533 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 6534 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6535 | } |
| 6536 | out << " " << *snapshot << "\n"; |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6537 | } |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6538 | }); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6539 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6540 | out << "\nInput list\n"; |
| 6541 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6542 | mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6543 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 6544 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 6545 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6546 | } |
| 6547 | out << " " << snapshot << "\n"; |
| 6548 | }); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6549 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6550 | out << "\nLayer Hierarchy\n" |
| 6551 | << mLayerHierarchyBuilder.getHierarchy() << "\nOffscreen Hierarchy\n" |
| 6552 | << mLayerHierarchyBuilder.getOffscreenHierarchy() << "\n\n"; |
| 6553 | result = out.str(); |
| 6554 | dumpHwcLayersMinidump(result); |
| 6555 | } |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6556 | } |
| 6557 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6558 | perfetto::protos::LayersProto SurfaceFlinger::dumpDrawingStateProto(uint32_t traceFlags) const { |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 6559 | std::unordered_set<uint64_t> stackIdsToSkip; |
| 6560 | |
| 6561 | // Determine if virtual layers display should be skipped |
| 6562 | if ((traceFlags & LayerTracing::TRACE_VIRTUAL_DISPLAYS) == 0) { |
| 6563 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 6564 | if (display->isVirtual()) { |
| 6565 | stackIdsToSkip.insert(display->getLayerStack().id); |
| 6566 | } |
| 6567 | } |
| 6568 | } |
| 6569 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6570 | if (mLegacyFrontEndEnabled) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6571 | perfetto::protos::LayersProto layersProto; |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 6572 | for (const sp<Layer>& layer : mDrawingState.layersSortedByZ) { |
| 6573 | if (stackIdsToSkip.find(layer->getLayerStack().id) != stackIdsToSkip.end()) { |
| 6574 | continue; |
| 6575 | } |
| 6576 | layer->writeToProto(layersProto, traceFlags); |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 6577 | } |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 6578 | return layersProto; |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 6579 | } |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 6580 | |
Vishnu Nair | 22be349 | 2023-04-20 10:08:21 -0700 | [diff] [blame] | 6581 | return LayerProtoFromSnapshotGenerator(mLayerSnapshotBuilder, mFrontEndDisplayInfos, |
| 6582 | mLegacyLayers, traceFlags) |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 6583 | .generate(mLayerHierarchyBuilder.getHierarchy()); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6584 | } |
| 6585 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6586 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> |
| 6587 | SurfaceFlinger::dumpDisplayProto() const { |
| 6588 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> displays; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6589 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6590 | perfetto::protos::DisplayProto* displayProto = displays.Add(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6591 | displayProto->set_id(display->getId().value); |
| 6592 | displayProto->set_name(display->getDisplayName()); |
| 6593 | displayProto->set_layer_stack(display->getLayerStack().id); |
DoÄŸancan Emek | fc4b6ed | 2023-07-26 15:24:04 +0000 | [diff] [blame] | 6594 | |
| 6595 | if (!display->isVirtual()) { |
| 6596 | const auto dpi = display->refreshRateSelector().getActiveMode().modePtr->getDpi(); |
| 6597 | displayProto->set_dpi_x(dpi.x); |
| 6598 | displayProto->set_dpi_y(dpi.y); |
| 6599 | } |
| 6600 | |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6601 | LayerProtoHelper::writeSizeToProto(display->getWidth(), display->getHeight(), |
| 6602 | [&]() { return displayProto->mutable_size(); }); |
| 6603 | LayerProtoHelper::writeToProto(display->getLayerStackSpaceRect(), [&]() { |
| 6604 | return displayProto->mutable_layer_stack_space_rect(); |
| 6605 | }); |
| 6606 | LayerProtoHelper::writeTransformToProto(display->getTransform(), |
| 6607 | displayProto->mutable_transform()); |
Vishnu Nair | 791d48a | 2021-12-02 16:55:13 -0800 | [diff] [blame] | 6608 | displayProto->set_is_virtual(display->isVirtual()); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6609 | } |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 6610 | return displays; |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6611 | } |
| 6612 | |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 6613 | void SurfaceFlinger::dumpHwc(std::string& result) const { |
| 6614 | getHwComposer().dump(result); |
| 6615 | } |
| 6616 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6617 | void SurfaceFlinger::dumpOffscreenLayersProto(perfetto::protos::LayersProto& layersProto, |
| 6618 | uint32_t traceFlags) const { |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6619 | // Add a fake invisible root layer to the proto output and parent all the offscreen layers to |
| 6620 | // it. |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6621 | perfetto::protos::LayerProto* rootProto = layersProto.add_layers(); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6622 | const int32_t offscreenRootLayerId = INT32_MAX - 2; |
| 6623 | rootProto->set_id(offscreenRootLayerId); |
| 6624 | rootProto->set_name("Offscreen Root"); |
Vishnu Nair | d5aeb61 | 2019-09-20 14:39:39 -0700 | [diff] [blame] | 6625 | rootProto->set_parent(-1); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6626 | |
| 6627 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6628 | // Add layer as child of the fake root |
| 6629 | rootProto->add_children(offscreenLayer->sequence); |
| 6630 | |
| 6631 | // Add layer |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6632 | auto* layerProto = offscreenLayer->writeToProto(layersProto, traceFlags); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6633 | layerProto->set_parent(offscreenRootLayerId); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6634 | } |
| 6635 | } |
| 6636 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6637 | perfetto::protos::LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) { |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 6638 | return mScheduler->schedule([=, this] { return dumpDrawingStateProto(traceFlags); }).get(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 6639 | } |
| 6640 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6641 | void SurfaceFlinger::dumpOffscreenLayers(std::string& result) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6642 | auto future = mScheduler->schedule([this] { |
| 6643 | std::string result; |
| 6644 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6645 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
Vishnu Nair | 76554eb | 2022-12-09 03:38:36 +0000 | [diff] [blame] | 6646 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6647 | } |
| 6648 | return result; |
| 6649 | }); |
| 6650 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6651 | result.append("Offscreen Layers:\n"); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6652 | result.append(future.get()); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6653 | } |
| 6654 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6655 | void SurfaceFlinger::dumpHwcLayersMinidumpLockedLegacy(std::string& result) const { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6656 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6657 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6658 | if (!displayId) { |
| 6659 | continue; |
| 6660 | } |
| 6661 | |
| 6662 | 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] | 6663 | displayId == mActiveDisplayId ? "active" : "inactive"); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6664 | Layer::miniDumpHeader(result); |
| 6665 | |
| 6666 | const DisplayDevice& ref = *display; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6667 | mDrawingState.traverseInZOrder([&](Layer* layer) { layer->miniDumpLegacy(result, ref); }); |
| 6668 | result.append("\n"); |
| 6669 | } |
| 6670 | } |
| 6671 | |
| 6672 | void SurfaceFlinger::dumpHwcLayersMinidump(std::string& result) const { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6673 | if (!mLayerLifecycleManagerEnabled) { |
| 6674 | return dumpHwcLayersMinidumpLockedLegacy(result); |
| 6675 | } |
| 6676 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6677 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6678 | if (!displayId) { |
| 6679 | continue; |
| 6680 | } |
| 6681 | |
| 6682 | StringAppendF(&result, "Display %s (%s) HWC layers:\n", to_string(*displayId).c_str(), |
| 6683 | displayId == mActiveDisplayId ? "active" : "inactive"); |
| 6684 | Layer::miniDumpHeader(result); |
| 6685 | |
| 6686 | const DisplayDevice& ref = *display; |
| 6687 | mLayerSnapshotBuilder.forEachVisibleSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6688 | if (!snapshot.hasSomethingToDraw() || |
| 6689 | ref.getLayerStack() != snapshot.outputFilter.layerStack) { |
| 6690 | return; |
| 6691 | } |
| 6692 | auto it = mLegacyLayers.find(snapshot.sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 6693 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 6694 | "Couldnt find layer object for %s", |
| 6695 | snapshot.getDebugString().c_str()); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6696 | it->second->miniDump(result, snapshot, ref); |
| 6697 | }); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6698 | result.append("\n"); |
| 6699 | } |
| 6700 | } |
| 6701 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6702 | void SurfaceFlinger::dumpAll(const DumpArgs& args, const std::string& compositionLayers, |
| 6703 | std::string& result) const { |
| 6704 | TimedLock lock(mStateLock, s2ns(1), __func__); |
| 6705 | if (!lock.locked()) { |
| 6706 | StringAppendF(&result, "Dumping without lock after timeout: %s (%d)\n", |
| 6707 | strerror(-lock.status), lock.status); |
| 6708 | } |
| 6709 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6710 | const bool colorize = !args.empty() && args[0] == String16("--color"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6711 | Colorizer colorizer(colorize); |
| 6712 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6713 | // figure out if we're stuck somewhere |
| 6714 | const nsecs_t now = systemTime(); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6715 | const nsecs_t inTransaction(mDebugInTransaction); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6716 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 6717 | |
| 6718 | /* |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6719 | * Dump library configuration. |
| 6720 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6721 | |
| 6722 | colorizer.bold(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6723 | result.append("Build configuration:"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6724 | colorizer.reset(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6725 | appendSfConfigString(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6726 | result.append("\n"); |
| 6727 | |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6728 | result.append("\nDisplay identification data:\n"); |
| 6729 | dumpDisplayIdentificationData(result); |
| 6730 | |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6731 | result.append("\nWide-Color information:\n"); |
| 6732 | dumpWideColorInfo(result); |
| 6733 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6734 | dumpHdrInfo(result); |
| 6735 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6736 | colorizer.bold(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6737 | result.append("Sync configuration: "); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6738 | colorizer.reset(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6739 | result.append(SyncFeatures::getInstance().toString()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6740 | result.append("\n\n"); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6741 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6742 | colorizer.bold(result); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6743 | result.append("Scheduler:\n"); |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6744 | colorizer.reset(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6745 | dumpScheduler(result); |
| 6746 | dumpEvents(result); |
| 6747 | dumpVsync(result); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 6748 | result.append("\n"); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6749 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6750 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6751 | * Dump the visible layer list |
| 6752 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6753 | colorizer.bold(result); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6754 | StringAppendF(&result, "SurfaceFlinger New Frontend Enabled:%s\n", |
| 6755 | mLayerLifecycleManagerEnabled ? "true" : "false"); |
| 6756 | StringAppendF(&result, "Active Layers - layers with client handles (count = %zu)\n", |
| 6757 | mNumLayers.load()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6758 | colorizer.reset(result); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6759 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 6760 | result.append(compositionLayers); |
Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 6761 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6762 | colorizer.bold(result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6763 | StringAppendF(&result, "Displays (%zu entries)\n", mDisplays.size()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6764 | colorizer.reset(result); |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6765 | dumpDisplays(result); |
| 6766 | dumpCompositionDisplays(result); |
| 6767 | result.push_back('\n'); |
Lloyd Pique | c3cb729 | 2019-05-17 15:25:14 -0700 | [diff] [blame] | 6768 | |
| 6769 | mCompositionEngine->dump(result); |
| 6770 | |
| 6771 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6772 | * Dump SurfaceFlinger global state |
| 6773 | */ |
| 6774 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6775 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6776 | result.append("SurfaceFlinger global state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6777 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6778 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 6779 | getRenderEngine().dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6780 | |
Robert Carr | beba6f0 | 2021-02-10 21:06:27 -0800 | [diff] [blame] | 6781 | result.append("ClientCache state:\n"); |
| 6782 | ClientCache::getInstance().dump(result); |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 6783 | DebugEGLImageTracker::getInstance()->dump(result); |
| 6784 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6785 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 6786 | display->getCompositionDisplay()->getState().undefinedRegion.dump(result, |
| 6787 | "undefinedRegion"); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 6788 | StringAppendF(&result, " orientation=%s, isPoweredOn=%d\n", |
| 6789 | toCString(display->getOrientation()), display->isPoweredOn()); |
Lloyd Pique | 2ae2b3b | 2017-12-14 17:18:17 -0800 | [diff] [blame] | 6790 | } |
Carlos Martinez Romero | 779dc1f | 2022-10-27 23:23:30 +0000 | [diff] [blame] | 6791 | StringAppendF(&result, " transaction-flags : %08x\n", mTransactionFlags.load()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6792 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 6793 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6794 | std::string fps, xDpi, yDpi; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 6795 | if (const auto activeModePtr = |
| 6796 | display->refreshRateSelector().getActiveMode().modePtr.get()) { |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 6797 | fps = to_string(activeModePtr->getVsyncRate()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6798 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6799 | const auto dpi = activeModePtr->getDpi(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6800 | xDpi = base::StringPrintf("%.2f", dpi.x); |
| 6801 | yDpi = base::StringPrintf("%.2f", dpi.y); |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6802 | } else { |
| 6803 | fps = "unknown"; |
| 6804 | xDpi = "unknown"; |
| 6805 | yDpi = "unknown"; |
| 6806 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6807 | StringAppendF(&result, |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6808 | " refresh-rate : %s\n" |
| 6809 | " x-dpi : %s\n" |
| 6810 | " y-dpi : %s\n", |
| 6811 | fps.c_str(), xDpi.c_str(), yDpi.c_str()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6812 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6813 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6814 | StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6815 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6816 | result.append("\nTransaction tracing: "); |
| 6817 | if (mTransactionTracing) { |
| 6818 | result.append("enabled\n"); |
| 6819 | mTransactionTracing->dump(result); |
| 6820 | } else { |
| 6821 | result.append("disabled\n"); |
| 6822 | } |
| 6823 | result.push_back('\n'); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6824 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6825 | if (mLegacyFrontEndEnabled) { |
| 6826 | dumpHwcLayersMinidumpLockedLegacy(result); |
| 6827 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6828 | |
Ady Abraham | 2790e9f | 2021-04-28 13:14:20 -0700 | [diff] [blame] | 6829 | { |
| 6830 | DumpArgs plannerArgs; |
| 6831 | plannerArgs.add(); // first argument is ignored |
| 6832 | plannerArgs.add(String16("--layers")); |
| 6833 | dumpPlannerInfo(plannerArgs, result); |
| 6834 | } |
| 6835 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6836 | /* |
| 6837 | * Dump HWComposer state |
| 6838 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6839 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6840 | result.append("h/w composer state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6841 | colorizer.reset(result); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6842 | const bool hwcDisabled = mDebugDisableHWC || mDebugFlashDelay; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6843 | StringAppendF(&result, " h/w composer %s\n", hwcDisabled ? "disabled" : "enabled"); |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 6844 | dumpHwc(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6845 | |
| 6846 | /* |
| 6847 | * Dump gralloc state |
| 6848 | */ |
| 6849 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 6850 | alloc.dump(result); |
Karthik Ravi Shankar | 171155a | 2017-06-28 15:40:24 -0700 | [diff] [blame] | 6851 | |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6852 | /* |
| 6853 | * Dump flag/property manager state |
| 6854 | */ |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 6855 | FlagManager::getInstance().dump(result); |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6856 | |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 6857 | result.append(mTimeStats->miniDump()); |
| 6858 | result.append("\n"); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 6859 | |
| 6860 | result.append("Window Infos:\n"); |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 6861 | auto windowInfosDebug = mWindowInfosListenerInvoker->getDebugInfo(); |
| 6862 | StringAppendF(&result, " max send vsync id: %" PRId64 "\n", |
| 6863 | ftl::to_underlying(windowInfosDebug.maxSendDelayVsyncId)); |
| 6864 | StringAppendF(&result, " max send delay (ns): %" PRId64 " ns\n", |
| 6865 | windowInfosDebug.maxSendDelayDuration); |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 6866 | StringAppendF(&result, " unsent messages: %zu\n", windowInfosDebug.pendingMessageCount); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 6867 | result.append("\n"); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6868 | } |
| 6869 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6870 | mat4 SurfaceFlinger::calculateColorMatrix(float saturation) { |
| 6871 | if (saturation == 1) { |
| 6872 | return mat4(); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6873 | } |
| 6874 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6875 | float3 luminance{0.213f, 0.715f, 0.072f}; |
| 6876 | luminance *= 1.0f - saturation; |
| 6877 | mat4 saturationMatrix = mat4(vec4{luminance.r + saturation, luminance.r, luminance.r, 0.0f}, |
| 6878 | vec4{luminance.g, luminance.g + saturation, luminance.g, 0.0f}, |
| 6879 | vec4{luminance.b, luminance.b, luminance.b + saturation, 0.0f}, |
| 6880 | vec4{0.0f, 0.0f, 0.0f, 1.0f}); |
| 6881 | return saturationMatrix; |
| 6882 | } |
| 6883 | |
| 6884 | void SurfaceFlinger::updateColorMatrixLocked() { |
| 6885 | mat4 colorMatrix = |
| 6886 | mClientColorMatrix * calculateColorMatrix(mGlobalSaturationFactor) * mDaltonizer(); |
| 6887 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6888 | if (mCurrentState.colorMatrix != colorMatrix) { |
| 6889 | mCurrentState.colorMatrix = colorMatrix; |
| 6890 | mCurrentState.colorMatrixChanged = true; |
| 6891 | setTransactionFlags(eTransactionNeeded); |
| 6892 | } |
| 6893 | } |
| 6894 | |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6895 | status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6896 | #pragma clang diagnostic push |
| 6897 | #pragma clang diagnostic error "-Wswitch-enum" |
| 6898 | switch (static_cast<ISurfaceComposerTag>(code)) { |
| 6899 | // These methods should at minimum make sure that the client requested |
| 6900 | // access to SF. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6901 | case GET_HDR_CAPABILITIES: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6902 | case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6903 | case GET_GAME_CONTENT_TYPE_SUPPORT: |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6904 | case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6905 | // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary |
| 6906 | // permission dynamically. Don't use the permission cache for this check. |
| 6907 | bool usePermissionCache = code != OVERRIDE_HDR_TYPES; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6908 | if (!callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 6909 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6910 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", |
| 6911 | ipc->getCallingPid(), ipc->getCallingUid()); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6912 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6913 | } |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 6914 | return OK; |
| 6915 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6916 | // The following calls are currently used by clients that do not |
| 6917 | // request necessary permissions. However, they do not expose any secret |
| 6918 | // information, so it is OK to pass them. |
Peiyong Lin | d1fedb4 | 2019-03-11 17:48:41 -0700 | [diff] [blame] | 6919 | case GET_ACTIVE_COLOR_MODE: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6920 | case GET_ACTIVE_DISPLAY_MODE: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6921 | case GET_DISPLAY_COLOR_MODES: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6922 | case GET_DISPLAY_MODES: |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 6923 | case GET_SCHEDULING_POLICY: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6924 | // Calling setTransactionState is safe, because you need to have been |
| 6925 | // granted a reference to Client* and Handle* to do anything with it. |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6926 | case SET_TRANSACTION_STATE: { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 6927 | // This is not sensitive information, so should not require permission control. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6928 | return OK; |
| 6929 | } |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 6930 | case BOOT_FINISHED: |
| 6931 | // Used by apps to hook Choreographer to SurfaceFlinger. |
| 6932 | case CREATE_DISPLAY_EVENT_CONNECTION: |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6933 | case CREATE_CONNECTION: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6934 | case CREATE_DISPLAY: |
| 6935 | case DESTROY_DISPLAY: |
| 6936 | case GET_PRIMARY_PHYSICAL_DISPLAY_ID: |
| 6937 | case GET_PHYSICAL_DISPLAY_IDS: |
| 6938 | case GET_PHYSICAL_DISPLAY_TOKEN: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6939 | case AUTHENTICATE_SURFACE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6940 | case SET_POWER_MODE: |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 6941 | case GET_SUPPORTED_FRAME_TIMESTAMPS: |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6942 | case GET_DISPLAY_STATE: |
| 6943 | case GET_DISPLAY_STATS: |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 6944 | case GET_STATIC_DISPLAY_INFO: |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 6945 | case GET_DYNAMIC_DISPLAY_INFO: |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 6946 | case GET_DISPLAY_NATIVE_PRIMARIES: |
| 6947 | case SET_ACTIVE_COLOR_MODE: |
| 6948 | case SET_BOOT_DISPLAY_MODE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6949 | case CLEAR_BOOT_DISPLAY_MODE: |
| 6950 | case GET_BOOT_DISPLAY_MODE_SUPPORT: |
| 6951 | case SET_AUTO_LOW_LATENCY_MODE: |
| 6952 | case SET_GAME_CONTENT_TYPE: |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6953 | case CAPTURE_LAYERS: |
| 6954 | case CAPTURE_DISPLAY: |
| 6955 | case CAPTURE_DISPLAY_BY_ID: |
Huihong Luo | 4ed1c91 | 2022-02-22 14:30:01 -0800 | [diff] [blame] | 6956 | case CLEAR_ANIMATION_FRAME_STATS: |
| 6957 | case GET_ANIMATION_FRAME_STATS: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6958 | case OVERRIDE_HDR_TYPES: |
| 6959 | case ON_PULL_ATOM: |
| 6960 | case ENABLE_VSYNC_INJECTIONS: |
| 6961 | case INJECT_VSYNC: |
| 6962 | case GET_LAYER_DEBUG_INFO: |
| 6963 | case GET_COLOR_MANAGEMENT: |
| 6964 | case GET_COMPOSITION_PREFERENCE: |
| 6965 | case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: |
| 6966 | case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6967 | case GET_DISPLAYED_CONTENT_SAMPLE: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6968 | case GET_PROTECTED_CONTENT_SUPPORT: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6969 | case IS_WIDE_COLOR_DISPLAY: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6970 | case ADD_REGION_SAMPLING_LISTENER: |
| 6971 | case REMOVE_REGION_SAMPLING_LISTENER: |
| 6972 | case ADD_FPS_LISTENER: |
| 6973 | case REMOVE_FPS_LISTENER: |
| 6974 | case ADD_TUNNEL_MODE_ENABLED_LISTENER: |
| 6975 | case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: |
| 6976 | case ADD_WINDOW_INFOS_LISTENER: |
| 6977 | case REMOVE_WINDOW_INFOS_LISTENER: |
| 6978 | case SET_DESIRED_DISPLAY_MODE_SPECS: |
| 6979 | case GET_DESIRED_DISPLAY_MODE_SPECS: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6980 | case GET_DISPLAY_BRIGHTNESS_SUPPORT: |
| 6981 | case SET_DISPLAY_BRIGHTNESS: |
| 6982 | case ADD_HDR_LAYER_INFO_LISTENER: |
| 6983 | case REMOVE_HDR_LAYER_INFO_LISTENER: |
| 6984 | case NOTIFY_POWER_BOOST: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6985 | case SET_GLOBAL_SHADOW_SETTINGS: |
| 6986 | case GET_DISPLAY_DECORATION_SUPPORT: |
| 6987 | case SET_FRAME_RATE: |
| 6988 | case SET_OVERRIDE_FRAME_RATE: |
| 6989 | case SET_FRAME_TIMELINE_INFO: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6990 | case ADD_TRANSACTION_TRACE_LISTENER: |
| 6991 | case GET_GPU_CONTEXT_PRIORITY: |
| 6992 | case GET_MAX_ACQUIRED_BUFFER_COUNT: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6993 | LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6994 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6995 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6996 | |
| 6997 | // These codes are used for the IBinder protocol to either interrogate the recipient |
| 6998 | // side of the transaction for its canonical interface descriptor or to dump its state. |
| 6999 | // We let them pass by default. |
| 7000 | if (code == IBinder::INTERFACE_TRANSACTION || code == IBinder::DUMP_TRANSACTION || |
| 7001 | code == IBinder::PING_TRANSACTION || code == IBinder::SHELL_COMMAND_TRANSACTION || |
| 7002 | code == IBinder::SYSPROPS_TRANSACTION) { |
| 7003 | return OK; |
| 7004 | } |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7005 | // Numbers from 1000 to 1045 are currently used for backdoors. The code |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7006 | // 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] | 7007 | if (code >= 1000 && code <= 1045) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7008 | ALOGV("Accessing SurfaceFlinger through backdoor code: %u", code); |
| 7009 | return OK; |
| 7010 | } |
| 7011 | ALOGE("Permission Denial: SurfaceFlinger did not recognize request code: %u", code); |
| 7012 | return PERMISSION_DENIED; |
| 7013 | #pragma clang diagnostic pop |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 7014 | } |
| 7015 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7016 | status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 7017 | uint32_t flags) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7018 | if (const status_t error = CheckTransactCodeCredentials(code); error != OK) { |
| 7019 | return error; |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 7020 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 7021 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7022 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 7023 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 7024 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Romain Guy | 8c6bbd6 | 2017-06-05 13:51:43 -0700 | [diff] [blame] | 7025 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7026 | const int uid = ipc->getCallingUid(); |
| 7027 | if (CC_UNLIKELY(uid != AID_SYSTEM |
| 7028 | && !PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 7029 | const int pid = ipc->getCallingPid(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 7030 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 7031 | "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] | 7032 | return PERMISSION_DENIED; |
| 7033 | } |
| 7034 | int n; |
| 7035 | switch (code) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7036 | case 1000: // Unused. |
| 7037 | case 1001: |
| 7038 | return NAME_NOT_FOUND; |
| 7039 | case 1002: // Toggle flashing on surface damage. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7040 | sfdo_setDebugFlash(data.readInt32()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7041 | return NO_ERROR; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 7042 | case 1004: // Force composite ahead of next VSYNC. |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 7043 | case 1006: |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7044 | sfdo_scheduleComposite(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7045 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7046 | case 1005: { // Force commit ahead of next VSYNC. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7047 | sfdo_scheduleCommit(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 7048 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7049 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7050 | case 1007: // Unused. |
| 7051 | return NAME_NOT_FOUND; |
| 7052 | case 1008: // Toggle forced GPU composition. |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 7053 | sfdo_forceClientComposition(data.readInt32() != 0); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 7054 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7055 | case 1009: // Toggle use of transform hint. |
| 7056 | mDebugDisableTransformHint = data.readInt32() != 0; |
| 7057 | scheduleRepaint(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 7058 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7059 | case 1010: // Interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 7060 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7061 | reply->writeInt32(0); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7062 | reply->writeInt32(mDebugFlashDelay); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 7063 | reply->writeInt32(0); |
Dianne Hackborn | 12839be | 2012-02-06 21:21:05 -0800 | [diff] [blame] | 7064 | reply->writeInt32(mDebugDisableHWC); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7065 | return NO_ERROR; |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 7066 | case 1013: // Unused. |
| 7067 | return NAME_NOT_FOUND; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7068 | case 1014: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7069 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7070 | // daltonize |
| 7071 | n = data.readInt32(); |
| 7072 | switch (n % 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7073 | case 1: |
| 7074 | mDaltonizer.setType(ColorBlindnessType::Protanomaly); |
| 7075 | break; |
| 7076 | case 2: |
| 7077 | mDaltonizer.setType(ColorBlindnessType::Deuteranomaly); |
| 7078 | break; |
| 7079 | case 3: |
| 7080 | mDaltonizer.setType(ColorBlindnessType::Tritanomaly); |
| 7081 | break; |
| 7082 | default: |
| 7083 | mDaltonizer.setType(ColorBlindnessType::None); |
| 7084 | break; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7085 | } |
| 7086 | if (n >= 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7087 | mDaltonizer.setMode(ColorBlindnessMode::Correction); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7088 | } else { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7089 | mDaltonizer.setMode(ColorBlindnessMode::Simulation); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7090 | } |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7091 | |
| 7092 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7093 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7094 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7095 | case 1015: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7096 | Mutex::Autolock _l(mStateLock); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7097 | // apply a color matrix |
| 7098 | n = data.readInt32(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7099 | if (n) { |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7100 | // color matrix is sent as a column-major mat4 matrix |
Alan Viverette | 794c5ba | 2013-10-03 16:40:52 -0700 | [diff] [blame] | 7101 | for (size_t i = 0 ; i < 4; i++) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7102 | for (size_t j = 0; j < 4; j++) { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7103 | mClientColorMatrix[i][j] = data.readFloat(); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7104 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7105 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7106 | } else { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7107 | mClientColorMatrix = mat4(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7108 | } |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 7109 | |
| 7110 | // Check that supplied matrix's last row is {0,0,0,1} so we can avoid |
| 7111 | // the division by w in the fragment shader |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7112 | float4 lastRow(transpose(mClientColorMatrix)[3]); |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 7113 | if (any(greaterThan(abs(lastRow - float4{0, 0, 0, 1}), float4{1e-4f}))) { |
| 7114 | ALOGE("The color transform's last row must be (0, 0, 0, 1)"); |
| 7115 | } |
| 7116 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7117 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7118 | return NO_ERROR; |
| 7119 | } |
Dominik Laskowski | 8d32ddc | 2019-08-07 11:25:35 -0700 | [diff] [blame] | 7120 | case 1016: { // Unused. |
| 7121 | return NAME_NOT_FOUND; |
Ruchi Kandoi | f52b3c8 | 2014-04-24 16:42:35 -0700 | [diff] [blame] | 7122 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 7123 | case 1017: { |
| 7124 | n = data.readInt32(); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 7125 | mForceFullDamage = n != 0; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 7126 | return NO_ERROR; |
| 7127 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7128 | case 1018: { // Set the render deadline as a duration until VSYNC. |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7129 | n = data.readInt32(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7130 | mScheduler->setDuration(scheduler::Cycle::Render, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7131 | return NO_ERROR; |
| 7132 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7133 | 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] | 7134 | n = data.readInt32(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7135 | mScheduler->setDuration(scheduler::Cycle::LastComposite, |
| 7136 | std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7137 | return NO_ERROR; |
| 7138 | } |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 7139 | case 1020: { // Unused |
| 7140 | return NAME_NOT_FOUND; |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 7141 | } |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 7142 | case 1021: { // Disable HWC virtual displays |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 7143 | const bool enable = data.readInt32() != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7144 | static_cast<void>( |
| 7145 | mScheduler->schedule([this, enable] { enableHalVirtualDisplays(enable); })); |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 7146 | return NO_ERROR; |
| 7147 | } |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7148 | case 1022: { // Set saturation boost |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7149 | Mutex::Autolock _l(mStateLock); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7150 | mGlobalSaturationFactor = std::max(0.0f, std::min(data.readFloat(), 2.0f)); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7151 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7152 | updateColorMatrixLocked(); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7153 | return NO_ERROR; |
| 7154 | } |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7155 | case 1023: { // Set color mode. |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7156 | mDisplayColorSetting = static_cast<DisplayColorSetting>(data.readInt32()); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7157 | |
| 7158 | if (int32_t colorMode; data.readInt32(&colorMode) == NO_ERROR) { |
| 7159 | mForceColorMode = static_cast<ui::ColorMode>(colorMode); |
Daniel Solomon | 7c7ede2 | 2019-07-11 16:35:40 -0700 | [diff] [blame] | 7160 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7161 | scheduleRepaint(); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 7162 | return NO_ERROR; |
| 7163 | } |
Peiyong Lin | 4bac91c | 2018-10-25 09:48:33 -0700 | [diff] [blame] | 7164 | // Deprecate, use 1030 to check whether the device is color managed. |
| 7165 | case 1024: { |
| 7166 | return NAME_NOT_FOUND; |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 7167 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7168 | // Deprecated, use perfetto to start/stop the layer tracing |
| 7169 | case 1025: { |
| 7170 | return NAME_NOT_FOUND; |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 7171 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7172 | // Deprecated, execute "adb shell perfetto --query" to see the ongoing tracing sessions |
| 7173 | case 1026: { |
| 7174 | return NAME_NOT_FOUND; |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 7175 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7176 | // Is a DisplayColorSetting supported? |
| 7177 | case 1027: { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7178 | const auto display = getDefaultDisplayDevice(); |
| 7179 | if (!display) { |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7180 | return NAME_NOT_FOUND; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7181 | } |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7182 | |
| 7183 | DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32()); |
| 7184 | switch (setting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7185 | case DisplayColorSetting::kManaged: |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7186 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7187 | reply->writeBool(true); |
| 7188 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7189 | case DisplayColorSetting::kEnhanced: |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7190 | reply->writeBool(display->hasRenderIntent(RenderIntent::ENHANCE)); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7191 | break; |
| 7192 | default: // vendor display color setting |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7193 | reply->writeBool( |
| 7194 | display->hasRenderIntent(static_cast<RenderIntent>(setting))); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7195 | break; |
| 7196 | } |
| 7197 | return NO_ERROR; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7198 | } |
Alec Mouri | 9c58bcd | 2020-09-09 18:57:07 -0700 | [diff] [blame] | 7199 | case 1028: { // Unused. |
| 7200 | return NAME_NOT_FOUND; |
Steven Thomas | 97f1f4c | 2018-06-01 12:04:16 -0700 | [diff] [blame] | 7201 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7202 | // Deprecated, use perfetto to set the active layer tracing buffer size |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 7203 | case 1029: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7204 | return NAME_NOT_FOUND; |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 7205 | } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 7206 | // Is device color managed? |
| 7207 | case 1030: { |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 7208 | // ColorDisplayManager stil calls this |
| 7209 | reply->writeBool(true); |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 7210 | return NO_ERROR; |
| 7211 | } |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7212 | // Override default composition data space |
| 7213 | // adb shell service call SurfaceFlinger 1031 i32 1 DATASPACE_NUMBER DATASPACE_NUMBER \ |
| 7214 | // && adb shell stop zygote && adb shell start zygote |
| 7215 | // to restore: adb shell service call SurfaceFlinger 1031 i32 0 && \ |
| 7216 | // adb shell stop zygote && adb shell start zygote |
| 7217 | case 1031: { |
| 7218 | Mutex::Autolock _l(mStateLock); |
| 7219 | n = data.readInt32(); |
| 7220 | if (n) { |
| 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 | mDefaultCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7228 | } |
| 7229 | n = data.readInt32(); |
| 7230 | if (n) { |
| 7231 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 7232 | if (!validateCompositionDataspace(dataspace)) { |
| 7233 | return BAD_VALUE; |
| 7234 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7235 | mWideColorGamutCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7236 | } |
| 7237 | } else { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7238 | // restore composition data space. |
| 7239 | mDefaultCompositionDataspace = defaultCompositionDataspace; |
| 7240 | mWideColorGamutCompositionDataspace = wideColorGamutCompositionDataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7241 | } |
| 7242 | return NO_ERROR; |
| 7243 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7244 | // Deprecated, use perfetto to set layer trace flags |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 7245 | case 1033: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7246 | return NAME_NOT_FOUND; |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 7247 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 7248 | case 1034: { |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7249 | n = data.readInt32(); |
| 7250 | if (n == 0 || n == 1) { |
| 7251 | sfdo_enableRefreshRateOverlay(static_cast<bool>(n)); |
| 7252 | } else { |
| 7253 | Mutex::Autolock lock(mStateLock); |
| 7254 | reply->writeBool(isRefreshRateOverlayEnabled()); |
| 7255 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 7256 | return NO_ERROR; |
| 7257 | } |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 7258 | case 1035: { |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7259 | // Parameters: |
| 7260 | // - (required) i32 mode id. |
| 7261 | // - (optional) i64 display id. Using default display if not provided. |
| 7262 | // - (optional) f min render rate. Using mode's fps is not provided. |
| 7263 | // - (optional) f max render rate. Using mode's fps is not provided. |
| 7264 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 7265 | const int modeId = data.readInt32(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 7266 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7267 | const auto display = [&]() -> sp<IBinder> { |
| 7268 | uint64_t value; |
| 7269 | if (data.readUint64(&value) != NO_ERROR) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7270 | return getDefaultDisplayDevice()->getDisplayToken().promote(); |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7271 | } |
| 7272 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7273 | if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(value)) { |
| 7274 | return getPhysicalDisplayToken(*id); |
| 7275 | } |
| 7276 | |
| 7277 | ALOGE("Invalid physical display ID"); |
| 7278 | return nullptr; |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7279 | }(); |
| 7280 | |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7281 | const auto getFps = [&] { |
| 7282 | float value; |
| 7283 | if (data.readFloat(&value) == NO_ERROR) { |
| 7284 | return Fps::fromValue(value); |
| 7285 | } |
| 7286 | |
| 7287 | return Fps(); |
| 7288 | }; |
| 7289 | |
| 7290 | const auto minFps = getFps(); |
| 7291 | const auto maxFps = getFps(); |
| 7292 | |
Shiyong Li | 2bcece9 | 2021-08-30 20:38:50 +0000 | [diff] [blame] | 7293 | mDebugDisplayModeSetByBackdoor = false; |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7294 | const status_t result = |
| 7295 | setActiveModeFromBackdoor(display, DisplayModeId{modeId}, minFps, maxFps); |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7296 | mDebugDisplayModeSetByBackdoor = result == NO_ERROR; |
| 7297 | return result; |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 7298 | } |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7299 | // Turn on/off frame rate flexibility mode. When turned on it overrides the display |
| 7300 | // manager frame rate policy a new policy which allows switching between all refresh |
| 7301 | // rates. |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7302 | case 1036: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7303 | if (data.readInt32() > 0) { // turn on |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7304 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7305 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7306 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7307 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7308 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7309 | // This is a little racy, but not in a way that hurts anything. As |
| 7310 | // we grab the defaultMode from the display manager policy, we could |
| 7311 | // be setting a new display manager policy, leaving us using a stale |
| 7312 | // defaultMode. The defaultMode doesn't matter for the override |
| 7313 | // policy though, since we set allowGroupSwitching to true, so it's |
| 7314 | // not a problem. |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7315 | scheduler::RefreshRateSelector::OverridePolicy overridePolicy; |
| 7316 | overridePolicy.defaultMode = display->refreshRateSelector() |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7317 | .getDisplayManagerPolicy() |
| 7318 | .defaultMode; |
| 7319 | overridePolicy.allowGroupSwitching = true; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7320 | return setDesiredDisplayModeSpecsInternal(display, overridePolicy); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7321 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7322 | .get(); |
| 7323 | } else { // turn off |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7324 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7325 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7326 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7327 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7328 | return setDesiredDisplayModeSpecsInternal( |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7329 | display, |
| 7330 | scheduler::RefreshRateSelector::NoOverridePolicy{}); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7331 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7332 | .get(); |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7333 | } |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7334 | } |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 7335 | // Inject a hotplug connected event for the primary display. This will deallocate and |
| 7336 | // reallocate the display state including framebuffers. |
| 7337 | case 1037: { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7338 | const hal::HWDisplayId hwcId = |
| 7339 | (Mutex::Autolock(mStateLock), getHwComposer().getPrimaryHwcDisplayId()); |
| 7340 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 7341 | onComposerHalHotplugEvent(hwcId, DisplayHotplugEvent::CONNECTED); |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 7342 | return NO_ERROR; |
| 7343 | } |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 7344 | // Modify the max number of display frames stored within FrameTimeline |
| 7345 | case 1038: { |
| 7346 | n = data.readInt32(); |
| 7347 | if (n < 0 || n > MAX_ALLOWED_DISPLAY_FRAMES) { |
| 7348 | ALOGW("Invalid max size. Maximum allowed is %d", MAX_ALLOWED_DISPLAY_FRAMES); |
| 7349 | return BAD_VALUE; |
| 7350 | } |
| 7351 | if (n == 0) { |
| 7352 | // restore to default |
| 7353 | mFrameTimeline->reset(); |
| 7354 | return NO_ERROR; |
| 7355 | } |
| 7356 | mFrameTimeline->setMaxDisplayFrames(n); |
| 7357 | return NO_ERROR; |
| 7358 | } |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 7359 | case 1039: { |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 7360 | PhysicalDisplayId displayId = [&]() { |
| 7361 | Mutex::Autolock lock(mStateLock); |
| 7362 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 7363 | }(); |
| 7364 | |
| 7365 | auto inUid = static_cast<uid_t>(data.readInt32()); |
| 7366 | const auto refreshRate = data.readFloat(); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 7367 | mScheduler->setPreferredRefreshRateForUid(FrameRateOverride{inUid, refreshRate}); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7368 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 7369 | return NO_ERROR; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 7370 | } |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7371 | // Toggle caching feature |
| 7372 | // First argument is an int32 - nonzero enables caching and zero disables caching |
| 7373 | // Second argument is an optional uint64 - if present, then limits enabling/disabling |
| 7374 | // caching to a particular physical display |
| 7375 | case 1040: { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7376 | auto future = mScheduler->schedule([&] { |
| 7377 | n = data.readInt32(); |
| 7378 | std::optional<PhysicalDisplayId> inputId = std::nullopt; |
| 7379 | if (uint64_t inputDisplayId; data.readUint64(&inputDisplayId) == NO_ERROR) { |
| 7380 | inputId = DisplayId::fromValue<PhysicalDisplayId>(inputDisplayId); |
| 7381 | if (!inputId || getPhysicalDisplayToken(*inputId)) { |
| 7382 | ALOGE("No display with id: %" PRIu64, inputDisplayId); |
| 7383 | return NAME_NOT_FOUND; |
| 7384 | } |
| 7385 | } |
| 7386 | { |
| 7387 | Mutex::Autolock lock(mStateLock); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7388 | mLayerCachingEnabled = n != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7389 | for (const auto& [_, display] : mDisplays) { |
| 7390 | if (!inputId || *inputId == display->getPhysicalId()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7391 | display->enableLayerCaching(mLayerCachingEnabled); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7392 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7393 | } |
| 7394 | } |
| 7395 | return OK; |
| 7396 | }); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7397 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7398 | if (const status_t error = future.get(); error != OK) { |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7399 | return error; |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7400 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7401 | scheduleRepaint(); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7402 | return NO_ERROR; |
| 7403 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 7404 | case 1041: { // Transaction tracing |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7405 | if (mTransactionTracing) { |
Vishnu Nair | 640261c | 2023-09-21 21:22:51 -0700 | [diff] [blame] | 7406 | int arg = data.readInt32(); |
| 7407 | if (arg == -1) { |
Vishnu Nair | 50858e6 | 2023-10-13 23:28:24 +0000 | [diff] [blame] | 7408 | mScheduler->schedule([&]() { mTransactionTracing.reset(); }).get(); |
Vishnu Nair | 640261c | 2023-09-21 21:22:51 -0700 | [diff] [blame] | 7409 | } else if (arg > 0) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7410 | // Transaction tracing is always running but allow the user to temporarily |
| 7411 | // increase the buffer when actively debugging. |
| 7412 | mTransactionTracing->setBufferSize( |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 7413 | TransactionTracing::LEGACY_ACTIVE_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7414 | } else { |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 7415 | TransactionTraceWriter::getInstance().invoke("", /* overwrite= */ true); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7416 | mTransactionTracing->setBufferSize( |
| 7417 | TransactionTracing::CONTINUOUS_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7418 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 7419 | } |
| 7420 | reply->writeInt32(NO_ERROR); |
| 7421 | return NO_ERROR; |
| 7422 | } |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 7423 | case 1042: { // Write transaction trace to file |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7424 | if (mTransactionTracing) { |
| 7425 | mTransactionTracing->writeToFile(); |
| 7426 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7427 | reply->writeInt32(NO_ERROR); |
| 7428 | return NO_ERROR; |
| 7429 | } |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 7430 | // hdr sdr ratio overlay |
| 7431 | case 1043: { |
| 7432 | auto future = mScheduler->schedule( |
| 7433 | [&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 7434 | n = data.readInt32(); |
| 7435 | mHdrSdrRatioOverlay = n != 0; |
| 7436 | switch (n) { |
| 7437 | case 0: |
| 7438 | case 1: |
| 7439 | enableHdrSdrRatioOverlay(mHdrSdrRatioOverlay); |
| 7440 | break; |
| 7441 | default: |
| 7442 | reply->writeBool(isHdrSdrRatioOverlayEnabled()); |
| 7443 | } |
| 7444 | }); |
| 7445 | future.wait(); |
| 7446 | return NO_ERROR; |
| 7447 | } |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 7448 | |
| 7449 | case 1044: { // Enable/Disable mirroring from one display to another |
| 7450 | /* |
| 7451 | * Mirror one display onto another. |
| 7452 | * Ensure the source and destination displays are on. |
| 7453 | * Commands: |
| 7454 | * 0: Mirror one display to another |
| 7455 | * 1: Disable mirroring to a previously mirrored display |
| 7456 | * 2: Disable mirroring on previously mirrored displays |
| 7457 | * |
| 7458 | * Ex: |
| 7459 | * Get the display ids: |
| 7460 | * adb shell dumpsys SurfaceFlinger --display-id |
| 7461 | * Mirror first display to the second: |
| 7462 | * adb shell service call SurfaceFlinger 1044 i64 0 i64 4619827677550801152 i64 |
| 7463 | * 4619827677550801153 |
| 7464 | * Stop mirroring: |
| 7465 | * adb shell service call SurfaceFlinger 1044 i64 1 |
| 7466 | */ |
| 7467 | |
| 7468 | int64_t arg0 = data.readInt64(); |
| 7469 | |
| 7470 | switch (arg0) { |
| 7471 | case 0: { |
| 7472 | // Mirror arg1 to arg2 |
| 7473 | int64_t arg1 = data.readInt64(); |
| 7474 | int64_t arg2 = data.readInt64(); |
| 7475 | // Enable mirroring for one display |
| 7476 | const auto display1id = DisplayId::fromValue(arg1); |
| 7477 | auto mirrorRoot = SurfaceComposerClient::getDefault()->mirrorDisplay( |
| 7478 | display1id.value()); |
| 7479 | auto id2 = DisplayId::fromValue<PhysicalDisplayId>(arg2); |
| 7480 | const auto token2 = getPhysicalDisplayToken(*id2); |
| 7481 | ui::LayerStack layerStack; |
| 7482 | { |
| 7483 | Mutex::Autolock lock(mStateLock); |
| 7484 | sp<DisplayDevice> display = getDisplayDeviceLocked(token2); |
| 7485 | layerStack = display->getLayerStack(); |
| 7486 | } |
| 7487 | SurfaceComposerClient::Transaction t; |
| 7488 | t.setDisplayLayerStack(token2, layerStack); |
| 7489 | t.setLayer(mirrorRoot, INT_MAX); // Top-most layer |
| 7490 | t.setLayerStack(mirrorRoot, layerStack); |
| 7491 | t.apply(); |
| 7492 | |
| 7493 | mMirrorMapForDebug.emplace_or_replace(arg2, mirrorRoot); |
| 7494 | break; |
| 7495 | } |
| 7496 | |
| 7497 | case 1: { |
| 7498 | // Disable mirroring for arg1 |
| 7499 | int64_t arg1 = data.readInt64(); |
| 7500 | mMirrorMapForDebug.erase(arg1); |
| 7501 | break; |
| 7502 | } |
| 7503 | |
| 7504 | case 2: { |
| 7505 | // Disable mirroring for all displays |
| 7506 | mMirrorMapForDebug.clear(); |
| 7507 | break; |
| 7508 | } |
| 7509 | |
| 7510 | default: |
| 7511 | return BAD_VALUE; |
| 7512 | } |
| 7513 | return NO_ERROR; |
| 7514 | } |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7515 | // Inject jank |
| 7516 | // First argument is a float that describes the fraction of frame duration to jank by. |
| 7517 | // Second argument is a delay in ms for triggering the jank. This is useful for working |
| 7518 | // with tools that steal the adb connection. This argument is optional. |
| 7519 | case 1045: { |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 7520 | if (FlagManager::getInstance().vrr_config()) { |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7521 | float jankAmount = data.readFloat(); |
| 7522 | int32_t jankDelayMs = 0; |
| 7523 | if (data.readInt32(&jankDelayMs) != NO_ERROR) { |
| 7524 | jankDelayMs = 0; |
| 7525 | } |
| 7526 | |
| 7527 | const auto jankDelayDuration = Duration(std::chrono::milliseconds(jankDelayMs)); |
| 7528 | |
| 7529 | const bool jankAmountValid = jankAmount > 0.0 && jankAmount < 100.0; |
| 7530 | |
| 7531 | if (!jankAmountValid) { |
| 7532 | ALOGD("Ignoring invalid jank amount: %f", jankAmount); |
| 7533 | reply->writeInt32(BAD_VALUE); |
| 7534 | return BAD_VALUE; |
| 7535 | } |
| 7536 | |
| 7537 | (void)mScheduler->scheduleDelayed( |
| 7538 | [&, jankAmount]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 7539 | mScheduler->injectPacesetterDelay(jankAmount); |
| 7540 | scheduleComposite(FrameHint::kActive); |
| 7541 | }, |
| 7542 | jankDelayDuration.ns()); |
| 7543 | reply->writeInt32(NO_ERROR); |
| 7544 | return NO_ERROR; |
| 7545 | } |
| 7546 | return err; |
| 7547 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7548 | } |
| 7549 | } |
| 7550 | return err; |
| 7551 | } |
| 7552 | |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7553 | void SurfaceFlinger::kernelTimerChanged(bool expired) { |
| 7554 | static bool updateOverlay = |
| 7555 | property_get_bool("debug.sf.kernel_idle_timer_update_overlay", true); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7556 | if (!updateOverlay) return; |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7557 | |
| 7558 | // Update the overlay on the main thread to avoid race conditions with |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 7559 | // RefreshRateSelector::getActiveMode |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 7560 | static_cast<void>(mScheduler->schedule([=, this] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7561 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7562 | if (!display) { |
| 7563 | ALOGW("%s: default display is null", __func__); |
| 7564 | return; |
| 7565 | } |
Adrian Salido | a942af8 | 2022-02-17 19:22:31 -0800 | [diff] [blame] | 7566 | if (!display->isRefreshRateOverlayEnabled()) return; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7567 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7568 | const auto desiredModeIdOpt = |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 7569 | display->getDesiredMode().transform([](const display::DisplayModeRequest& request) { |
| 7570 | return request.mode.modePtr->getId(); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7571 | }); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7572 | |
| 7573 | const bool timerExpired = mKernelIdleTimerEnabled && expired; |
| 7574 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7575 | if (display->onKernelTimerChanged(desiredModeIdOpt, timerExpired)) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 7576 | mScheduler->scheduleFrame(); |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7577 | } |
| 7578 | })); |
| 7579 | } |
| 7580 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7581 | std::pair<std::optional<KernelIdleTimerController>, std::chrono::milliseconds> |
| 7582 | SurfaceFlinger::getKernelIdleTimerProperties(DisplayId displayId) { |
| 7583 | const bool isKernelIdleTimerHwcSupported = getHwComposer().getComposer()->isSupported( |
| 7584 | android::Hwc2::Composer::OptionalFeature::KernelIdleTimer); |
| 7585 | const auto timeout = getIdleTimerTimeout(displayId); |
| 7586 | if (isKernelIdleTimerHwcSupported) { |
| 7587 | if (const auto id = PhysicalDisplayId::tryCast(displayId); |
| 7588 | getHwComposer().hasDisplayIdleTimerCapability(*id)) { |
| 7589 | // In order to decide if we can use the HWC api for idle timer |
| 7590 | // we query DisplayCapability::DISPLAY_IDLE_TIMER directly on the composer |
| 7591 | // without relying on hasDisplayCapability. |
| 7592 | // hasDisplayCapability relies on DisplayCapabilities |
| 7593 | // which are updated after we set the PowerMode::ON. |
| 7594 | // DISPLAY_IDLE_TIMER is a display driver property |
| 7595 | // and is available before the PowerMode::ON |
| 7596 | return {KernelIdleTimerController::HwcApi, timeout}; |
| 7597 | } |
| 7598 | return {std::nullopt, timeout}; |
| 7599 | } |
| 7600 | if (getKernelIdleTimerSyspropConfig(displayId)) { |
| 7601 | return {KernelIdleTimerController::Sysprop, timeout}; |
| 7602 | } |
| 7603 | |
| 7604 | return {std::nullopt, timeout}; |
| 7605 | } |
| 7606 | |
| 7607 | void SurfaceFlinger::updateKernelIdleTimer(std::chrono::milliseconds timeout, |
| 7608 | KernelIdleTimerController controller, |
| 7609 | PhysicalDisplayId displayId) { |
| 7610 | switch (controller) { |
| 7611 | case KernelIdleTimerController::HwcApi: { |
| 7612 | getHwComposer().setIdleTimerEnabled(displayId, timeout); |
| 7613 | break; |
| 7614 | } |
| 7615 | case KernelIdleTimerController::Sysprop: { |
| 7616 | base::SetProperty(KERNEL_IDLE_TIMER_PROP, timeout > 0ms ? "true" : "false"); |
| 7617 | break; |
| 7618 | } |
| 7619 | } |
| 7620 | } |
| 7621 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7622 | void SurfaceFlinger::toggleKernelIdleTimer() { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7623 | using KernelIdleTimerAction = scheduler::RefreshRateSelector::KernelIdleTimerAction; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7624 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7625 | const auto display = getDefaultDisplayDeviceLocked(); |
| 7626 | if (!display) { |
| 7627 | ALOGW("%s: default display is null", __func__); |
| 7628 | return; |
| 7629 | } |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7630 | |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7631 | // If the support for kernel idle timer is disabled for the active display, |
| 7632 | // don't do anything. |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7633 | const std::optional<KernelIdleTimerController> kernelIdleTimerController = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7634 | display->refreshRateSelector().kernelIdleTimerController(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7635 | if (!kernelIdleTimerController.has_value()) { |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7636 | return; |
| 7637 | } |
| 7638 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7639 | const KernelIdleTimerAction action = display->refreshRateSelector().getIdleTimerAction(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7640 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7641 | switch (action) { |
| 7642 | case KernelIdleTimerAction::TurnOff: |
| 7643 | if (mKernelIdleTimerEnabled) { |
| 7644 | ATRACE_INT("KernelIdleTimer", 0); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7645 | std::chrono::milliseconds constexpr kTimerDisabledTimeout = 0ms; |
| 7646 | updateKernelIdleTimer(kTimerDisabledTimeout, kernelIdleTimerController.value(), |
| 7647 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7648 | mKernelIdleTimerEnabled = false; |
| 7649 | } |
| 7650 | break; |
| 7651 | case KernelIdleTimerAction::TurnOn: |
| 7652 | if (!mKernelIdleTimerEnabled) { |
| 7653 | ATRACE_INT("KernelIdleTimer", 1); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7654 | const std::chrono::milliseconds timeout = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7655 | display->refreshRateSelector().getIdleTimerTimeout(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7656 | updateKernelIdleTimer(timeout, kernelIdleTimerController.value(), |
| 7657 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7658 | mKernelIdleTimerEnabled = true; |
| 7659 | } |
| 7660 | break; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7661 | } |
| 7662 | } |
| 7663 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7664 | // A simple RAII class to disconnect from an ANativeWindow* when it goes out of scope |
| 7665 | class WindowDisconnector { |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7666 | public: |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7667 | WindowDisconnector(ANativeWindow* window, int api) : mWindow(window), mApi(api) {} |
| 7668 | ~WindowDisconnector() { |
| 7669 | native_window_api_disconnect(mWindow, mApi); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7670 | } |
| 7671 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7672 | private: |
| 7673 | ANativeWindow* mWindow; |
| 7674 | const int mApi; |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7675 | }; |
| 7676 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7677 | static bool hasCaptureBlackoutContentPermission() { |
| 7678 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7679 | const int pid = ipc->getCallingPid(); |
| 7680 | const int uid = ipc->getCallingUid(); |
| 7681 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 7682 | PermissionCache::checkPermission(sCaptureBlackoutContent, pid, uid); |
| 7683 | } |
| 7684 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7685 | static status_t validateScreenshotPermissions(const CaptureArgs& captureArgs) { |
| 7686 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7687 | const int pid = ipc->getCallingPid(); |
| 7688 | const int uid = ipc->getCallingUid(); |
| 7689 | if (uid == AID_GRAPHICS || PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 7690 | return OK; |
| 7691 | } |
| 7692 | |
| 7693 | // If the caller doesn't have the correct permissions but is only attempting to screenshot |
| 7694 | // itself, we allow it to continue. |
| 7695 | if (captureArgs.uid == uid) { |
| 7696 | return OK; |
| 7697 | } |
| 7698 | |
| 7699 | ALOGE("Permission Denial: can't take screenshot pid=%d, uid=%d", pid, uid); |
| 7700 | return PERMISSION_DENIED; |
| 7701 | } |
| 7702 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7703 | status_t SurfaceFlinger::setSchedFifo(bool enabled) { |
| 7704 | static constexpr int kFifoPriority = 2; |
| 7705 | static constexpr int kOtherPriority = 0; |
| 7706 | |
| 7707 | struct sched_param param = {0}; |
| 7708 | int sched_policy; |
| 7709 | if (enabled) { |
| 7710 | sched_policy = SCHED_FIFO; |
| 7711 | param.sched_priority = kFifoPriority; |
| 7712 | } else { |
| 7713 | sched_policy = SCHED_OTHER; |
| 7714 | param.sched_priority = kOtherPriority; |
| 7715 | } |
| 7716 | |
| 7717 | if (sched_setscheduler(0, sched_policy, ¶m) != 0) { |
| 7718 | return -errno; |
| 7719 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7720 | |
| 7721 | return NO_ERROR; |
| 7722 | } |
| 7723 | |
| 7724 | status_t SurfaceFlinger::setSchedAttr(bool enabled) { |
| 7725 | static const unsigned int kUclampMin = |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 7726 | base::GetUintProperty<unsigned int>("ro.surface_flinger.uclamp.min"s, 0U); |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7727 | |
| 7728 | if (!kUclampMin) { |
| 7729 | // uclamp.min set to 0 (default), skip setting |
| 7730 | return NO_ERROR; |
| 7731 | } |
| 7732 | |
| 7733 | // Currently, there is no wrapper in bionic: b/183240349. |
| 7734 | struct sched_attr { |
| 7735 | uint32_t size; |
| 7736 | uint32_t sched_policy; |
| 7737 | uint64_t sched_flags; |
| 7738 | int32_t sched_nice; |
| 7739 | uint32_t sched_priority; |
| 7740 | uint64_t sched_runtime; |
| 7741 | uint64_t sched_deadline; |
| 7742 | uint64_t sched_period; |
| 7743 | uint32_t sched_util_min; |
| 7744 | uint32_t sched_util_max; |
| 7745 | }; |
| 7746 | |
| 7747 | sched_attr attr = {}; |
| 7748 | attr.size = sizeof(attr); |
| 7749 | |
| 7750 | attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP); |
| 7751 | attr.sched_util_min = enabled ? kUclampMin : 0; |
| 7752 | attr.sched_util_max = 1024; |
| 7753 | |
| 7754 | if (syscall(__NR_sched_setattr, 0, &attr, 0)) { |
| 7755 | return -errno; |
| 7756 | } |
| 7757 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7758 | return NO_ERROR; |
| 7759 | } |
| 7760 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7761 | namespace { |
| 7762 | |
| 7763 | ui::Dataspace pickBestDataspace(ui::Dataspace requestedDataspace, const DisplayDevice* display, |
| 7764 | bool capturingHdrLayers, bool hintForSeamlessTransition) { |
| 7765 | if (requestedDataspace != ui::Dataspace::UNKNOWN || display == nullptr) { |
| 7766 | return requestedDataspace; |
| 7767 | } |
| 7768 | |
| 7769 | const auto& state = display->getCompositionDisplay()->getState(); |
| 7770 | |
| 7771 | const auto dataspaceForColorMode = ui::pickDataspaceFor(state.colorMode); |
| 7772 | |
Alec Mouri | 2964072 | 2023-05-16 23:22:41 +0000 | [diff] [blame] | 7773 | // TODO: Enable once HDR screenshots are ready. |
| 7774 | if constexpr (/* DISABLES CODE */ (false)) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7775 | // For now since we only support 8-bit screenshots, just use HLG and |
| 7776 | // assume that 1.0 >= display max luminance. This isn't quite as future |
| 7777 | // proof as PQ is, but is good enough. |
| 7778 | // Consider using PQ once we support 16-bit screenshots and we're able |
| 7779 | // to consistently supply metadata to image encoders. |
| 7780 | return ui::Dataspace::BT2020_HLG; |
| 7781 | } |
| 7782 | |
| 7783 | return dataspaceForColorMode; |
| 7784 | } |
| 7785 | |
| 7786 | } // namespace |
| 7787 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7788 | static void invokeScreenCaptureError(const status_t status, |
| 7789 | const sp<IScreenCaptureListener>& captureListener) { |
| 7790 | ScreenCaptureResults captureResults; |
| 7791 | captureResults.fenceResult = base::unexpected(status); |
| 7792 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7793 | } |
| 7794 | |
| 7795 | void SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, |
| 7796 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7797 | ATRACE_CALL(); |
| 7798 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7799 | status_t validate = validateScreenshotPermissions(args); |
| 7800 | if (validate != OK) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7801 | invokeScreenCaptureError(validate, captureListener); |
| 7802 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7803 | } |
| 7804 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7805 | if (!args.displayToken) { |
| 7806 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7807 | return; |
| 7808 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7809 | |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 7810 | if (args.captureSecureLayers && !hasCaptureBlackoutContentPermission()) { |
| 7811 | ALOGE("Attempting to capture secure layers without CAPTURE_BLACKOUT_CONTENT"); |
| 7812 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 7813 | return; |
| 7814 | } |
| 7815 | |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7816 | wp<const DisplayDevice> displayWeak; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7817 | ui::LayerStack layerStack; |
| 7818 | ui::Size reqSize(args.width, args.height); |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7819 | std::unordered_set<uint32_t> excludeLayerIds; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7820 | { |
| 7821 | Mutex::Autolock lock(mStateLock); |
| 7822 | sp<DisplayDevice> display = getDisplayDeviceLocked(args.displayToken); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7823 | if (!display) { |
| 7824 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7825 | return; |
| 7826 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7827 | displayWeak = display; |
| 7828 | layerStack = display->getLayerStack(); |
| 7829 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7830 | // 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] | 7831 | if (args.width == 0 || args.height == 0) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7832 | reqSize = display->getLayerStackSpaceRect().getSize(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7833 | } |
| 7834 | |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7835 | for (const auto& handle : args.excludeHandles) { |
| 7836 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7837 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7838 | excludeLayerIds.emplace(excludeLayer); |
| 7839 | } else { |
| 7840 | ALOGW("Invalid layer handle passed as excludeLayer to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7841 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7842 | return; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7843 | } |
| 7844 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7845 | } |
| 7846 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7847 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
Alec Mouri | c44a1ff | 2023-05-19 23:49:05 +0000 | [diff] [blame] | 7848 | return DisplayRenderArea::create(displayWeak, args.sourceCrop, reqSize, args.dataspace, |
Melody Hsu | 70a63e5 | 2023-11-17 19:49:12 +0000 | [diff] [blame] | 7849 | args.hintForSeamlessTransition, args.captureSecureLayers); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7850 | }); |
| 7851 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7852 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7853 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7854 | getLayerSnapshots = |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7855 | getLayerSnapshotsForScreenshots(layerStack, args.uid, std::move(excludeLayerIds)); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7856 | } else { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7857 | auto traverseLayers = [this, args, excludeLayerIds, |
| 7858 | layerStack](const LayerVector::Visitor& visitor) { |
| 7859 | traverseLayersInLayerStack(layerStack, args.uid, std::move(excludeLayerIds), visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7860 | }; |
| 7861 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7862 | } |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 7863 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7864 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, args.pixelFormat, |
| 7865 | args.allowProtected, args.grayscale, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7866 | } |
| 7867 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7868 | void SurfaceFlinger::captureDisplay(DisplayId displayId, const CaptureArgs& args, |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7869 | const sp<IScreenCaptureListener>& captureListener) { |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7870 | ui::LayerStack layerStack; |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7871 | wp<const DisplayDevice> displayWeak; |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7872 | ui::Size size; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7873 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7874 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7875 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7876 | const auto display = getDisplayDeviceLocked(displayId); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7877 | if (!display) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7878 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7879 | return; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7880 | } |
| 7881 | |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7882 | displayWeak = display; |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7883 | layerStack = display->getLayerStack(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7884 | size = display->getLayerStackSpaceRect().getSize(); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7885 | } |
| 7886 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7887 | size.width *= args.frameScaleX; |
| 7888 | size.height *= args.frameScaleY; |
| 7889 | |
| 7890 | // We could query a real value for this but it'll be a long, long time until we support |
| 7891 | // displays that need upwards of 1GB per buffer so... |
| 7892 | constexpr auto kMaxTextureSize = 16384; |
| 7893 | if (size.width <= 0 || size.height <= 0 || size.width >= kMaxTextureSize || |
| 7894 | size.height >= kMaxTextureSize) { |
| 7895 | ALOGE("capture display resolved to invalid size %d x %d", size.width, size.height); |
| 7896 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7897 | return; |
| 7898 | } |
| 7899 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7900 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7901 | return DisplayRenderArea::create(displayWeak, Rect(), size, args.dataspace, |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7902 | args.hintForSeamlessTransition, |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7903 | false /* captureSecureLayers */); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7904 | }); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7905 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7906 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7907 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7908 | getLayerSnapshots = getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID, |
| 7909 | /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7910 | } else { |
| 7911 | auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7912 | traverseLayersInLayerStack(layerStack, CaptureArgs::UNSET_UID, {}, visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7913 | }; |
| 7914 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7915 | } |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7916 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7917 | if (captureListener == nullptr) { |
| 7918 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7919 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7920 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7921 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7922 | |
| 7923 | constexpr bool kAllowProtected = false; |
| 7924 | constexpr bool kGrayscale = false; |
| 7925 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7926 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, size, args.pixelFormat, |
| 7927 | kAllowProtected, kGrayscale, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7928 | } |
| 7929 | |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 7930 | ScreenCaptureResults SurfaceFlinger::captureLayersSync(const LayerCaptureArgs& args) { |
| 7931 | sp<SyncScreenCaptureListener> captureListener = sp<SyncScreenCaptureListener>::make(); |
| 7932 | captureLayers(args, captureListener); |
| 7933 | return captureListener->waitForResults(); |
| 7934 | } |
| 7935 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7936 | void SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, |
| 7937 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7938 | ATRACE_CALL(); |
| 7939 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7940 | status_t validate = validateScreenshotPermissions(args); |
| 7941 | if (validate != OK) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7942 | invokeScreenCaptureError(validate, captureListener); |
| 7943 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7944 | } |
| 7945 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7946 | ui::Size reqSize; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7947 | sp<Layer> parent; |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7948 | Rect crop(args.sourceCrop); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7949 | std::unordered_set<uint32_t> excludeLayerIds; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7950 | ui::Dataspace dataspace = args.dataspace; |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7951 | |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 7952 | if (args.captureSecureLayers && !hasCaptureBlackoutContentPermission()) { |
| 7953 | ALOGE("Attempting to capture secure layers without CAPTURE_BLACKOUT_CONTENT"); |
| 7954 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 7955 | return; |
| 7956 | } |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7957 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7958 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7959 | Mutex::Autolock lock(mStateLock); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7960 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 7961 | parent = LayerHandle::getLayer(args.layerHandle); |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7962 | if (parent == nullptr) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7963 | ALOGE("captureLayers called with an invalid or removed parent"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7964 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7965 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7966 | } |
| 7967 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 7968 | Rect parentSourceBounds = parent->getCroppedBufferSize(parent->getDrawingState()); |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7969 | if (args.sourceCrop.width() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7970 | crop.left = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7971 | crop.right = parentSourceBounds.getWidth(); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7972 | } |
| 7973 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7974 | if (args.sourceCrop.height() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7975 | crop.top = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7976 | crop.bottom = parentSourceBounds.getHeight(); |
| 7977 | } |
| 7978 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7979 | if (crop.isEmpty() || args.frameScaleX <= 0.0f || args.frameScaleY <= 0.0f) { |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7980 | // Error out if the layer has no source bounds (i.e. they are boundless) and a source |
| 7981 | // crop was not specified, or an invalid frame scale was provided. |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7982 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7983 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7984 | } |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7985 | reqSize = ui::Size(crop.width() * args.frameScaleX, crop.height() * args.frameScaleY); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7986 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7987 | for (const auto& handle : args.excludeHandles) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7988 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7989 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7990 | excludeLayerIds.emplace(excludeLayer); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7991 | } else { |
| 7992 | ALOGW("Invalid layer handle passed as excludeLayer to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7993 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7994 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7995 | } |
| 7996 | } |
| 7997 | } // mStateLock |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7998 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7999 | // really small crop or frameScale |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 8000 | if (reqSize.width <= 0 || reqSize.height <= 0) { |
| 8001 | ALOGW("Failed to captureLayes: crop or scale too small"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8002 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8003 | return; |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 8004 | } |
| 8005 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 8006 | bool childrenOnly = args.childrenOnly; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 8007 | RenderAreaFuture renderAreaFuture = ftl::defer([=, this]() -> std::unique_ptr<RenderArea> { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8008 | ui::Transform layerTransform; |
| 8009 | Rect layerBufferSize; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8010 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8011 | frontend::LayerSnapshot* snapshot = |
| 8012 | mLayerSnapshotBuilder.getSnapshot(parent->getSequence()); |
| 8013 | if (!snapshot) { |
| 8014 | ALOGW("Couldn't find layer snapshot for %d", parent->getSequence()); |
| 8015 | } else { |
| 8016 | layerTransform = snapshot->localTransform; |
| 8017 | layerBufferSize = snapshot->bufferSize; |
| 8018 | } |
| 8019 | } else { |
| 8020 | layerTransform = parent->getTransform(); |
| 8021 | layerBufferSize = parent->getBufferSize(parent->getDrawingState()); |
| 8022 | } |
| 8023 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 8024 | return std::make_unique<LayerRenderArea>(*this, parent, crop, reqSize, dataspace, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8025 | childrenOnly, args.captureSecureLayers, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8026 | layerTransform, layerBufferSize, |
| 8027 | args.hintForSeamlessTransition); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 8028 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8029 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8030 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8031 | std::optional<FloatRect> parentCrop = std::nullopt; |
| 8032 | if (args.childrenOnly) { |
| 8033 | parentCrop = crop.isEmpty() ? FloatRect(0, 0, reqSize.width, reqSize.height) |
| 8034 | : crop.toFloatRect(); |
| 8035 | } |
| 8036 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8037 | getLayerSnapshots = getLayerSnapshotsForScreenshots(parent->sequence, args.uid, |
| 8038 | std::move(excludeLayerIds), |
| 8039 | args.childrenOnly, parentCrop); |
| 8040 | } else { |
| 8041 | auto traverseLayers = [parent, args, excludeLayerIds](const LayerVector::Visitor& visitor) { |
| 8042 | parent->traverseChildrenInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
| 8043 | if (!layer->isVisible()) { |
| 8044 | return; |
| 8045 | } else if (args.childrenOnly && layer == parent.get()) { |
| 8046 | return; |
| 8047 | } else if (args.uid != CaptureArgs::UNSET_UID && args.uid != layer->getOwnerUid()) { |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 8048 | return; |
| 8049 | } |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 8050 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8051 | auto p = sp<Layer>::fromExisting(layer); |
| 8052 | while (p != nullptr) { |
| 8053 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 8054 | return; |
| 8055 | } |
| 8056 | p = p->getParent(); |
| 8057 | } |
| 8058 | |
| 8059 | visitor(layer); |
| 8060 | }); |
| 8061 | }; |
| 8062 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 8063 | } |
Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 8064 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 8065 | if (captureListener == nullptr) { |
| 8066 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8067 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8068 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 8069 | } |
| 8070 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8071 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, args.pixelFormat, |
| 8072 | args.allowProtected, args.grayscale, captureListener); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8073 | } |
| 8074 | |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8075 | bool SurfaceFlinger::layersHasProtectedLayer( |
| 8076 | const std::vector<std::pair<Layer*, sp<LayerFE>>>& layers) const { |
| 8077 | bool protectedLayerFound = false; |
| 8078 | for (auto& [_, layerFe] : layers) { |
| 8079 | protectedLayerFound |= |
| 8080 | (layerFe->mSnapshot->isVisible && layerFe->mSnapshot->hasProtectedContent); |
| 8081 | if (protectedLayerFound) { |
| 8082 | break; |
| 8083 | } |
| 8084 | } |
| 8085 | return protectedLayerFound; |
| 8086 | } |
| 8087 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8088 | void SurfaceFlinger::captureScreenCommon(RenderAreaFuture renderAreaFuture, |
| 8089 | GetLayerSnapshotsFunction getLayerSnapshots, |
| 8090 | ui::Size bufferSize, ui::PixelFormat reqPixelFormat, |
| 8091 | bool allowProtected, bool grayscale, |
| 8092 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8093 | ATRACE_CALL(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 8094 | |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 8095 | if (exceedsMaxRenderTargetSize(bufferSize.getWidth(), bufferSize.getHeight())) { |
| 8096 | ALOGE("Attempted to capture screen with size (%" PRId32 ", %" PRId32 |
| 8097 | ") that exceeds render target size limit.", |
| 8098 | bufferSize.getWidth(), bufferSize.getHeight()); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8099 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8100 | return; |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 8101 | } |
| 8102 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 8103 | // Loop over all visible layers to see whether there's any protected layer. A protected layer is |
| 8104 | // typically a layer with DRM contents, or have the GRALLOC_USAGE_PROTECTED set on the buffer. |
| 8105 | // A protected layer has no implication on whether it's secure, which is explicitly set by |
| 8106 | // application to avoid being screenshot or drawn via unsecure display. |
| 8107 | const bool supportsProtected = getRenderEngine().supportsProtectedContent(); |
| 8108 | bool hasProtectedLayer = false; |
| 8109 | if (allowProtected && supportsProtected) { |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8110 | // Snapshots must be taken from the main thread. |
| 8111 | auto layers = mScheduler->schedule([=]() { return getLayerSnapshots(); }).get(); |
| 8112 | hasProtectedLayer = layersHasProtectedLayer(layers); |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 8113 | } |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8114 | const bool isProtected = hasProtectedLayer && allowProtected && supportsProtected; |
Richard Liu | cbcb895 | 2020-04-08 10:51:55 +0000 | [diff] [blame] | 8115 | const uint32_t usage = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER | |
| 8116 | GRALLOC_USAGE_HW_TEXTURE | |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8117 | (isProtected ? GRALLOC_USAGE_PROTECTED |
| 8118 | : GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8119 | sp<GraphicBuffer> buffer = |
| 8120 | getFactory().createGraphicBuffer(bufferSize.getWidth(), bufferSize.getHeight(), |
| 8121 | static_cast<android_pixel_format>(reqPixelFormat), |
| 8122 | 1 /* layerCount */, usage, "screenshot"); |
Alec Mouri | 7013b6f | 2021-02-12 11:16:54 -0800 | [diff] [blame] | 8123 | |
| 8124 | const status_t bufferStatus = buffer->initCheck(); |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 8125 | if (bufferStatus != OK) { |
| 8126 | // Animations may end up being really janky, but don't crash here. |
| 8127 | // Otherwise an irreponsible process may cause an SF crash by allocating |
| 8128 | // too much. |
| 8129 | ALOGE("%s: Buffer failed to allocate: %d", __func__, bufferStatus); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8130 | invokeScreenCaptureError(bufferStatus, captureListener); |
| 8131 | return; |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 8132 | } |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8133 | const std::shared_ptr<renderengine::ExternalTexture> texture = std::make_shared< |
| 8134 | renderengine::impl::ExternalTexture>(buffer, getRenderEngine(), |
| 8135 | renderengine::impl::ExternalTexture::Usage:: |
| 8136 | WRITEABLE); |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8137 | auto futureFence = |
| 8138 | captureScreenshot(std::move(renderAreaFuture), getLayerSnapshots, texture, |
| 8139 | false /* regionSampling */, grayscale, isProtected, captureListener); |
| 8140 | futureFence.get(); |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 8141 | } |
| 8142 | |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8143 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenshot( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8144 | RenderAreaFuture renderAreaFuture, GetLayerSnapshotsFunction getLayerSnapshots, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 8145 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8146 | bool grayscale, bool isProtected, const sp<IScreenCaptureListener>& captureListener) { |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 8147 | ATRACE_CALL(); |
| 8148 | |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8149 | auto takeScreenshotFn = [=, this, renderAreaFuture = std::move(renderAreaFuture)]() REQUIRES( |
| 8150 | kMainThreadContext) mutable -> ftl::SharedFuture<FenceResult> { |
| 8151 | ScreenCaptureResults captureResults; |
| 8152 | std::shared_ptr<RenderArea> renderArea = renderAreaFuture.get(); |
| 8153 | if (!renderArea) { |
| 8154 | ALOGW("Skipping screen capture because of invalid render area."); |
| 8155 | if (captureListener) { |
| 8156 | captureResults.fenceResult = base::unexpected(NO_MEMORY); |
| 8157 | captureListener->onScreenCaptureCompleted(captureResults); |
| 8158 | } |
| 8159 | return ftl::yield<FenceResult>(base::unexpected(NO_ERROR)).share(); |
| 8160 | } |
| 8161 | |
| 8162 | ftl::SharedFuture<FenceResult> renderFuture; |
| 8163 | renderArea->render([&]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 8164 | renderFuture = renderScreenImpl(renderArea, getLayerSnapshots, buffer, regionSampling, |
| 8165 | grayscale, isProtected, captureResults); |
| 8166 | }); |
| 8167 | |
| 8168 | if (captureListener) { |
| 8169 | // Defer blocking on renderFuture back to the Binder thread. |
| 8170 | return ftl::Future(std::move(renderFuture)) |
| 8171 | .then([captureListener, captureResults = std::move(captureResults)]( |
| 8172 | FenceResult fenceResult) mutable -> FenceResult { |
| 8173 | captureResults.fenceResult = std::move(fenceResult); |
Nolan Scobie | 1d2deb2 | 2022-11-18 12:57:47 -0500 | [diff] [blame] | 8174 | captureListener->onScreenCaptureCompleted(captureResults); |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8175 | return base::unexpected(NO_ERROR); |
| 8176 | }) |
| 8177 | .share(); |
| 8178 | } |
| 8179 | return renderFuture; |
| 8180 | }; |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 8181 | |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8182 | auto future = |
| 8183 | mScheduler->schedule(FTL_FAKE_GUARD(kMainThreadContext, std::move(takeScreenshotFn))); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 8184 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8185 | // Flatten nested futures. |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 8186 | auto chain = ftl::Future(std::move(future)).then([](ftl::SharedFuture<FenceResult> future) { |
| 8187 | return future; |
| 8188 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8189 | |
| 8190 | return chain.share(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 8191 | } |
| 8192 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 8193 | ftl::SharedFuture<FenceResult> SurfaceFlinger::renderScreenImpl( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8194 | std::shared_ptr<const RenderArea> renderArea, GetLayerSnapshotsFunction getLayerSnapshots, |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 8195 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8196 | bool grayscale, bool isProtected, ScreenCaptureResults& captureResults) { |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 8197 | ATRACE_CALL(); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8198 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8199 | auto layers = getLayerSnapshots(); |
Alec Mouri | b4814de | 2023-09-11 22:09:03 +0000 | [diff] [blame] | 8200 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8201 | for (auto& [_, layerFE] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8202 | frontend::LayerSnapshot* snapshot = layerFE->mSnapshot.get(); |
| 8203 | captureResults.capturedSecureLayers |= (snapshot->isVisible && snapshot->isSecure); |
| 8204 | captureResults.capturedHdrLayers |= isHdrLayer(*snapshot); |
| 8205 | layerFE->mSnapshot->geomLayerTransform = |
| 8206 | renderArea->getTransform() * layerFE->mSnapshot->geomLayerTransform; |
Patrick Williams | c6e0cce | 2023-02-28 23:04:45 -0600 | [diff] [blame] | 8207 | layerFE->mSnapshot->geomInverseLayerTransform = |
| 8208 | layerFE->mSnapshot->geomLayerTransform.inverse(); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8209 | } |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8210 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8211 | auto capturedBuffer = buffer; |
| 8212 | |
| 8213 | auto requestedDataspace = renderArea->getReqDataSpace(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8214 | auto parent = renderArea->getParentLayer(); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 8215 | auto renderIntent = RenderIntent::TONE_MAP_COLORIMETRIC; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 8216 | auto sdrWhitePointNits = DisplayDevice::sDefaultMaxLumiance; |
| 8217 | auto displayBrightnessNits = DisplayDevice::sDefaultMaxLumiance; |
| 8218 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8219 | captureResults.capturedDataspace = requestedDataspace; |
| 8220 | |
| 8221 | { |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8222 | Mutex::Autolock lock(mStateLock); |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8223 | const DisplayDevice* display = nullptr; |
| 8224 | if (parent) { |
| 8225 | display = findDisplay([layerStack = parent->getLayerStack()](const auto& display) { |
| 8226 | return display.getLayerStack() == layerStack; |
| 8227 | }).get(); |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8228 | } |
| 8229 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8230 | if (display == nullptr) { |
| 8231 | display = renderArea->getDisplayDevice().get(); |
| 8232 | } |
| 8233 | |
| 8234 | if (display == nullptr) { |
| 8235 | display = getDefaultDisplayDeviceLocked().get(); |
| 8236 | } |
| 8237 | |
| 8238 | if (display != nullptr) { |
| 8239 | const auto& state = display->getCompositionDisplay()->getState(); |
| 8240 | captureResults.capturedDataspace = |
| 8241 | pickBestDataspace(requestedDataspace, display, captureResults.capturedHdrLayers, |
| 8242 | renderArea->getHintForSeamlessTransition()); |
| 8243 | sdrWhitePointNits = state.sdrWhitePointNits; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8244 | |
Alec Mouri | b4814de | 2023-09-11 22:09:03 +0000 | [diff] [blame] | 8245 | // TODO(b/298219334): Clean this up once we verify this doesn't break anything |
| 8246 | static constexpr bool kScreenshotsDontDim = true; |
| 8247 | |
| 8248 | if (kScreenshotsDontDim && !captureResults.capturedHdrLayers) { |
| 8249 | displayBrightnessNits = sdrWhitePointNits; |
| 8250 | } else { |
| 8251 | displayBrightnessNits = state.displayBrightnessNits; |
| 8252 | // Only clamp the display brightness if this is not a seamless transition. Otherwise |
| 8253 | // for seamless transitions it's important to match the current display state as the |
| 8254 | // buffer will be shown under these same conditions, and we want to avoid any |
| 8255 | // flickers |
| 8256 | if (sdrWhitePointNits > 1.0f && !renderArea->getHintForSeamlessTransition()) { |
| 8257 | // Restrict the amount of HDR "headroom" in the screenshot to avoid over-dimming |
| 8258 | // the SDR portion. 2.0 chosen by experimentation |
| 8259 | constexpr float kMaxScreenshotHeadroom = 2.0f; |
| 8260 | displayBrightnessNits = std::min(sdrWhitePointNits * kMaxScreenshotHeadroom, |
| 8261 | displayBrightnessNits); |
| 8262 | } |
Alec Mouri | 5e488f8 | 2023-09-15 01:27:49 +0000 | [diff] [blame] | 8263 | } |
Alec Mouri | ffb3221 | 2023-09-16 19:29:15 +0000 | [diff] [blame] | 8264 | |
| 8265 | // Screenshots leaving the device should be colorimetric |
| 8266 | if (requestedDataspace == ui::Dataspace::UNKNOWN && |
| 8267 | renderArea->getHintForSeamlessTransition()) { |
Alec Mouri | 5e488f8 | 2023-09-15 01:27:49 +0000 | [diff] [blame] | 8268 | renderIntent = state.renderIntent; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8269 | } |
| 8270 | } |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8271 | } |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8272 | |
| 8273 | captureResults.buffer = capturedBuffer->getBuffer(); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8274 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8275 | ui::LayerStack layerStack{ui::DEFAULT_LAYER_STACK}; |
| 8276 | if (!layers.empty()) { |
| 8277 | const sp<LayerFE>& layerFE = layers.back().second; |
| 8278 | layerStack = layerFE->getCompositionState()->outputFilter.layerStack; |
Yichi Chen | 40773d9 | 2020-04-01 10:10:18 +0800 | [diff] [blame] | 8279 | } |
Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 8280 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8281 | auto copyLayerFEs = [&layers]() { |
| 8282 | std::vector<sp<compositionengine::LayerFE>> layerFEs; |
| 8283 | layerFEs.reserve(layers.size()); |
| 8284 | for (const auto& [_, layerFE] : layers) { |
| 8285 | layerFEs.push_back(layerFE); |
| 8286 | } |
| 8287 | return layerFEs; |
| 8288 | }; |
| 8289 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8290 | auto present = [this, buffer = capturedBuffer, dataspace = captureResults.capturedDataspace, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8291 | sdrWhitePointNits, displayBrightnessNits, grayscale, isProtected, |
| 8292 | layerFEs = copyLayerFEs(), layerStack, regionSampling, |
| 8293 | renderArea = std::move(renderArea), renderIntent]() -> FenceResult { |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8294 | std::unique_ptr<compositionengine::CompositionEngine> compositionEngine = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8295 | mFactory.createCompositionEngine(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8296 | compositionEngine->setRenderEngine(mRenderEngine.get()); |
| 8297 | |
| 8298 | compositionengine::Output::ColorProfile colorProfile{.dataspace = dataspace, |
| 8299 | .renderIntent = renderIntent}; |
| 8300 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8301 | float targetBrightness = 1.0f; |
| 8302 | if (dataspace == ui::Dataspace::BT2020_HLG) { |
| 8303 | const float maxBrightnessNits = displayBrightnessNits / sdrWhitePointNits * 203; |
| 8304 | // With a low dimming ratio, don't fit the entire curve. Otherwise mixed content |
| 8305 | // will appear way too bright. |
| 8306 | if (maxBrightnessNits < 1000.f) { |
| 8307 | targetBrightness = 1000.f / maxBrightnessNits; |
| 8308 | } |
| 8309 | } |
| 8310 | |
Alec Mouri | ffb3221 | 2023-09-16 19:29:15 +0000 | [diff] [blame] | 8311 | // Screenshots leaving the device must not dim in gamma space. |
| 8312 | const bool dimInGammaSpaceForEnhancedScreenshots = mDimInGammaSpaceForEnhancedScreenshots && |
| 8313 | renderArea->getHintForSeamlessTransition(); |
| 8314 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8315 | std::shared_ptr<ScreenCaptureOutput> output = createScreenCaptureOutput( |
| 8316 | ScreenCaptureOutputArgs{.compositionEngine = *compositionEngine, |
| 8317 | .colorProfile = colorProfile, |
| 8318 | .renderArea = *renderArea, |
| 8319 | .layerStack = layerStack, |
| 8320 | .buffer = std::move(buffer), |
| 8321 | .sdrWhitePointNits = sdrWhitePointNits, |
| 8322 | .displayBrightnessNits = displayBrightnessNits, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8323 | .targetBrightness = targetBrightness, |
Alec Mouri | 7dae9c1 | 2023-07-13 19:40:53 +0000 | [diff] [blame] | 8324 | .regionSampling = regionSampling, |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 8325 | .treat170mAsSrgb = mTreat170mAsSrgb, |
| 8326 | .dimInGammaSpaceForEnhancedScreenshots = |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8327 | dimInGammaSpaceForEnhancedScreenshots, |
| 8328 | .isProtected = isProtected}); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8329 | |
| 8330 | const float colorSaturation = grayscale ? 0 : 1; |
| 8331 | compositionengine::CompositionRefreshArgs refreshArgs{ |
| 8332 | .outputs = {output}, |
| 8333 | .layers = std::move(layerFEs), |
| 8334 | .updatingOutputGeometryThisFrame = true, |
| 8335 | .updatingGeometryThisFrame = true, |
| 8336 | .colorTransformMatrix = calculateColorMatrix(colorSaturation), |
| 8337 | }; |
| 8338 | compositionEngine->present(refreshArgs); |
| 8339 | |
| 8340 | return output->getRenderSurface()->getClientTargetAcquireFence(); |
| 8341 | }; |
| 8342 | |
| 8343 | // If RenderEngine is threaded, we can safely call CompositionEngine::present off the main |
| 8344 | // thread as the RenderEngine::drawLayers call will run on RenderEngine's thread. Otherwise, |
| 8345 | // we need RenderEngine to run on the main thread so we call CompositionEngine::present |
| 8346 | // immediately. |
| 8347 | // |
| 8348 | // TODO(b/196334700) Once we use RenderEngineThreaded everywhere we can always defer the call |
| 8349 | // to CompositionEngine::present. |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 8350 | auto presentFuture = mRenderEngine->isThreaded() ? ftl::defer(std::move(present)).share() |
| 8351 | : ftl::yield(present()).share(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8352 | |
| 8353 | for (auto& [layer, layerFE] : layers) { |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 8354 | layer->onLayerDisplayed(presentFuture, ui::INVALID_LAYER_STACK, |
| 8355 | [layerFE = std::move(layerFE)](FenceResult) { |
| 8356 | if (FlagManager::getInstance() |
| 8357 | .screenshot_fence_preservation()) { |
| 8358 | const auto compositionResult = |
| 8359 | layerFE->stealCompositionResult(); |
| 8360 | const auto& fences = compositionResult.releaseFences; |
| 8361 | // CompositionEngine may choose to cull layers that |
| 8362 | // aren't visible, so pass a non-fence. |
| 8363 | return fences.empty() ? Fence::NO_FENCE |
| 8364 | : fences.back().first.get(); |
| 8365 | } else { |
| 8366 | return layerFE->stealCompositionResult() |
| 8367 | .releaseFences.back() |
| 8368 | .first.get(); |
| 8369 | } |
| 8370 | }); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8371 | } |
| 8372 | |
| 8373 | return presentFuture; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 8374 | } |
| 8375 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8376 | void SurfaceFlinger::traverseLegacyLayers(const LayerVector::Visitor& visitor) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8377 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8378 | for (auto& layer : mLegacyLayers) { |
| 8379 | visitor(layer.second.get()); |
| 8380 | } |
| 8381 | } else { |
| 8382 | mDrawingState.traverse(visitor); |
| 8383 | } |
| 8384 | } |
| 8385 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 8386 | // --------------------------------------------------------------------------- |
| 8387 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 8388 | void SurfaceFlinger::State::traverse(const LayerVector::Visitor& visitor) const { |
| 8389 | layersSortedByZ.traverse(visitor); |
| 8390 | } |
| 8391 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 8392 | void SurfaceFlinger::State::traverseInZOrder(const LayerVector::Visitor& visitor) const { |
| 8393 | layersSortedByZ.traverseInZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 8394 | } |
| 8395 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 8396 | void SurfaceFlinger::State::traverseInReverseZOrder(const LayerVector::Visitor& visitor) const { |
| 8397 | layersSortedByZ.traverseInReverseZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 8398 | } |
| 8399 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8400 | void SurfaceFlinger::traverseLayersInLayerStack(ui::LayerStack layerStack, const int32_t uid, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8401 | std::unordered_set<uint32_t> excludeLayerIds, |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 8402 | const LayerVector::Visitor& visitor) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8403 | // We loop through the first level of layers without traversing, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 8404 | // as we need to determine which layers belong to the requested display. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8405 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 8406 | if (layer->getLayerStack() != layerStack) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8407 | continue; |
| 8408 | } |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 8409 | // relative layers are traversed in Layer::traverseInZOrder |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8410 | layer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 8411 | if (layer->isInternalDisplayOverlay()) { |
Adrian Roos | 8acf5a0 | 2018-01-17 21:28:19 +0100 | [diff] [blame] | 8412 | return; |
| 8413 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8414 | if (!layer->isVisible()) { |
| 8415 | return; |
| 8416 | } |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8417 | if (uid != CaptureArgs::UNSET_UID && layer->getOwnerUid() != uid) { |
| 8418 | return; |
| 8419 | } |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8420 | |
| 8421 | if (!excludeLayerIds.empty()) { |
| 8422 | auto p = sp<Layer>::fromExisting(layer); |
| 8423 | while (p != nullptr) { |
| 8424 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 8425 | return; |
| 8426 | } |
| 8427 | p = p->getParent(); |
| 8428 | } |
| 8429 | } |
| 8430 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8431 | visitor(layer); |
| 8432 | }); |
| 8433 | } |
| 8434 | } |
| 8435 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8436 | ftl::Optional<scheduler::FrameRateMode> SurfaceFlinger::getPreferredDisplayMode( |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8437 | PhysicalDisplayId displayId, DisplayModeId defaultModeId) const { |
| 8438 | if (const auto schedulerMode = mScheduler->getPreferredDisplayMode(); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8439 | schedulerMode.modePtr->getPhysicalDisplayId() == displayId) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8440 | return schedulerMode; |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8441 | } |
| 8442 | |
| 8443 | return mPhysicalDisplays.get(displayId) |
| 8444 | .transform(&PhysicalDisplay::snapshotRef) |
| 8445 | .and_then([&](const display::DisplaySnapshot& snapshot) { |
| 8446 | return snapshot.displayModes().get(defaultModeId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 8447 | }) |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8448 | .transform([](const DisplayModePtr& modePtr) { |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 8449 | return scheduler::FrameRateMode{modePtr->getPeakFps(), ftl::as_non_null(modePtr)}; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8450 | }); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8451 | } |
| 8452 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8453 | status_t SurfaceFlinger::setDesiredDisplayModeSpecsInternal( |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 8454 | const sp<DisplayDevice>& display, |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8455 | const scheduler::RefreshRateSelector::PolicyVariant& policy) { |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8456 | const auto displayId = display->getPhysicalId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8457 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8458 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 8459 | Mutex::Autolock lock(mStateLock); |
| 8460 | |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 8461 | if (mDebugDisplayModeSetByBackdoor) { |
| 8462 | // ignore this request as mode is overridden by backdoor |
| 8463 | return NO_ERROR; |
| 8464 | } |
| 8465 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8466 | auto& selector = display->refreshRateSelector(); |
| 8467 | using SetPolicyResult = scheduler::RefreshRateSelector::SetPolicyResult; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8468 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8469 | switch (selector.setPolicy(policy)) { |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8470 | case SetPolicyResult::Invalid: |
| 8471 | return BAD_VALUE; |
| 8472 | case SetPolicyResult::Unchanged: |
| 8473 | return NO_ERROR; |
| 8474 | case SetPolicyResult::Changed: |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8475 | break; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8476 | } |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8477 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 8478 | if (!shouldApplyRefreshRateSelectorPolicy(*display)) { |
| 8479 | ALOGV("%s(%s): Skipped applying policy", __func__, to_string(displayId).c_str()); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8480 | return NO_ERROR; |
| 8481 | } |
| 8482 | |
| 8483 | return applyRefreshRateSelectorPolicy(displayId, selector); |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8484 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8485 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 8486 | bool SurfaceFlinger::shouldApplyRefreshRateSelectorPolicy(const DisplayDevice& display) const { |
| 8487 | if (display.isPoweredOn() || mPhysicalDisplays.size() == 1) return true; |
| 8488 | |
| 8489 | LOG_ALWAYS_FATAL_IF(display.isVirtual()); |
| 8490 | const auto displayId = display.getPhysicalId(); |
| 8491 | |
| 8492 | // The display is powered off, and this is a multi-display device. If the display is the |
| 8493 | // inactive internal display of a dual-display foldable, then the policy will be applied |
| 8494 | // when it becomes active upon powering on. |
| 8495 | // |
| 8496 | // TODO(b/255635711): Remove this function (i.e. returning `false` as a special case) once |
| 8497 | // concurrent mode setting across multiple (potentially powered off) displays is supported. |
| 8498 | // |
| 8499 | return displayId == mActiveDisplayId || |
| 8500 | !mPhysicalDisplays.get(displayId) |
| 8501 | .transform(&PhysicalDisplay::isInternal) |
| 8502 | .value_or(false); |
| 8503 | } |
| 8504 | |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8505 | status_t SurfaceFlinger::applyRefreshRateSelectorPolicy( |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8506 | PhysicalDisplayId displayId, const scheduler::RefreshRateSelector& selector, bool force) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8507 | const scheduler::RefreshRateSelector::Policy currentPolicy = selector.getCurrentPolicy(); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8508 | ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str()); |
Adrian Salido | ab6ef6c | 2019-08-28 10:02:49 -0700 | [diff] [blame] | 8509 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 8510 | // TODO(b/140204874): Leave the event in until we do proper testing with all apps that might |
| 8511 | // be depending in this callback. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8512 | if (const auto activeMode = selector.getActiveMode(); displayId == mActiveDisplayId) { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8513 | mScheduler->onPrimaryDisplayModeChanged(scheduler::Cycle::Render, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8514 | toggleKernelIdleTimer(); |
| 8515 | } else { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8516 | mScheduler->onNonPrimaryDisplayModeChanged(scheduler::Cycle::Render, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8517 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 8518 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8519 | auto preferredModeOpt = getPreferredDisplayMode(displayId, currentPolicy.defaultMode); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8520 | if (!preferredModeOpt) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8521 | ALOGE("%s: Preferred mode is unknown", __func__); |
| 8522 | return NAME_NOT_FOUND; |
| 8523 | } |
| 8524 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8525 | auto preferredMode = std::move(*preferredModeOpt); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8526 | const auto preferredModeId = preferredMode.modePtr->getId(); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 8527 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8528 | const Fps preferredFps = preferredMode.fps; |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8529 | ALOGV("Switching to Scheduler preferred mode %d (%s)", ftl::to_underlying(preferredModeId), |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8530 | to_string(preferredFps).c_str()); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8531 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8532 | if (!selector.isModeAllowed(preferredMode)) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8533 | ALOGE("%s: Preferred mode %d is disallowed", __func__, ftl::to_underlying(preferredModeId)); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8534 | return INVALID_OPERATION; |
Dominik Laskowski | 4f1dd8c | 2019-04-17 15:54:30 -0700 | [diff] [blame] | 8535 | } |
| 8536 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 8537 | setDesiredMode({std::move(preferredMode), .emitEvent = true, .force = force}); |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 8538 | |
| 8539 | // Update the frameRateOverride list as the display render rate might have changed |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8540 | if (mScheduler->updateFrameRateOverrides(scheduler::GlobalSignals{}, preferredFps)) { |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 8541 | triggerOnFrameRateOverridesChanged(); |
| 8542 | } |
| 8543 | |
Ady Abraham | d9b3ea6 | 2019-02-26 14:08:03 -0800 | [diff] [blame] | 8544 | return NO_ERROR; |
| 8545 | } |
| 8546 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8547 | namespace { |
| 8548 | FpsRange translate(const gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange& aidlRange) { |
| 8549 | return FpsRange{Fps::fromValue(aidlRange.min), Fps::fromValue(aidlRange.max)}; |
| 8550 | } |
| 8551 | |
| 8552 | FpsRanges translate(const gui::DisplayModeSpecs::RefreshRateRanges& aidlRanges) { |
| 8553 | return FpsRanges{translate(aidlRanges.physical), translate(aidlRanges.render)}; |
| 8554 | } |
| 8555 | |
| 8556 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange translate(const FpsRange& range) { |
| 8557 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange aidlRange; |
| 8558 | aidlRange.min = range.min.getValue(); |
| 8559 | aidlRange.max = range.max.getValue(); |
| 8560 | return aidlRange; |
| 8561 | } |
| 8562 | |
| 8563 | gui::DisplayModeSpecs::RefreshRateRanges translate(const FpsRanges& ranges) { |
| 8564 | gui::DisplayModeSpecs::RefreshRateRanges aidlRanges; |
| 8565 | aidlRanges.physical = translate(ranges.physical); |
| 8566 | aidlRanges.render = translate(ranges.render); |
| 8567 | return aidlRanges; |
| 8568 | } |
| 8569 | |
| 8570 | } // namespace |
| 8571 | |
| 8572 | status_t SurfaceFlinger::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 8573 | const gui::DisplayModeSpecs& specs) { |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8574 | ATRACE_CALL(); |
| 8575 | |
| 8576 | if (!displayToken) { |
| 8577 | return BAD_VALUE; |
| 8578 | } |
| 8579 | |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 8580 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8581 | const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayToken)); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8582 | if (!display) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8583 | ALOGE("Attempt to set desired display modes for invalid display token %p", |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8584 | displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8585 | return NAME_NOT_FOUND; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8586 | } else if (display->isVirtual()) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8587 | ALOGW("Attempt to set desired display modes for virtual display"); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8588 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8589 | } else { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8590 | using Policy = scheduler::RefreshRateSelector::DisplayManagerPolicy; |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8591 | const Policy policy{DisplayModeId(specs.defaultMode), translate(specs.primaryRanges), |
| 8592 | translate(specs.appRequestRanges), specs.allowGroupSwitching}; |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 8593 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8594 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8595 | } |
| 8596 | }); |
| 8597 | |
| 8598 | return future.get(); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8599 | } |
| 8600 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 8601 | status_t SurfaceFlinger::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8602 | gui::DisplayModeSpecs* outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8603 | ATRACE_CALL(); |
| 8604 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8605 | if (!displayToken || !outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8606 | return BAD_VALUE; |
| 8607 | } |
| 8608 | |
| 8609 | Mutex::Autolock lock(mStateLock); |
| 8610 | const auto display = getDisplayDeviceLocked(displayToken); |
| 8611 | if (!display) { |
| 8612 | return NAME_NOT_FOUND; |
| 8613 | } |
| 8614 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8615 | if (display->isVirtual()) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 8616 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8617 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8618 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8619 | scheduler::RefreshRateSelector::Policy policy = |
| 8620 | display->refreshRateSelector().getDisplayManagerPolicy(); |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8621 | outSpecs->defaultMode = ftl::to_underlying(policy.defaultMode); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8622 | outSpecs->allowGroupSwitching = policy.allowGroupSwitching; |
| 8623 | outSpecs->primaryRanges = translate(policy.primaryRanges); |
| 8624 | outSpecs->appRequestRanges = translate(policy.appRequestRanges); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8625 | return NO_ERROR; |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8626 | } |
| 8627 | |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 8628 | void SurfaceFlinger::onLayerFirstRef(Layer* layer) { |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8629 | mNumLayers++; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8630 | if (!layer->isRemovedFromCurrentState()) { |
| 8631 | mScheduler->registerLayer(layer); |
| 8632 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8633 | } |
| 8634 | |
| 8635 | void SurfaceFlinger::onLayerDestroyed(Layer* layer) { |
| 8636 | mNumLayers--; |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8637 | removeHierarchyFromOffscreenLayers(layer); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8638 | if (!layer->isRemovedFromCurrentState()) { |
| 8639 | mScheduler->deregisterLayer(layer); |
| 8640 | } |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 8641 | if (mTransactionTracing) { |
| 8642 | mTransactionTracing->onLayerRemoved(layer->getSequence()); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 8643 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 8644 | mScheduler->onLayerDestroyed(layer); |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8645 | } |
| 8646 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8647 | void SurfaceFlinger::onLayerUpdate() { |
| 8648 | scheduleCommit(FrameHint::kActive); |
| 8649 | } |
| 8650 | |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8651 | // WARNING: ONLY CALL THIS FROM LAYER DTOR |
| 8652 | // Here we add children in the current state to offscreen layers and remove the |
| 8653 | // layer itself from the offscreen layer list. Since |
| 8654 | // this is the dtor, it is safe to access the current state. This keeps us |
| 8655 | // from dangling children layers such that they are not reachable from the |
| 8656 | // Drawing state nor the offscreen layer list |
| 8657 | // See b/141111965 |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8658 | void SurfaceFlinger::removeHierarchyFromOffscreenLayers(Layer* layer) { |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8659 | for (auto& child : layer->getCurrentChildren()) { |
| 8660 | mOffscreenLayers.emplace(child.get()); |
| 8661 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8662 | mOffscreenLayers.erase(layer); |
| 8663 | } |
| 8664 | |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8665 | void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) { |
| 8666 | mOffscreenLayers.erase(layer); |
| 8667 | } |
| 8668 | |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 8669 | status_t SurfaceFlinger::setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, |
| 8670 | float lightPosY, float lightPosZ, |
| 8671 | float lightRadius) { |
| 8672 | Mutex::Autolock _l(mStateLock); |
| 8673 | mCurrentState.globalShadowSettings.ambientColor = vec4(ambientColor); |
| 8674 | mCurrentState.globalShadowSettings.spotColor = vec4(spotColor); |
| 8675 | mCurrentState.globalShadowSettings.lightPos.y = lightPosY; |
| 8676 | mCurrentState.globalShadowSettings.lightPos.z = lightPosZ; |
| 8677 | mCurrentState.globalShadowSettings.lightRadius = lightRadius; |
| 8678 | |
| 8679 | // these values are overridden when calculating the shadow settings for a layer. |
| 8680 | mCurrentState.globalShadowSettings.lightPos.x = 0.f; |
| 8681 | mCurrentState.globalShadowSettings.length = 0.f; |
Vishnu Nair | b13bb95 | 2019-11-15 10:24:08 -0800 | [diff] [blame] | 8682 | return NO_ERROR; |
| 8683 | } |
| 8684 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8685 | const std::unordered_map<std::string, uint32_t>& SurfaceFlinger::getGenericLayerMetadataKeyMap() |
| 8686 | const { |
| 8687 | // TODO(b/149500060): Remove this fixed/static mapping. Please prefer taking |
| 8688 | // on the work to remove the table in that bug rather than adding more to |
| 8689 | // it. |
| 8690 | static const std::unordered_map<std::string, uint32_t> genericLayerMetadataKeyMap{ |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8691 | {"org.chromium.arc.V1_0.TaskId", gui::METADATA_TASK_ID}, |
| 8692 | {"org.chromium.arc.V1_0.CursorInfo", gui::METADATA_MOUSE_CURSOR}, |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8693 | }; |
| 8694 | return genericLayerMetadataKeyMap; |
| 8695 | } |
| 8696 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8697 | status_t SurfaceFlinger::setGameModeFrameRateOverride(uid_t uid, float frameRate) { |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 8698 | PhysicalDisplayId displayId = [&]() { |
| 8699 | Mutex::Autolock lock(mStateLock); |
| 8700 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 8701 | }(); |
| 8702 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8703 | mScheduler->setGameModeFrameRateForUid(FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8704 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 8705 | return NO_ERROR; |
| 8706 | } |
| 8707 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8708 | status_t SurfaceFlinger::setGameDefaultFrameRateOverride(uid_t uid, float frameRate) { |
| 8709 | if (FlagManager::getInstance().game_default_frame_rate()) { |
| 8710 | mScheduler->setGameDefaultFrameRateForUid( |
| 8711 | FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
| 8712 | } |
| 8713 | return NO_ERROR; |
| 8714 | } |
| 8715 | |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8716 | status_t SurfaceFlinger::updateSmallAreaDetection( |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 8717 | std::vector<std::pair<int32_t, float>>& appIdThresholdMappings) { |
| 8718 | mScheduler->updateSmallAreaDetection(appIdThresholdMappings); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8719 | return NO_ERROR; |
| 8720 | } |
| 8721 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 8722 | status_t SurfaceFlinger::setSmallAreaDetectionThreshold(int32_t appId, float threshold) { |
| 8723 | mScheduler->setSmallAreaDetectionThreshold(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8724 | return NO_ERROR; |
| 8725 | } |
| 8726 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8727 | void SurfaceFlinger::enableRefreshRateOverlay(bool enable) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 8728 | bool setByHwc = getHwComposer().hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8729 | for (const auto& [id, display] : mPhysicalDisplays) { |
Sally Qi | de329f2 | 2023-09-26 16:21:39 -0700 | [diff] [blame] | 8730 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal || |
| 8731 | FlagManager::getInstance().refresh_rate_overlay_on_external_display()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8732 | if (const auto device = getDisplayDeviceLocked(id)) { |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 8733 | const auto enableOverlay = [&](const bool setByHwc) FTL_FAKE_GUARD( |
| 8734 | kMainThreadContext) { |
| 8735 | device->enableRefreshRateOverlay(enable, setByHwc, mRefreshRateOverlaySpinner, |
| 8736 | mRefreshRateOverlayRenderRate, |
| 8737 | mRefreshRateOverlayShowInMiddle); |
| 8738 | }; |
| 8739 | enableOverlay(setByHwc); |
| 8740 | if (setByHwc) { |
| 8741 | const auto status = |
| 8742 | getHwComposer().setRefreshRateChangedCallbackDebugEnabled(id, enable); |
| 8743 | if (status != NO_ERROR) { |
| 8744 | ALOGE("Error updating the refresh rate changed callback debug enabled"); |
| 8745 | enableOverlay(/*setByHwc*/ false); |
| 8746 | } |
| 8747 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8748 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8749 | } |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 8750 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8751 | } |
| 8752 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 8753 | void SurfaceFlinger::enableHdrSdrRatioOverlay(bool enable) { |
| 8754 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 8755 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal) { |
| 8756 | if (const auto device = getDisplayDeviceLocked(id)) { |
| 8757 | device->enableHdrSdrRatioOverlay(enable); |
| 8758 | } |
| 8759 | } |
| 8760 | } |
| 8761 | } |
| 8762 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8763 | int SurfaceFlinger::getGpuContextPriority() { |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 8764 | return getRenderEngine().getContextPriority(); |
Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 8765 | } |
| 8766 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8767 | int SurfaceFlinger::calculateMaxAcquiredBufferCount(Fps refreshRate, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8768 | std::chrono::nanoseconds presentLatency) { |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8769 | auto pipelineDepth = presentLatency.count() / refreshRate.getPeriodNsecs(); |
| 8770 | if (presentLatency.count() % refreshRate.getPeriodNsecs()) { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8771 | pipelineDepth++; |
| 8772 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8773 | return std::max(minAcquiredBuffers, static_cast<int64_t>(pipelineDepth - 1)); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8774 | } |
| 8775 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8776 | status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 8777 | Fps maxRefreshRate = 60_Hz; |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8778 | |
| 8779 | if (!getHwComposer().isHeadless()) { |
| 8780 | if (const auto display = getDefaultDisplayDevice()) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8781 | maxRefreshRate = display->refreshRateSelector().getSupportedRefreshRateRange().max; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8782 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8783 | } |
| 8784 | |
| 8785 | *buffers = getMaxAcquiredBufferCountForRefreshRate(maxRefreshRate); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8786 | return NO_ERROR; |
| 8787 | } |
| 8788 | |
rnlee | ed20fa4 | 2021-08-10 18:00:03 -0700 | [diff] [blame] | 8789 | uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 8790 | Fps refreshRate = 60_Hz; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8791 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8792 | if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) { |
| 8793 | refreshRate = *frameRateOverride; |
| 8794 | } else if (!getHwComposer().isHeadless()) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8795 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked())) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8796 | refreshRate = display->refreshRateSelector().getActiveMode().fps; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8797 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8798 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8799 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8800 | return getMaxAcquiredBufferCountForRefreshRate(refreshRate); |
| 8801 | } |
| 8802 | |
| 8803 | int SurfaceFlinger::getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 8804 | const auto vsyncConfig = |
| 8805 | mScheduler->getVsyncConfiguration().getConfigsForRefreshRate(refreshRate).late; |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8806 | const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration; |
| 8807 | return calculateMaxAcquiredBufferCount(refreshRate, presentLatency); |
| 8808 | } |
| 8809 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 8810 | void SurfaceFlinger::handleLayerCreatedLocked(const LayerCreatedState& state, VsyncId vsyncId) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8811 | sp<Layer> layer = state.layer.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8812 | if (!layer) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8813 | ALOGD("Layer was destroyed soon after creation %p", state.layer.unsafe_get()); |
| 8814 | return; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8815 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 8816 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8817 | |
| 8818 | sp<Layer> parent; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8819 | bool addToRoot = state.addToRoot; |
| 8820 | if (state.initialParent != nullptr) { |
| 8821 | parent = state.initialParent.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8822 | if (parent == nullptr) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8823 | ALOGD("Parent was destroyed soon after creation %p", state.initialParent.unsafe_get()); |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 8824 | addToRoot = false; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8825 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8826 | } |
| 8827 | |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 8828 | if (parent == nullptr && addToRoot) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 8829 | layer->setIsAtRoot(true); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8830 | mCurrentState.layersSortedByZ.add(layer); |
| 8831 | } else if (parent == nullptr) { |
| 8832 | layer->onRemovedFromCurrentState(); |
| 8833 | } else if (parent->isRemovedFromCurrentState()) { |
| 8834 | parent->addChild(layer); |
| 8835 | layer->onRemovedFromCurrentState(); |
| 8836 | } else { |
| 8837 | parent->addChild(layer); |
| 8838 | } |
| 8839 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 8840 | ui::LayerStack layerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 8841 | sp<const DisplayDevice> hintDisplay; |
| 8842 | // Find the display that includes the layer. |
| 8843 | for (const auto& [token, display] : mDisplays) { |
| 8844 | if (display->getLayerStack() == layerStack) { |
| 8845 | hintDisplay = display; |
| 8846 | break; |
| 8847 | } |
| 8848 | } |
| 8849 | |
| 8850 | if (hintDisplay) { |
| 8851 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
| 8852 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8853 | } |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8854 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8855 | void SurfaceFlinger::sample() { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8856 | if (!mLumaSampling || !mRegionSamplingThread) { |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8857 | return; |
| 8858 | } |
| 8859 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 8860 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 8861 | const auto scheduleFrameTimeOpt = scheduledFrameResultOpt |
| 8862 | ? std::optional{scheduledFrameResultOpt->callbackTime} |
| 8863 | : std::nullopt; |
| 8864 | mRegionSamplingThread->onCompositionComplete(scheduleFrameTimeOpt); |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8865 | } |
| 8866 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8867 | void SurfaceFlinger::onActiveDisplaySizeChanged(const DisplayDevice& activeDisplay) { |
| 8868 | mScheduler->onActiveDisplayAreaChanged(activeDisplay.getWidth() * activeDisplay.getHeight()); |
| 8869 | getRenderEngine().onActiveDisplaySizeChanged(activeDisplay.getSize()); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8870 | } |
| 8871 | |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 8872 | sp<DisplayDevice> SurfaceFlinger::getActivatableDisplay() const { |
| 8873 | if (mPhysicalDisplays.size() == 1) return nullptr; |
| 8874 | |
| 8875 | // TODO(b/255635821): Choose the pacesetter display, considering both internal and external |
| 8876 | // displays. For now, pick the other internal display, assuming a dual-display foldable. |
| 8877 | return findDisplay([this](const DisplayDevice& display) REQUIRES(mStateLock) { |
| 8878 | const auto idOpt = PhysicalDisplayId::tryCast(display.getId()); |
| 8879 | return idOpt && *idOpt != mActiveDisplayId && display.isPoweredOn() && |
| 8880 | mPhysicalDisplays.get(*idOpt) |
| 8881 | .transform(&PhysicalDisplay::isInternal) |
| 8882 | .value_or(false); |
| 8883 | }); |
| 8884 | } |
| 8885 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8886 | void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveDisplayPtr, |
| 8887 | const DisplayDevice& activeDisplay) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8888 | ATRACE_CALL(); |
| 8889 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8890 | // 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] | 8891 | // because DM is about to send its policy via setDesiredDisplayModeSpecs. |
| 8892 | bool forceApplyPolicy = false; |
| 8893 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8894 | if (inactiveDisplayPtr) { |
| 8895 | inactiveDisplayPtr->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false); |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 8896 | forceApplyPolicy = true; |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 8897 | } |
| 8898 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8899 | mActiveDisplayId = activeDisplay.getPhysicalId(); |
| 8900 | activeDisplay.getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 8901 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 8902 | mScheduler->resetPhaseConfiguration(activeDisplay.getActiveMode().fps); |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 8903 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8904 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8905 | mScheduler->setModeChangePending(false); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8906 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 8907 | mScheduler->setPacesetterDisplay(mActiveDisplayId); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 8908 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8909 | onActiveDisplaySizeChanged(activeDisplay); |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8910 | mActiveDisplayTransformHint = activeDisplay.getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 8911 | sActiveDisplayRotationFlags = ui::Transform::toRotationFlags(activeDisplay.getOrientation()); |
Ady Abraham | 85d692d | 2021-09-28 14:08:54 -0700 | [diff] [blame] | 8912 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 8913 | // 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] | 8914 | // that case, its preferred mode has not been propagated to HWC (via setDesiredMode). In either |
| 8915 | // case, the Scheduler's cachedModeChangedParams must be initialized to the newly active mode, |
| 8916 | // 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] | 8917 | applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay.refreshRateSelector(), |
| 8918 | forceApplyPolicy); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8919 | } |
| 8920 | |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 8921 | status_t SurfaceFlinger::addWindowInfosListener(const sp<IWindowInfosListener>& windowInfosListener, |
| 8922 | gui::WindowInfosListenerInfo* outInfo) { |
| 8923 | mWindowInfosListenerInvoker->addWindowInfosListener(windowInfosListener, outInfo); |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 8924 | setTransactionFlags(eInputInfoUpdateNeeded); |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 8925 | return NO_ERROR; |
| 8926 | } |
| 8927 | |
| 8928 | status_t SurfaceFlinger::removeWindowInfosListener( |
| 8929 | const sp<IWindowInfosListener>& windowInfosListener) const { |
| 8930 | mWindowInfosListenerInvoker->removeWindowInfosListener(windowInfosListener); |
| 8931 | return NO_ERROR; |
| 8932 | } |
| 8933 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 8934 | status_t SurfaceFlinger::getStalledTransactionInfo( |
| 8935 | int pid, std::optional<TransactionHandler::StalledTransactionInfo>& result) { |
| 8936 | result = mTransactionHandler.getStalledTransactionInfo(pid); |
| 8937 | return NO_ERROR; |
| 8938 | } |
| 8939 | |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 8940 | void SurfaceFlinger::updateHdcpLevels(hal::HWDisplayId hwcDisplayId, int32_t connectedLevel, |
| 8941 | int32_t maxLevel) { |
| 8942 | if (!FlagManager::getInstance().connected_display()) { |
| 8943 | return; |
| 8944 | } |
| 8945 | |
| 8946 | Mutex::Autolock lock(mStateLock); |
| 8947 | |
| 8948 | const auto idOpt = getHwComposer().toPhysicalDisplayId(hwcDisplayId); |
| 8949 | if (!idOpt) { |
| 8950 | ALOGE("No display found for HDCP level changed event: connected=%d, max=%d for " |
| 8951 | "display=%" PRIu64, |
| 8952 | connectedLevel, maxLevel, hwcDisplayId); |
| 8953 | return; |
| 8954 | } |
| 8955 | |
| 8956 | const bool isInternalDisplay = |
| 8957 | mPhysicalDisplays.get(*idOpt).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 8958 | if (isInternalDisplay) { |
| 8959 | ALOGW("Unexpected HDCP level changed for internal display: connected=%d, max=%d for " |
| 8960 | "display=%" PRIu64, |
| 8961 | connectedLevel, maxLevel, hwcDisplayId); |
| 8962 | return; |
| 8963 | } |
| 8964 | |
| 8965 | static_cast<void>(mScheduler->schedule([this, displayId = *idOpt, connectedLevel, maxLevel]() { |
| 8966 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayId))) { |
| 8967 | Mutex::Autolock lock(mStateLock); |
| 8968 | display->setSecure(connectedLevel >= 2 /* HDCP_V1 */); |
| 8969 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8970 | mScheduler->onHdcpLevelsChanged(scheduler::Cycle::Render, displayId, connectedLevel, |
| 8971 | maxLevel); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 8972 | })); |
| 8973 | } |
| 8974 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8975 | std::shared_ptr<renderengine::ExternalTexture> SurfaceFlinger::getExternalTextureFromBufferData( |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8976 | BufferData& bufferData, const char* layerName, uint64_t transactionId) { |
| 8977 | if (bufferData.buffer && |
| 8978 | exceedsMaxRenderTargetSize(bufferData.buffer->getWidth(), bufferData.buffer->getHeight())) { |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 8979 | std::string errorMessage = |
| 8980 | base::StringPrintf("Attempted to create an ExternalTexture with size (%u, %u) for " |
| 8981 | "layer %s that exceeds render target size limit of %u.", |
| 8982 | bufferData.buffer->getWidth(), bufferData.buffer->getHeight(), |
| 8983 | layerName, static_cast<uint32_t>(mMaxRenderTargetSize)); |
| 8984 | ALOGD("%s", errorMessage.c_str()); |
| 8985 | if (bufferData.releaseBufferListener) { |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 8986 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
| 8987 | String8(errorMessage.c_str())); |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 8988 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8989 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8990 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8991 | |
| 8992 | bool cachedBufferChanged = |
| 8993 | bufferData.flags.test(BufferData::BufferDataChange::cachedBufferChanged); |
| 8994 | if (cachedBufferChanged && bufferData.buffer) { |
| 8995 | auto result = ClientCache::getInstance().add(bufferData.cachedBuffer, bufferData.buffer); |
| 8996 | if (result.ok()) { |
| 8997 | return result.value(); |
| 8998 | } |
| 8999 | |
| 9000 | if (result.error() == ClientCache::AddError::CacheFull) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 9001 | ALOGE("Attempted to create an ExternalTexture for layer %s but CacheFull", layerName); |
| 9002 | |
| 9003 | if (bufferData.releaseBufferListener) { |
| 9004 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 9005 | String8("Buffer processing hung due to full buffer cache")); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 9006 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 9007 | } |
| 9008 | |
| 9009 | return nullptr; |
| 9010 | } |
| 9011 | |
| 9012 | if (cachedBufferChanged) { |
| 9013 | return ClientCache::getInstance().get(bufferData.cachedBuffer); |
| 9014 | } |
| 9015 | |
| 9016 | if (bufferData.buffer) { |
| 9017 | return std::make_shared< |
| 9018 | renderengine::impl::ExternalTexture>(bufferData.buffer, getRenderEngine(), |
| 9019 | renderengine::impl::ExternalTexture::Usage:: |
| 9020 | READABLE); |
| 9021 | } |
| 9022 | |
| 9023 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 9024 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9025 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 9026 | bool SurfaceFlinger::commitMirrorDisplays(VsyncId vsyncId) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9027 | std::vector<MirrorDisplayState> mirrorDisplays; |
| 9028 | { |
| 9029 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
| 9030 | mirrorDisplays = std::move(mMirrorDisplays); |
| 9031 | mMirrorDisplays.clear(); |
| 9032 | if (mirrorDisplays.size() == 0) { |
| 9033 | return false; |
| 9034 | } |
| 9035 | } |
| 9036 | |
| 9037 | sp<IBinder> unused; |
| 9038 | for (const auto& mirrorDisplay : mirrorDisplays) { |
| 9039 | // Set mirror layer's default layer stack to -1 so it doesn't end up rendered on a display |
| 9040 | // accidentally. |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 9041 | sp<Layer> rootMirrorLayer = LayerHandle::getLayer(mirrorDisplay.rootHandle); |
Qi Jing | b8e4c13 | 2023-08-25 23:01:47 +0000 | [diff] [blame] | 9042 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(rootMirrorLayer); |
| 9043 | bool ret = rootMirrorLayer->setLayerStack(ui::LayerStack::fromValue(-1)); |
| 9044 | if (idx >= 0 && ret) { |
| 9045 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 9046 | mCurrentState.layersSortedByZ.add(rootMirrorLayer); |
| 9047 | } |
| 9048 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9049 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 9050 | if (layer->getLayerStack() != mirrorDisplay.layerStack || |
| 9051 | layer->isInternalDisplayOverlay()) { |
| 9052 | continue; |
| 9053 | } |
| 9054 | |
| 9055 | LayerCreationArgs mirrorArgs(this, mirrorDisplay.client, "MirrorLayerParent", |
| 9056 | ISurfaceComposerClient::eNoColorFill, |
| 9057 | gui::LayerMetadata()); |
| 9058 | sp<Layer> childMirror; |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 9059 | { |
| 9060 | Mutex::Autolock lock(mStateLock); |
| 9061 | createEffectLayer(mirrorArgs, &unused, &childMirror); |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 9062 | MUTEX_ALIAS(mStateLock, childMirror->mFlinger->mStateLock); |
Vishnu Nair | de17725 | 2023-04-21 12:44:10 -0700 | [diff] [blame] | 9063 | childMirror->setClonedChild(layer->createClone(childMirror->getSequence())); |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 9064 | childMirror->reparent(mirrorDisplay.rootHandle); |
| 9065 | } |
| 9066 | // lock on mStateLock needs to be released before binder handle gets destroyed |
| 9067 | unused.clear(); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9068 | } |
| 9069 | } |
| 9070 | return true; |
| 9071 | } |
| 9072 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9073 | bool SurfaceFlinger::commitCreatedLayers(VsyncId vsyncId, |
| 9074 | std::vector<LayerCreatedState>& createdLayers) { |
| 9075 | if (createdLayers.size() == 0) { |
| 9076 | return false; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9077 | } |
| 9078 | |
| 9079 | Mutex::Autolock _l(mStateLock); |
| 9080 | for (const auto& createdLayer : createdLayers) { |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 9081 | handleLayerCreatedLocked(createdLayer, vsyncId); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9082 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9083 | mLayersAdded = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9084 | return mLayersAdded; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9085 | } |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9086 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 9087 | void SurfaceFlinger::updateLayerMetadataSnapshot() { |
| 9088 | LayerMetadata parentMetadata; |
| 9089 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 9090 | layer->updateMetadataSnapshot(parentMetadata); |
| 9091 | } |
| 9092 | |
| 9093 | std::unordered_set<Layer*> visited; |
| 9094 | mDrawingState.traverse([&visited](Layer* layer) { |
| 9095 | if (visited.find(layer) != visited.end()) { |
| 9096 | return; |
| 9097 | } |
| 9098 | |
| 9099 | // If the layer isRelativeOf, then either it's relative metadata will be set |
| 9100 | // recursively when updateRelativeMetadataSnapshot is called on its relative parent or |
| 9101 | // it's relative parent has been deleted. Clear the layer's relativeLayerMetadata to ensure |
| 9102 | // that layers with deleted relative parents don't hold stale relativeLayerMetadata. |
| 9103 | if (layer->getDrawingState().isRelativeOf) { |
| 9104 | layer->editLayerSnapshot()->relativeLayerMetadata = {}; |
| 9105 | return; |
| 9106 | } |
| 9107 | |
| 9108 | layer->updateRelativeMetadataSnapshot({}, visited); |
| 9109 | }); |
| 9110 | } |
| 9111 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9112 | void SurfaceFlinger::moveSnapshotsFromCompositionArgs( |
| 9113 | compositionengine::CompositionRefreshArgs& refreshArgs, |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 9114 | const std::vector<std::pair<Layer*, LayerFE*>>& layers) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9115 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9116 | std::vector<std::unique_ptr<frontend::LayerSnapshot>>& snapshots = |
| 9117 | mLayerSnapshotBuilder.getSnapshots(); |
| 9118 | for (auto [_, layerFE] : layers) { |
| 9119 | auto i = layerFE->mSnapshot->globalZ; |
| 9120 | snapshots[i] = std::move(layerFE->mSnapshot); |
| 9121 | } |
| 9122 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9123 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9124 | for (auto [layer, layerFE] : layers) { |
| 9125 | layer->updateLayerSnapshot(std::move(layerFE->mSnapshot)); |
| 9126 | } |
| 9127 | } |
| 9128 | } |
| 9129 | |
| 9130 | std::vector<std::pair<Layer*, LayerFE*>> SurfaceFlinger::moveSnapshotsToCompositionArgs( |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 9131 | compositionengine::CompositionRefreshArgs& refreshArgs, bool cursorOnly) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9132 | std::vector<std::pair<Layer*, LayerFE*>> layers; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9133 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9134 | nsecs_t currentTime = systemTime(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9135 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 9136 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 9137 | if (cursorOnly && |
| 9138 | snapshot->compositionType != |
| 9139 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) { |
| 9140 | return; |
| 9141 | } |
| 9142 | |
| 9143 | if (!snapshot->hasSomethingToDraw()) { |
| 9144 | return; |
| 9145 | } |
| 9146 | |
| 9147 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 9148 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 9149 | "Couldnt find layer object for %s", |
| 9150 | snapshot->getDebugString().c_str()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9151 | auto& legacyLayer = it->second; |
| 9152 | sp<LayerFE> layerFE = legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9153 | snapshot->fps = getLayerFramerate(currentTime, snapshot->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9154 | layerFE->mSnapshot = std::move(snapshot); |
| 9155 | refreshArgs.layers.push_back(layerFE); |
| 9156 | layers.emplace_back(legacyLayer.get(), layerFE.get()); |
| 9157 | }); |
| 9158 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9159 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 9160 | auto moveSnapshots = [&layers, &refreshArgs, cursorOnly](Layer* layer) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9161 | if (const auto& layerFE = layer->getCompositionEngineLayerFE()) { |
| 9162 | if (cursorOnly && |
| 9163 | layer->getLayerSnapshot()->compositionType != |
| 9164 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) |
| 9165 | return; |
| 9166 | layer->updateSnapshot(refreshArgs.updatingGeometryThisFrame); |
| 9167 | layerFE->mSnapshot = layer->stealLayerSnapshot(); |
| 9168 | refreshArgs.layers.push_back(layerFE); |
| 9169 | layers.emplace_back(layer, layerFE.get()); |
| 9170 | } |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 9171 | }; |
| 9172 | |
| 9173 | if (cursorOnly || !mVisibleRegionsDirty) { |
| 9174 | // for hot path avoid traversals by walking though the previous composition list |
| 9175 | for (sp<Layer> layer : mPreviouslyComposedLayers) { |
| 9176 | moveSnapshots(layer.get()); |
| 9177 | } |
| 9178 | } else { |
| 9179 | mPreviouslyComposedLayers.clear(); |
| 9180 | mDrawingState.traverseInZOrder( |
| 9181 | [&moveSnapshots](Layer* layer) { moveSnapshots(layer); }); |
| 9182 | mPreviouslyComposedLayers.reserve(layers.size()); |
| 9183 | for (auto [layer, _] : layers) { |
| 9184 | mPreviouslyComposedLayers.push_back(sp<Layer>::fromExisting(layer)); |
| 9185 | } |
| 9186 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9187 | } |
| 9188 | |
| 9189 | return layers; |
| 9190 | } |
| 9191 | |
| 9192 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9193 | SurfaceFlinger::getLayerSnapshotsForScreenshots( |
| 9194 | std::optional<ui::LayerStack> layerStack, uint32_t uid, |
| 9195 | std::function<bool(const frontend::LayerSnapshot&, bool& outStopTraversal)> |
| 9196 | snapshotFilterFn) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9197 | return [&, layerStack, uid]() { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9198 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers; |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9199 | bool stopTraversal = false; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9200 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 9201 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9202 | if (stopTraversal) { |
| 9203 | return; |
| 9204 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9205 | if (layerStack && snapshot->outputFilter.layerStack != *layerStack) { |
| 9206 | return; |
| 9207 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 9208 | if (uid != CaptureArgs::UNSET_UID && snapshot->uid != gui::Uid(uid)) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9209 | return; |
| 9210 | } |
| 9211 | if (!snapshot->hasSomethingToDraw()) { |
| 9212 | return; |
| 9213 | } |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9214 | if (snapshotFilterFn && !snapshotFilterFn(*snapshot, stopTraversal)) { |
| 9215 | return; |
| 9216 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9217 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9218 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 9219 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 9220 | "Couldnt find layer object for %s", |
| 9221 | snapshot->getDebugString().c_str()); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9222 | Layer* legacyLayer = (it == mLegacyLayers.end()) ? nullptr : it->second.get(); |
| 9223 | sp<LayerFE> layerFE = getFactory().createLayerFE(snapshot->name); |
| 9224 | layerFE->mSnapshot = std::make_unique<frontend::LayerSnapshot>(*snapshot); |
| 9225 | layers.emplace_back(legacyLayer, std::move(layerFE)); |
| 9226 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9227 | |
| 9228 | return layers; |
| 9229 | }; |
| 9230 | } |
| 9231 | |
| 9232 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9233 | SurfaceFlinger::getLayerSnapshotsForScreenshots(std::optional<ui::LayerStack> layerStack, |
| 9234 | uint32_t uid, |
| 9235 | std::unordered_set<uint32_t> excludeLayerIds) { |
| 9236 | return [&, layerStack, uid, excludeLayerIds = std::move(excludeLayerIds)]() { |
| 9237 | if (excludeLayerIds.empty()) { |
| 9238 | auto getLayerSnapshotsFn = |
| 9239 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 9240 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9241 | return layers; |
| 9242 | } |
| 9243 | |
| 9244 | frontend::LayerSnapshotBuilder::Args |
| 9245 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 9246 | .layerLifecycleManager = mLayerLifecycleManager, |
| 9247 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
| 9248 | .displays = mFrontEndDisplayInfos, |
| 9249 | .displayChanges = true, |
| 9250 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9251 | .supportsBlur = mSupportsBlur, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9252 | .forceFullDamage = mForceFullDamage, |
| 9253 | .excludeLayerIds = std::move(excludeLayerIds), |
| 9254 | .supportedLayerGenericMetadata = |
| 9255 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 9256 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 9257 | .skipRoundCornersWhenProtected = |
| 9258 | !getRenderEngine().supportsProtectedContent()}; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9259 | mLayerSnapshotBuilder.update(args); |
| 9260 | |
| 9261 | auto getLayerSnapshotsFn = |
| 9262 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 9263 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9264 | |
| 9265 | args.excludeLayerIds.clear(); |
| 9266 | mLayerSnapshotBuilder.update(args); |
| 9267 | |
| 9268 | return layers; |
| 9269 | }; |
| 9270 | } |
| 9271 | |
| 9272 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9273 | SurfaceFlinger::getLayerSnapshotsForScreenshots(uint32_t rootLayerId, uint32_t uid, |
| 9274 | std::unordered_set<uint32_t> excludeLayerIds, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 9275 | bool childrenOnly, |
| 9276 | const std::optional<FloatRect>& parentCrop) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9277 | return [&, rootLayerId, uid, excludeLayerIds = std::move(excludeLayerIds), childrenOnly, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9278 | parentCrop]() { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9279 | auto root = mLayerHierarchyBuilder.getPartialHierarchy(rootLayerId, childrenOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9280 | frontend::LayerSnapshotBuilder::Args |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9281 | args{.root = root, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9282 | .layerLifecycleManager = mLayerLifecycleManager, |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9283 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9284 | .displays = mFrontEndDisplayInfos, |
| 9285 | .displayChanges = true, |
| 9286 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9287 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9288 | .forceFullDamage = mForceFullDamage, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 9289 | .parentCrop = parentCrop, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9290 | .excludeLayerIds = std::move(excludeLayerIds), |
| 9291 | .supportedLayerGenericMetadata = |
| 9292 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 9293 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 9294 | .skipRoundCornersWhenProtected = |
| 9295 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | c54fdb0 | 2023-11-21 17:19:58 -0800 | [diff] [blame] | 9296 | // The layer may not exist if it was just created and a screenshot was requested immediately |
| 9297 | // after. In this case, the hierarchy will be empty so we will not render any layers. |
| 9298 | args.rootSnapshot.isSecure = mLayerLifecycleManager.getLayerFromId(rootLayerId) && |
| 9299 | mLayerLifecycleManager.isLayerSecure(rootLayerId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9300 | mLayerSnapshotBuilder.update(args); |
| 9301 | |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9302 | auto getLayerSnapshotsFn = |
| 9303 | getLayerSnapshotsForScreenshots({}, uid, /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9304 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9305 | args.root = mLayerHierarchyBuilder.getHierarchy(); |
| 9306 | args.parentCrop.reset(); |
| 9307 | args.excludeLayerIds.clear(); |
| 9308 | mLayerSnapshotBuilder.update(args); |
| 9309 | return layers; |
| 9310 | }; |
| 9311 | } |
| 9312 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9313 | frontend::Update SurfaceFlinger::flushLifecycleUpdates() { |
| 9314 | frontend::Update update; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9315 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 9316 | // Locking: |
| 9317 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 9318 | // we must keep a copy of the transactions (specifically the composer |
| 9319 | // states) around outside the scope of the lock. |
| 9320 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 9321 | // transactions with layers still in the createdLayer queue, flush the transactions |
| 9322 | // before committing the created layers. |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 9323 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9324 | update.transactions = mTransactionHandler.flushTransactions(); |
| 9325 | { |
| 9326 | // TODO(b/238781169) lockless queue this and keep order. |
| 9327 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 9328 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 9329 | mCreatedLayers.clear(); |
| 9330 | update.newLayers = std::move(mNewLayers); |
| 9331 | mNewLayers.clear(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9332 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 9333 | mNewLayerArgs.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9334 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 9335 | mDestroyedHandles.clear(); |
| 9336 | } |
| 9337 | return update; |
| 9338 | } |
| 9339 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9340 | void SurfaceFlinger::doActiveLayersTracingIfNeeded(bool isCompositionComputed, |
| 9341 | bool visibleRegionDirty, TimePoint time, |
| 9342 | VsyncId vsyncId) { |
| 9343 | if (!mLayerTracing.isActiveTracingStarted()) { |
| 9344 | return; |
| 9345 | } |
| 9346 | if (isCompositionComputed != |
| 9347 | mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_COMPOSITION)) { |
| 9348 | return; |
| 9349 | } |
| 9350 | if (!visibleRegionDirty && |
| 9351 | !mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_BUFFERS)) { |
| 9352 | return; |
| 9353 | } |
| 9354 | auto snapshot = takeLayersSnapshotProto(mLayerTracing.getActiveTracingFlags(), time, vsyncId, |
| 9355 | visibleRegionDirty); |
| 9356 | mLayerTracing.addProtoSnapshotToOstream(std::move(snapshot), LayerTracing::Mode::MODE_ACTIVE); |
| 9357 | } |
| 9358 | |
| 9359 | perfetto::protos::LayersSnapshotProto SurfaceFlinger::takeLayersSnapshotProto( |
| 9360 | uint32_t traceFlags, TimePoint time, VsyncId vsyncId, bool visibleRegionDirty) { |
| 9361 | ATRACE_CALL(); |
| 9362 | perfetto::protos::LayersSnapshotProto snapshot; |
| 9363 | snapshot.set_elapsed_realtime_nanos(time.ns()); |
| 9364 | snapshot.set_vsync_id(ftl::to_underlying(vsyncId)); |
| 9365 | snapshot.set_where(visibleRegionDirty ? "visibleRegionsDirty" : "bufferLatched"); |
| 9366 | snapshot.set_excludes_composition_state((traceFlags & LayerTracing::Flag::TRACE_COMPOSITION) == |
| 9367 | 0); |
| 9368 | |
| 9369 | auto layers = dumpDrawingStateProto(traceFlags); |
| 9370 | if (traceFlags & LayerTracing::Flag::TRACE_EXTRA) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9371 | dumpOffscreenLayersProto(layers); |
| 9372 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9373 | *snapshot.mutable_layers() = std::move(layers); |
| 9374 | |
| 9375 | if (traceFlags & LayerTracing::Flag::TRACE_HWC) { |
| 9376 | std::string hwcDump; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9377 | dumpHwc(hwcDump); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9378 | snapshot.set_hwc_blob(std::move(hwcDump)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9379 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9380 | |
| 9381 | *snapshot.mutable_displays() = dumpDisplayProto(); |
| 9382 | |
| 9383 | return snapshot; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9384 | } |
| 9385 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 9386 | // sfdo functions |
| 9387 | |
| 9388 | void SurfaceFlinger::sfdo_enableRefreshRateOverlay(bool active) { |
| 9389 | auto future = mScheduler->schedule( |
| 9390 | [&]() FTL_FAKE_GUARD(mStateLock) |
| 9391 | FTL_FAKE_GUARD(kMainThreadContext) { enableRefreshRateOverlay(active); }); |
| 9392 | future.wait(); |
| 9393 | } |
| 9394 | |
| 9395 | void SurfaceFlinger::sfdo_setDebugFlash(int delay) { |
| 9396 | if (delay > 0) { |
| 9397 | mDebugFlashDelay = delay; |
| 9398 | } else { |
| 9399 | mDebugFlashDelay = mDebugFlashDelay ? 0 : 1; |
| 9400 | } |
| 9401 | scheduleRepaint(); |
| 9402 | } |
| 9403 | |
| 9404 | void SurfaceFlinger::sfdo_scheduleComposite() { |
| 9405 | scheduleComposite(SurfaceFlinger::FrameHint::kActive); |
| 9406 | } |
| 9407 | |
| 9408 | void SurfaceFlinger::sfdo_scheduleCommit() { |
| 9409 | Mutex::Autolock lock(mStateLock); |
| 9410 | setTransactionFlags(eTransactionNeeded | eDisplayTransactionNeeded | eTraversalNeeded); |
| 9411 | } |
| 9412 | |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 9413 | void SurfaceFlinger::sfdo_forceClientComposition(bool enabled) { |
| 9414 | mDebugDisableHWC = enabled; |
| 9415 | scheduleRepaint(); |
| 9416 | } |
| 9417 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9418 | // gui::ISurfaceComposer |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9419 | |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9420 | binder::Status SurfaceComposerAIDL::bootFinished() { |
| 9421 | status_t status = checkAccessPermission(); |
| 9422 | if (status != OK) { |
| 9423 | return binderStatusFromStatusT(status); |
| 9424 | } |
| 9425 | mFlinger->bootFinished(); |
| 9426 | return binder::Status::ok(); |
| 9427 | } |
| 9428 | |
| 9429 | binder::Status SurfaceComposerAIDL::createDisplayEventConnection( |
| 9430 | VsyncSource vsyncSource, EventRegistration eventRegistration, |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 9431 | const sp<IBinder>& layerHandle, sp<IDisplayEventConnection>* outConnection) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9432 | sp<IDisplayEventConnection> conn = |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 9433 | mFlinger->createDisplayEventConnection(vsyncSource, eventRegistration, layerHandle); |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9434 | if (conn == nullptr) { |
| 9435 | *outConnection = nullptr; |
| 9436 | return binderStatusFromStatusT(BAD_VALUE); |
| 9437 | } else { |
| 9438 | *outConnection = conn; |
| 9439 | return binder::Status::ok(); |
| 9440 | } |
| 9441 | } |
| 9442 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9443 | binder::Status SurfaceComposerAIDL::createConnection(sp<gui::ISurfaceComposerClient>* outClient) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 9444 | const sp<Client> client = sp<Client>::make(mFlinger); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9445 | if (client->initCheck() == NO_ERROR) { |
| 9446 | *outClient = client; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 9447 | if (FlagManager::getInstance().misc1()) { |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 9448 | const int policy = SCHED_FIFO; |
| 9449 | client->setMinSchedulerPolicy(policy, sched_get_priority_min(policy)); |
| 9450 | } |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9451 | return binder::Status::ok(); |
| 9452 | } else { |
| 9453 | *outClient = nullptr; |
| 9454 | return binderStatusFromStatusT(BAD_VALUE); |
| 9455 | } |
| 9456 | } |
| 9457 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9458 | binder::Status SurfaceComposerAIDL::createDisplay(const std::string& displayName, bool secure, |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 9459 | float requestedRefreshRate, |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9460 | sp<IBinder>* outDisplay) { |
| 9461 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9462 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9463 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9464 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9465 | String8 displayName8 = String8::format("%s", displayName.c_str()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 9466 | *outDisplay = mFlinger->createDisplay(displayName8, secure, requestedRefreshRate); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9467 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9468 | } |
| 9469 | |
| 9470 | binder::Status SurfaceComposerAIDL::destroyDisplay(const sp<IBinder>& display) { |
| 9471 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9472 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9473 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9474 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9475 | mFlinger->destroyDisplay(display); |
| 9476 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9477 | } |
| 9478 | |
| 9479 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) { |
| 9480 | std::vector<PhysicalDisplayId> physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); |
| 9481 | std::vector<int64_t> displayIds; |
| 9482 | displayIds.reserve(physicalDisplayIds.size()); |
| 9483 | for (auto item : physicalDisplayIds) { |
| 9484 | displayIds.push_back(static_cast<int64_t>(item.value)); |
| 9485 | } |
| 9486 | *outDisplayIds = displayIds; |
| 9487 | return binder::Status::ok(); |
| 9488 | } |
| 9489 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9490 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, |
| 9491 | sp<IBinder>* outDisplay) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9492 | status_t status = checkAccessPermission(); |
| 9493 | if (status != OK) { |
| 9494 | return binderStatusFromStatusT(status); |
| 9495 | } |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9496 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 9497 | *outDisplay = mFlinger->getPhysicalDisplayToken(*id); |
| 9498 | return binder::Status::ok(); |
| 9499 | } |
| 9500 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9501 | binder::Status SurfaceComposerAIDL::setPowerMode(const sp<IBinder>& display, int mode) { |
| 9502 | status_t status = checkAccessPermission(); |
| 9503 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9504 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9505 | } |
| 9506 | mFlinger->setPowerMode(display, mode); |
| 9507 | return binder::Status::ok(); |
| 9508 | } |
| 9509 | |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 9510 | binder::Status SurfaceComposerAIDL::getSupportedFrameTimestamps( |
| 9511 | std::vector<FrameEvent>* outSupported) { |
| 9512 | status_t status; |
| 9513 | if (!outSupported) { |
| 9514 | status = UNEXPECTED_NULL; |
| 9515 | } else { |
| 9516 | outSupported->clear(); |
| 9517 | status = mFlinger->getSupportedFrameTimestamps(outSupported); |
| 9518 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9519 | return binderStatusFromStatusT(status); |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 9520 | } |
| 9521 | |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9522 | binder::Status SurfaceComposerAIDL::getDisplayStats(const sp<IBinder>& display, |
| 9523 | gui::DisplayStatInfo* outStatInfo) { |
| 9524 | DisplayStatInfo statInfo; |
| 9525 | status_t status = mFlinger->getDisplayStats(display, &statInfo); |
| 9526 | if (status == NO_ERROR) { |
| 9527 | outStatInfo->vsyncTime = static_cast<long>(statInfo.vsyncTime); |
| 9528 | outStatInfo->vsyncPeriod = static_cast<long>(statInfo.vsyncPeriod); |
| 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 | |
| 9533 | binder::Status SurfaceComposerAIDL::getDisplayState(const sp<IBinder>& display, |
| 9534 | gui::DisplayState* outState) { |
| 9535 | ui::DisplayState state; |
| 9536 | status_t status = mFlinger->getDisplayState(display, &state); |
| 9537 | if (status == NO_ERROR) { |
| 9538 | outState->layerStack = state.layerStack.id; |
| 9539 | outState->orientation = static_cast<gui::Rotation>(state.orientation); |
| 9540 | outState->layerStackSpaceRect.width = state.layerStackSpaceRect.width; |
| 9541 | outState->layerStackSpaceRect.height = state.layerStackSpaceRect.height; |
| 9542 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9543 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9544 | } |
| 9545 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9546 | binder::Status SurfaceComposerAIDL::getStaticDisplayInfo(int64_t displayId, |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9547 | gui::StaticDisplayInfo* outInfo) { |
| 9548 | using Tag = gui::DeviceProductInfo::ManufactureOrModelDate::Tag; |
| 9549 | ui::StaticDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9550 | |
| 9551 | status_t status = mFlinger->getStaticDisplayInfo(displayId, &info); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9552 | if (status == NO_ERROR) { |
| 9553 | // convert ui::StaticDisplayInfo to gui::StaticDisplayInfo |
| 9554 | outInfo->connectionType = static_cast<gui::DisplayConnectionType>(info.connectionType); |
| 9555 | outInfo->density = info.density; |
| 9556 | outInfo->secure = info.secure; |
| 9557 | outInfo->installOrientation = static_cast<gui::Rotation>(info.installOrientation); |
| 9558 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9559 | if (const std::optional<DeviceProductInfo> dpi = info.deviceProductInfo) { |
| 9560 | gui::DeviceProductInfo dinfo; |
| 9561 | dinfo.name = std::move(dpi->name); |
| 9562 | dinfo.manufacturerPnpId = std::vector<uint8_t>(dpi->manufacturerPnpId.begin(), |
| 9563 | dpi->manufacturerPnpId.end()); |
| 9564 | dinfo.productId = dpi->productId; |
| 9565 | dinfo.relativeAddress = |
| 9566 | std::vector<uint8_t>(dpi->relativeAddress.begin(), dpi->relativeAddress.end()); |
| 9567 | if (const auto* model = |
| 9568 | std::get_if<DeviceProductInfo::ModelYear>(&dpi->manufactureOrModelDate)) { |
| 9569 | gui::DeviceProductInfo::ModelYear modelYear; |
| 9570 | modelYear.year = model->year; |
| 9571 | dinfo.manufactureOrModelDate.set<Tag::modelYear>(modelYear); |
| 9572 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureYear>( |
| 9573 | &dpi->manufactureOrModelDate)) { |
| 9574 | gui::DeviceProductInfo::ManufactureYear date; |
| 9575 | date.modelYear.year = manufacture->year; |
| 9576 | dinfo.manufactureOrModelDate.set<Tag::manufactureYear>(date); |
| 9577 | } else if (const auto* manufacture = |
| 9578 | std::get_if<DeviceProductInfo::ManufactureWeekAndYear>( |
| 9579 | &dpi->manufactureOrModelDate)) { |
| 9580 | gui::DeviceProductInfo::ManufactureWeekAndYear date; |
| 9581 | date.manufactureYear.modelYear.year = manufacture->year; |
| 9582 | date.week = manufacture->week; |
| 9583 | dinfo.manufactureOrModelDate.set<Tag::manufactureWeekAndYear>(date); |
| 9584 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9585 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9586 | outInfo->deviceProductInfo = dinfo; |
| 9587 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9588 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9589 | return binderStatusFromStatusT(status); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9590 | } |
| 9591 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9592 | void SurfaceComposerAIDL::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo& info, |
| 9593 | gui::DynamicDisplayInfo*& outInfo) { |
| 9594 | // convert ui::DynamicDisplayInfo to gui::DynamicDisplayInfo |
| 9595 | outInfo->supportedDisplayModes.clear(); |
| 9596 | outInfo->supportedDisplayModes.reserve(info.supportedDisplayModes.size()); |
| 9597 | for (const auto& mode : info.supportedDisplayModes) { |
| 9598 | gui::DisplayMode outMode; |
| 9599 | outMode.id = mode.id; |
| 9600 | outMode.resolution.width = mode.resolution.width; |
| 9601 | outMode.resolution.height = mode.resolution.height; |
| 9602 | outMode.xDpi = mode.xDpi; |
| 9603 | outMode.yDpi = mode.yDpi; |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 9604 | outMode.peakRefreshRate = mode.peakRefreshRate; |
Alec Mouri | d122a1c | 2023-09-30 01:36:33 +0000 | [diff] [blame] | 9605 | outMode.vsyncRate = mode.vsyncRate; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9606 | outMode.appVsyncOffset = mode.appVsyncOffset; |
| 9607 | outMode.sfVsyncOffset = mode.sfVsyncOffset; |
| 9608 | outMode.presentationDeadline = mode.presentationDeadline; |
| 9609 | outMode.group = mode.group; |
| 9610 | std::transform(mode.supportedHdrTypes.begin(), mode.supportedHdrTypes.end(), |
| 9611 | std::back_inserter(outMode.supportedHdrTypes), |
| 9612 | [](const ui::Hdr& value) { return static_cast<int32_t>(value); }); |
| 9613 | outInfo->supportedDisplayModes.push_back(outMode); |
| 9614 | } |
| 9615 | |
| 9616 | outInfo->activeDisplayModeId = info.activeDisplayModeId; |
| 9617 | outInfo->renderFrameRate = info.renderFrameRate; |
| 9618 | |
| 9619 | outInfo->supportedColorModes.clear(); |
| 9620 | outInfo->supportedColorModes.reserve(info.supportedColorModes.size()); |
| 9621 | for (const auto& cmode : info.supportedColorModes) { |
| 9622 | outInfo->supportedColorModes.push_back(static_cast<int32_t>(cmode)); |
| 9623 | } |
| 9624 | |
| 9625 | outInfo->activeColorMode = static_cast<int32_t>(info.activeColorMode); |
| 9626 | |
| 9627 | gui::HdrCapabilities& hdrCapabilities = outInfo->hdrCapabilities; |
| 9628 | hdrCapabilities.supportedHdrTypes.clear(); |
| 9629 | hdrCapabilities.supportedHdrTypes.reserve(info.hdrCapabilities.getSupportedHdrTypes().size()); |
| 9630 | for (const auto& hdr : info.hdrCapabilities.getSupportedHdrTypes()) { |
| 9631 | hdrCapabilities.supportedHdrTypes.push_back(static_cast<int32_t>(hdr)); |
| 9632 | } |
| 9633 | hdrCapabilities.maxLuminance = info.hdrCapabilities.getDesiredMaxLuminance(); |
| 9634 | hdrCapabilities.maxAverageLuminance = info.hdrCapabilities.getDesiredMaxAverageLuminance(); |
| 9635 | hdrCapabilities.minLuminance = info.hdrCapabilities.getDesiredMinLuminance(); |
| 9636 | |
| 9637 | outInfo->autoLowLatencyModeSupported = info.autoLowLatencyModeSupported; |
| 9638 | outInfo->gameContentTypeSupported = info.gameContentTypeSupported; |
| 9639 | outInfo->preferredBootDisplayMode = info.preferredBootDisplayMode; |
| 9640 | } |
| 9641 | |
| 9642 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromToken( |
| 9643 | const sp<IBinder>& display, gui::DynamicDisplayInfo* outInfo) { |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9644 | ui::DynamicDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9645 | status_t status = mFlinger->getDynamicDisplayInfoFromToken(display, &info); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9646 | if (status == NO_ERROR) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9647 | getDynamicDisplayInfoInternal(info, outInfo); |
| 9648 | } |
| 9649 | return binderStatusFromStatusT(status); |
| 9650 | } |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 9651 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9652 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromId(int64_t displayId, |
| 9653 | gui::DynamicDisplayInfo* outInfo) { |
| 9654 | ui::DynamicDisplayInfo info; |
| 9655 | status_t status = mFlinger->getDynamicDisplayInfoFromId(displayId, &info); |
| 9656 | if (status == NO_ERROR) { |
| 9657 | getDynamicDisplayInfoInternal(info, outInfo); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9658 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9659 | return binderStatusFromStatusT(status); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9660 | } |
| 9661 | |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9662 | binder::Status SurfaceComposerAIDL::getDisplayNativePrimaries(const sp<IBinder>& display, |
| 9663 | gui::DisplayPrimaries* outPrimaries) { |
| 9664 | ui::DisplayPrimaries primaries; |
| 9665 | status_t status = mFlinger->getDisplayNativePrimaries(display, primaries); |
| 9666 | if (status == NO_ERROR) { |
| 9667 | outPrimaries->red.X = primaries.red.X; |
| 9668 | outPrimaries->red.Y = primaries.red.Y; |
| 9669 | outPrimaries->red.Z = primaries.red.Z; |
| 9670 | |
| 9671 | outPrimaries->green.X = primaries.green.X; |
| 9672 | outPrimaries->green.Y = primaries.green.Y; |
| 9673 | outPrimaries->green.Z = primaries.green.Z; |
| 9674 | |
| 9675 | outPrimaries->blue.X = primaries.blue.X; |
| 9676 | outPrimaries->blue.Y = primaries.blue.Y; |
| 9677 | outPrimaries->blue.Z = primaries.blue.Z; |
| 9678 | |
| 9679 | outPrimaries->white.X = primaries.white.X; |
| 9680 | outPrimaries->white.Y = primaries.white.Y; |
| 9681 | outPrimaries->white.Z = primaries.white.Z; |
| 9682 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9683 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9684 | } |
| 9685 | |
| 9686 | binder::Status SurfaceComposerAIDL::setActiveColorMode(const sp<IBinder>& display, int colorMode) { |
| 9687 | status_t status = checkAccessPermission(); |
| 9688 | if (status == OK) { |
| 9689 | status = mFlinger->setActiveColorMode(display, static_cast<ui::ColorMode>(colorMode)); |
| 9690 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9691 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9692 | } |
| 9693 | |
| 9694 | binder::Status SurfaceComposerAIDL::setBootDisplayMode(const sp<IBinder>& display, |
| 9695 | int displayModeId) { |
| 9696 | status_t status = checkAccessPermission(); |
| 9697 | if (status == OK) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 9698 | status = mFlinger->setBootDisplayMode(display, DisplayModeId{displayModeId}); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9699 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9700 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9701 | } |
| 9702 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9703 | binder::Status SurfaceComposerAIDL::clearBootDisplayMode(const sp<IBinder>& display) { |
| 9704 | status_t status = checkAccessPermission(); |
| 9705 | if (status == OK) { |
| 9706 | status = mFlinger->clearBootDisplayMode(display); |
| 9707 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9708 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9709 | } |
| 9710 | |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 9711 | binder::Status SurfaceComposerAIDL::getOverlaySupport(gui::OverlayProperties* outProperties) { |
| 9712 | status_t status = checkAccessPermission(); |
| 9713 | if (status == OK) { |
| 9714 | status = mFlinger->getOverlaySupport(outProperties); |
| 9715 | } |
| 9716 | return binderStatusFromStatusT(status); |
| 9717 | } |
| 9718 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9719 | binder::Status SurfaceComposerAIDL::getBootDisplayModeSupport(bool* outMode) { |
| 9720 | status_t status = checkAccessPermission(); |
| 9721 | if (status == OK) { |
| 9722 | status = mFlinger->getBootDisplayModeSupport(outMode); |
| 9723 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9724 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9725 | } |
| 9726 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9727 | binder::Status SurfaceComposerAIDL::getHdrConversionCapabilities( |
| 9728 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) { |
| 9729 | status_t status = checkAccessPermission(); |
| 9730 | if (status == OK) { |
| 9731 | status = mFlinger->getHdrConversionCapabilities(hdrConversionCapabilities); |
| 9732 | } |
| 9733 | return binderStatusFromStatusT(status); |
| 9734 | } |
| 9735 | |
| 9736 | binder::Status SurfaceComposerAIDL::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 9737 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 9738 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9739 | status_t status = checkAccessPermission(); |
| 9740 | if (status == OK) { |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 9741 | status = mFlinger->setHdrConversionStrategy(hdrConversionStrategy, |
| 9742 | outPreferredHdrOutputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9743 | } |
| 9744 | return binderStatusFromStatusT(status); |
| 9745 | } |
| 9746 | |
| 9747 | binder::Status SurfaceComposerAIDL::getHdrOutputConversionSupport(bool* outMode) { |
| 9748 | status_t status = checkAccessPermission(); |
| 9749 | if (status == OK) { |
| 9750 | status = mFlinger->getHdrOutputConversionSupport(outMode); |
| 9751 | } |
| 9752 | return binderStatusFromStatusT(status); |
| 9753 | } |
| 9754 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9755 | binder::Status SurfaceComposerAIDL::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) { |
| 9756 | status_t status = checkAccessPermission(); |
| 9757 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9758 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9759 | } |
| 9760 | mFlinger->setAutoLowLatencyMode(display, on); |
| 9761 | return binder::Status::ok(); |
| 9762 | } |
| 9763 | |
| 9764 | binder::Status SurfaceComposerAIDL::setGameContentType(const sp<IBinder>& display, bool on) { |
| 9765 | status_t status = checkAccessPermission(); |
| 9766 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9767 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9768 | } |
| 9769 | mFlinger->setGameContentType(display, on); |
| 9770 | return binder::Status::ok(); |
| 9771 | } |
| 9772 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9773 | binder::Status SurfaceComposerAIDL::captureDisplay( |
| 9774 | const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9775 | mFlinger->captureDisplay(args, captureListener); |
| 9776 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9777 | } |
| 9778 | |
| 9779 | binder::Status SurfaceComposerAIDL::captureDisplayById( |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 9780 | int64_t displayId, const CaptureArgs& args, |
| 9781 | const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9782 | // status_t status; |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9783 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9784 | const int uid = ipc->getCallingUid(); |
| 9785 | if (uid == AID_ROOT || uid == AID_GRAPHICS || uid == AID_SYSTEM || uid == AID_SHELL) { |
| 9786 | std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId)); |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 9787 | mFlinger->captureDisplay(*id, args, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9788 | } else { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9789 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9790 | } |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9791 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9792 | } |
| 9793 | |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 9794 | binder::Status SurfaceComposerAIDL::captureLayersSync(const LayerCaptureArgs& args, |
| 9795 | ScreenCaptureResults* outResults) { |
| 9796 | *outResults = mFlinger->captureLayersSync(args); |
| 9797 | return binderStatusFromStatusT(NO_ERROR); |
| 9798 | } |
| 9799 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9800 | binder::Status SurfaceComposerAIDL::captureLayers( |
| 9801 | const LayerCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9802 | mFlinger->captureLayers(args, captureListener); |
| 9803 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9804 | } |
| 9805 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9806 | binder::Status SurfaceComposerAIDL::overrideHdrTypes(const sp<IBinder>& display, |
| 9807 | const std::vector<int32_t>& hdrTypes) { |
| 9808 | // overrideHdrTypes is used by CTS tests, which acquire the necessary |
| 9809 | // permission dynamically. Don't use the permission cache for this check. |
| 9810 | status_t status = checkAccessPermission(false); |
| 9811 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9812 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9813 | } |
| 9814 | |
| 9815 | std::vector<ui::Hdr> hdrTypesVector; |
| 9816 | for (int32_t i : hdrTypes) { |
| 9817 | hdrTypesVector.push_back(static_cast<ui::Hdr>(i)); |
| 9818 | } |
| 9819 | status = mFlinger->overrideHdrTypes(display, hdrTypesVector); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9820 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9821 | } |
| 9822 | |
| 9823 | binder::Status SurfaceComposerAIDL::onPullAtom(int32_t atomId, gui::PullAtomData* outPullData) { |
| 9824 | status_t status; |
| 9825 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 9826 | if (uid != AID_SYSTEM) { |
| 9827 | status = PERMISSION_DENIED; |
| 9828 | } else { |
| 9829 | status = mFlinger->onPullAtom(atomId, &outPullData->data, &outPullData->success); |
| 9830 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9831 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9832 | } |
| 9833 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9834 | binder::Status SurfaceComposerAIDL::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
| 9835 | if (!outLayers) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9836 | return binderStatusFromStatusT(UNEXPECTED_NULL); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9837 | } |
| 9838 | |
| 9839 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9840 | const int pid = ipc->getCallingPid(); |
| 9841 | const int uid = ipc->getCallingUid(); |
| 9842 | if ((uid != AID_SHELL) && !PermissionCache::checkPermission(sDump, pid, uid)) { |
| 9843 | 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] | 9844 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9845 | } |
| 9846 | status_t status = mFlinger->getLayerDebugInfo(outLayers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9847 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9848 | } |
| 9849 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9850 | binder::Status SurfaceComposerAIDL::getCompositionPreference(gui::CompositionPreference* outPref) { |
| 9851 | ui::Dataspace dataspace; |
| 9852 | ui::PixelFormat pixelFormat; |
| 9853 | ui::Dataspace wideColorGamutDataspace; |
| 9854 | ui::PixelFormat wideColorGamutPixelFormat; |
| 9855 | status_t status = |
| 9856 | mFlinger->getCompositionPreference(&dataspace, &pixelFormat, &wideColorGamutDataspace, |
| 9857 | &wideColorGamutPixelFormat); |
| 9858 | if (status == NO_ERROR) { |
| 9859 | outPref->defaultDataspace = static_cast<int32_t>(dataspace); |
| 9860 | outPref->defaultPixelFormat = static_cast<int32_t>(pixelFormat); |
| 9861 | outPref->wideColorGamutDataspace = static_cast<int32_t>(wideColorGamutDataspace); |
| 9862 | outPref->wideColorGamutPixelFormat = static_cast<int32_t>(wideColorGamutPixelFormat); |
| 9863 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9864 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9865 | } |
| 9866 | |
| 9867 | binder::Status SurfaceComposerAIDL::getDisplayedContentSamplingAttributes( |
| 9868 | const sp<IBinder>& display, gui::ContentSamplingAttributes* outAttrs) { |
| 9869 | status_t status = checkAccessPermission(); |
| 9870 | if (status != OK) { |
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 | ui::PixelFormat format; |
| 9875 | ui::Dataspace dataspace; |
| 9876 | uint8_t componentMask; |
| 9877 | status = mFlinger->getDisplayedContentSamplingAttributes(display, &format, &dataspace, |
| 9878 | &componentMask); |
| 9879 | if (status == NO_ERROR) { |
| 9880 | outAttrs->format = static_cast<int32_t>(format); |
| 9881 | outAttrs->dataspace = static_cast<int32_t>(dataspace); |
| 9882 | outAttrs->componentMask = static_cast<int8_t>(componentMask); |
| 9883 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9884 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9885 | } |
| 9886 | |
| 9887 | binder::Status SurfaceComposerAIDL::setDisplayContentSamplingEnabled(const sp<IBinder>& display, |
| 9888 | bool enable, |
| 9889 | int8_t componentMask, |
| 9890 | int64_t maxFrames) { |
| 9891 | status_t status = checkAccessPermission(); |
| 9892 | if (status == OK) { |
| 9893 | status = mFlinger->setDisplayContentSamplingEnabled(display, enable, |
| 9894 | static_cast<uint8_t>(componentMask), |
| 9895 | static_cast<uint64_t>(maxFrames)); |
| 9896 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9897 | return binderStatusFromStatusT(status); |
| 9898 | } |
| 9899 | |
| 9900 | binder::Status SurfaceComposerAIDL::getDisplayedContentSample(const sp<IBinder>& display, |
| 9901 | int64_t maxFrames, int64_t timestamp, |
| 9902 | gui::DisplayedFrameStats* outStats) { |
| 9903 | if (!outStats) { |
| 9904 | return binderStatusFromStatusT(BAD_VALUE); |
| 9905 | } |
| 9906 | |
| 9907 | status_t status = checkAccessPermission(); |
| 9908 | if (status != OK) { |
| 9909 | return binderStatusFromStatusT(status); |
| 9910 | } |
| 9911 | |
| 9912 | DisplayedFrameStats stats; |
| 9913 | status = mFlinger->getDisplayedContentSample(display, static_cast<uint64_t>(maxFrames), |
| 9914 | static_cast<uint64_t>(timestamp), &stats); |
| 9915 | if (status == NO_ERROR) { |
| 9916 | // convert from ui::DisplayedFrameStats to gui::DisplayedFrameStats |
| 9917 | outStats->numFrames = static_cast<int64_t>(stats.numFrames); |
| 9918 | outStats->component_0_sample.reserve(stats.component_0_sample.size()); |
| 9919 | for (const auto& s : stats.component_0_sample) { |
| 9920 | outStats->component_0_sample.push_back(static_cast<int64_t>(s)); |
| 9921 | } |
| 9922 | outStats->component_1_sample.reserve(stats.component_1_sample.size()); |
| 9923 | for (const auto& s : stats.component_1_sample) { |
| 9924 | outStats->component_1_sample.push_back(static_cast<int64_t>(s)); |
| 9925 | } |
| 9926 | outStats->component_2_sample.reserve(stats.component_2_sample.size()); |
| 9927 | for (const auto& s : stats.component_2_sample) { |
| 9928 | outStats->component_2_sample.push_back(static_cast<int64_t>(s)); |
| 9929 | } |
| 9930 | outStats->component_3_sample.reserve(stats.component_3_sample.size()); |
| 9931 | for (const auto& s : stats.component_3_sample) { |
| 9932 | outStats->component_3_sample.push_back(static_cast<int64_t>(s)); |
| 9933 | } |
| 9934 | } |
| 9935 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9936 | } |
| 9937 | |
| 9938 | binder::Status SurfaceComposerAIDL::getProtectedContentSupport(bool* outSupported) { |
| 9939 | status_t status = mFlinger->getProtectedContentSupport(outSupported); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9940 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9941 | } |
| 9942 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9943 | binder::Status SurfaceComposerAIDL::isWideColorDisplay(const sp<IBinder>& token, |
| 9944 | bool* outIsWideColorDisplay) { |
| 9945 | status_t status = mFlinger->isWideColorDisplay(token, outIsWideColorDisplay); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9946 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9947 | } |
| 9948 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9949 | binder::Status SurfaceComposerAIDL::addRegionSamplingListener( |
| 9950 | const gui::ARect& samplingArea, const sp<IBinder>& stopLayerHandle, |
| 9951 | const sp<gui::IRegionSamplingListener>& listener) { |
| 9952 | status_t status = checkReadFrameBufferPermission(); |
| 9953 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9954 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9955 | } |
| 9956 | android::Rect rect; |
| 9957 | rect.left = samplingArea.left; |
| 9958 | rect.top = samplingArea.top; |
| 9959 | rect.right = samplingArea.right; |
| 9960 | rect.bottom = samplingArea.bottom; |
| 9961 | status = mFlinger->addRegionSamplingListener(rect, stopLayerHandle, listener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9962 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9963 | } |
| 9964 | |
| 9965 | binder::Status SurfaceComposerAIDL::removeRegionSamplingListener( |
| 9966 | const sp<gui::IRegionSamplingListener>& listener) { |
| 9967 | status_t status = checkReadFrameBufferPermission(); |
| 9968 | if (status == OK) { |
| 9969 | status = mFlinger->removeRegionSamplingListener(listener); |
| 9970 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9971 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9972 | } |
| 9973 | |
| 9974 | binder::Status SurfaceComposerAIDL::addFpsListener(int32_t taskId, |
| 9975 | const sp<gui::IFpsListener>& listener) { |
| 9976 | status_t status = checkReadFrameBufferPermission(); |
| 9977 | if (status == OK) { |
| 9978 | status = mFlinger->addFpsListener(taskId, listener); |
| 9979 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9980 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9981 | } |
| 9982 | |
| 9983 | binder::Status SurfaceComposerAIDL::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 9984 | status_t status = checkReadFrameBufferPermission(); |
| 9985 | if (status == OK) { |
| 9986 | status = mFlinger->removeFpsListener(listener); |
| 9987 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9988 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9989 | } |
| 9990 | |
| 9991 | binder::Status SurfaceComposerAIDL::addTunnelModeEnabledListener( |
| 9992 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 9993 | status_t status = checkAccessPermission(); |
| 9994 | if (status == OK) { |
| 9995 | status = mFlinger->addTunnelModeEnabledListener(listener); |
| 9996 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9997 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9998 | } |
| 9999 | |
| 10000 | binder::Status SurfaceComposerAIDL::removeTunnelModeEnabledListener( |
| 10001 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 10002 | status_t status = checkAccessPermission(); |
| 10003 | if (status == OK) { |
| 10004 | status = mFlinger->removeTunnelModeEnabledListener(listener); |
| 10005 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10006 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10007 | } |
| 10008 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 10009 | binder::Status SurfaceComposerAIDL::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 10010 | const gui::DisplayModeSpecs& specs) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10011 | status_t status = checkAccessPermission(); |
| 10012 | if (status == OK) { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 10013 | status = mFlinger->setDesiredDisplayModeSpecs(displayToken, specs); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10014 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10015 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10016 | } |
| 10017 | |
| 10018 | binder::Status SurfaceComposerAIDL::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 10019 | gui::DisplayModeSpecs* outSpecs) { |
| 10020 | if (!outSpecs) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10021 | return binderStatusFromStatusT(BAD_VALUE); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10022 | } |
| 10023 | |
| 10024 | status_t status = checkAccessPermission(); |
| 10025 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10026 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10027 | } |
| 10028 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 10029 | status = mFlinger->getDesiredDisplayModeSpecs(displayToken, outSpecs); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10030 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10031 | } |
| 10032 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10033 | binder::Status SurfaceComposerAIDL::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 10034 | bool* outSupport) { |
| 10035 | status_t status = mFlinger->getDisplayBrightnessSupport(displayToken, outSupport); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10036 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10037 | } |
| 10038 | |
| 10039 | binder::Status SurfaceComposerAIDL::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 10040 | const gui::DisplayBrightness& brightness) { |
| 10041 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10042 | if (status == OK) { |
| 10043 | status = mFlinger->setDisplayBrightness(displayToken, brightness); |
| 10044 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10045 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10046 | } |
| 10047 | |
| 10048 | binder::Status SurfaceComposerAIDL::addHdrLayerInfoListener( |
| 10049 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 10050 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10051 | if (status == OK) { |
| 10052 | status = mFlinger->addHdrLayerInfoListener(displayToken, listener); |
| 10053 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10054 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10055 | } |
| 10056 | |
| 10057 | binder::Status SurfaceComposerAIDL::removeHdrLayerInfoListener( |
| 10058 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 10059 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10060 | if (status == OK) { |
| 10061 | status = mFlinger->removeHdrLayerInfoListener(displayToken, listener); |
| 10062 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10063 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10064 | } |
| 10065 | |
| 10066 | binder::Status SurfaceComposerAIDL::notifyPowerBoost(int boostId) { |
| 10067 | status_t status = checkAccessPermission(); |
| 10068 | if (status == OK) { |
| 10069 | status = mFlinger->notifyPowerBoost(boostId); |
| 10070 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10071 | return binderStatusFromStatusT(status); |
| 10072 | } |
| 10073 | |
| 10074 | binder::Status SurfaceComposerAIDL::setGlobalShadowSettings(const gui::Color& ambientColor, |
| 10075 | const gui::Color& spotColor, |
| 10076 | float lightPosY, float lightPosZ, |
| 10077 | float lightRadius) { |
| 10078 | status_t status = checkAccessPermission(); |
| 10079 | if (status != OK) { |
| 10080 | return binderStatusFromStatusT(status); |
| 10081 | } |
| 10082 | |
| 10083 | half4 ambientColorHalf = {ambientColor.r, ambientColor.g, ambientColor.b, ambientColor.a}; |
| 10084 | half4 spotColorHalf = {spotColor.r, spotColor.g, spotColor.b, spotColor.a}; |
| 10085 | status = mFlinger->setGlobalShadowSettings(ambientColorHalf, spotColorHalf, lightPosY, |
| 10086 | lightPosZ, lightRadius); |
| 10087 | return binderStatusFromStatusT(status); |
| 10088 | } |
| 10089 | |
| 10090 | binder::Status SurfaceComposerAIDL::getDisplayDecorationSupport( |
| 10091 | const sp<IBinder>& displayToken, std::optional<gui::DisplayDecorationSupport>* outSupport) { |
| 10092 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport> support; |
| 10093 | status_t status = mFlinger->getDisplayDecorationSupport(displayToken, &support); |
| 10094 | if (status != NO_ERROR) { |
| 10095 | ALOGE("getDisplayDecorationSupport failed with error %d", status); |
| 10096 | return binderStatusFromStatusT(status); |
| 10097 | } |
| 10098 | |
| 10099 | if (!support || !support.has_value()) { |
| 10100 | outSupport->reset(); |
| 10101 | } else { |
| 10102 | outSupport->emplace(); |
| 10103 | outSupport->value().format = static_cast<int32_t>(support->format); |
| 10104 | outSupport->value().alphaInterpretation = |
| 10105 | static_cast<int32_t>(support->alphaInterpretation); |
| 10106 | } |
| 10107 | |
| 10108 | return binder::Status::ok(); |
| 10109 | } |
| 10110 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10111 | binder::Status SurfaceComposerAIDL::setGameModeFrameRateOverride(int32_t uid, float frameRate) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10112 | status_t status; |
| 10113 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10114 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10115 | status = mFlinger->setGameModeFrameRateOverride(uid, frameRate); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10116 | } else { |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10117 | ALOGE("setGameModeFrameRateOverride() permission denied for uid: %d", c_uid); |
| 10118 | status = PERMISSION_DENIED; |
| 10119 | } |
| 10120 | return binderStatusFromStatusT(status); |
| 10121 | } |
| 10122 | |
| 10123 | binder::Status SurfaceComposerAIDL::setGameDefaultFrameRateOverride(int32_t uid, float frameRate) { |
| 10124 | status_t status; |
| 10125 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10126 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 10127 | status = mFlinger->setGameDefaultFrameRateOverride(uid, frameRate); |
| 10128 | } else { |
| 10129 | ALOGE("setGameDefaultFrameRateOverride() permission denied for uid: %d", c_uid); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10130 | status = PERMISSION_DENIED; |
| 10131 | } |
| 10132 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10133 | } |
| 10134 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 10135 | binder::Status SurfaceComposerAIDL::enableRefreshRateOverlay(bool active) { |
| 10136 | mFlinger->sfdo_enableRefreshRateOverlay(active); |
| 10137 | return binder::Status::ok(); |
| 10138 | } |
| 10139 | |
| 10140 | binder::Status SurfaceComposerAIDL::setDebugFlash(int delay) { |
| 10141 | mFlinger->sfdo_setDebugFlash(delay); |
| 10142 | return binder::Status::ok(); |
| 10143 | } |
| 10144 | |
| 10145 | binder::Status SurfaceComposerAIDL::scheduleComposite() { |
| 10146 | mFlinger->sfdo_scheduleComposite(); |
| 10147 | return binder::Status::ok(); |
| 10148 | } |
| 10149 | |
| 10150 | binder::Status SurfaceComposerAIDL::scheduleCommit() { |
| 10151 | mFlinger->sfdo_scheduleCommit(); |
| 10152 | return binder::Status::ok(); |
| 10153 | } |
| 10154 | |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 10155 | binder::Status SurfaceComposerAIDL::forceClientComposition(bool enabled) { |
| 10156 | mFlinger->sfdo_forceClientComposition(enabled); |
| 10157 | return binder::Status::ok(); |
| 10158 | } |
| 10159 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10160 | binder::Status SurfaceComposerAIDL::updateSmallAreaDetection(const std::vector<int32_t>& appIds, |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10161 | const std::vector<float>& thresholds) { |
| 10162 | status_t status; |
| 10163 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10164 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10165 | if (appIds.size() != thresholds.size()) return binderStatusFromStatusT(BAD_VALUE); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10166 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10167 | std::vector<std::pair<int32_t, float>> mappings; |
| 10168 | const size_t size = appIds.size(); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10169 | mappings.reserve(size); |
| 10170 | for (int i = 0; i < size; i++) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10171 | auto row = std::make_pair(appIds[i], thresholds[i]); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10172 | mappings.push_back(row); |
| 10173 | } |
| 10174 | status = mFlinger->updateSmallAreaDetection(mappings); |
| 10175 | } else { |
| 10176 | ALOGE("updateSmallAreaDetection() permission denied for uid: %d", c_uid); |
| 10177 | status = PERMISSION_DENIED; |
| 10178 | } |
| 10179 | return binderStatusFromStatusT(status); |
| 10180 | } |
| 10181 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10182 | binder::Status SurfaceComposerAIDL::setSmallAreaDetectionThreshold(int32_t appId, float threshold) { |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10183 | status_t status; |
| 10184 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10185 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10186 | status = mFlinger->setSmallAreaDetectionThreshold(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10187 | } else { |
| 10188 | ALOGE("setSmallAreaDetectionThreshold() permission denied for uid: %d", c_uid); |
| 10189 | status = PERMISSION_DENIED; |
| 10190 | } |
| 10191 | return binderStatusFromStatusT(status); |
| 10192 | } |
| 10193 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10194 | binder::Status SurfaceComposerAIDL::getGpuContextPriority(int32_t* outPriority) { |
| 10195 | *outPriority = mFlinger->getGpuContextPriority(); |
| 10196 | return binder::Status::ok(); |
| 10197 | } |
| 10198 | |
| 10199 | binder::Status SurfaceComposerAIDL::getMaxAcquiredBufferCount(int32_t* buffers) { |
| 10200 | status_t status = mFlinger->getMaxAcquiredBufferCount(buffers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10201 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10202 | } |
| 10203 | |
| 10204 | binder::Status SurfaceComposerAIDL::addWindowInfosListener( |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 10205 | const sp<gui::IWindowInfosListener>& windowInfosListener, |
| 10206 | gui::WindowInfosListenerInfo* outInfo) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10207 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10208 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10209 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10210 | // TODO(b/270566761) update permissions check so that only system_server and shell can add |
| 10211 | // WindowInfosListeners |
| 10212 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 10213 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 10214 | status = mFlinger->addWindowInfosListener(windowInfosListener, outInfo); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10215 | } else { |
| 10216 | status = PERMISSION_DENIED; |
| 10217 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10218 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10219 | } |
| 10220 | |
| 10221 | binder::Status SurfaceComposerAIDL::removeWindowInfosListener( |
| 10222 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 10223 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10224 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10225 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10226 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 10227 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10228 | status = mFlinger->removeWindowInfosListener(windowInfosListener); |
| 10229 | } else { |
| 10230 | status = PERMISSION_DENIED; |
| 10231 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10232 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10233 | } |
| 10234 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 10235 | binder::Status SurfaceComposerAIDL::getStalledTransactionInfo( |
| 10236 | int pid, std::optional<gui::StalledTransactionInfo>* outInfo) { |
| 10237 | const int callingPid = IPCThreadState::self()->getCallingPid(); |
| 10238 | const int callingUid = IPCThreadState::self()->getCallingUid(); |
| 10239 | if (!checkPermission(sAccessSurfaceFlinger, callingPid, callingUid)) { |
| 10240 | return binderStatusFromStatusT(PERMISSION_DENIED); |
| 10241 | } |
| 10242 | |
| 10243 | std::optional<TransactionHandler::StalledTransactionInfo> stalledTransactionInfo; |
| 10244 | status_t status = mFlinger->getStalledTransactionInfo(pid, stalledTransactionInfo); |
| 10245 | if (stalledTransactionInfo) { |
| 10246 | gui::StalledTransactionInfo result; |
| 10247 | result.layerName = String16{stalledTransactionInfo->layerName.c_str()}, |
| 10248 | result.bufferId = stalledTransactionInfo->bufferId, |
| 10249 | result.frameNumber = stalledTransactionInfo->frameNumber, |
| 10250 | outInfo->emplace(std::move(result)); |
| 10251 | } else { |
| 10252 | outInfo->reset(); |
| 10253 | } |
| 10254 | return binderStatusFromStatusT(status); |
| 10255 | } |
| 10256 | |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 10257 | binder::Status SurfaceComposerAIDL::getSchedulingPolicy(gui::SchedulingPolicy* outPolicy) { |
| 10258 | return gui::getSchedulingPolicy(outPolicy); |
| 10259 | } |
| 10260 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 10261 | status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { |
| 10262 | if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
| 10263 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10264 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", ipc->getCallingPid(), |
| 10265 | ipc->getCallingUid()); |
| 10266 | return PERMISSION_DENIED; |
| 10267 | } |
| 10268 | return OK; |
| 10269 | } |
| 10270 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10271 | status_t SurfaceComposerAIDL::checkControlDisplayBrightnessPermission() { |
| 10272 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10273 | const int pid = ipc->getCallingPid(); |
| 10274 | const int uid = ipc->getCallingUid(); |
Rheygine Medel | 9e9281e | 2022-09-22 10:13:56 -0700 | [diff] [blame] | 10275 | if ((uid != AID_GRAPHICS) && (uid != AID_SYSTEM) && |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10276 | !PermissionCache::checkPermission(sControlDisplayBrightness, pid, uid)) { |
| 10277 | ALOGE("Permission Denial: can't control brightness pid=%d, uid=%d", pid, uid); |
| 10278 | return PERMISSION_DENIED; |
| 10279 | } |
| 10280 | return OK; |
| 10281 | } |
| 10282 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10283 | status_t SurfaceComposerAIDL::checkReadFrameBufferPermission() { |
| 10284 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10285 | const int pid = ipc->getCallingPid(); |
| 10286 | const int uid = ipc->getCallingUid(); |
| 10287 | if ((uid != AID_GRAPHICS) && !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 10288 | ALOGE("Permission Denial: can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 10289 | return PERMISSION_DENIED; |
| 10290 | } |
| 10291 | return OK; |
| 10292 | } |
| 10293 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 10294 | void SurfaceFlinger::forceFutureUpdate(int delayInMs) { |
| 10295 | static_cast<void>(mScheduler->scheduleDelayed([&]() { scheduleRepaint(); }, ms2ns(delayInMs))); |
| 10296 | } |
| 10297 | |
Vishnu Nair | 2f65e97 | 2023-04-04 16:36:28 +0000 | [diff] [blame] | 10298 | const DisplayDevice* SurfaceFlinger::getDisplayFromLayerStack(ui::LayerStack layerStack) { |
| 10299 | for (const auto& [_, display] : mDisplays) { |
| 10300 | if (display->getLayerStack() == layerStack) { |
| 10301 | return display.get(); |
| 10302 | } |
| 10303 | } |
| 10304 | return nullptr; |
| 10305 | } |
| 10306 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 10307 | } // namespace android |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 10308 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 10309 | #if defined(__gl_h_) |
| 10310 | #error "don't include gl/gl.h in this file" |
| 10311 | #endif |
| 10312 | |
| 10313 | #if defined(__gl2_h_) |
| 10314 | #error "don't include gl2/gl2.h in this file" |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 10315 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 10316 | |
| 10317 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 10318 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |