The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 20 | #pragma clang diagnostic ignored "-Wextra" |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 21 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 22 | //#define LOG_NDEBUG 0 |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 23 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 24 | |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 25 | #include "SurfaceFlinger.h" |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 26 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 27 | #include <aidl/android/hardware/power/Boost.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 28 | #include <android-base/parseint.h> |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 29 | #include <android-base/properties.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 30 | #include <android-base/stringprintf.h> |
| 31 | #include <android-base/strings.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 32 | #include <android/configuration.h> |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 33 | #include <android/gui/IDisplayEventConnection.h> |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 34 | #include <android/gui/StaticDisplayInfo.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 35 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 36 | #include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h> |
| 37 | #include <android/hardware/configstore/1.1/types.h> |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 38 | #include <android/native_window.h> |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 39 | #include <android/os/IInputFlinger.h> |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 40 | #include <binder/IPCThreadState.h> |
| 41 | #include <binder/IServiceManager.h> |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 42 | #include <binder/PermissionCache.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 43 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 44 | #include <compositionengine/CompositionRefreshArgs.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 45 | #include <compositionengine/Display.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 46 | #include <compositionengine/DisplayColorProfile.h> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 47 | #include <compositionengine/DisplayColorProfileCreationArgs.h> |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 48 | #include <compositionengine/DisplayCreationArgs.h> |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 49 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 50 | #include <compositionengine/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 51 | #include <compositionengine/RenderSurface.h> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 52 | #include <compositionengine/impl/DisplayColorProfile.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 53 | #include <compositionengine/impl/OutputCompositionState.h> |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 54 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 55 | #include <configstore/Utils.h> |
| 56 | #include <cutils/compiler.h> |
| 57 | #include <cutils/properties.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 58 | #include <ftl/algorithm.h> |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 59 | #include <ftl/concat.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 60 | #include <ftl/fake_guard.h> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 61 | #include <ftl/future.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 62 | #include <ftl/unit.h> |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 63 | #include <gui/AidlStatusUtil.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 64 | #include <gui/BufferQueue.h> |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 65 | #include <gui/DebugEGLImageTracker.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 66 | #include <gui/IProducerListener.h> |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 67 | #include <gui/LayerDebugInfo.h> |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 68 | #include <gui/LayerMetadata.h> |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 69 | #include <gui/LayerState.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 70 | #include <gui/Surface.h> |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 71 | #include <gui/SurfaceComposerClient.h> |
rnlee | 60f46b5 | 2021-05-21 15:14:07 -0700 | [diff] [blame] | 72 | #include <gui/TraceUtils.h> |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 73 | #include <hidl/ServiceManagement.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 74 | #include <layerproto/LayerProtoParser.h> |
| 75 | #include <log/log.h> |
| 76 | #include <private/android_filesystem_config.h> |
| 77 | #include <private/gui/SyncFeatures.h> |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 78 | #include <processgroup/processgroup.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 79 | #include <renderengine/RenderEngine.h> |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 80 | #include <renderengine/impl/ExternalTexture.h> |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 81 | #include <scheduler/FrameTargeter.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 82 | #include <sys/types.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 83 | #include <ui/ColorSpace.h> |
| 84 | #include <ui/DebugUtils.h> |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 85 | #include <ui/DisplayId.h> |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 86 | #include <ui/DisplayMode.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 87 | #include <ui/DisplayStatInfo.h> |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 88 | #include <ui/DisplayState.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 89 | #include <ui/DynamicDisplayInfo.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 90 | #include <ui/GraphicBufferAllocator.h> |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 91 | #include <ui/HdrRenderTypeUtils.h> |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 92 | #include <ui/LayerStack.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 93 | #include <ui/PixelFormat.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 94 | #include <ui/StaticDisplayInfo.h> |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 95 | #include <unistd.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | #include <utils/StopWatch.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 97 | #include <utils/String16.h> |
| 98 | #include <utils/String8.h> |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 99 | #include <utils/Timers.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 100 | #include <utils/misc.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 101 | #include <algorithm> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 102 | #include <cerrno> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 103 | #include <cinttypes> |
| 104 | #include <cmath> |
| 105 | #include <cstdint> |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 106 | #include <filesystem> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 107 | #include <functional> |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 108 | #include <memory> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 109 | #include <mutex> |
| 110 | #include <optional> |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 111 | #include <string> |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 112 | #include <type_traits> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 113 | #include <unordered_map> |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 114 | #include <vector> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | |
Alec Mouri | 9b133ca | 2023-11-14 19:00:01 +0000 | [diff] [blame] | 116 | #include <common/FlagManager.h> |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 117 | #include <gui/LayerStatePermissions.h> |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 118 | #include <gui/SchedulingPolicy.h> |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 119 | #include <gui/SyncScreenCaptureListener.h> |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 120 | #include <ui/DisplayIdentification.h> |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 121 | #include "BackgroundExecutor.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 122 | #include "Client.h" |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 123 | #include "ClientCache.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 124 | #include "Colorizer.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 125 | #include "DisplayDevice.h" |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 126 | #include "DisplayHardware/ComposerHal.h" |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 127 | #include "DisplayHardware/FramebufferSurface.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 128 | #include "DisplayHardware/HWComposer.h" |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 129 | #include "DisplayHardware/Hal.h" |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 130 | #include "DisplayHardware/PowerAdvisor.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 131 | #include "DisplayHardware/VirtualDisplaySurface.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 132 | #include "DisplayRenderArea.h" |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 133 | #include "Effects/Daltonizer.h" |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 134 | #include "FpsReporter.h" |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 135 | #include "FrameTimeline/FrameTimeline.h" |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 136 | #include "FrameTracer/FrameTracer.h" |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 137 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 138 | #include "FrontEnd/LayerHandle.h" |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 139 | #include "FrontEnd/LayerLifecycleManager.h" |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 140 | #include "FrontEnd/LayerLog.h" |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 141 | #include "FrontEnd/LayerSnapshot.h" |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 142 | #include "HdrLayerInfoReporter.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 143 | #include "Layer.h" |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 144 | #include "LayerProtoHelper.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 145 | #include "LayerRenderArea.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 146 | #include "LayerVector.h" |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 147 | #include "MutexUtils.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 148 | #include "NativeWindowSurface.h" |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 149 | #include "RegionSamplingThread.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 150 | #include "Scheduler/EventThread.h" |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 151 | #include "Scheduler/LayerHistory.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 152 | #include "Scheduler/Scheduler.h" |
Ady Abraham | c581d3c | 2020-08-06 17:34:27 -0700 | [diff] [blame] | 153 | #include "Scheduler/VsyncConfiguration.h" |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 154 | #include "Scheduler/VsyncModulator.h" |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 155 | #include "ScreenCaptureOutput.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 156 | #include "StartPropertySetThread.h" |
| 157 | #include "SurfaceFlingerProperties.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 158 | #include "TimeStats/TimeStats.h" |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 159 | #include "TunnelModeEnabledReporter.h" |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 160 | #include "Utils/Dumper.h" |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 161 | #include "WindowInfosListenerInvoker.h" |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 162 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 163 | #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 164 | #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 165 | #include <aidl/android/hardware/graphics/composer3/RenderIntent.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 166 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 167 | #undef NO_THREAD_SAFETY_ANALYSIS |
| 168 | #define NO_THREAD_SAFETY_ANALYSIS \ |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 169 | _Pragma("GCC error \"Prefer <ftl/fake_guard.h> or MutexUtils.h helpers.\"") |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 170 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 171 | // To enable layer borders in the system, change the below flag to true. |
| 172 | #undef DOES_CONTAIN_BORDER |
| 173 | #define DOES_CONTAIN_BORDER false |
| 174 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | namespace android { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 176 | using namespace std::chrono_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 177 | using namespace std::string_literals; |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 178 | using namespace std::string_view_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 179 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 180 | using namespace hardware::configstore; |
| 181 | using namespace hardware::configstore::V1_0; |
| 182 | using namespace sysprop; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 183 | using ftl::Flags; |
| 184 | using namespace ftl::flag_operators; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 185 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 186 | using aidl::android::hardware::graphics::common::DisplayDecorationSupport; |
| 187 | using aidl::android::hardware::graphics::composer3::Capability; |
| 188 | using aidl::android::hardware::graphics::composer3::DisplayCapability; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 189 | using CompositionStrategyPredictionState = android::compositionengine::impl:: |
| 190 | OutputCompositionState::CompositionStrategyPredictionState; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 191 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 192 | using base::StringAppendF; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 193 | using display::PhysicalDisplay; |
| 194 | using display::PhysicalDisplays; |
Vishnu Nair | af6d297 | 2022-11-18 06:26:38 +0000 | [diff] [blame] | 195 | using frontend::TransactionHandler; |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 196 | using gui::DisplayInfo; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 197 | using gui::GameMode; |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 198 | using gui::IDisplayEventConnection; |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 199 | using gui::IWindowInfosListener; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 200 | using gui::LayerMetadata; |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 201 | using gui::WindowInfo; |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 202 | using gui::aidl_utils::binderStatusFromStatusT; |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 203 | using scheduler::VsyncModulator; |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 204 | using ui::Dataspace; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 205 | using ui::DisplayPrimaries; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 206 | using ui::RenderIntent; |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 207 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 208 | using KernelIdleTimerController = scheduler::RefreshRateSelector::KernelIdleTimerController; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 209 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 210 | namespace hal = android::hardware::graphics::composer::hal; |
| 211 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 212 | namespace { |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 213 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 214 | static constexpr int FOUR_K_WIDTH = 3840; |
| 215 | static constexpr int FOUR_K_HEIGHT = 2160; |
| 216 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 217 | // TODO(b/141333600): Consolidate with DisplayMode::Builder::getDefaultDensity. |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 218 | constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 219 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 220 | float getDensityFromProperty(const char* property, bool required) { |
| 221 | char value[PROPERTY_VALUE_MAX]; |
| 222 | const float density = property_get(property, value, nullptr) > 0 ? std::atof(value) : 0.f; |
| 223 | if (!density && required) { |
| 224 | ALOGE("%s must be defined as a build property", property); |
| 225 | return FALLBACK_DENSITY; |
| 226 | } |
| 227 | return density; |
| 228 | } |
| 229 | |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 230 | // Currently we only support V0_SRGB and DISPLAY_P3 as composition preference. |
| 231 | bool validateCompositionDataspace(Dataspace dataspace) { |
| 232 | return dataspace == Dataspace::V0_SRGB || dataspace == Dataspace::DISPLAY_P3; |
| 233 | } |
| 234 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 235 | std::chrono::milliseconds getIdleTimerTimeout(DisplayId displayId) { |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 236 | if (const int32_t displayIdleTimerMs = |
| 237 | base::GetIntProperty("debug.sf.set_idle_timer_ms_"s + |
| 238 | std::to_string(displayId.value), |
| 239 | 0); |
| 240 | displayIdleTimerMs > 0) { |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 241 | return std::chrono::milliseconds(displayIdleTimerMs); |
| 242 | } |
| 243 | |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 244 | const int32_t setIdleTimerMs = base::GetIntProperty("debug.sf.set_idle_timer_ms"s, 0); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 245 | const int32_t millis = setIdleTimerMs ? setIdleTimerMs : sysprop::set_idle_timer_ms(0); |
| 246 | return std::chrono::milliseconds(millis); |
| 247 | } |
| 248 | |
| 249 | bool getKernelIdleTimerSyspropConfig(DisplayId displayId) { |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 250 | const bool displaySupportKernelIdleTimer = |
| 251 | base::GetBoolProperty("debug.sf.support_kernel_idle_timer_"s + |
| 252 | std::to_string(displayId.value), |
| 253 | false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 254 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 255 | return displaySupportKernelIdleTimer || sysprop::support_kernel_idle_timer(false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 258 | bool isAbove4k30(const ui::DisplayMode& outMode) { |
| 259 | using fps_approx_ops::operator>; |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 260 | Fps refreshRate = Fps::fromValue(outMode.peakRefreshRate); |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 261 | return outMode.resolution.getWidth() >= FOUR_K_WIDTH && |
| 262 | outMode.resolution.getHeight() >= FOUR_K_HEIGHT && refreshRate > 30_Hz; |
| 263 | } |
| 264 | |
| 265 | void excludeDolbyVisionIf4k30Present(const std::vector<ui::Hdr>& displayHdrTypes, |
| 266 | ui::DisplayMode& outMode) { |
| 267 | if (isAbove4k30(outMode) && |
| 268 | std::any_of(displayHdrTypes.begin(), displayHdrTypes.end(), |
| 269 | [](ui::Hdr type) { return type == ui::Hdr::DOLBY_VISION_4K30; })) { |
| 270 | for (ui::Hdr type : displayHdrTypes) { |
| 271 | if (type != ui::Hdr::DOLBY_VISION_4K30 && type != ui::Hdr::DOLBY_VISION) { |
| 272 | outMode.supportedHdrTypes.push_back(type); |
| 273 | } |
| 274 | } |
| 275 | } else { |
| 276 | for (ui::Hdr type : displayHdrTypes) { |
| 277 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 278 | outMode.supportedHdrTypes.push_back(type); |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | HdrCapabilities filterOut4k30(const HdrCapabilities& displayHdrCapabilities) { |
| 285 | std::vector<ui::Hdr> hdrTypes; |
| 286 | for (ui::Hdr type : displayHdrCapabilities.getSupportedHdrTypes()) { |
| 287 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 288 | hdrTypes.push_back(type); |
| 289 | } |
| 290 | } |
| 291 | return {hdrTypes, displayHdrCapabilities.getDesiredMaxLuminance(), |
| 292 | displayHdrCapabilities.getDesiredMaxAverageLuminance(), |
| 293 | displayHdrCapabilities.getDesiredMinLuminance()}; |
| 294 | } |
| 295 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 296 | uint32_t getLayerIdFromSurfaceControl(sp<SurfaceControl> surfaceControl) { |
| 297 | if (!surfaceControl) { |
| 298 | return UNASSIGNED_LAYER_ID; |
| 299 | } |
| 300 | return LayerHandle::getLayerId(surfaceControl->getHandle()); |
| 301 | } |
| 302 | |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 303 | /** |
| 304 | * Returns true if the file at path exists and is newer than duration. |
| 305 | */ |
| 306 | bool fileNewerThan(const std::string& path, std::chrono::minutes duration) { |
| 307 | using Clock = std::filesystem::file_time_type::clock; |
| 308 | std::error_code error; |
| 309 | std::filesystem::file_time_type updateTime = std::filesystem::last_write_time(path, error); |
| 310 | if (error) { |
| 311 | return false; |
| 312 | } |
| 313 | return duration > (Clock::now() - updateTime); |
| 314 | } |
| 315 | |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 316 | bool isFrameIntervalOnCadence(TimePoint expectedPresentTime, TimePoint lastExpectedPresentTimestamp, |
| 317 | Fps lastFrameInterval, Period timeout, Duration threshold) { |
| 318 | if (lastFrameInterval.getPeriodNsecs() == 0) { |
| 319 | return false; |
| 320 | } |
| 321 | |
| 322 | const auto expectedPresentTimeDeltaNs = |
| 323 | expectedPresentTime.ns() - lastExpectedPresentTimestamp.ns(); |
| 324 | |
| 325 | if (expectedPresentTimeDeltaNs > timeout.ns()) { |
| 326 | return false; |
| 327 | } |
| 328 | |
| 329 | const auto expectedPresentPeriods = static_cast<nsecs_t>( |
| 330 | std::round(static_cast<float>(expectedPresentTimeDeltaNs) / |
| 331 | static_cast<float>(lastFrameInterval.getPeriodNsecs()))); |
| 332 | const auto calculatedPeriodsOutNs = lastFrameInterval.getPeriodNsecs() * expectedPresentPeriods; |
| 333 | const auto calculatedExpectedPresentTimeNs = |
| 334 | lastExpectedPresentTimestamp.ns() + calculatedPeriodsOutNs; |
| 335 | const auto presentTimeDelta = |
| 336 | std::abs(expectedPresentTime.ns() - calculatedExpectedPresentTimeNs); |
| 337 | return presentTimeDelta < threshold.ns(); |
| 338 | } |
| 339 | |
| 340 | bool isExpectedPresentWithinTimeout(TimePoint expectedPresentTime, |
| 341 | TimePoint lastExpectedPresentTimestamp, |
| 342 | std::optional<Period> timeoutOpt, Duration threshold) { |
| 343 | if (!timeoutOpt) { |
| 344 | // Always within timeout if timeoutOpt is absent and don't send hint |
| 345 | // for the timeout |
| 346 | return true; |
| 347 | } |
| 348 | |
| 349 | if (timeoutOpt->ns() == 0) { |
| 350 | // Always outside timeout if timeoutOpt is 0 and always send |
| 351 | // the hint for the timeout. |
| 352 | return false; |
| 353 | } |
| 354 | |
| 355 | if (expectedPresentTime.ns() < lastExpectedPresentTimestamp.ns() + timeoutOpt->ns()) { |
| 356 | return true; |
| 357 | } |
| 358 | |
| 359 | // Check if within the threshold as it can be just outside the timeout |
| 360 | return std::abs(expectedPresentTime.ns() - |
| 361 | (lastExpectedPresentTimestamp.ns() + timeoutOpt->ns())) < threshold.ns(); |
| 362 | } |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 363 | } // namespace anonymous |
| 364 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | // --------------------------------------------------------------------------- |
| 366 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 367 | const String16 sHardwareTest("android.permission.HARDWARE_TEST"); |
| 368 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 369 | const String16 sRotateSurfaceFlinger("android.permission.ROTATE_SURFACE_FLINGER"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 370 | const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER"); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 371 | const String16 sControlDisplayBrightness("android.permission.CONTROL_DISPLAY_BRIGHTNESS"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 372 | const String16 sDump("android.permission.DUMP"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 373 | const String16 sCaptureBlackoutContent("android.permission.CAPTURE_BLACKOUT_CONTENT"); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 374 | const String16 sInternalSystemWindow("android.permission.INTERNAL_SYSTEM_WINDOW"); |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 375 | const String16 sWakeupSurfaceFlinger("android.permission.WAKEUP_SURFACE_FLINGER"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 376 | |
Amy Hsu | c8cdfef | 2020-05-07 13:06:25 +0800 | [diff] [blame] | 377 | const char* KERNEL_IDLE_TIMER_PROP = "graphics.display.kernel_idle_timer.enabled"; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 378 | |
| 379 | // --------------------------------------------------------------------------- |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 380 | int64_t SurfaceFlinger::dispSyncPresentTimeOffset; |
| 381 | bool SurfaceFlinger::useHwcForRgbToYuv; |
| 382 | bool SurfaceFlinger::hasSyncFramework; |
| 383 | int64_t SurfaceFlinger::maxFrameBufferAcquiredBuffers; |
| 384 | int64_t SurfaceFlinger::minAcquiredBuffers = 1; |
| 385 | uint32_t SurfaceFlinger::maxGraphicsWidth; |
| 386 | uint32_t SurfaceFlinger::maxGraphicsHeight; |
| 387 | bool SurfaceFlinger::useContextPriority; |
| 388 | Dataspace SurfaceFlinger::defaultCompositionDataspace = Dataspace::V0_SRGB; |
| 389 | ui::PixelFormat SurfaceFlinger::defaultCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
| 390 | Dataspace SurfaceFlinger::wideColorGamutCompositionDataspace = Dataspace::V0_SRGB; |
| 391 | ui::PixelFormat SurfaceFlinger::wideColorGamutCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 392 | LatchUnsignaledConfig SurfaceFlinger::enableLatchUnsignaledConfig; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 393 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 394 | std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) { |
| 395 | switch(displayColorSetting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 396 | case DisplayColorSetting::kManaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 397 | return std::string("Managed"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 398 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 399 | return std::string("Unmanaged"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 400 | case DisplayColorSetting::kEnhanced: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 401 | return std::string("Enhanced"); |
| 402 | default: |
| 403 | return std::string("Unknown ") + |
| 404 | std::to_string(static_cast<int>(displayColorSetting)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 405 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 408 | bool callingThreadHasPermission(const String16& permission) { |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 409 | IPCThreadState* ipc = IPCThreadState::self(); |
| 410 | const int pid = ipc->getCallingPid(); |
| 411 | const int uid = ipc->getCallingUid(); |
| 412 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 413 | PermissionCache::checkPermission(permission, pid, uid); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 414 | } |
| 415 | |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 416 | ui::Transform::RotationFlags SurfaceFlinger::sActiveDisplayRotationFlags = ui::Transform::ROT_0; |
| 417 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 418 | SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag) |
| 419 | : mFactory(factory), |
| 420 | mPid(getpid()), |
Yiwei Zhang | f0229a7 | 2019-09-09 19:28:02 -0700 | [diff] [blame] | 421 | mTimeStats(std::make_shared<impl::TimeStats>()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 422 | mFrameTracer(mFactory.createFrameTracer()), |
| 423 | mFrameTimeline(mFactory.createFrameTimeline(mTimeStats, mPid)), |
| 424 | mCompositionEngine(mFactory.createCompositionEngine()), |
| 425 | mHwcServiceName(base::GetProperty("debug.sf.hwc_service_name"s, "default"s)), |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 426 | mTunnelModeEnabledReporter(sp<TunnelModeEnabledReporter>::make()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 427 | mEmulatedDisplayDensity(getDensityFromProperty("qemu.sf.lcd_density", false)), |
| 428 | mInternalDisplayDensity( |
| 429 | getDensityFromProperty("ro.sf.lcd_density", !mEmulatedDisplayDensity)), |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 430 | mPowerAdvisor(std::make_unique<Hwc2::impl::PowerAdvisor>(*this)), |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 431 | mWindowInfosListenerInvoker(sp<WindowInfosListenerInvoker>::make()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 432 | ALOGI("Using HWComposer service: %s", mHwcServiceName.c_str()); |
| 433 | } |
Fabien Sanglard | 0cc1938 | 2017-03-06 11:54:40 -0800 | [diff] [blame] | 434 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 435 | SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { |
| 436 | ATRACE_CALL(); |
| 437 | ALOGI("SurfaceFlinger is starting"); |
| 438 | |
| 439 | hasSyncFramework = running_without_sync_framework(true); |
| 440 | |
| 441 | dispSyncPresentTimeOffset = present_time_offset_from_vsync_ns(0); |
| 442 | |
| 443 | useHwcForRgbToYuv = force_hwc_copy_for_virtual_displays(false); |
| 444 | |
| 445 | maxFrameBufferAcquiredBuffers = max_frame_buffer_acquired_buffers(2); |
| 446 | minAcquiredBuffers = |
| 447 | SurfaceFlingerProperties::min_acquired_buffers().value_or(minAcquiredBuffers); |
| 448 | |
| 449 | maxGraphicsWidth = std::max(max_graphics_width(0), 0); |
| 450 | maxGraphicsHeight = std::max(max_graphics_height(0), 0); |
| 451 | |
| 452 | mSupportsWideColor = has_wide_color_display(false); |
| 453 | mDefaultCompositionDataspace = |
| 454 | static_cast<ui::Dataspace>(default_composition_dataspace(Dataspace::V0_SRGB)); |
| 455 | mWideColorGamutCompositionDataspace = static_cast<ui::Dataspace>(wcg_composition_dataspace( |
| 456 | mSupportsWideColor ? Dataspace::DISPLAY_P3 : Dataspace::V0_SRGB)); |
| 457 | defaultCompositionDataspace = mDefaultCompositionDataspace; |
| 458 | wideColorGamutCompositionDataspace = mWideColorGamutCompositionDataspace; |
| 459 | defaultCompositionPixelFormat = static_cast<ui::PixelFormat>( |
| 460 | default_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 461 | wideColorGamutCompositionPixelFormat = |
| 462 | static_cast<ui::PixelFormat>(wcg_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 463 | |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 464 | mLayerCachingEnabled = |
| 465 | base::GetBoolProperty("debug.sf.enable_layer_caching"s, |
| 466 | sysprop::SurfaceFlingerProperties::enable_layer_caching() |
| 467 | .value_or(false)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 468 | |
| 469 | useContextPriority = use_context_priority(true); |
| 470 | |
| 471 | mInternalDisplayPrimaries = sysprop::getDisplayNativePrimaries(); |
| 472 | |
| 473 | // debugging stuff... |
| 474 | char value[PROPERTY_VALUE_MAX]; |
| 475 | |
| 476 | property_get("ro.build.type", value, "user"); |
| 477 | mIsUserBuild = strcmp(value, "user") == 0; |
| 478 | |
| 479 | mDebugFlashDelay = base::GetUintProperty("debug.sf.showupdates"s, 0u); |
| 480 | |
| 481 | mBackpressureGpuComposition = base::GetBoolProperty("debug.sf.enable_gl_backpressure"s, true); |
| 482 | ALOGI_IF(mBackpressureGpuComposition, "Enabling backpressure for GPU composition"); |
| 483 | |
| 484 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 485 | bool supportsBlurs = atoi(value); |
| 486 | mSupportsBlur = supportsBlurs; |
| 487 | ALOGI_IF(!mSupportsBlur, "Disabling blur effects, they are not supported."); |
| 488 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 489 | property_get("debug.sf.luma_sampling", value, "1"); |
| 490 | mLumaSampling = atoi(value); |
| 491 | |
| 492 | property_get("debug.sf.disable_client_composition_cache", value, "0"); |
| 493 | mDisableClientCompositionCache = atoi(value); |
| 494 | |
| 495 | property_get("debug.sf.predict_hwc_composition_strategy", value, "1"); |
| 496 | mPredictCompositionStrategy = atoi(value); |
| 497 | |
| 498 | property_get("debug.sf.treat_170m_as_sRGB", value, "0"); |
| 499 | mTreat170mAsSrgb = atoi(value); |
| 500 | |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 501 | property_get("debug.sf.dim_in_gamma_in_enhanced_screenshots", value, 0); |
| 502 | mDimInGammaSpaceForEnhancedScreenshots = atoi(value); |
| 503 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 504 | mIgnoreHwcPhysicalDisplayOrientation = |
| 505 | base::GetBoolProperty("debug.sf.ignore_hwc_physical_display_orientation"s, false); |
| 506 | |
| 507 | // We should be reading 'persist.sys.sf.color_saturation' here |
| 508 | // but since /data may be encrypted, we need to wait until after vold |
| 509 | // comes online to attempt to read the property. The property is |
| 510 | // instead read after the boot animation |
| 511 | |
| 512 | if (base::GetBoolProperty("debug.sf.treble_testing_override"s, false)) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 513 | // Without the override SurfaceFlinger cannot connect to HIDL |
| 514 | // services that are not listed in the manifests. Considered |
| 515 | // deriving the setting from the set service name, but it |
| 516 | // would be brittle if the name that's not 'default' is used |
| 517 | // for production purposes later on. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 518 | ALOGI("Enabling Treble testing override"); |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 519 | android::hardware::details::setTrebleTestingOverride(true); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 520 | } |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 521 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 522 | // TODO (b/270966065) Update the HWC based refresh rate overlay to support spinner |
| 523 | mRefreshRateOverlaySpinner = property_get_bool("debug.sf.show_refresh_rate_overlay_spinner", 0); |
| 524 | mRefreshRateOverlayRenderRate = |
| 525 | property_get_bool("debug.sf.show_refresh_rate_overlay_render_rate", 0); |
| 526 | mRefreshRateOverlayShowInMiddle = |
| 527 | property_get_bool("debug.sf.show_refresh_rate_overlay_in_middle", 0); |
| 528 | |
| 529 | if (!mIsUserBuild && base::GetBoolProperty("debug.sf.enable_transaction_tracing"s, true)) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 530 | mTransactionTracing.emplace(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 531 | mLayerTracing.setTransactionTracing(*mTransactionTracing); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 532 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 533 | |
| 534 | mIgnoreHdrCameraLayers = ignore_hdr_camera_layers(false); |
| 535 | |
| 536 | mLayerLifecycleManagerEnabled = |
Vishnu Nair | f42d9bd | 2023-08-23 21:35:33 +0000 | [diff] [blame] | 537 | base::GetBoolProperty("persist.debug.sf.enable_layer_lifecycle_manager"s, true); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 538 | mLegacyFrontEndEnabled = !mLayerLifecycleManagerEnabled || |
| 539 | base::GetBoolProperty("persist.debug.sf.enable_legacy_frontend"s, false); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 540 | |
| 541 | // These are set by the HWC implementation to indicate that they will use the workarounds. |
| 542 | mIsHotplugErrViaNegVsync = |
| 543 | base::GetBoolProperty("debug.sf.hwc_hotplug_error_via_neg_vsync"s, false); |
| 544 | |
| 545 | mIsHdcpViaNegVsync = base::GetBoolProperty("debug.sf.hwc_hdcp_via_neg_vsync"s, false); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | LatchUnsignaledConfig SurfaceFlinger::getLatchUnsignaledConfig() { |
Ady Abraham | d9e8d1b | 2022-02-25 00:36:10 +0000 | [diff] [blame] | 549 | if (base::GetBoolProperty("debug.sf.auto_latch_unsignaled"s, true)) { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 550 | return LatchUnsignaledConfig::AutoSingleLayer; |
| 551 | } |
| 552 | |
| 553 | return LatchUnsignaledConfig::Disabled; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | } |
| 555 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 556 | SurfaceFlinger::~SurfaceFlinger() = default; |
| 557 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 558 | void SurfaceFlinger::binderDied(const wp<IBinder>&) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 559 | // the window manager died on us. prepare its eulogy. |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 560 | mBootFinished = false; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 561 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 562 | static_cast<void>(mScheduler->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 563 | // Sever the link to inputflinger since it's gone as well. |
| 564 | mInputFlinger.clear(); |
Vishnu Nair | b9df470 | 2021-03-01 11:53:15 -0800 | [diff] [blame] | 565 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 566 | initializeDisplays(); |
| 567 | })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 568 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 569 | startBootAnim(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 570 | } |
| 571 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 572 | void SurfaceFlinger::run() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 573 | mScheduler->run(); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 574 | } |
| 575 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 576 | sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName, bool secure, |
| 577 | float requestedRefreshRate) { |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 578 | // onTransact already checks for some permissions, but adding an additional check here. |
| 579 | // This is to ensure that only system and graphics can request to create a secure |
| 580 | // display. Secure displays can show secure content so we add an additional restriction on it. |
| 581 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 582 | if (secure && uid != AID_GRAPHICS && uid != AID_SYSTEM) { |
| 583 | ALOGE("Only privileged processes can create a secure display"); |
| 584 | return nullptr; |
| 585 | } |
| 586 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 587 | class DisplayToken : public BBinder { |
| 588 | sp<SurfaceFlinger> flinger; |
| 589 | virtual ~DisplayToken() { |
| 590 | // no more references, this display must be terminated |
| 591 | Mutex::Autolock _l(flinger->mStateLock); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 592 | flinger->mCurrentState.displays.removeItem(wp<IBinder>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 593 | flinger->setTransactionFlags(eDisplayTransactionNeeded); |
| 594 | } |
| 595 | public: |
Chih-Hung Hsieh | c406791 | 2016-05-03 14:03:27 -0700 | [diff] [blame] | 596 | explicit DisplayToken(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 597 | : flinger(flinger) { |
| 598 | } |
| 599 | }; |
| 600 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 601 | sp<BBinder> token = sp<DisplayToken>::make(sp<SurfaceFlinger>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 602 | |
| 603 | Mutex::Autolock _l(mStateLock); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 604 | // Display ID is assigned when virtual display is allocated by HWC. |
| 605 | DisplayDeviceState state; |
| 606 | state.isSecure = secure; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 607 | // Set display as protected when marked as secure to ensure no behavior change |
| 608 | // TODO (b/314820005): separate as a different arg when creating the display. |
| 609 | state.isProtected = secure; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 610 | state.displayName = displayName; |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 611 | state.requestedRefreshRate = Fps::fromValue(requestedRefreshRate); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 612 | mCurrentState.displays.add(token, state); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 613 | return token; |
| 614 | } |
| 615 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 616 | void SurfaceFlinger::destroyDisplay(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 617 | Mutex::Autolock lock(mStateLock); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 618 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 619 | const ssize_t index = mCurrentState.displays.indexOfKey(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 620 | if (index < 0) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 621 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 622 | return; |
| 623 | } |
| 624 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 625 | const DisplayDeviceState& state = mCurrentState.displays.valueAt(index); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 626 | if (state.physical) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 627 | ALOGE("%s: Invalid operation on physical display", __func__); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 628 | return; |
| 629 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 630 | mCurrentState.displays.removeItemsAt(index); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 631 | setTransactionFlags(eDisplayTransactionNeeded); |
| 632 | } |
| 633 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 634 | void SurfaceFlinger::enableHalVirtualDisplays(bool enable) { |
| 635 | auto& generator = mVirtualDisplayIdGenerators.hal; |
| 636 | if (!generator && enable) { |
| 637 | ALOGI("Enabling HAL virtual displays"); |
| 638 | generator.emplace(getHwComposer().getMaxVirtualDisplayCount()); |
| 639 | } else if (generator && !enable) { |
| 640 | ALOGW_IF(generator->inUse(), "Disabling HAL virtual displays while in use"); |
| 641 | generator.reset(); |
| 642 | } |
| 643 | } |
| 644 | |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 645 | VirtualDisplayId SurfaceFlinger::acquireVirtualDisplay(ui::Size resolution, |
| 646 | ui::PixelFormat format) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 647 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 648 | if (const auto id = generator->generateId()) { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 649 | if (getHwComposer().allocateVirtualDisplay(*id, resolution, &format)) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 650 | return *id; |
| 651 | } |
| 652 | |
| 653 | generator->releaseId(*id); |
| 654 | } else { |
| 655 | ALOGW("%s: Exhausted HAL virtual displays", __func__); |
| 656 | } |
| 657 | |
| 658 | ALOGW("%s: Falling back to GPU virtual display", __func__); |
| 659 | } |
| 660 | |
| 661 | const auto id = mVirtualDisplayIdGenerators.gpu.generateId(); |
| 662 | LOG_ALWAYS_FATAL_IF(!id, "Failed to generate ID for GPU virtual display"); |
| 663 | return *id; |
| 664 | } |
| 665 | |
| 666 | void SurfaceFlinger::releaseVirtualDisplay(VirtualDisplayId displayId) { |
| 667 | if (const auto id = HalVirtualDisplayId::tryCast(displayId)) { |
| 668 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 669 | generator->releaseId(*id); |
| 670 | } |
| 671 | return; |
| 672 | } |
| 673 | |
| 674 | const auto id = GpuVirtualDisplayId::tryCast(displayId); |
| 675 | LOG_ALWAYS_FATAL_IF(!id); |
| 676 | mVirtualDisplayIdGenerators.gpu.releaseId(*id); |
| 677 | } |
| 678 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 679 | std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdsLocked() const { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 680 | std::vector<PhysicalDisplayId> displayIds; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 681 | displayIds.reserve(mPhysicalDisplays.size()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 682 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 683 | const auto defaultDisplayId = getDefaultDisplayDeviceLocked()->getPhysicalId(); |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 684 | displayIds.push_back(defaultDisplayId); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 685 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 686 | for (const auto& [id, display] : mPhysicalDisplays) { |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 687 | if (id != defaultDisplayId) { |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 688 | displayIds.push_back(id); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 689 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 690 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 691 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 692 | return displayIds; |
| 693 | } |
| 694 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 695 | std::optional<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdLocked( |
| 696 | const sp<display::DisplayToken>& displayToken) const { |
| 697 | return ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 698 | .transform(&ftl::to_key<PhysicalDisplays>); |
| 699 | } |
| 700 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 701 | sp<IBinder> SurfaceFlinger::getPhysicalDisplayToken(PhysicalDisplayId displayId) const { |
| 702 | Mutex::Autolock lock(mStateLock); |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 703 | return getPhysicalDisplayTokenLocked(displayId); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 706 | HWComposer& SurfaceFlinger::getHwComposer() const { |
| 707 | return mCompositionEngine->getHwComposer(); |
| 708 | } |
| 709 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 710 | renderengine::RenderEngine& SurfaceFlinger::getRenderEngine() const { |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 711 | return *mRenderEngine; |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 714 | compositionengine::CompositionEngine& SurfaceFlinger::getCompositionEngine() const { |
| 715 | return *mCompositionEngine.get(); |
| 716 | } |
| 717 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 718 | void SurfaceFlinger::bootFinished() { |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 719 | if (mBootFinished == true) { |
| 720 | ALOGE("Extra call to bootFinished"); |
| 721 | return; |
| 722 | } |
| 723 | mBootFinished = true; |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame] | 724 | FlagManager::getMutableInstance().markBootCompleted(); |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 725 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 726 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 727 | } |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 728 | |
| 729 | if (mRenderEnginePrimeCacheFuture.valid()) { |
| 730 | mRenderEnginePrimeCacheFuture.get(); |
| 731 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 732 | const nsecs_t now = systemTime(); |
| 733 | const nsecs_t duration = now - mBootTime; |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 734 | ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 735 | |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 736 | mFrameTracer->initialize(); |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 737 | mFrameTimeline->onBootFinished(); |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 738 | getRenderEngine().setEnableTracing(FlagManager::getInstance().use_skia_tracing()); |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 739 | |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 740 | // wait patiently for the window manager death |
| 741 | const String16 name("window"); |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 742 | mWindowManager = defaultServiceManager()->waitForService(name); |
Steven Moreland | a904bb9 | 2019-07-02 17:37:23 -0700 | [diff] [blame] | 743 | if (mWindowManager != 0) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 744 | mWindowManager->linkToDeath(sp<IBinder::DeathRecipient>::fromExisting(this)); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | // stop boot animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 748 | // formerly we would just kill the process, but we now ask it to exit so it |
| 749 | // can choose where to stop the animation. |
| 750 | property_set("service.bootanim.exit", "1"); |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 751 | |
| 752 | const int LOGTAG_SF_STOP_BOOTANIM = 60110; |
| 753 | LOG_EVENT_LONG(LOGTAG_SF_STOP_BOOTANIM, |
| 754 | ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 755 | |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 756 | sp<IBinder> input(defaultServiceManager()->waitForService(String16("inputflinger"))); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 757 | |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 758 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 759 | if (input == nullptr) { |
| 760 | ALOGE("Failed to link to input service"); |
| 761 | } else { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 762 | mInputFlinger = interface_cast<os::IInputFlinger>(input); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 763 | } |
| 764 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 765 | readPersistentProperties(); |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 766 | const bool hintSessionEnabled = FlagManager::getInstance().use_adpf_cpu_hint(); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 767 | mPowerAdvisor->enablePowerHintSession(hintSessionEnabled); |
| 768 | const bool hintSessionUsed = mPowerAdvisor->usePowerHintSession(); |
Matt Buckley | 547cc0c | 2023-10-27 22:22:36 +0000 | [diff] [blame] | 769 | // Ordering is important here, as onBootFinished signals to PowerAdvisor that concurrency |
| 770 | // is safe because its variables are initialized. |
| 771 | mPowerAdvisor->onBootFinished(); |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 772 | ALOGD("Power hint is %s", |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 773 | hintSessionUsed ? "supported" : (hintSessionEnabled ? "unsupported" : "disabled")); |
| 774 | if (hintSessionUsed) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 775 | std::optional<pid_t> renderEngineTid = getRenderEngine().getRenderEngineTid(); |
| 776 | std::vector<int32_t> tidList; |
| 777 | tidList.emplace_back(gettid()); |
| 778 | if (renderEngineTid.has_value()) { |
| 779 | tidList.emplace_back(*renderEngineTid); |
| 780 | } |
Matt Buckley | 547cc0c | 2023-10-27 22:22:36 +0000 | [diff] [blame] | 781 | if (!mPowerAdvisor->startPowerHintSession(std::move(tidList))) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 782 | ALOGW("Cannot start power hint session"); |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 783 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 784 | } |
| 785 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 786 | mBootStage = BootStage::FINISHED; |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 787 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 788 | if (base::GetBoolProperty("sf.debug.show_refresh_rate_overlay"s, false)) { |
| 789 | ftl::FakeGuard guard(mStateLock); |
| 790 | enableRefreshRateOverlay(true); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 791 | } |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 792 | })); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 795 | void chooseRenderEngineType(renderengine::RenderEngineCreationArgs::Builder& builder) { |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 796 | char prop[PROPERTY_VALUE_MAX]; |
Leon Scroggins III | f840ae5 | 2024-01-25 15:10:12 -0500 | [diff] [blame] | 797 | property_get(PROPERTY_DEBUG_RENDERENGINE_BACKEND, prop, ""); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 798 | |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 799 | if (strcmp(prop, "skiagl") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 800 | builder.setThreaded(renderengine::RenderEngine::Threaded::NO) |
| 801 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::GL); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 802 | } else if (strcmp(prop, "skiaglthreaded") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 803 | builder.setThreaded(renderengine::RenderEngine::Threaded::YES) |
| 804 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::GL); |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 805 | } else if (strcmp(prop, "skiavk") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 806 | builder.setThreaded(renderengine::RenderEngine::Threaded::NO) |
| 807 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::VK); |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 808 | } else if (strcmp(prop, "skiavkthreaded") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 809 | builder.setThreaded(renderengine::RenderEngine::Threaded::YES) |
| 810 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::VK); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 811 | } else { |
Leon Scroggins III | f3369ed | 2024-02-16 17:52:42 -0500 | [diff] [blame] | 812 | const auto kVulkan = renderengine::RenderEngine::GraphicsApi::VK; |
| 813 | const bool useVulkan = FlagManager::getInstance().vulkan_renderengine() && |
| 814 | renderengine::RenderEngine::canSupport(kVulkan); |
| 815 | builder.setGraphicsApi(useVulkan ? kVulkan : renderengine::RenderEngine::GraphicsApi::GL); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 819 | // Do not call property_set on main thread which will be blocked by init |
| 820 | // Use StartPropertySetThread instead. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 821 | void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) { |
Parth Sane | 343626c | 2023-04-06 16:17:04 +0000 | [diff] [blame] | 822 | ATRACE_CALL(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 823 | ALOGI( "SurfaceFlinger's main thread ready to run. " |
| 824 | "Initializing graphics H/W..."); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 825 | addTransactionReadyFilters(); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 826 | Mutex::Autolock lock(mStateLock); |
Kevin DuBois | 413287f | 2019-02-25 08:46:47 -0800 | [diff] [blame] | 827 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 828 | // Get a RenderEngine for the given display / config (can't fail) |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 829 | // TODO(b/77156734): We need to stop casting and use HAL types when possible. |
Alec Mouri | da4cf3b | 2019-02-12 15:33:01 -0800 | [diff] [blame] | 830 | // Sending maxFrameBufferAcquiredBuffers as the cache size is tightly tuned to single-display. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 831 | auto builder = renderengine::RenderEngineCreationArgs::Builder() |
| 832 | .setPixelFormat(static_cast<int32_t>(defaultCompositionPixelFormat)) |
| 833 | .setImageCacheSize(maxFrameBufferAcquiredBuffers) |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 834 | .setEnableProtectedContext(enable_protected_contents(false)) |
| 835 | .setPrecacheToneMapperShaderOnly(false) |
| 836 | .setSupportsBackgroundBlur(mSupportsBlur) |
| 837 | .setContextPriority( |
| 838 | useContextPriority |
| 839 | ? renderengine::RenderEngine::ContextPriority::REALTIME |
| 840 | : renderengine::RenderEngine::ContextPriority::MEDIUM); |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 841 | chooseRenderEngineType(builder); |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 842 | mRenderEngine = renderengine::RenderEngine::create(builder.build()); |
| 843 | mCompositionEngine->setRenderEngine(mRenderEngine.get()); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 844 | mMaxRenderTargetSize = |
| 845 | std::min(getRenderEngine().getMaxTextureSize(), getRenderEngine().getMaxViewportDims()); |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 846 | |
| 847 | // Set SF main policy after initializing RenderEngine which has its own policy. |
| 848 | if (!SetTaskProfiles(0, {"SFMainPolicy"})) { |
| 849 | ALOGW("Failed to set main task profile"); |
| 850 | } |
| 851 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 852 | mCompositionEngine->setTimeStats(mTimeStats); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 853 | mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName)); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 854 | mCompositionEngine->getHwComposer().setCallback(*this); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 855 | ClientCache::getInstance().setRenderEngine(&getRenderEngine()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 856 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 857 | enableLatchUnsignaledConfig = getLatchUnsignaledConfig(); |
| 858 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 859 | if (base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false)) { |
| 860 | enableHalVirtualDisplays(true); |
| 861 | } |
| 862 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 863 | // Process hotplug for displays connected at boot. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 864 | LOG_ALWAYS_FATAL_IF(!configureLocked(), |
| 865 | "Initial display configuration failed: HWC did not hotplug"); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 866 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 867 | // Commit primary display. |
| 868 | sp<const DisplayDevice> display; |
| 869 | if (const auto indexOpt = mCurrentState.getDisplayIndex(getPrimaryDisplayIdLocked())) { |
| 870 | const auto& displays = mCurrentState.displays; |
| 871 | |
| 872 | const auto& token = displays.keyAt(*indexOpt); |
| 873 | const auto& state = displays.valueAt(*indexOpt); |
| 874 | |
| 875 | processDisplayAdded(token, state); |
| 876 | mDrawingState.displays.add(token, state); |
| 877 | |
| 878 | display = getDefaultDisplayDeviceLocked(); |
| 879 | } |
| 880 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 881 | LOG_ALWAYS_FATAL_IF(!display, "Failed to configure the primary display"); |
| 882 | LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(display->getPhysicalId()), |
| 883 | "Primary display is disconnected"); |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 884 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 885 | // TODO(b/241285876): The Scheduler needlessly depends on creating the CompositionEngine part of |
| 886 | // the DisplayDevice, hence the above commit of the primary display. Remove that special case by |
| 887 | // initializing the Scheduler after configureLocked, once decoupled from DisplayDevice. |
| 888 | initScheduler(display); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 889 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 890 | mLayerTracing.setTakeLayersSnapshotProtoFunction([&](uint32_t traceFlags) { |
| 891 | auto snapshot = perfetto::protos::LayersSnapshotProto{}; |
| 892 | mScheduler |
| 893 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 894 | snapshot = takeLayersSnapshotProto(traceFlags, TimePoint::now(), |
| 895 | mLastCommittedVsyncId, true); |
| 896 | }) |
| 897 | .wait(); |
| 898 | return snapshot; |
| 899 | }); |
| 900 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 901 | // Commit secondary display(s). |
| 902 | processDisplayChangesLocked(); |
| 903 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 904 | // initialize our drawing state |
| 905 | mDrawingState = mCurrentState; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 906 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 907 | onActiveDisplayChangedLocked(nullptr, *display); |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 908 | |
| 909 | static_cast<void>(mScheduler->schedule( |
| 910 | [this]() FTL_FAKE_GUARD(kMainThreadContext) { initializeDisplays(); })); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 911 | |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 912 | mPowerAdvisor->init(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 913 | |
Bruno BELANYI | fd02878 | 2023-10-13 14:39:53 +0000 | [diff] [blame] | 914 | if (base::GetBoolProperty("service.sf.prime_shader_cache"s, true)) { |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 915 | if (setSchedFifo(false) != NO_ERROR) { |
| 916 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 917 | } |
| 918 | |
Bruno BELANYI | b9b5b70 | 2023-10-13 13:25:11 +0000 | [diff] [blame] | 919 | bool shouldPrimeUltraHDR = |
| 920 | base::GetBoolProperty("ro.surface_flinger.prime_shader_cache.ultrahdr"s, false); |
| 921 | mRenderEnginePrimeCacheFuture = getRenderEngine().primeCache(shouldPrimeUltraHDR); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 922 | |
| 923 | if (setSchedFifo(true) != NO_ERROR) { |
linkai | d696a4f | 2023-11-14 10:13:36 +0800 | [diff] [blame] | 924 | ALOGW("Can't set SCHED_FIFO after primeCache"); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 925 | } |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 926 | } |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 927 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 928 | // Inform native graphics APIs whether the present timestamp is supported: |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 929 | |
| 930 | const bool presentFenceReliable = |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 931 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE); |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 932 | mStartPropertySetThread = getFactory().createStartPropertySetThread(presentFenceReliable); |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 933 | |
| 934 | if (mStartPropertySetThread->Start() != NO_ERROR) { |
| 935 | ALOGE("Run StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 936 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 938 | initTransactionTraceWriter(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 939 | ALOGV("Done initializing"); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 940 | } |
| 941 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 942 | void SurfaceFlinger::initTransactionTraceWriter() { |
| 943 | if (!mTransactionTracing) { |
| 944 | return; |
| 945 | } |
| 946 | TransactionTraceWriter::getInstance().setWriterFunction( |
| 947 | [&](const std::string& filename, bool overwrite) { |
| 948 | auto writeFn = [&]() { |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 949 | if (!overwrite && fileNewerThan(filename, std::chrono::minutes{10})) { |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 950 | ALOGD("TransactionTraceWriter: file=%s already exists", filename.c_str()); |
| 951 | return; |
| 952 | } |
| 953 | mTransactionTracing->flush(); |
| 954 | mTransactionTracing->writeToFile(filename); |
| 955 | }; |
| 956 | if (std::this_thread::get_id() == mMainThreadId) { |
| 957 | writeFn(); |
| 958 | } else { |
| 959 | mScheduler->schedule(writeFn).get(); |
| 960 | } |
| 961 | }); |
| 962 | } |
| 963 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 964 | void SurfaceFlinger::readPersistentProperties() { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 965 | Mutex::Autolock _l(mStateLock); |
| 966 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 967 | char value[PROPERTY_VALUE_MAX]; |
| 968 | |
| 969 | property_get("persist.sys.sf.color_saturation", value, "1.0"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 970 | mGlobalSaturationFactor = atof(value); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 971 | updateColorMatrixLocked(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 972 | ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 973 | |
| 974 | property_get("persist.sys.sf.native_mode", value, "0"); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 975 | mDisplayColorSetting = static_cast<DisplayColorSetting>(atoi(value)); |
Peiyong Lin | a3ea559 | 2019-02-10 14:45:00 -0800 | [diff] [blame] | 976 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 977 | mForceColorMode = |
| 978 | static_cast<ui::ColorMode>(base::GetIntProperty("persist.sys.sf.color_mode"s, 0)); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 981 | void SurfaceFlinger::startBootAnim() { |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 982 | // Start boot animation service by setting a property mailbox |
| 983 | // if property setting thread is already running, Start() will be just a NOP |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 984 | mStartPropertySetThread->Start(); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 985 | // Wait until property was set |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 986 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 987 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 988 | } |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 989 | } |
| 990 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | // ---------------------------------------------------------------------------- |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 992 | |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 993 | status_t SurfaceFlinger::getSupportedFrameTimestamps( |
| 994 | std::vector<FrameEvent>* outSupported) const { |
| 995 | *outSupported = { |
| 996 | FrameEvent::REQUESTED_PRESENT, |
| 997 | FrameEvent::ACQUIRE, |
| 998 | FrameEvent::LATCH, |
| 999 | FrameEvent::FIRST_REFRESH_START, |
| 1000 | FrameEvent::LAST_REFRESH_START, |
| 1001 | FrameEvent::GPU_COMPOSITION_DONE, |
| 1002 | FrameEvent::DEQUEUE_READY, |
| 1003 | FrameEvent::RELEASE, |
| 1004 | }; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1005 | |
| 1006 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 1007 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 1008 | if (!getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 1009 | outSupported->push_back(FrameEvent::DISPLAY_PRESENT); |
| 1010 | } |
| 1011 | return NO_ERROR; |
| 1012 | } |
| 1013 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1014 | status_t SurfaceFlinger::getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState* state) { |
| 1015 | if (!displayToken || !state) { |
| 1016 | return BAD_VALUE; |
| 1017 | } |
| 1018 | |
| 1019 | Mutex::Autolock lock(mStateLock); |
| 1020 | |
| 1021 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1022 | if (!display) { |
| 1023 | return NAME_NOT_FOUND; |
| 1024 | } |
| 1025 | |
| 1026 | state->layerStack = display->getLayerStack(); |
| 1027 | state->orientation = display->getOrientation(); |
| 1028 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 1029 | const Rect layerStackRect = display->getLayerStackSpaceRect(); |
| 1030 | state->layerStackSpaceRect = |
| 1031 | layerStackRect.isValid() ? layerStackRect.getSize() : display->getSize(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1032 | |
| 1033 | return NO_ERROR; |
| 1034 | } |
| 1035 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1036 | status_t SurfaceFlinger::getStaticDisplayInfo(int64_t displayId, ui::StaticDisplayInfo* info) { |
| 1037 | if (!info) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1038 | return BAD_VALUE; |
| 1039 | } |
| 1040 | |
| 1041 | Mutex::Autolock lock(mStateLock); |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1042 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 1043 | const auto displayOpt = mPhysicalDisplays.get(*id).and_then(getDisplayDeviceAndSnapshot()); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1044 | |
| 1045 | if (!displayOpt) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1046 | return NAME_NOT_FOUND; |
| 1047 | } |
| 1048 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1049 | const auto& [display, snapshotRef] = *displayOpt; |
| 1050 | const auto& snapshot = snapshotRef.get(); |
| 1051 | |
| 1052 | info->connectionType = snapshot.connectionType(); |
| 1053 | info->deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1054 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1055 | if (mEmulatedDisplayDensity) { |
| 1056 | info->density = mEmulatedDisplayDensity; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1057 | } else { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1058 | info->density = info->connectionType == ui::DisplayConnectionType::Internal |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1059 | ? mInternalDisplayDensity |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1060 | : FALLBACK_DENSITY; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1061 | } |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 1062 | info->density /= ACONFIGURATION_DENSITY_MEDIUM; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1063 | |
| 1064 | info->secure = display->isSecure(); |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1065 | info->installOrientation = display->getPhysicalOrientation(); |
Vishnu Nair | d0a8965 | 2022-01-13 12:05:54 -0800 | [diff] [blame] | 1066 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1067 | return NO_ERROR; |
| 1068 | } |
| 1069 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1070 | void SurfaceFlinger::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo*& info, |
| 1071 | const sp<DisplayDevice>& display, |
| 1072 | const display::DisplaySnapshot& snapshot) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1073 | const auto& displayModes = snapshot.displayModes(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1074 | info->supportedDisplayModes.clear(); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1075 | info->supportedDisplayModes.reserve(displayModes.size()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1076 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1077 | for (const auto& [id, mode] : displayModes) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1078 | ui::DisplayMode outMode; |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1079 | outMode.id = ftl::to_underlying(id); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1080 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1081 | auto [width, height] = mode->getResolution(); |
| 1082 | auto [xDpi, yDpi] = mode->getDpi(); |
Yiwei Zhang | 27de5df | 2018-08-23 17:04:51 -0700 | [diff] [blame] | 1083 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1084 | if (const auto physicalOrientation = display->getPhysicalOrientation(); |
| 1085 | physicalOrientation == ui::ROTATION_90 || physicalOrientation == ui::ROTATION_270) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1086 | std::swap(width, height); |
| 1087 | std::swap(xDpi, yDpi); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1090 | outMode.resolution = ui::Size(width, height); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1091 | |
Huan Song | f7eeb10 | 2022-03-28 11:02:38 -0700 | [diff] [blame] | 1092 | outMode.xDpi = xDpi; |
| 1093 | outMode.yDpi = yDpi; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1094 | |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1095 | const auto peakFps = mode->getPeakFps(); |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 1096 | outMode.peakRefreshRate = peakFps.getValue(); |
Alec Mouri | d122a1c | 2023-09-30 01:36:33 +0000 | [diff] [blame] | 1097 | outMode.vsyncRate = mode->getVsyncRate().getValue(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1098 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1099 | const auto vsyncConfigSet = mScheduler->getVsyncConfiguration().getConfigsForRefreshRate( |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 1100 | Fps::fromValue(outMode.peakRefreshRate)); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1101 | outMode.appVsyncOffset = vsyncConfigSet.late.appOffset; |
| 1102 | outMode.sfVsyncOffset = vsyncConfigSet.late.sfOffset; |
| 1103 | outMode.group = mode->getGroup(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1104 | |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1105 | // This is how far in advance a buffer must be queued for |
| 1106 | // presentation at a given time. If you want a buffer to appear |
| 1107 | // on the screen at time N, you must submit the buffer before |
| 1108 | // (N - presentationDeadline). |
| 1109 | // |
| 1110 | // Normally it's one full refresh period (to give SF a chance to |
| 1111 | // latch the buffer), but this can be reduced by configuring a |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 1112 | // VsyncController offset. Any additional delays introduced by the hardware |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1113 | // composer or panel must be accounted for here. |
| 1114 | // |
| 1115 | // We add an additional 1ms to allow for processing time and |
| 1116 | // differences between the ideal and actual refresh rate. |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1117 | outMode.presentationDeadline = peakFps.getPeriodNsecs() - outMode.sfVsyncOffset + 1000000; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1118 | excludeDolbyVisionIf4k30Present(display->getHdrCapabilities().getSupportedHdrTypes(), |
| 1119 | outMode); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1120 | info->supportedDisplayModes.push_back(outMode); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1123 | info->supportedColorModes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1124 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1125 | const PhysicalDisplayId displayId = snapshot.displayId(); |
| 1126 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1127 | const auto mode = display->refreshRateSelector().getActiveMode(); |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1128 | info->activeDisplayModeId = ftl::to_underlying(mode.modePtr->getId()); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1129 | info->renderFrameRate = mode.fps.getValue(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1130 | info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1131 | info->hdrCapabilities = filterOut4k30(display->getHdrCapabilities()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1132 | |
Marin Shalamanov | b173f75 | 2021-02-16 19:38:36 +0100 | [diff] [blame] | 1133 | info->autoLowLatencyModeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1134 | getHwComposer().hasDisplayCapability(displayId, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1135 | DisplayCapability::AUTO_LOW_LATENCY_MODE); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1136 | info->gameContentTypeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1137 | getHwComposer().supportsContentType(displayId, hal::ContentType::GAME); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1138 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1139 | info->preferredBootDisplayMode = static_cast<ui::DisplayModeId>(-1); |
Kriti Dang | ac0a74d | 2022-03-16 11:52:35 +0100 | [diff] [blame] | 1140 | |
| 1141 | if (getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG)) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1142 | if (const auto hwcId = getHwComposer().getPreferredBootDisplayMode(displayId)) { |
| 1143 | if (const auto modeId = snapshot.translateModeId(*hwcId)) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1144 | info->preferredBootDisplayMode = ftl::to_underlying(*modeId); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1145 | } |
| 1146 | } |
| 1147 | } |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1148 | } |
Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame] | 1149 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1150 | status_t SurfaceFlinger::getDynamicDisplayInfoFromId(int64_t physicalDisplayId, |
| 1151 | ui::DynamicDisplayInfo* info) { |
| 1152 | if (!info) { |
| 1153 | return BAD_VALUE; |
| 1154 | } |
| 1155 | |
| 1156 | Mutex::Autolock lock(mStateLock); |
| 1157 | |
| 1158 | const auto id_ = |
| 1159 | DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(physicalDisplayId)); |
| 1160 | const auto displayOpt = mPhysicalDisplays.get(*id_).and_then(getDisplayDeviceAndSnapshot()); |
| 1161 | |
| 1162 | if (!displayOpt) { |
| 1163 | return NAME_NOT_FOUND; |
| 1164 | } |
| 1165 | |
| 1166 | const auto& [display, snapshotRef] = *displayOpt; |
| 1167 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
| 1168 | return NO_ERROR; |
| 1169 | } |
| 1170 | |
| 1171 | status_t SurfaceFlinger::getDynamicDisplayInfoFromToken(const sp<IBinder>& displayToken, |
| 1172 | ui::DynamicDisplayInfo* info) { |
| 1173 | if (!displayToken || !info) { |
| 1174 | return BAD_VALUE; |
| 1175 | } |
| 1176 | |
| 1177 | Mutex::Autolock lock(mStateLock); |
| 1178 | |
| 1179 | const auto displayOpt = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1180 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1181 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1182 | |
| 1183 | if (!displayOpt) { |
| 1184 | return NAME_NOT_FOUND; |
| 1185 | } |
| 1186 | |
| 1187 | const auto& [display, snapshotRef] = *displayOpt; |
| 1188 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1189 | return NO_ERROR; |
| 1190 | } |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 1191 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1192 | status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>& displayToken, |
| 1193 | DisplayStatInfo* outStats) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1194 | if (!outStats) { |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1195 | return BAD_VALUE; |
| 1196 | } |
| 1197 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1198 | std::optional<PhysicalDisplayId> displayIdOpt; |
| 1199 | { |
| 1200 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1201 | if (displayToken) { |
| 1202 | displayIdOpt = getPhysicalDisplayIdLocked(displayToken); |
| 1203 | if (!displayIdOpt) { |
| 1204 | ALOGW("%s: Invalid physical display token %p", __func__, displayToken.get()); |
| 1205 | return NAME_NOT_FOUND; |
| 1206 | } |
| 1207 | } else { |
| 1208 | // TODO (b/277364366): Clients should be updated to pass in the display they |
| 1209 | // want, rather than us picking an arbitrary one (the active display, in this |
| 1210 | // case). |
| 1211 | displayIdOpt = mActiveDisplayId; |
| 1212 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1213 | } |
| 1214 | |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1215 | const auto schedule = mScheduler->getVsyncSchedule(displayIdOpt); |
| 1216 | if (!schedule) { |
| 1217 | ALOGE("%s: Missing VSYNC schedule for display %s!", __func__, |
| 1218 | to_string(*displayIdOpt).c_str()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1219 | return NAME_NOT_FOUND; |
| 1220 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1221 | outStats->vsyncTime = schedule->vsyncDeadlineAfter(TimePoint::now()).ns(); |
| 1222 | outStats->vsyncPeriod = schedule->period().ns(); |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1223 | return NO_ERROR; |
| 1224 | } |
| 1225 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1226 | void SurfaceFlinger::setDesiredMode(display::DisplayModeRequest&& desiredMode) { |
| 1227 | const auto mode = desiredMode.mode; |
| 1228 | const auto displayId = mode.modePtr->getPhysicalDisplayId(); |
| 1229 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1230 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
| 1231 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1232 | const auto display = getDisplayDeviceLocked(displayId); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1233 | if (!display) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1234 | ALOGW("%s: display is no longer valid", __func__); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1235 | return; |
| 1236 | } |
| 1237 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1238 | const bool emitEvent = desiredMode.emitEvent; |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 1239 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1240 | switch (display->setDesiredMode(std::move(desiredMode))) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1241 | case DisplayDevice::DesiredModeAction::InitiateDisplayModeSwitch: |
| 1242 | // DisplayDevice::setDesiredMode updated the render rate, so inform Scheduler. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1243 | mScheduler->setRenderRate(displayId, |
| 1244 | display->refreshRateSelector().getActiveMode().fps); |
Ady Abraham | 95a37e2 | 2023-01-18 22:57:28 -0800 | [diff] [blame] | 1245 | |
| 1246 | // Schedule a new frame to initiate the display mode switch. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1247 | scheduleComposite(FrameHint::kNone); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1248 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1249 | // Start receiving vsync samples now, so that we can detect a period |
| 1250 | // switch. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1251 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 1252 | mode.modePtr.get()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1253 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1254 | // As we called to set period, we will call to onRefreshRateChangeCompleted once |
| 1255 | // VsyncController model is locked. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1256 | mScheduler->modulateVsync(displayId, &VsyncModulator::onRefreshRateChangeInitiated); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1257 | |
| 1258 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1259 | mScheduler->updatePhaseConfiguration(mode.fps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1260 | } |
| 1261 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1262 | mScheduler->setModeChangePending(true); |
| 1263 | break; |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1264 | case DisplayDevice::DesiredModeAction::InitiateRenderRateSwitch: |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1265 | mScheduler->setRenderRate(displayId, mode.fps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1266 | |
| 1267 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1268 | mScheduler->updatePhaseConfiguration(mode.fps); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1269 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1270 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1271 | if (emitEvent) { |
| 1272 | dispatchDisplayModeChangeEvent(displayId, mode); |
| 1273 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1274 | break; |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1275 | case DisplayDevice::DesiredModeAction::None: |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1276 | break; |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1277 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1278 | } |
| 1279 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1280 | status_t SurfaceFlinger::setActiveModeFromBackdoor(const sp<display::DisplayToken>& displayToken, |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1281 | DisplayModeId modeId, Fps minFps, Fps maxFps) { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1282 | ATRACE_CALL(); |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1283 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 1284 | if (!displayToken) { |
| 1285 | return BAD_VALUE; |
| 1286 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1287 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1288 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1289 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1290 | const auto displayOpt = |
| 1291 | FTL_FAKE_GUARD(mStateLock, |
| 1292 | ftl::find_if(mPhysicalDisplays, |
| 1293 | PhysicalDisplay::hasToken(displayToken)) |
| 1294 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1295 | .and_then(getDisplayDeviceAndSnapshot())); |
| 1296 | if (!displayOpt) { |
| 1297 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1298 | return NAME_NOT_FOUND; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1299 | } |
| 1300 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1301 | const auto& [display, snapshotRef] = *displayOpt; |
| 1302 | const auto& snapshot = snapshotRef.get(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1303 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1304 | const auto fpsOpt = snapshot.displayModes().get(modeId).transform( |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1305 | [](const DisplayModePtr& mode) { return mode->getPeakFps(); }); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1306 | |
| 1307 | if (!fpsOpt) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1308 | ALOGE("%s: Invalid mode %d for display %s", whence, ftl::to_underlying(modeId), |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1309 | to_string(snapshot.displayId()).c_str()); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1310 | return BAD_VALUE; |
| 1311 | } |
| 1312 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1313 | const Fps fps = *fpsOpt; |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1314 | const FpsRange physical = {fps, fps}; |
| 1315 | const FpsRange render = {minFps.isValid() ? minFps : fps, maxFps.isValid() ? maxFps : fps}; |
| 1316 | const FpsRanges ranges = {physical, render}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1317 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1318 | // Keep the old switching type. |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1319 | const bool allowGroupSwitching = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1320 | display->refreshRateSelector().getCurrentPolicy().allowGroupSwitching; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1321 | |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1322 | const scheduler::RefreshRateSelector::DisplayManagerPolicy policy{modeId, ranges, ranges, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 1323 | allowGroupSwitching}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1324 | |
| 1325 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1326 | }); |
| 1327 | |
| 1328 | return future.get(); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1329 | } |
| 1330 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1331 | void SurfaceFlinger::finalizeDisplayModeChange(DisplayDevice& display) { |
| 1332 | const auto displayId = display.getPhysicalId(); |
| 1333 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1334 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1335 | const auto pendingModeOpt = display.getPendingMode(); |
| 1336 | if (!pendingModeOpt) { |
| 1337 | // There is no pending mode change. This can happen if the active |
| 1338 | // display changed and the mode change happened on a different display. |
| 1339 | return; |
| 1340 | } |
Ady Abraham | faac6da | 2021-07-15 10:04:40 -0700 | [diff] [blame] | 1341 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1342 | const auto& activeMode = pendingModeOpt->mode; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1343 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1344 | if (display.getActiveMode().modePtr->getResolution() != activeMode.modePtr->getResolution()) { |
| 1345 | auto& state = mCurrentState.displays.editValueFor(display.getDisplayToken()); |
| 1346 | // We need to generate new sequenceId in order to recreate the display (and this |
| 1347 | // way the framebuffer). |
| 1348 | state.sequenceId = DisplayDeviceState{}.sequenceId; |
| 1349 | state.physical->activeMode = activeMode.modePtr.get(); |
| 1350 | processDisplayChangesLocked(); |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1351 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1352 | // processDisplayChangesLocked will update all necessary components so we're done here. |
| 1353 | return; |
| 1354 | } |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 1355 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1356 | display.finalizeModeChange(activeMode.modePtr->getId(), activeMode.modePtr->getVsyncRate(), |
| 1357 | activeMode.fps); |
| 1358 | |
| 1359 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1360 | mScheduler->updatePhaseConfiguration(activeMode.fps); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | if (pendingModeOpt->emitEvent) { |
| 1364 | dispatchDisplayModeChangeEvent(displayId, activeMode); |
| 1365 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1366 | } |
| 1367 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1368 | void SurfaceFlinger::dropModeRequest(const sp<DisplayDevice>& display) { |
| 1369 | display->clearDesiredMode(); |
| 1370 | if (display->getPhysicalId() == mActiveDisplayId) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1371 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1372 | mScheduler->setModeChangePending(false); |
| 1373 | } |
Ady Abraham | 53852a5 | 2019-05-28 18:07:44 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1376 | void SurfaceFlinger::applyActiveMode(const sp<DisplayDevice>& display) { |
| 1377 | const auto activeModeOpt = display->getDesiredMode(); |
| 1378 | auto activeModePtr = activeModeOpt->mode.modePtr; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1379 | const auto displayId = activeModePtr->getPhysicalDisplayId(); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1380 | const auto renderFps = activeModeOpt->mode.fps; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1381 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1382 | dropModeRequest(display); |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1383 | |
| 1384 | constexpr bool kAllowToEnable = true; |
| 1385 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, std::move(activeModePtr).take()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1386 | mScheduler->setRenderRate(displayId, renderFps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1387 | |
| 1388 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1389 | mScheduler->updatePhaseConfiguration(renderFps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1390 | } |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1391 | } |
| 1392 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1393 | void SurfaceFlinger::initiateDisplayModeChanges() { |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1394 | ATRACE_CALL(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1395 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1396 | std::optional<PhysicalDisplayId> displayToUpdateImmediately; |
| 1397 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1398 | for (const auto& [id, physical] : mPhysicalDisplays) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1399 | const auto display = getDisplayDeviceLocked(id); |
| 1400 | if (!display) continue; |
| 1401 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1402 | auto desiredModeOpt = display->getDesiredMode(); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1403 | if (!desiredModeOpt) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1404 | continue; |
| 1405 | } |
| 1406 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 1407 | if (!shouldApplyRefreshRateSelectorPolicy(*display)) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1408 | dropModeRequest(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1409 | continue; |
| 1410 | } |
| 1411 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1412 | const auto desiredModeId = desiredModeOpt->mode.modePtr->getId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1413 | const auto displayModePtrOpt = physical.snapshot().displayModes().get(desiredModeId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1414 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1415 | if (!displayModePtrOpt) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1416 | ALOGW("Desired display mode is no longer supported. Mode ID = %d", |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1417 | ftl::to_underlying(desiredModeId)); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1418 | continue; |
| 1419 | } |
| 1420 | |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1421 | ALOGV("%s changing active mode to %d(%s) for display %s", __func__, |
| 1422 | ftl::to_underlying(desiredModeId), |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1423 | to_string(displayModePtrOpt->get()->getVsyncRate()).c_str(), |
| 1424 | to_string(display->getId()).c_str()); |
| 1425 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1426 | if ((!FlagManager::getInstance().connected_display() || !desiredModeOpt->force) && |
| 1427 | display->getActiveMode() == desiredModeOpt->mode) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1428 | applyActiveMode(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1429 | continue; |
| 1430 | } |
| 1431 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1432 | // Desired active mode was set, it is different than the mode currently in use, however |
| 1433 | // allowed modes might have changed by the time we process the refresh. |
| 1434 | // Make sure the desired mode is still allowed |
| 1435 | if (!display->refreshRateSelector().isModeAllowed(desiredModeOpt->mode)) { |
| 1436 | dropModeRequest(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1437 | continue; |
| 1438 | } |
| 1439 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1440 | // TODO(b/142753666) use constrains |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1441 | hal::VsyncPeriodChangeConstraints constraints; |
| 1442 | constraints.desiredTimeNanos = systemTime(); |
| 1443 | constraints.seamlessRequired = false; |
| 1444 | hal::VsyncPeriodChangeTimeline outTimeline; |
| 1445 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1446 | if (!display->initiateModeChange(std::move(*desiredModeOpt), constraints, outTimeline)) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1447 | continue; |
| 1448 | } |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1449 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1450 | display->refreshRateSelector().onModeChangeInitiated(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1451 | mScheduler->onNewVsyncPeriodChangeTimeline(outTimeline); |
| 1452 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1453 | if (outTimeline.refreshRequired) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 1454 | scheduleComposite(FrameHint::kNone); |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1455 | } else { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1456 | // TODO(b/255635711): Remove `displayToUpdateImmediately` to `finalizeDisplayModeChange` |
| 1457 | // for all displays. This was only needed when the loop iterated over `mDisplays` rather |
| 1458 | // than `mPhysicalDisplays`. |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1459 | displayToUpdateImmediately = display->getPhysicalId(); |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | if (displayToUpdateImmediately) { |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1464 | const auto display = getDisplayDeviceLocked(*displayToUpdateImmediately); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1465 | finalizeDisplayModeChange(*display); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1466 | |
| 1467 | const auto desiredModeOpt = display->getDesiredMode(); |
| 1468 | if (desiredModeOpt && display->getActiveMode() == desiredModeOpt->mode) { |
| 1469 | applyActiveMode(display); |
| 1470 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1471 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1472 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1473 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1474 | void SurfaceFlinger::disableExpensiveRendering() { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1475 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1476 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1477 | ATRACE_NAME(whence); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1478 | if (mPowerAdvisor->isUsingExpensiveRendering()) { |
Dominik Laskowski | bc6c860 | 2022-01-11 08:53:24 -0800 | [diff] [blame] | 1479 | for (const auto& [_, display] : mDisplays) { |
| 1480 | constexpr bool kDisable = false; |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1481 | mPowerAdvisor->setExpensiveRenderingExpected(display->getId(), kDisable); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1482 | } |
| 1483 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1484 | }); |
| 1485 | |
| 1486 | future.wait(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1489 | status_t SurfaceFlinger::getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1490 | ui::DisplayPrimaries& primaries) { |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1491 | if (!displayToken) { |
| 1492 | return BAD_VALUE; |
| 1493 | } |
| 1494 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1495 | Mutex::Autolock lock(mStateLock); |
| 1496 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1497 | const auto display = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1498 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>); |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1499 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1500 | return NAME_NOT_FOUND; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1501 | } |
| 1502 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1503 | if (!display.transform(&PhysicalDisplay::isInternal).value()) { |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1504 | return INVALID_OPERATION; |
| 1505 | } |
| 1506 | |
| 1507 | // TODO(b/229846990): For now, assume that all internal displays have the same primaries. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1508 | primaries = mInternalDisplayPrimaries; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1509 | return NO_ERROR; |
| 1510 | } |
| 1511 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1512 | status_t SurfaceFlinger::setActiveColorMode(const sp<IBinder>& displayToken, ui::ColorMode mode) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1513 | if (!displayToken) { |
| 1514 | return BAD_VALUE; |
| 1515 | } |
| 1516 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1517 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1518 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1519 | const auto displayOpt = |
| 1520 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1521 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1522 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1523 | |
| 1524 | if (!displayOpt) { |
| 1525 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1526 | return NAME_NOT_FOUND; |
| 1527 | } |
| 1528 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1529 | const auto& [display, snapshotRef] = *displayOpt; |
| 1530 | const auto& snapshot = snapshotRef.get(); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1531 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1532 | const auto modes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1533 | const bool exists = std::find(modes.begin(), modes.end(), mode) != modes.end(); |
| 1534 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1535 | if (mode < ui::ColorMode::NATIVE || !exists) { |
| 1536 | ALOGE("%s: Invalid color mode %s (%d) for display %s", whence, |
| 1537 | decodeColorMode(mode).c_str(), mode, to_string(snapshot.displayId()).c_str()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1538 | return BAD_VALUE; |
| 1539 | } |
| 1540 | |
| 1541 | display->getCompositionDisplay()->setColorProfile( |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 1542 | {mode, Dataspace::UNKNOWN, RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1543 | |
| 1544 | return NO_ERROR; |
| 1545 | }); |
| 1546 | |
Dominik Laskowski | 0a5f921 | 2021-08-05 17:00:04 -0700 | [diff] [blame] | 1547 | // TODO(b/195698395): Propagate error. |
| 1548 | future.wait(); |
| 1549 | return NO_ERROR; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1550 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1551 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1552 | status_t SurfaceFlinger::getBootDisplayModeSupport(bool* outSupport) const { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1553 | auto future = mScheduler->schedule( |
| 1554 | [this] { return getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG); }); |
| 1555 | |
| 1556 | *outSupport = future.get(); |
| 1557 | return NO_ERROR; |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1558 | } |
| 1559 | |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1560 | status_t SurfaceFlinger::getOverlaySupport(gui::OverlayProperties* outProperties) const { |
| 1561 | const auto& aidlProperties = getHwComposer().getOverlaySupport(); |
| 1562 | // convert aidl OverlayProperties to gui::OverlayProperties |
| 1563 | outProperties->combinations.reserve(aidlProperties.combinations.size()); |
| 1564 | for (const auto& combination : aidlProperties.combinations) { |
| 1565 | std::vector<int32_t> pixelFormats; |
| 1566 | pixelFormats.reserve(combination.pixelFormats.size()); |
| 1567 | std::transform(combination.pixelFormats.cbegin(), combination.pixelFormats.cend(), |
| 1568 | std::back_inserter(pixelFormats), |
| 1569 | [](const auto& val) { return static_cast<int32_t>(val); }); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1570 | std::vector<int32_t> standards; |
| 1571 | standards.reserve(combination.standards.size()); |
| 1572 | std::transform(combination.standards.cbegin(), combination.standards.cend(), |
| 1573 | std::back_inserter(standards), |
| 1574 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1575 | std::vector<int32_t> transfers; |
| 1576 | transfers.reserve(combination.transfers.size()); |
| 1577 | std::transform(combination.transfers.cbegin(), combination.transfers.cend(), |
| 1578 | std::back_inserter(transfers), |
| 1579 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1580 | std::vector<int32_t> ranges; |
| 1581 | ranges.reserve(combination.ranges.size()); |
| 1582 | std::transform(combination.ranges.cbegin(), combination.ranges.cend(), |
| 1583 | std::back_inserter(ranges), |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1584 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1585 | gui::OverlayProperties::SupportedBufferCombinations outCombination; |
| 1586 | outCombination.pixelFormats = std::move(pixelFormats); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1587 | outCombination.standards = std::move(standards); |
| 1588 | outCombination.transfers = std::move(transfers); |
| 1589 | outCombination.ranges = std::move(ranges); |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1590 | outProperties->combinations.emplace_back(outCombination); |
| 1591 | } |
Sally Qi | 8b4cb55 | 2022-12-14 16:24:31 -0800 | [diff] [blame] | 1592 | outProperties->supportMixedColorSpaces = aidlProperties.supportMixedColorSpaces; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 1593 | return NO_ERROR; |
| 1594 | } |
| 1595 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1596 | status_t SurfaceFlinger::setBootDisplayMode(const sp<display::DisplayToken>& displayToken, |
| 1597 | DisplayModeId modeId) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1598 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1599 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1600 | const auto snapshotOpt = |
| 1601 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1602 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1603 | .transform(&PhysicalDisplay::snapshotRef); |
| 1604 | |
| 1605 | if (!snapshotOpt) { |
| 1606 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1607 | return NAME_NOT_FOUND; |
| 1608 | } |
Kriti Dang | f50d677 | 2022-02-18 15:09:12 +0100 | [diff] [blame] | 1609 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1610 | const auto& snapshot = snapshotOpt->get(); |
| 1611 | const auto hwcIdOpt = snapshot.displayModes().get(modeId).transform( |
| 1612 | [](const DisplayModePtr& mode) { return mode->getHwcId(); }); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1613 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1614 | if (!hwcIdOpt) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1615 | ALOGE("%s: Invalid mode %d for display %s", whence, ftl::to_underlying(modeId), |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1616 | to_string(snapshot.displayId()).c_str()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1617 | return BAD_VALUE; |
| 1618 | } |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1619 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1620 | return getHwComposer().setBootDisplayMode(snapshot.displayId(), *hwcIdOpt); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1621 | }); |
| 1622 | return future.get(); |
| 1623 | } |
| 1624 | |
| 1625 | status_t SurfaceFlinger::clearBootDisplayMode(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1626 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1627 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1628 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1629 | return getHwComposer().clearBootDisplayMode(*displayId); |
| 1630 | } else { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1631 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1632 | return BAD_VALUE; |
| 1633 | } |
| 1634 | }); |
| 1635 | return future.get(); |
| 1636 | } |
| 1637 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1638 | status_t SurfaceFlinger::getHdrConversionCapabilities( |
| 1639 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) const { |
| 1640 | bool hdrOutputConversionSupport; |
| 1641 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1642 | if (hdrOutputConversionSupport == false) { |
| 1643 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1644 | return INVALID_OPERATION; |
| 1645 | } |
| 1646 | const auto aidlConversionCapability = getHwComposer().getHdrConversionCapabilities(); |
| 1647 | for (auto capability : aidlConversionCapability) { |
| 1648 | gui::HdrConversionCapability tempCapability; |
Kriti Dang | 3c243dc | 2023-03-07 15:00:13 +0100 | [diff] [blame] | 1649 | tempCapability.sourceType = static_cast<int>(capability.sourceType); |
| 1650 | tempCapability.outputType = static_cast<int>(capability.outputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1651 | tempCapability.addsLatency = capability.addsLatency; |
| 1652 | hdrConversionCapabilities->push_back(tempCapability); |
| 1653 | } |
| 1654 | return NO_ERROR; |
| 1655 | } |
| 1656 | |
| 1657 | status_t SurfaceFlinger::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1658 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 1659 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1660 | bool hdrOutputConversionSupport; |
| 1661 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1662 | if (hdrOutputConversionSupport == false) { |
| 1663 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1664 | return INVALID_OPERATION; |
| 1665 | } |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1666 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) mutable -> status_t { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1667 | using AidlHdrConversionStrategy = |
| 1668 | aidl::android::hardware::graphics::common::HdrConversionStrategy; |
| 1669 | using GuiHdrConversionStrategyTag = gui::HdrConversionStrategy::Tag; |
| 1670 | AidlHdrConversionStrategy aidlConversionStrategy; |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1671 | status_t status; |
| 1672 | aidl::android::hardware::graphics::common::Hdr aidlPreferredHdrOutputType; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1673 | switch (hdrConversionStrategy.getTag()) { |
| 1674 | case GuiHdrConversionStrategyTag::passthrough: { |
| 1675 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::passthrough>( |
| 1676 | hdrConversionStrategy.get<GuiHdrConversionStrategyTag::passthrough>()); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1677 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1678 | &aidlPreferredHdrOutputType); |
| 1679 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1680 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1681 | } |
| 1682 | case GuiHdrConversionStrategyTag::autoAllowedHdrTypes: { |
| 1683 | auto autoHdrTypes = |
| 1684 | hdrConversionStrategy |
| 1685 | .get<GuiHdrConversionStrategyTag::autoAllowedHdrTypes>(); |
| 1686 | std::vector<aidl::android::hardware::graphics::common::Hdr> aidlAutoHdrTypes; |
| 1687 | for (auto type : autoHdrTypes) { |
| 1688 | aidlAutoHdrTypes.push_back( |
| 1689 | static_cast<aidl::android::hardware::graphics::common::Hdr>(type)); |
| 1690 | } |
| 1691 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::autoAllowedHdrTypes>( |
| 1692 | aidlAutoHdrTypes); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1693 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1694 | &aidlPreferredHdrOutputType); |
| 1695 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1696 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1697 | } |
| 1698 | case GuiHdrConversionStrategyTag::forceHdrConversion: { |
| 1699 | auto forceHdrConversion = |
| 1700 | hdrConversionStrategy |
| 1701 | .get<GuiHdrConversionStrategyTag::forceHdrConversion>(); |
| 1702 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::forceHdrConversion>( |
| 1703 | static_cast<aidl::android::hardware::graphics::common::Hdr>( |
| 1704 | forceHdrConversion)); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1705 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1706 | &aidlPreferredHdrOutputType); |
| 1707 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1708 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1709 | } |
| 1710 | } |
| 1711 | }); |
| 1712 | return future.get(); |
| 1713 | } |
| 1714 | |
| 1715 | status_t SurfaceFlinger::getHdrOutputConversionSupport(bool* outSupport) const { |
| 1716 | auto future = mScheduler->schedule([this] { |
| 1717 | return getHwComposer().hasCapability(Capability::HDR_OUTPUT_CONVERSION_CONFIG); |
| 1718 | }); |
| 1719 | |
| 1720 | *outSupport = future.get(); |
| 1721 | return NO_ERROR; |
| 1722 | } |
| 1723 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1724 | void SurfaceFlinger::setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1725 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1726 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1727 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1728 | getHwComposer().setAutoLowLatencyMode(*displayId, on); |
| 1729 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1730 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1731 | } |
| 1732 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1733 | } |
| 1734 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1735 | void SurfaceFlinger::setGameContentType(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1736 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1737 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1738 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1739 | const auto type = on ? hal::ContentType::GAME : hal::ContentType::NONE; |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1740 | getHwComposer().setContentType(*displayId, type); |
| 1741 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1742 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1743 | } |
| 1744 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1745 | } |
| 1746 | |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1747 | status_t SurfaceFlinger::overrideHdrTypes(const sp<IBinder>& displayToken, |
| 1748 | const std::vector<ui::Hdr>& hdrTypes) { |
| 1749 | Mutex::Autolock lock(mStateLock); |
| 1750 | |
| 1751 | auto display = getDisplayDeviceLocked(displayToken); |
| 1752 | if (!display) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1753 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1754 | return NAME_NOT_FOUND; |
| 1755 | } |
| 1756 | |
| 1757 | display->overrideHdrTypes(hdrTypes); |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 1758 | mScheduler->dispatchHotplug(display->getPhysicalId(), scheduler::Scheduler::Hotplug::Connected); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1759 | return NO_ERROR; |
| 1760 | } |
| 1761 | |
Huihong Luo | 30aa437 | 2022-10-03 14:54:12 -0700 | [diff] [blame] | 1762 | status_t SurfaceFlinger::onPullAtom(const int32_t atomId, std::vector<uint8_t>* pulledData, |
| 1763 | bool* success) { |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 1764 | *success = mTimeStats->onPullAtom(atomId, pulledData); |
| 1765 | return NO_ERROR; |
| 1766 | } |
| 1767 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1768 | status_t SurfaceFlinger::getDisplayedContentSamplingAttributes(const sp<IBinder>& displayToken, |
| 1769 | ui::PixelFormat* outFormat, |
| 1770 | ui::Dataspace* outDataspace, |
| 1771 | uint8_t* outComponentMask) const { |
| 1772 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 1773 | return BAD_VALUE; |
| 1774 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1775 | |
| 1776 | Mutex::Autolock lock(mStateLock); |
| 1777 | |
| 1778 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1779 | if (!displayId) { |
| 1780 | return NAME_NOT_FOUND; |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1781 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1782 | |
| 1783 | return getHwComposer().getDisplayedContentSamplingAttributes(*displayId, outFormat, |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1784 | outDataspace, outComponentMask); |
| 1785 | } |
| 1786 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1787 | status_t SurfaceFlinger::setDisplayContentSamplingEnabled(const sp<IBinder>& displayToken, |
| 1788 | bool enable, uint8_t componentMask, |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1789 | uint64_t maxFrames) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1790 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1791 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1792 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1793 | return getHwComposer().setDisplayContentSamplingEnabled(*displayId, enable, |
| 1794 | componentMask, maxFrames); |
| 1795 | } else { |
| 1796 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
| 1797 | return NAME_NOT_FOUND; |
| 1798 | } |
| 1799 | }); |
| 1800 | |
| 1801 | return future.get(); |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1802 | } |
| 1803 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1804 | status_t SurfaceFlinger::getDisplayedContentSample(const sp<IBinder>& displayToken, |
| 1805 | uint64_t maxFrames, uint64_t timestamp, |
| 1806 | DisplayedFrameStats* outStats) const { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1807 | Mutex::Autolock lock(mStateLock); |
| 1808 | |
| 1809 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1810 | if (!displayId) { |
| 1811 | return NAME_NOT_FOUND; |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1814 | return getHwComposer().getDisplayedContentSample(*displayId, maxFrames, timestamp, outStats); |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1815 | } |
| 1816 | |
Peiyong Lin | 3c2791e | 2019-01-14 17:05:18 -0800 | [diff] [blame] | 1817 | status_t SurfaceFlinger::getProtectedContentSupport(bool* outSupported) const { |
| 1818 | if (!outSupported) { |
| 1819 | return BAD_VALUE; |
| 1820 | } |
| 1821 | *outSupported = getRenderEngine().supportsProtectedContent(); |
| 1822 | return NO_ERROR; |
| 1823 | } |
| 1824 | |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1825 | status_t SurfaceFlinger::isWideColorDisplay(const sp<IBinder>& displayToken, |
| 1826 | bool* outIsWideColorDisplay) const { |
| 1827 | if (!displayToken || !outIsWideColorDisplay) { |
| 1828 | return BAD_VALUE; |
| 1829 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1830 | |
| 1831 | Mutex::Autolock lock(mStateLock); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1832 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1833 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1834 | return NAME_NOT_FOUND; |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1835 | } |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 1836 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1837 | *outIsWideColorDisplay = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1838 | display->isPrimary() ? mSupportsWideColor : display->hasWideColorGamut(); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1839 | return NO_ERROR; |
| 1840 | } |
| 1841 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 1842 | status_t SurfaceFlinger::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1843 | outLayers->clear(); |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1844 | auto future = mScheduler->schedule([=, this] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1845 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Vishnu Nair | 43bccf8 | 2020-06-05 10:53:37 -0700 | [diff] [blame] | 1846 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 1847 | outLayers->push_back(layer->getLayerDebugInfo(display.get())); |
| 1848 | }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1849 | }); |
| 1850 | |
| 1851 | future.wait(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1852 | return NO_ERROR; |
| 1853 | } |
| 1854 | |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1855 | status_t SurfaceFlinger::getCompositionPreference( |
| 1856 | Dataspace* outDataspace, ui::PixelFormat* outPixelFormat, |
| 1857 | Dataspace* outWideColorGamutDataspace, |
| 1858 | ui::PixelFormat* outWideColorGamutPixelFormat) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1859 | *outDataspace = mDefaultCompositionDataspace; |
| 1860 | *outPixelFormat = defaultCompositionPixelFormat; |
| 1861 | *outWideColorGamutDataspace = mWideColorGamutCompositionDataspace; |
| 1862 | *outWideColorGamutPixelFormat = wideColorGamutCompositionPixelFormat; |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 1863 | return NO_ERROR; |
| 1864 | } |
| 1865 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1866 | status_t SurfaceFlinger::addRegionSamplingListener(const Rect& samplingArea, |
| 1867 | const sp<IBinder>& stopLayerHandle, |
| 1868 | const sp<IRegionSamplingListener>& listener) { |
Leon Scroggins III | ae16b80 | 2022-01-12 11:42:05 -0500 | [diff] [blame] | 1869 | if (!listener || samplingArea == Rect::INVALID_RECT || samplingArea.isEmpty()) { |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1870 | return BAD_VALUE; |
| 1871 | } |
Alec Mouri | 9a02eda | 2020-04-21 17:39:34 -0700 | [diff] [blame] | 1872 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 1873 | // LayerHandle::getLayer promotes the layer object in a binder thread but we will not destroy |
| 1874 | // the layer here since the caller has a strong ref to the layer's handle. |
Vishnu Nair | 9d77a5c | 2022-10-28 06:31:21 +0000 | [diff] [blame] | 1875 | const sp<Layer> stopLayer = LayerHandle::getLayer(stopLayerHandle); |
| 1876 | mRegionSamplingThread->addListener(samplingArea, |
| 1877 | stopLayer ? stopLayer->getSequence() : UNASSIGNED_LAYER_ID, |
| 1878 | listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1879 | return NO_ERROR; |
| 1880 | } |
| 1881 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1882 | status_t SurfaceFlinger::removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) { |
tangrobin | af45f01 | 2019-02-26 18:10:10 +0800 | [diff] [blame] | 1883 | if (!listener) { |
| 1884 | return BAD_VALUE; |
| 1885 | } |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1886 | mRegionSamplingThread->removeListener(listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1887 | return NO_ERROR; |
| 1888 | } |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1889 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1890 | status_t SurfaceFlinger::addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) { |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1891 | if (!listener) { |
| 1892 | return BAD_VALUE; |
| 1893 | } |
| 1894 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1895 | mFpsReporter->addListener(listener, taskId); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1896 | return NO_ERROR; |
| 1897 | } |
| 1898 | |
| 1899 | status_t SurfaceFlinger::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 1900 | if (!listener) { |
| 1901 | return BAD_VALUE; |
| 1902 | } |
| 1903 | mFpsReporter->removeListener(listener); |
| 1904 | return NO_ERROR; |
| 1905 | } |
| 1906 | |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 1907 | status_t SurfaceFlinger::addTunnelModeEnabledListener( |
| 1908 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1909 | if (!listener) { |
| 1910 | return BAD_VALUE; |
| 1911 | } |
| 1912 | |
| 1913 | mTunnelModeEnabledReporter->addListener(listener); |
| 1914 | return NO_ERROR; |
| 1915 | } |
| 1916 | |
| 1917 | status_t SurfaceFlinger::removeTunnelModeEnabledListener( |
| 1918 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1919 | if (!listener) { |
| 1920 | return BAD_VALUE; |
| 1921 | } |
| 1922 | |
| 1923 | mTunnelModeEnabledReporter->removeListener(listener); |
| 1924 | return NO_ERROR; |
| 1925 | } |
| 1926 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1927 | status_t SurfaceFlinger::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 1928 | bool* outSupport) const { |
| 1929 | if (!displayToken || !outSupport) { |
| 1930 | return BAD_VALUE; |
| 1931 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1932 | |
| 1933 | Mutex::Autolock lock(mStateLock); |
| 1934 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1935 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1936 | if (!displayId) { |
| 1937 | return NAME_NOT_FOUND; |
| 1938 | } |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1939 | *outSupport = getHwComposer().hasDisplayCapability(*displayId, DisplayCapability::BRIGHTNESS); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1940 | return NO_ERROR; |
| 1941 | } |
| 1942 | |
John Reck | 22be696 | 2021-03-10 12:59:54 -0500 | [diff] [blame] | 1943 | status_t SurfaceFlinger::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 1944 | const gui::DisplayBrightness& brightness) { |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1945 | if (!displayToken) { |
| 1946 | return BAD_VALUE; |
| 1947 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1948 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1949 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1950 | return ftl::Future(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 1951 | // TODO(b/241285876): Validate that the display is physical instead of failing later. |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 1952 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1953 | const bool supportsDisplayBrightnessCommand = |
| 1954 | getHwComposer().getComposer()->isSupported( |
| 1955 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 1956 | // If we support applying display brightness as a command, then we also support |
| 1957 | // dimming SDR layers. |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1958 | if (supportsDisplayBrightnessCommand) { |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1959 | auto compositionDisplay = display->getCompositionDisplay(); |
| 1960 | float currentDimmingRatio = |
| 1961 | compositionDisplay->editState().sdrWhitePointNits / |
| 1962 | compositionDisplay->editState().displayBrightnessNits; |
Sally Qi | 0ea47b5 | 2023-06-22 13:27:20 -0700 | [diff] [blame] | 1963 | static constexpr float kDimmingThreshold = 0.02f; |
| 1964 | if (brightness.sdrWhitePointNits == 0.f || |
| 1965 | abs(brightness.sdrWhitePointNits - brightness.displayBrightnessNits) / |
| 1966 | brightness.sdrWhitePointNits >= |
| 1967 | kDimmingThreshold) { |
| 1968 | // to optimize, skip brightness setter if the brightness difference ratio |
| 1969 | // is lower than threshold |
| 1970 | compositionDisplay |
| 1971 | ->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 1972 | brightness.displayBrightnessNits); |
| 1973 | } else { |
| 1974 | compositionDisplay->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 1975 | brightness.sdrWhitePointNits); |
| 1976 | } |
| 1977 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1978 | FTL_FAKE_GUARD(kMainThreadContext, |
| 1979 | display->stageBrightness(brightness.displayBrightness)); |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 1980 | float currentHdrSdrRatio = |
| 1981 | compositionDisplay->editState().displayBrightnessNits / |
| 1982 | compositionDisplay->editState().sdrWhitePointNits; |
| 1983 | FTL_FAKE_GUARD(kMainThreadContext, |
| 1984 | display->updateHdrSdrRatioOverlayRatio(currentHdrSdrRatio)); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1985 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1986 | if (brightness.sdrWhitePointNits / brightness.displayBrightnessNits != |
| 1987 | currentDimmingRatio) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1988 | scheduleComposite(FrameHint::kNone); |
| 1989 | } else { |
| 1990 | scheduleCommit(FrameHint::kNone); |
| 1991 | } |
| 1992 | return ftl::yield<status_t>(OK); |
| 1993 | } else { |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1994 | return getHwComposer() |
| 1995 | .setDisplayBrightness(display->getPhysicalId(), |
| 1996 | brightness.displayBrightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 1997 | brightness.displayBrightnessNits, |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1998 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 1999 | .applyImmediately = true}); |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 2000 | } |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2001 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2002 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 2003 | return ftl::yield<status_t>(NAME_NOT_FOUND); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2004 | } |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 2005 | })) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 2006 | .then([](ftl::Future<status_t> task) { return task; }) |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2007 | .get(); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2010 | status_t SurfaceFlinger::addHdrLayerInfoListener(const sp<IBinder>& displayToken, |
| 2011 | const sp<gui::IHdrLayerInfoListener>& listener) { |
| 2012 | if (!displayToken) { |
| 2013 | return BAD_VALUE; |
| 2014 | } |
| 2015 | |
| 2016 | Mutex::Autolock lock(mStateLock); |
| 2017 | |
| 2018 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2019 | if (!display) { |
| 2020 | return NAME_NOT_FOUND; |
| 2021 | } |
| 2022 | const auto displayId = display->getId(); |
| 2023 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2024 | if (!hdrInfoReporter) { |
| 2025 | hdrInfoReporter = sp<HdrLayerInfoReporter>::make(); |
| 2026 | } |
| 2027 | hdrInfoReporter->addListener(listener); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2028 | |
| 2029 | |
| 2030 | mAddingHDRLayerInfoListener = true; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2031 | return OK; |
| 2032 | } |
| 2033 | |
| 2034 | status_t SurfaceFlinger::removeHdrLayerInfoListener( |
| 2035 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 2036 | if (!displayToken) { |
| 2037 | return BAD_VALUE; |
| 2038 | } |
| 2039 | |
| 2040 | Mutex::Autolock lock(mStateLock); |
| 2041 | |
| 2042 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2043 | if (!display) { |
| 2044 | return NAME_NOT_FOUND; |
| 2045 | } |
| 2046 | const auto displayId = display->getId(); |
| 2047 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2048 | if (hdrInfoReporter) { |
| 2049 | hdrInfoReporter->removeListener(listener); |
| 2050 | } |
| 2051 | return OK; |
| 2052 | } |
| 2053 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2054 | status_t SurfaceFlinger::notifyPowerBoost(int32_t boostId) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 2055 | using aidl::android::hardware::power::Boost; |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2056 | Boost powerBoost = static_cast<Boost>(boostId); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2057 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2058 | if (powerBoost == Boost::INTERACTION) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2059 | mScheduler->onTouchHint(); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | return NO_ERROR; |
| 2063 | } |
| 2064 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2065 | status_t SurfaceFlinger::getDisplayDecorationSupport( |
| 2066 | const sp<IBinder>& displayToken, |
| 2067 | std::optional<DisplayDecorationSupport>* outSupport) const { |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2068 | if (!displayToken || !outSupport) { |
| 2069 | return BAD_VALUE; |
| 2070 | } |
| 2071 | |
| 2072 | Mutex::Autolock lock(mStateLock); |
| 2073 | |
| 2074 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 2075 | if (!displayId) { |
| 2076 | return NAME_NOT_FOUND; |
| 2077 | } |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2078 | getHwComposer().getDisplayDecorationSupport(*displayId, outSupport); |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2079 | return NO_ERROR; |
| 2080 | } |
| 2081 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 2082 | // ---------------------------------------------------------------------------- |
| 2083 | |
Jorim Jaggi | b1e2f8d | 2017-06-08 15:43:59 -0700 | [diff] [blame] | 2084 | sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection( |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 2085 | gui::ISurfaceComposer::VsyncSource vsyncSource, EventRegistrationFlags eventRegistration, |
| 2086 | const sp<IBinder>& layerHandle) { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 2087 | const auto cycle = vsyncSource == gui::ISurfaceComposer::VsyncSource::eVsyncSourceSurfaceFlinger |
| 2088 | ? scheduler::Cycle::LastComposite |
| 2089 | : scheduler::Cycle::Render; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 2090 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 2091 | return mScheduler->createDisplayEventConnection(cycle, eventRegistration, layerHandle); |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2094 | void SurfaceFlinger::scheduleCommit(FrameHint hint) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2095 | if (hint == FrameHint::kActive) { |
| 2096 | mScheduler->resetIdleTimer(); |
| 2097 | } |
Matt Buckley | 15ecd1c | 2022-11-01 21:57:16 +0000 | [diff] [blame] | 2098 | mPowerAdvisor->notifyDisplayUpdateImminentAndCpuReset(); |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 2099 | mScheduler->scheduleFrame(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2100 | } |
| 2101 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2102 | void SurfaceFlinger::scheduleComposite(FrameHint hint) { |
| 2103 | mMustComposite = true; |
| 2104 | scheduleCommit(hint); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | void SurfaceFlinger::scheduleRepaint() { |
| 2108 | mGeometryDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2109 | scheduleComposite(FrameHint::kActive); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2112 | void SurfaceFlinger::scheduleSample() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2113 | static_cast<void>(mScheduler->schedule([this] { sample(); })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2114 | } |
| 2115 | |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 2116 | nsecs_t SurfaceFlinger::getVsyncPeriodFromHWC() const { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2117 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
| 2118 | return display->getVsyncPeriodFromHWC(); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2119 | } |
| 2120 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2121 | return 0; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2122 | } |
| 2123 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2124 | void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp, |
| 2125 | std::optional<hal::VsyncPeriodNanos> vsyncPeriod) { |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2126 | if (FlagManager::getInstance().connected_display() && timestamp < 0 && |
| 2127 | vsyncPeriod.has_value()) { |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2128 | // use ~0 instead of -1 as AidlComposerHal.cpp passes the param as unsigned int32 |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2129 | if (mIsHotplugErrViaNegVsync && vsyncPeriod.value() == ~0) { |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2130 | const auto errorCode = static_cast<int32_t>(-timestamp); |
| 2131 | ALOGD("%s: Hotplug error %d for display %" PRIu64, __func__, errorCode, hwcDisplayId); |
| 2132 | mScheduler->dispatchHotplugError(errorCode); |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2133 | return; |
| 2134 | } |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2135 | |
| 2136 | if (mIsHdcpViaNegVsync && vsyncPeriod.value() == ~1) { |
| 2137 | const int32_t value = static_cast<int32_t>(-timestamp); |
| 2138 | // one byte is good enough to encode android.hardware.drm.HdcpLevel |
| 2139 | const int32_t maxLevel = (value >> 8) & 0xFF; |
| 2140 | const int32_t connectedLevel = value & 0xFF; |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2141 | ALOGD("%s: HDCP levels changed (connected=%d, max=%d) for display %" PRIu64, __func__, |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2142 | connectedLevel, maxLevel, hwcDisplayId); |
| 2143 | updateHdcpLevels(hwcDisplayId, connectedLevel, maxLevel); |
| 2144 | return; |
| 2145 | } |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
Dominik Laskowski | 3d48304 | 2023-02-22 17:58:56 -0500 | [diff] [blame] | 2148 | ATRACE_NAME(vsyncPeriod |
| 2149 | ? ftl::Concat(__func__, ' ', hwcDisplayId, ' ', *vsyncPeriod, "ns").c_str() |
| 2150 | : ftl::Concat(__func__, ' ', hwcDisplayId).c_str()); |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 2151 | |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2152 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2153 | if (const auto displayIdOpt = getHwComposer().onVsync(hwcDisplayId, timestamp)) { |
| 2154 | if (mScheduler->addResyncSample(*displayIdOpt, timestamp, vsyncPeriod)) { |
| 2155 | // period flushed |
| 2156 | mScheduler->modulateVsync(displayIdOpt, &VsyncModulator::onRefreshRateChangeCompleted); |
| 2157 | } |
Alec Mouri | 754c98a | 2019-03-18 18:53:42 -0700 | [diff] [blame] | 2158 | } |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2161 | void SurfaceFlinger::onComposerHalHotplugEvent(hal::HWDisplayId hwcDisplayId, |
| 2162 | DisplayHotplugEvent event) { |
| 2163 | if (event == DisplayHotplugEvent::CONNECTED || event == DisplayHotplugEvent::DISCONNECTED) { |
| 2164 | hal::Connection connection = (event == DisplayHotplugEvent::CONNECTED) |
| 2165 | ? hal::Connection::CONNECTED |
| 2166 | : hal::Connection::DISCONNECTED; |
| 2167 | { |
| 2168 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 2169 | mPendingHotplugEvents.push_back(HotplugEvent{hwcDisplayId, connection}); |
| 2170 | } |
| 2171 | |
| 2172 | if (mScheduler) { |
| 2173 | mScheduler->scheduleConfigure(); |
| 2174 | } |
| 2175 | |
| 2176 | return; |
Jiwen 'Steve' Cai | ccfd682 | 2018-02-21 16:15:58 -0800 | [diff] [blame] | 2177 | } |
| 2178 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2179 | if (FlagManager::getInstance().hotplug2()) { |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2180 | // TODO(b/311403559): use enum type instead of int |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2181 | const auto errorCode = static_cast<int32_t>(event); |
| 2182 | ALOGD("%s: Hotplug error %d for display %" PRIu64, __func__, errorCode, hwcDisplayId); |
| 2183 | mScheduler->dispatchHotplugError(errorCode); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2184 | } |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2187 | void SurfaceFlinger::onComposerHalVsyncPeriodTimingChanged( |
| 2188 | hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline& timeline) { |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2189 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2190 | mScheduler->onNewVsyncPeriodChangeTimeline(timeline); |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2191 | |
| 2192 | if (timeline.refreshRequired) { |
| 2193 | scheduleComposite(FrameHint::kNone); |
| 2194 | } |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 2195 | } |
| 2196 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2197 | void SurfaceFlinger::onComposerHalSeamlessPossible(hal::HWDisplayId) { |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 2198 | // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and |
Ady Abraham | b0433bc | 2020-01-08 17:31:06 -0800 | [diff] [blame] | 2199 | // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE. |
| 2200 | } |
| 2201 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2202 | void SurfaceFlinger::onComposerHalRefresh(hal::HWDisplayId) { |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2203 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2204 | scheduleComposite(FrameHint::kNone); |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2205 | } |
| 2206 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2207 | void SurfaceFlinger::onComposerHalVsyncIdle(hal::HWDisplayId) { |
Ady Abraham | e9befd7 | 2022-02-24 17:24:44 -0800 | [diff] [blame] | 2208 | ATRACE_CALL(); |
| 2209 | mScheduler->forceNextResync(); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2210 | } |
| 2211 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 2212 | void SurfaceFlinger::onRefreshRateChangedDebug(const RefreshRateChangedDebugData& data) { |
| 2213 | ATRACE_CALL(); |
| 2214 | if (const auto displayId = getHwComposer().toPhysicalDisplayId(data.display); displayId) { |
ramindani | 19919ff | 2023-12-07 11:27:06 -0800 | [diff] [blame] | 2215 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 2216 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
ramindani | 19919ff | 2023-12-07 11:27:06 -0800 | [diff] [blame] | 2217 | const Fps fps = Fps::fromPeriodNsecs(getHwComposer().getComposer()->isVrrSupported() |
| 2218 | ? data.refreshPeriodNanos |
| 2219 | : data.vsyncPeriodNanos); |
| 2220 | ATRACE_FORMAT("%s Fps %d", whence, fps.getIntValue()); |
| 2221 | const auto display = getDisplayDeviceLocked(*displayId); |
| 2222 | FTL_FAKE_GUARD(kMainThreadContext, |
| 2223 | display->updateRefreshRateOverlayRate(fps, display->getActiveMode().fps, |
| 2224 | /* setByHwc */ true)); |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 2225 | })); |
| 2226 | } |
ramindani | 12bfe6b | 2023-02-03 13:29:19 -0800 | [diff] [blame] | 2227 | } |
| 2228 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2229 | void SurfaceFlinger::configure() { |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2230 | Mutex::Autolock lock(mStateLock); |
| 2231 | if (configureLocked()) { |
| 2232 | setTransactionFlags(eDisplayTransactionNeeded); |
| 2233 | } |
| 2234 | } |
| 2235 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2236 | bool SurfaceFlinger::updateLayerSnapshotsLegacy(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2237 | bool flushTransactions, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2238 | bool& outTransactionsAreEmpty) { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2239 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2240 | frontend::Update update; |
| 2241 | if (flushTransactions) { |
| 2242 | update = flushLifecycleUpdates(); |
| 2243 | if (mTransactionTracing) { |
| 2244 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2245 | update, mFrontEndDisplayInfos, |
| 2246 | mFrontEndDisplayInfosChanged); |
| 2247 | } |
| 2248 | } |
| 2249 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2250 | bool needsTraversal = false; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2251 | if (flushTransactions) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2252 | needsTraversal |= commitMirrorDisplays(vsyncId); |
| 2253 | needsTraversal |= commitCreatedLayers(vsyncId, update.layerCreatedStates); |
| 2254 | needsTraversal |= applyTransactions(update.transactions, vsyncId); |
| 2255 | } |
| 2256 | outTransactionsAreEmpty = !needsTraversal; |
| 2257 | const bool shouldCommit = (getTransactionFlags() & ~eTransactionFlushNeeded) || needsTraversal; |
| 2258 | if (shouldCommit) { |
| 2259 | commitTransactions(); |
| 2260 | } |
| 2261 | |
| 2262 | bool mustComposite = latchBuffers() || shouldCommit; |
| 2263 | updateLayerGeometry(); |
| 2264 | return mustComposite; |
| 2265 | } |
| 2266 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2267 | void SurfaceFlinger::updateLayerHistory(nsecs_t now) { |
| 2268 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 2269 | using Changes = frontend::RequestedLayerState::Changes; |
| 2270 | if (snapshot->path.isClone()) { |
| 2271 | continue; |
| 2272 | } |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 2273 | |
Jerry Chang | 3667800 | 2023-11-29 16:56:17 +0000 | [diff] [blame] | 2274 | const bool updateSmallDirty = FlagManager::getInstance().enable_small_area_detection() && |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2275 | ((snapshot->clientChanges & layer_state_t::eSurfaceDamageRegionChanged) || |
| 2276 | snapshot->changes.any(Changes::Geometry)); |
| 2277 | |
| 2278 | const bool hasChanges = |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 2279 | snapshot->changes.any(Changes::FrameRate | Changes::Buffer | Changes::Animation | |
| 2280 | Changes::Geometry | Changes::Visibility) || |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2281 | (snapshot->clientChanges & layer_state_t::eDefaultFrameRateCompatibilityChanged) != |
| 2282 | 0; |
| 2283 | |
| 2284 | if (!updateSmallDirty && !hasChanges) { |
| 2285 | continue; |
| 2286 | } |
| 2287 | |
| 2288 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 2289 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 2290 | "Couldn't find layer object for %s", |
| 2291 | snapshot->getDebugString().c_str()); |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2292 | |
| 2293 | if (updateSmallDirty) { |
| 2294 | // Update small dirty flag while surface damage region or geometry changed |
| 2295 | it->second->setIsSmallDirty(snapshot.get()); |
| 2296 | } |
| 2297 | |
| 2298 | if (!hasChanges) { |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2299 | continue; |
| 2300 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2301 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2302 | const auto layerProps = scheduler::LayerProps{ |
| 2303 | .visible = snapshot->isVisible, |
| 2304 | .bounds = snapshot->geomLayerBounds, |
| 2305 | .transform = snapshot->geomLayerTransform, |
| 2306 | .setFrameRateVote = snapshot->frameRate, |
| 2307 | .frameRateSelectionPriority = snapshot->frameRateSelectionPriority, |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2308 | .isSmallDirty = snapshot->isSmallDirty, |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 2309 | .isFrontBuffered = snapshot->isFrontBuffered(), |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2310 | }; |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2311 | |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 2312 | if (snapshot->changes.any(Changes::Geometry | Changes::Visibility)) { |
| 2313 | mScheduler->setLayerProperties(snapshot->sequence, layerProps); |
| 2314 | } |
| 2315 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2316 | if (snapshot->clientChanges & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 2317 | mScheduler->setDefaultFrameRateCompatibility(snapshot->sequence, |
| 2318 | snapshot->defaultFrameRateCompatibility); |
| 2319 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2320 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2321 | if (snapshot->changes.test(Changes::Animation)) { |
| 2322 | it->second->recordLayerHistoryAnimationTx(layerProps, now); |
| 2323 | } |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 2324 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2325 | if (snapshot->changes.test(Changes::FrameRate)) { |
| 2326 | it->second->setFrameRateForLayerTree(snapshot->frameRate, layerProps, now); |
| 2327 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2328 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2329 | if (snapshot->changes.test(Changes::Buffer)) { |
| 2330 | it->second->recordLayerHistoryBufferUpdate(layerProps, now); |
| 2331 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2335 | bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2336 | bool flushTransactions, bool& outTransactionsAreEmpty) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2337 | using Changes = frontend::RequestedLayerState::Changes; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2338 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2339 | frontend::Update update; |
| 2340 | if (flushTransactions) { |
| 2341 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 2342 | // Locking: |
| 2343 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 2344 | // we must keep a copy of the transactions (specifically the composer |
| 2345 | // states) around outside the scope of the lock. |
| 2346 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 2347 | // transactions with layers still in the createdLayer queue, collect the transactions |
| 2348 | // before committing the created layers. |
| 2349 | // 3. Transactions can only be flushed after adding layers, since the layer can be a newly |
| 2350 | // created one |
| 2351 | mTransactionHandler.collectTransactions(); |
| 2352 | { |
| 2353 | // TODO(b/238781169) lockless queue this and keep order. |
| 2354 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 2355 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 2356 | mCreatedLayers.clear(); |
| 2357 | update.newLayers = std::move(mNewLayers); |
| 2358 | mNewLayers.clear(); |
| 2359 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 2360 | mNewLayerArgs.clear(); |
| 2361 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 2362 | mDestroyedHandles.clear(); |
| 2363 | } |
| 2364 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2365 | mLayerLifecycleManager.addLayers(std::move(update.newLayers)); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2366 | update.transactions = mTransactionHandler.flushTransactions(); |
| 2367 | if (mTransactionTracing) { |
| 2368 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2369 | update, mFrontEndDisplayInfos, |
| 2370 | mFrontEndDisplayInfosChanged); |
| 2371 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2372 | mLayerLifecycleManager.applyTransactions(update.transactions); |
| 2373 | mLayerLifecycleManager.onHandlesDestroyed(update.destroyedHandles); |
| 2374 | for (auto& legacyLayer : update.layerCreatedStates) { |
| 2375 | sp<Layer> layer = legacyLayer.layer.promote(); |
| 2376 | if (layer) { |
| 2377 | mLegacyLayers[layer->sequence] = layer; |
| 2378 | } |
| 2379 | } |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 2380 | mLayerHierarchyBuilder.update(mLayerLifecycleManager); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2381 | } |
| 2382 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2383 | bool mustComposite = false; |
| 2384 | mustComposite |= applyAndCommitDisplayTransactionStates(update.transactions); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2385 | |
| 2386 | { |
| 2387 | ATRACE_NAME("LayerSnapshotBuilder:update"); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2388 | frontend::LayerSnapshotBuilder::Args |
| 2389 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 2390 | .layerLifecycleManager = mLayerLifecycleManager, |
| 2391 | .displays = mFrontEndDisplayInfos, |
| 2392 | .displayChanges = mFrontEndDisplayInfosChanged, |
| 2393 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2394 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2395 | .forceFullDamage = mForceFullDamage, |
| 2396 | .supportedLayerGenericMetadata = |
| 2397 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 2398 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 2399 | .skipRoundCornersWhenProtected = |
| 2400 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2401 | mLayerSnapshotBuilder.update(args); |
| 2402 | } |
| 2403 | |
| 2404 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Geometry | Changes::Input | |
Vishnu Nair | 40d0228 | 2023-02-28 21:11:40 +0000 | [diff] [blame] | 2405 | Changes::Hierarchy | Changes::Visibility)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2406 | mUpdateInputInfo = true; |
| 2407 | } |
| 2408 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::VisibleRegion | Changes::Hierarchy | |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2409 | Changes::Visibility | Changes::Geometry)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2410 | mVisibleRegionsDirty = true; |
| 2411 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2412 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Hierarchy | Changes::FrameRate)) { |
| 2413 | // The frame rate of attached choreographers can only change as a result of a |
| 2414 | // FrameRate change (including when Hierarchy changes). |
| 2415 | mUpdateAttachedChoreographer = true; |
| 2416 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2417 | outTransactionsAreEmpty = mLayerLifecycleManager.getGlobalChanges().get() == 0; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2418 | mustComposite |= mLayerLifecycleManager.getGlobalChanges().get() != 0; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2419 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2420 | bool newDataLatched = false; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2421 | if (!mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2422 | ATRACE_NAME("DisplayCallbackAndStatsUpdates"); |
Vishnu Nair | d2a38f9 | 2023-08-23 18:43:01 -0700 | [diff] [blame] | 2423 | mustComposite |= applyTransactions(update.transactions, vsyncId); |
Vishnu Nair | c1d19d7 | 2023-08-10 12:35:11 -0700 | [diff] [blame] | 2424 | traverseLegacyLayers([&](Layer* layer) { layer->commitTransaction(); }); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2425 | const nsecs_t latchTime = systemTime(); |
| 2426 | bool unused = false; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2427 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2428 | for (auto& layer : mLayerLifecycleManager.getLayers()) { |
| 2429 | if (layer->changes.test(frontend::RequestedLayerState::Changes::Created) && |
| 2430 | layer->bgColorLayer) { |
| 2431 | sp<Layer> bgColorLayer = getFactory().createEffectLayer( |
| 2432 | LayerCreationArgs(this, nullptr, layer->name, |
| 2433 | ISurfaceComposerClient::eFXSurfaceEffect, LayerMetadata(), |
Vishnu Nair | e4af095 | 2023-05-01 09:11:33 -0700 | [diff] [blame] | 2434 | std::make_optional(layer->id), true)); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2435 | mLegacyLayers[bgColorLayer->sequence] = bgColorLayer; |
| 2436 | } |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2437 | const bool willReleaseBufferOnLatch = layer->willReleaseBufferOnLatch(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2438 | |
| 2439 | auto it = mLegacyLayers.find(layer->id); |
Vishnu Nair | 1009dbd | 2024-01-17 10:42:29 -0800 | [diff] [blame] | 2440 | if (it == mLegacyLayers.end() && |
| 2441 | layer->changes.test(frontend::RequestedLayerState::Changes::Destroyed)) { |
| 2442 | // Layer handle was created and immediately destroyed. It was destroyed before it |
| 2443 | // was added to the map. |
| 2444 | continue; |
| 2445 | } |
| 2446 | |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 2447 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 2448 | "Couldnt find layer object for %s", |
| 2449 | layer->getDebugString().c_str()); |
Vishnu Nair | f32ff9b | 2023-08-23 14:32:30 -0700 | [diff] [blame] | 2450 | if (!layer->hasReadyFrame() && !willReleaseBufferOnLatch) { |
| 2451 | if (!it->second->hasBuffer()) { |
| 2452 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 2453 | // instead of a missed frame. This is used to identify scenarios where we |
| 2454 | // could not latch a buffer or apply a transaction due to backpressure. |
| 2455 | // We only update the latch time for buffer less layers here, the latch time |
| 2456 | // is updated for buffer layers when the buffer is latched. |
| 2457 | it->second->updateLastLatchTime(latchTime); |
| 2458 | } |
| 2459 | continue; |
| 2460 | } |
| 2461 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2462 | const bool bgColorOnly = |
| 2463 | !layer->externalTexture && (layer->bgColorLayerId != UNASSIGNED_LAYER_ID); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2464 | if (willReleaseBufferOnLatch) { |
| 2465 | mLayersWithBuffersRemoved.emplace(it->second); |
| 2466 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2467 | it->second->latchBufferImpl(unused, latchTime, bgColorOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2468 | newDataLatched = true; |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2469 | |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2470 | mLayersWithQueuedFrames.emplace(it->second); |
| 2471 | mLayersIdsWithQueuedFrames.emplace(it->second->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2472 | } |
| 2473 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2474 | updateLayerHistory(latchTime); |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2475 | mLayerSnapshotBuilder.forEachVisibleSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2476 | if (mLayersIdsWithQueuedFrames.find(snapshot.path.id) == |
| 2477 | mLayersIdsWithQueuedFrames.end()) |
| 2478 | return; |
| 2479 | Region visibleReg; |
| 2480 | visibleReg.set(snapshot.transformedBoundsWithoutTransparentRegion); |
| 2481 | invalidateLayerStack(snapshot.outputFilter, visibleReg); |
| 2482 | }); |
| 2483 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2484 | for (auto& destroyedLayer : mLayerLifecycleManager.getDestroyedLayers()) { |
| 2485 | mLegacyLayers.erase(destroyedLayer->id); |
| 2486 | } |
| 2487 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2488 | { |
| 2489 | ATRACE_NAME("LLM:commitChanges"); |
| 2490 | mLayerLifecycleManager.commitChanges(); |
| 2491 | } |
| 2492 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2493 | // enter boot animation on first buffer latch |
| 2494 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 2495 | ALOGI("Enter boot animation"); |
| 2496 | mBootStage = BootStage::BOOTANIMATION; |
| 2497 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2498 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2499 | mustComposite |= (getTransactionFlags() & ~eTransactionFlushNeeded) || newDataLatched; |
Vishnu Nair | 8134c1a | 2023-10-17 22:55:49 -0700 | [diff] [blame] | 2500 | if (mustComposite && !mLegacyFrontEndEnabled) { |
| 2501 | commitTransactions(); |
| 2502 | } |
| 2503 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2504 | return mustComposite; |
| 2505 | } |
| 2506 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2507 | bool SurfaceFlinger::commit(PhysicalDisplayId pacesetterId, |
| 2508 | const scheduler::FrameTargets& frameTargets) { |
| 2509 | const scheduler::FrameTarget& pacesetterFrameTarget = *frameTargets.get(pacesetterId)->get(); |
| 2510 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2511 | const VsyncId vsyncId = pacesetterFrameTarget.vsyncId(); |
| 2512 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2513 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2514 | if (pacesetterFrameTarget.didMissFrame()) { |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2515 | mTimeStats->incrementMissedFrames(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2516 | } |
| 2517 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2518 | // If a mode set is pending and the fence hasn't fired yet, wait for the next commit. |
| 2519 | if (std::any_of(frameTargets.begin(), frameTargets.end(), |
| 2520 | [this](const auto& pair) FTL_FAKE_GUARD(mStateLock) |
| 2521 | FTL_FAKE_GUARD(kMainThreadContext) { |
| 2522 | if (!pair.second->isFramePending()) return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2523 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2524 | if (const auto display = getDisplayDeviceLocked(pair.first)) { |
| 2525 | return display->isModeSetPending(); |
| 2526 | } |
| 2527 | |
| 2528 | return false; |
| 2529 | })) { |
| 2530 | mScheduler->scheduleFrame(); |
| 2531 | return false; |
| 2532 | } |
| 2533 | |
| 2534 | { |
| 2535 | Mutex::Autolock lock(mStateLock); |
| 2536 | |
| 2537 | for (const auto [id, target] : frameTargets) { |
| 2538 | // TODO(b/241285876): This is `nullptr` when the DisplayDevice is about to be removed in |
| 2539 | // this commit, since the PhysicalDisplay has already been removed. Rather than checking |
| 2540 | // for `nullptr` below, change Scheduler::onFrameSignal to filter out the FrameTarget of |
| 2541 | // the removed display. |
| 2542 | const auto display = getDisplayDeviceLocked(id); |
| 2543 | |
| 2544 | if (display && display->isModeSetPending()) { |
| 2545 | finalizeDisplayModeChange(*display); |
| 2546 | } |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2547 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2548 | } |
| 2549 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2550 | if (pacesetterFrameTarget.isFramePending()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2551 | if (mBackpressureGpuComposition || pacesetterFrameTarget.didMissHwcFrame()) { |
Ady Abraham | e988303 | 2023-11-20 17:54:54 -0800 | [diff] [blame] | 2552 | if (FlagManager::getInstance().vrr_config()) { |
| 2553 | mScheduler->getVsyncSchedule()->getTracker().onFrameMissed( |
| 2554 | pacesetterFrameTarget.expectedPresentTime()); |
| 2555 | } |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2556 | scheduleCommit(FrameHint::kNone); |
| 2557 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2558 | } |
| 2559 | } |
| 2560 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2561 | const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); |
| 2562 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2563 | // Save this once per commit + composite to ensure consistency |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2564 | // TODO (b/240619471): consider removing active display check once AOD is fixed |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 2565 | const auto activeDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(mActiveDisplayId)); |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2566 | mPowerHintSessionEnabled = mPowerAdvisor->usePowerHintSession() && activeDisplay && |
| 2567 | activeDisplay->getPowerMode() == hal::PowerMode::ON; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2568 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2569 | mPowerAdvisor->setCommitStart(pacesetterFrameTarget.frameBeginTime()); |
| 2570 | mPowerAdvisor->setExpectedPresentTime(pacesetterFrameTarget.expectedPresentTime()); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2571 | |
| 2572 | // Frame delay is how long we should have minus how long we actually have. |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 2573 | const Duration idealSfWorkDuration = |
| 2574 | mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2575 | const Duration frameDelay = |
| 2576 | idealSfWorkDuration - pacesetterFrameTarget.expectedFrameDuration(); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2577 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2578 | mPowerAdvisor->setFrameDelay(frameDelay); |
| 2579 | mPowerAdvisor->setTotalFrameTargetWorkDuration(idealSfWorkDuration); |
Matt Buckley | 676e439 | 2023-05-25 22:09:26 +0000 | [diff] [blame] | 2580 | |
| 2581 | const auto& display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get(); |
| 2582 | const Period idealVsyncPeriod = display->getActiveMode().fps.getPeriod(); |
| 2583 | mPowerAdvisor->updateTargetWorkDuration(idealVsyncPeriod); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2584 | } |
| 2585 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2586 | if (mRefreshRateOverlaySpinner || mHdrSdrRatioOverlay) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 2587 | Mutex::Autolock lock(mStateLock); |
| 2588 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2589 | display->animateOverlay(); |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2590 | } |
| 2591 | } |
| 2592 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2593 | // Composite if transactions were committed, or if requested by HWC. |
| 2594 | bool mustComposite = mMustComposite.exchange(false); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2595 | { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2596 | mFrameTimeline->setSfWakeUp(ftl::to_underlying(vsyncId), |
| 2597 | pacesetterFrameTarget.frameBeginTime().ns(), |
Pascal Muetschard | ac7bcd9 | 2023-10-03 15:05:36 +0200 | [diff] [blame] | 2598 | Fps::fromPeriodNsecs(vsyncPeriod.ns()), |
| 2599 | mScheduler->getPacesetterRefreshRate()); |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 2600 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2601 | const bool flushTransactions = clearTransactionFlags(eTransactionFlushNeeded); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2602 | bool transactionsAreEmpty; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2603 | if (mLegacyFrontEndEnabled) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2604 | mustComposite |= |
| 2605 | updateLayerSnapshotsLegacy(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2606 | flushTransactions, transactionsAreEmpty); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2607 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2608 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2609 | mustComposite |= |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2610 | updateLayerSnapshots(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2611 | flushTransactions, transactionsAreEmpty); |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | if (transactionFlushNeeded()) { |
| 2615 | setTransactionFlags(eTransactionFlushNeeded); |
| 2616 | } |
| 2617 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2618 | // This has to be called after latchBuffers because we want to include the layers that have |
| 2619 | // been latched in the commit callback |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2620 | if (transactionsAreEmpty) { |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2621 | // Invoke empty transaction callbacks early. |
| 2622 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 2623 | } else { |
| 2624 | // Invoke OnCommit callbacks. |
| 2625 | mTransactionCallbackInvoker.sendCallbacks(true /* onCommitOnly */); |
| 2626 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | // Layers need to get updated (in the previous line) before we can use them for |
| 2630 | // choosing the refresh rate. |
| 2631 | // Hold mStateLock as chooseRefreshRateForContent promotes wp<Layer> to sp<Layer> |
| 2632 | // and may eventually call to ~Layer() if it holds the last reference |
| 2633 | { |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2634 | bool updateAttachedChoreographer = mUpdateAttachedChoreographer; |
| 2635 | mUpdateAttachedChoreographer = false; |
| 2636 | |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 2637 | Mutex::Autolock lock(mStateLock); |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2638 | mScheduler->chooseRefreshRateForContent(mLayerLifecycleManagerEnabled |
| 2639 | ? &mLayerHierarchyBuilder.getHierarchy() |
| 2640 | : nullptr, |
| 2641 | updateAttachedChoreographer); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2642 | initiateDisplayModeChanges(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2643 | } |
| 2644 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2645 | updateCursorAsync(); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2646 | if (!mustComposite) { |
| 2647 | updateInputFlinger(vsyncId, pacesetterFrameTarget.frameBeginTime()); |
| 2648 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2649 | doActiveLayersTracingIfNeeded(false, mVisibleRegionsDirty, |
| 2650 | pacesetterFrameTarget.frameBeginTime(), vsyncId); |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 2651 | |
Pablo Gamito | 6be8244 | 2022-06-13 11:04:34 +0000 | [diff] [blame] | 2652 | mLastCommittedVsyncId = vsyncId; |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2653 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2654 | persistDisplayBrightness(mustComposite); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2655 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2656 | return mustComposite && CC_LIKELY(mBootStage != BootStage::BOOTLOADER); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2659 | CompositeResultsPerDisplay SurfaceFlinger::composite( |
| 2660 | PhysicalDisplayId pacesetterId, const scheduler::FrameTargeters& frameTargeters) { |
| 2661 | const scheduler::FrameTarget& pacesetterTarget = |
| 2662 | frameTargeters.get(pacesetterId)->get()->target(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2663 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2664 | const VsyncId vsyncId = pacesetterTarget.vsyncId(); |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2665 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2666 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2667 | compositionengine::CompositionRefreshArgs refreshArgs; |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 2668 | refreshArgs.powerCallback = this; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2669 | const auto& displays = FTL_FAKE_GUARD(mStateLock, mDisplays); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2670 | refreshArgs.outputs.reserve(displays.size()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2671 | |
| 2672 | // Add outputs for physical displays. |
| 2673 | for (const auto& [id, targeter] : frameTargeters) { |
| 2674 | ftl::FakeGuard guard(mStateLock); |
| 2675 | |
| 2676 | if (const auto display = getCompositionDisplayLocked(id)) { |
| 2677 | refreshArgs.outputs.push_back(display); |
| 2678 | } |
Leon Scroggins III | 370b8b5 | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 2679 | |
| 2680 | refreshArgs.frameTargets.try_emplace(id, &targeter->target()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2681 | } |
| 2682 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2683 | std::vector<DisplayId> displayIds; |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2684 | for (const auto& [_, display] : displays) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2685 | displayIds.push_back(display->getId()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2686 | display->tracePowerMode(); |
| 2687 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2688 | // Add outputs for virtual displays. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2689 | if (display->isVirtual()) { |
| 2690 | const Fps refreshRate = display->getAdjustedRefreshRate(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2691 | |
| 2692 | if (!refreshRate.isValid() || |
| 2693 | mScheduler->isVsyncInPhase(pacesetterTarget.frameBeginTime(), refreshRate)) { |
| 2694 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2695 | } |
| 2696 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2697 | } |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2698 | mPowerAdvisor->setDisplays(displayIds); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2699 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 2700 | const bool updateTaskMetadata = mCompositionEngine->getFeatureFlags().test( |
| 2701 | compositionengine::Feature::kSnapshotLayerMetadata); |
| 2702 | if (updateTaskMetadata && (mVisibleRegionsDirty || mLayerMetadataSnapshotNeeded)) { |
| 2703 | updateLayerMetadataSnapshot(); |
| 2704 | mLayerMetadataSnapshotNeeded = false; |
| 2705 | } |
| 2706 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2707 | if (DOES_CONTAIN_BORDER) { |
| 2708 | refreshArgs.borderInfoList.clear(); |
| 2709 | mDrawingState.traverse([&refreshArgs](Layer* layer) { |
| 2710 | if (layer->isBorderEnabled()) { |
| 2711 | compositionengine::BorderRenderInfo info; |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 2712 | info.width = layer->getBorderWidth(); |
| 2713 | info.color = layer->getBorderColor(); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2714 | layer->traverse(LayerVector::StateSet::Drawing, [&info](Layer* ilayer) { |
| 2715 | info.layerIds.push_back(ilayer->getSequence()); |
| 2716 | }); |
| 2717 | refreshArgs.borderInfoList.emplace_back(std::move(info)); |
| 2718 | } |
| 2719 | }); |
| 2720 | } |
| 2721 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 2722 | refreshArgs.bufferIdsToUncache = std::move(mBufferIdsToUncache); |
| 2723 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2724 | refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); |
Alec Mouri | 5c9c960 | 2020-09-01 15:10:40 -0700 | [diff] [blame] | 2725 | for (auto layer : mLayersWithQueuedFrames) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 2726 | if (auto layerFE = layer->getCompositionEngineLayerFE()) |
| 2727 | refreshArgs.layersWithQueuedFrames.push_back(layerFE); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2728 | } |
| 2729 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 2730 | refreshArgs.outputColorSetting = mDisplayColorSetting; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 2731 | refreshArgs.forceOutputColorMode = mForceColorMode; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2732 | |
| 2733 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2734 | refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || mVisibleRegionsDirty; |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 2735 | refreshArgs.internalDisplayRotationFlags = getActiveDisplayRotationFlags(); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2736 | |
| 2737 | if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) { |
| 2738 | refreshArgs.colorTransformMatrix = mDrawingState.colorMatrix; |
| 2739 | mDrawingState.colorMatrixChanged = false; |
| 2740 | } |
| 2741 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2742 | refreshArgs.devOptForceClientComposition = mDebugDisableHWC; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2743 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2744 | if (mDebugFlashDelay != 0) { |
| 2745 | refreshArgs.devOptForceClientComposition = true; |
| 2746 | refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay); |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 2747 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2748 | |
ramindani | 0491e64 | 2023-11-16 17:42:14 -0800 | [diff] [blame] | 2749 | // TODO(b/255601557) Update frameInterval per display |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 2750 | refreshArgs.frameInterval = |
| 2751 | mScheduler->getNextFrameInterval(pacesetterId, pacesetterTarget.expectedPresentTime()); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 2752 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 2753 | const auto scheduledFrameTimeOpt = scheduledFrameResultOpt |
| 2754 | ? std::optional{scheduledFrameResultOpt->callbackTime} |
| 2755 | : std::nullopt; |
| 2756 | refreshArgs.scheduledFrameTime = scheduledFrameTimeOpt; |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 2757 | refreshArgs.hasTrustedPresentationListener = mNumTrustedPresentationListeners > 0; |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2758 | // Store the present time just before calling to the composition engine so we could notify |
| 2759 | // the scheduler. |
| 2760 | const auto presentTime = systemTime(); |
| 2761 | |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2762 | constexpr bool kCursorOnly = false; |
| 2763 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
| 2764 | |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2765 | if (mLayerLifecycleManagerEnabled && !mVisibleRegionsDirty) { |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2766 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 2767 | auto compositionDisplay = display->getCompositionDisplay(); |
| 2768 | if (!compositionDisplay->getState().isEnabled) continue; |
| 2769 | for (auto outputLayer : compositionDisplay->getOutputLayersOrderedByZ()) { |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2770 | if (outputLayer->getLayerFE().getCompositionState() == nullptr) { |
| 2771 | // This is unexpected but instead of crashing, capture traces to disk |
| 2772 | // and recover gracefully by forcing CE to rebuild layer stack. |
| 2773 | ALOGE("Output layer %s for display %s %" PRIu64 " has a null " |
| 2774 | "snapshot. Forcing mVisibleRegionsDirty", |
| 2775 | outputLayer->getLayerFE().getDebugName(), |
| 2776 | compositionDisplay->getName().c_str(), compositionDisplay->getId().value); |
| 2777 | |
| 2778 | TransactionTraceWriter::getInstance().invoke(__func__, /* overwrite= */ false); |
| 2779 | mVisibleRegionsDirty = true; |
| 2780 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
| 2781 | refreshArgs.updatingGeometryThisFrame = mVisibleRegionsDirty; |
| 2782 | } |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2783 | } |
| 2784 | } |
| 2785 | } |
| 2786 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2787 | mCompositionEngine->present(refreshArgs); |
| 2788 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2789 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2790 | for (auto [layer, layerFE] : layers) { |
| 2791 | CompositionResult compositionResult{layerFE->stealCompositionResult()}; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2792 | layer->onPreComposition(compositionResult.refreshStartTime); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2793 | for (auto& [releaseFence, layerStack] : compositionResult.releaseFences) { |
Vishnu Nair | 332e6ba | 2023-01-25 17:16:19 -0800 | [diff] [blame] | 2794 | Layer* clonedFrom = layer->getClonedFrom().get(); |
| 2795 | auto owningLayer = clonedFrom ? clonedFrom : layer; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2796 | owningLayer->onLayerDisplayed(std::move(releaseFence), layerStack); |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2797 | } |
| 2798 | if (compositionResult.lastClientCompositionFence) { |
| 2799 | layer->setWasClientComposed(compositionResult.lastClientCompositionFence); |
| 2800 | } |
| 2801 | } |
| 2802 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2803 | mTimeStats->recordFrameDuration(pacesetterTarget.frameBeginTime().ns(), systemTime()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2804 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2805 | // Send a power hint after presentation is finished. |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2806 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2807 | // Now that the current frame has been presented above, PowerAdvisor needs the present time |
| 2808 | // of the previous frame (whose fence is signaled by now) to determine how long the HWC had |
| 2809 | // waited on that fence to retire before presenting. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2810 | const auto& previousPresentFence = pacesetterTarget.presentFenceForPreviousFrame(); |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2811 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2812 | mPowerAdvisor->setSfPresentTiming(TimePoint::fromNs(previousPresentFence->getSignalTime()), |
| 2813 | TimePoint::now()); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 2814 | mPowerAdvisor->reportActualWorkDuration(); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2815 | } |
| 2816 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2817 | if (mScheduler->onCompositionPresented(presentTime)) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2818 | scheduleComposite(FrameHint::kNone); |
| 2819 | } |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2820 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 2821 | mNotifyExpectedPresentMap[pacesetterId].hintStatus = NotifyExpectedPresentHintStatus::Start; |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2822 | onCompositionPresented(pacesetterId, frameTargeters, presentTime); |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 2823 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2824 | const bool hadGpuComposited = |
| 2825 | multiDisplayUnion(mCompositionCoverage).test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2826 | mCompositionCoverage.clear(); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2827 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2828 | TimeStats::ClientCompositionRecord clientCompositionRecord; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2829 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2830 | for (const auto& [_, display] : displays) { |
| 2831 | const auto& state = display->getCompositionDisplay()->getState(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2832 | CompositionCoverageFlags& flags = |
| 2833 | mCompositionCoverage.try_emplace(display->getId()).first->second; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2834 | |
| 2835 | if (state.usesDeviceComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2836 | flags |= CompositionCoverage::Hwc; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | if (state.reusedClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2840 | flags |= CompositionCoverage::GpuReuse; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2841 | } else if (state.usesClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2842 | flags |= CompositionCoverage::Gpu; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2843 | } |
| 2844 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2845 | clientCompositionRecord.predicted |= |
| 2846 | (state.strategyPrediction != CompositionStrategyPredictionState::DISABLED); |
| 2847 | clientCompositionRecord.predictionSucceeded |= |
| 2848 | (state.strategyPrediction == CompositionStrategyPredictionState::SUCCESS); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2849 | } |
| 2850 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2851 | const auto coverage = multiDisplayUnion(mCompositionCoverage); |
| 2852 | const bool hasGpuComposited = coverage.test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2853 | |
| 2854 | clientCompositionRecord.hadClientComposition = hasGpuComposited; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2855 | clientCompositionRecord.reused = coverage.test(CompositionCoverage::GpuReuse); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2856 | clientCompositionRecord.changed = hadGpuComposited != hasGpuComposited; |
| 2857 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2858 | mTimeStats->pushCompositionStrategyState(clientCompositionRecord); |
| 2859 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2860 | using namespace ftl::flag_operators; |
| 2861 | |
| 2862 | // TODO(b/160583065): Enable skip validation when SF caches all client composition layers. |
| 2863 | const bool hasGpuUseOrReuse = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2864 | coverage.any(CompositionCoverage::Gpu | CompositionCoverage::GpuReuse); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2865 | mScheduler->modulateVsync({}, &VsyncModulator::onDisplayRefresh, hasGpuUseOrReuse); |
Dan Stoza | 14cd37c | 2015-07-09 12:43:33 -0700 | [diff] [blame] | 2866 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 2867 | mLayersWithQueuedFrames.clear(); |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2868 | mLayersIdsWithQueuedFrames.clear(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2869 | doActiveLayersTracingIfNeeded(true, mVisibleRegionsDirty, pacesetterTarget.frameBeginTime(), |
| 2870 | vsyncId); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2871 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2872 | updateInputFlinger(vsyncId, pacesetterTarget.frameBeginTime()); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2873 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2874 | if (mVisibleRegionsDirty) mHdrLayerInfoChanged = true; |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 2875 | mVisibleRegionsDirty = false; |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2876 | |
| 2877 | if (mCompositionEngine->needsAnotherUpdate()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2878 | scheduleCommit(FrameHint::kNone); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2879 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2880 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2881 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2882 | mPowerAdvisor->setCompositeEnd(TimePoint::now()); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2883 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2884 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2885 | CompositeResultsPerDisplay resultsPerDisplay; |
| 2886 | |
| 2887 | // Filter out virtual displays. |
| 2888 | for (const auto& [id, coverage] : mCompositionCoverage) { |
| 2889 | if (const auto idOpt = PhysicalDisplayId::tryCast(id)) { |
| 2890 | resultsPerDisplay.try_emplace(*idOpt, CompositeResult{coverage}); |
| 2891 | } |
| 2892 | } |
| 2893 | |
| 2894 | return resultsPerDisplay; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2895 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2896 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2897 | void SurfaceFlinger::updateLayerGeometry() { |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2898 | ATRACE_CALL(); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 2899 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2900 | if (mVisibleRegionsDirty) { |
| 2901 | computeLayerBounds(); |
| 2902 | } |
| 2903 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2904 | for (auto& layer : mLayersPendingRefresh) { |
| 2905 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2906 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2907 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2908 | } |
| 2909 | mLayersPendingRefresh.clear(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2910 | } |
| 2911 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2912 | bool SurfaceFlinger::isHdrLayer(const frontend::LayerSnapshot& snapshot) const { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2913 | // Even though the camera layer may be using an HDR transfer function or otherwise be "HDR" |
| 2914 | // the device may need to avoid boosting the brightness as a result of these layers to |
| 2915 | // reduce power consumption during camera recording |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2916 | if (mIgnoreHdrCameraLayers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2917 | if (snapshot.externalTexture && |
| 2918 | (snapshot.externalTexture->getUsage() & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) { |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2919 | return false; |
| 2920 | } |
| 2921 | } |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 2922 | // RANGE_EXTENDED layer may identify themselves as being "HDR" |
| 2923 | // via a desired hdr/sdr ratio |
| 2924 | auto pixelFormat = snapshot.buffer |
| 2925 | ? std::make_optional(static_cast<ui::PixelFormat>(snapshot.buffer->getPixelFormat())) |
| 2926 | : std::nullopt; |
| 2927 | |
| 2928 | if (getHdrRenderType(snapshot.dataspace, pixelFormat, snapshot.desiredHdrSdrRatio) != |
| 2929 | HdrRenderType::SDR) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2930 | return true; |
| 2931 | } |
| 2932 | // If the layer is not allowed to be dimmed, treat it as HDR. WindowManager may disable |
| 2933 | // dimming in order to keep animations invoking SDR screenshots of HDR layers seamless. |
| 2934 | // Treat such tagged layers as HDR so that DisplayManagerService does not try to change |
| 2935 | // the screen brightness |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2936 | if (!snapshot.dimmingEnabled) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2937 | return true; |
| 2938 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2939 | return false; |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2940 | } |
| 2941 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2942 | ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId, |
| 2943 | bool isPrimary) const { |
| 2944 | const auto id = PhysicalDisplayId::tryCast(displayId); |
| 2945 | if (!id) { |
| 2946 | return ui::ROTATION_0; |
| 2947 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2948 | if (!mIgnoreHwcPhysicalDisplayOrientation && |
Neha Jain | 7b31cca | 2023-01-09 23:10:42 +0000 | [diff] [blame] | 2949 | getHwComposer().getComposer()->isSupported( |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2950 | Hwc2::Composer::OptionalFeature::PhysicalDisplayOrientation)) { |
| 2951 | switch (getHwComposer().getPhysicalDisplayOrientation(*id)) { |
| 2952 | case Hwc2::AidlTransform::ROT_90: |
| 2953 | return ui::ROTATION_90; |
| 2954 | case Hwc2::AidlTransform::ROT_180: |
| 2955 | return ui::ROTATION_180; |
| 2956 | case Hwc2::AidlTransform::ROT_270: |
| 2957 | return ui::ROTATION_270; |
| 2958 | default: |
| 2959 | return ui::ROTATION_0; |
| 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | if (isPrimary) { |
| 2964 | using Values = SurfaceFlingerProperties::primary_display_orientation_values; |
| 2965 | switch (primary_display_orientation(Values::ORIENTATION_0)) { |
| 2966 | case Values::ORIENTATION_90: |
| 2967 | return ui::ROTATION_90; |
| 2968 | case Values::ORIENTATION_180: |
| 2969 | return ui::ROTATION_180; |
| 2970 | case Values::ORIENTATION_270: |
| 2971 | return ui::ROTATION_270; |
| 2972 | default: |
| 2973 | break; |
| 2974 | } |
| 2975 | } |
| 2976 | return ui::ROTATION_0; |
| 2977 | } |
| 2978 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2979 | void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId, |
| 2980 | const scheduler::FrameTargeters& frameTargeters, |
| 2981 | nsecs_t presentStartTime) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2982 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2983 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2984 | ui::PhysicalDisplayMap<PhysicalDisplayId, std::shared_ptr<FenceTime>> presentFences; |
| 2985 | ui::PhysicalDisplayMap<PhysicalDisplayId, const sp<Fence>> gpuCompositionDoneFences; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2986 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2987 | for (const auto& [id, targeter] : frameTargeters) { |
| 2988 | auto presentFence = getHwComposer().getPresentFence(id); |
| 2989 | |
| 2990 | if (id == pacesetterId) { |
| 2991 | mTransactionCallbackInvoker.addPresentFence(presentFence); |
| 2992 | } |
| 2993 | |
| 2994 | if (auto fenceTime = targeter->setPresentFence(std::move(presentFence)); |
| 2995 | fenceTime->isValid()) { |
| 2996 | presentFences.try_emplace(id, std::move(fenceTime)); |
| 2997 | } |
| 2998 | |
| 2999 | ftl::FakeGuard guard(mStateLock); |
| 3000 | if (const auto display = getCompositionDisplayLocked(id); |
| 3001 | display && display->getState().usesClientComposition) { |
| 3002 | gpuCompositionDoneFences |
| 3003 | .try_emplace(id, display->getRenderSurface()->getClientTargetAcquireFence()); |
| 3004 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3005 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3006 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3007 | const auto pacesetterDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(pacesetterId)); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3008 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3009 | std::shared_ptr<FenceTime> pacesetterPresentFenceTime = |
| 3010 | presentFences.get(pacesetterId) |
| 3011 | .transform([](const FenceTimePtr& ptr) { return ptr; }) |
| 3012 | .value_or(FenceTime::NO_FENCE); |
| 3013 | |
| 3014 | std::shared_ptr<FenceTime> pacesetterGpuCompositionDoneFenceTime = |
| 3015 | gpuCompositionDoneFences.get(pacesetterId) |
| 3016 | .transform([](sp<Fence> fence) { |
| 3017 | return std::make_shared<FenceTime>(std::move(fence)); |
| 3018 | }) |
| 3019 | .value_or(FenceTime::NO_FENCE); |
| 3020 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 3021 | const TimePoint presentTime = TimePoint::now(); |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 3022 | |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 3023 | // Set presentation information before calling Layer::releasePendingBuffer, such that jank |
| 3024 | // information from previous' frame classification is already available when sending jank info |
| 3025 | // to clients, so they get jank classification as early as possible. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3026 | mFrameTimeline->setSfPresent(presentTime.ns(), pacesetterPresentFenceTime, |
| 3027 | pacesetterGpuCompositionDoneFenceTime); |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 3028 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 3029 | // We use the CompositionEngine::getLastFrameRefreshTimestamp() which might |
| 3030 | // 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] | 3031 | // but that should be okay since CompositorTiming has snapping logic. |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 3032 | const TimePoint compositeTime = |
| 3033 | TimePoint::fromNs(mCompositionEngine->getLastFrameRefreshTimestamp()); |
| 3034 | const Duration presentLatency = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3035 | getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE) |
| 3036 | ? Duration::zero() |
| 3037 | : mPresentLatencyTracker.trackPendingFrame(compositeTime, pacesetterPresentFenceTime); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3038 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3039 | const auto schedule = mScheduler->getVsyncSchedule(); |
| 3040 | const TimePoint vsyncDeadline = schedule->vsyncDeadlineAfter(presentTime); |
| 3041 | const Period vsyncPeriod = schedule->period(); |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 3042 | const nsecs_t vsyncPhase = |
| 3043 | mScheduler->getVsyncConfiguration().getCurrentConfigs().late.sfOffset; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3044 | |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 3045 | const CompositorTiming compositorTiming(vsyncDeadline.ns(), vsyncPeriod.ns(), vsyncPhase, |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 3046 | presentLatency.ns()); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 3047 | |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 3048 | ui::DisplayMap<ui::LayerStack, const DisplayDevice*> layerStackToDisplay; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3049 | { |
| 3050 | if (!mLayersWithBuffersRemoved.empty() || mNumTrustedPresentationListeners > 0) { |
| 3051 | Mutex::Autolock lock(mStateLock); |
| 3052 | for (const auto& [token, display] : mDisplays) { |
| 3053 | layerStackToDisplay.emplace_or_replace(display->getLayerStack(), display.get()); |
| 3054 | } |
| 3055 | } |
| 3056 | } |
| 3057 | |
| 3058 | for (auto layer : mLayersWithBuffersRemoved) { |
Vishnu Nair | f10a87b | 2023-05-01 14:02:51 -0700 | [diff] [blame] | 3059 | std::vector<ui::LayerStack> previouslyPresentedLayerStacks = |
| 3060 | std::move(layer->mPreviouslyPresentedLayerStacks); |
| 3061 | layer->mPreviouslyPresentedLayerStacks.clear(); |
| 3062 | for (auto layerStack : previouslyPresentedLayerStacks) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3063 | auto optDisplay = layerStackToDisplay.get(layerStack); |
| 3064 | if (optDisplay && !optDisplay->get()->isVirtual()) { |
| 3065 | auto fence = getHwComposer().getPresentFence(optDisplay->get()->getPhysicalId()); |
| 3066 | layer->onLayerDisplayed(ftl::yield<FenceResult>(fence).share(), |
| 3067 | ui::INVALID_LAYER_STACK); |
| 3068 | } |
| 3069 | } |
| 3070 | layer->releasePendingBuffer(presentTime.ns()); |
| 3071 | } |
| 3072 | mLayersWithBuffersRemoved.clear(); |
| 3073 | |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 3074 | for (const auto& layer: mLayersWithQueuedFrames) { |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 3075 | layer->onCompositionPresented(pacesetterDisplay.get(), |
| 3076 | pacesetterGpuCompositionDoneFenceTime, |
| 3077 | pacesetterPresentFenceTime, compositorTiming); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3078 | layer->releasePendingBuffer(presentTime.ns()); |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 3079 | } |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 3080 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3081 | std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>> |
| 3082 | hdrInfoListeners; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3083 | bool haveNewListeners = false; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3084 | { |
| 3085 | Mutex::Autolock lock(mStateLock); |
| 3086 | if (mFpsReporter) { |
Andy Yu | aef688b | 2024-01-23 17:14:23 -0800 | [diff] [blame] | 3087 | mFpsReporter->dispatchLayerFps(mLayerHierarchyBuilder.getHierarchy()); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3088 | } |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 3089 | |
| 3090 | if (mTunnelModeEnabledReporter) { |
| 3091 | mTunnelModeEnabledReporter->updateTunnelModeStatus(); |
| 3092 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3093 | hdrInfoListeners.reserve(mHdrLayerInfoListeners.size()); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 3094 | for (const auto& [displayId, reporter] : mHdrLayerInfoListeners) { |
| 3095 | if (reporter && reporter->hasListeners()) { |
| 3096 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 3097 | hdrInfoListeners.emplace_back(display->getCompositionDisplay(), reporter); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3098 | } |
| 3099 | } |
| 3100 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3101 | haveNewListeners = mAddingHDRLayerInfoListener; // grab this with state lock |
| 3102 | mAddingHDRLayerInfoListener = false; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3103 | } |
| 3104 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3105 | if (haveNewListeners || mHdrLayerInfoChanged) { |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3106 | for (auto& [compositionDisplay, listener] : hdrInfoListeners) { |
| 3107 | HdrLayerInfoReporter::HdrLayerInfo info; |
| 3108 | int32_t maxArea = 0; |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 3109 | |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3110 | auto updateInfoFn = |
| 3111 | [&](const std::shared_ptr<compositionengine::Display>& compositionDisplay, |
| 3112 | const frontend::LayerSnapshot& snapshot, const sp<LayerFE>& layerFe) { |
| 3113 | if (snapshot.isVisible && |
| 3114 | compositionDisplay->includesLayer(snapshot.outputFilter)) { |
| 3115 | if (isHdrLayer(snapshot)) { |
| 3116 | const auto* outputLayer = |
| 3117 | compositionDisplay->getOutputLayerForLayer(layerFe); |
| 3118 | if (outputLayer) { |
| 3119 | const float desiredHdrSdrRatio = |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 3120 | snapshot.desiredHdrSdrRatio < 1.f |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3121 | ? std::numeric_limits<float>::infinity() |
| 3122 | : snapshot.desiredHdrSdrRatio; |
| 3123 | info.mergeDesiredRatio(desiredHdrSdrRatio); |
| 3124 | info.numberOfHdrLayers++; |
| 3125 | const auto displayFrame = outputLayer->getState().displayFrame; |
| 3126 | const int32_t area = |
| 3127 | displayFrame.width() * displayFrame.height(); |
| 3128 | if (area > maxArea) { |
| 3129 | maxArea = area; |
| 3130 | info.maxW = displayFrame.width(); |
| 3131 | info.maxH = displayFrame.height(); |
| 3132 | } |
| 3133 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3134 | } |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 3135 | } |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3136 | }; |
| 3137 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3138 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3139 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 3140 | [&, compositionDisplay = compositionDisplay]( |
| 3141 | std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 3142 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 3143 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 3144 | "Couldnt find layer object for %s", |
| 3145 | snapshot->getDebugString().c_str()); |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3146 | auto& legacyLayer = it->second; |
| 3147 | sp<LayerFE> layerFe = |
| 3148 | legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
| 3149 | |
| 3150 | updateInfoFn(compositionDisplay, *snapshot, layerFe); |
| 3151 | }); |
| 3152 | } else { |
| 3153 | mDrawingState.traverse([&, compositionDisplay = compositionDisplay](Layer* layer) { |
| 3154 | const auto layerFe = layer->getCompositionEngineLayerFE(); |
| 3155 | const frontend::LayerSnapshot& snapshot = *layer->getLayerSnapshot(); |
| 3156 | updateInfoFn(compositionDisplay, snapshot, layerFe); |
| 3157 | }); |
| 3158 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3159 | listener->dispatchHdrLayerInfo(info); |
| 3160 | } |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3161 | } |
| 3162 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3163 | mHdrLayerInfoChanged = false; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3164 | |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 3165 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 3166 | mTransactionCallbackInvoker.clearCompletedTransactions(); |
| 3167 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3168 | mTimeStats->incrementTotalFrames(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3169 | mTimeStats->setPresentFenceGlobal(pacesetterPresentFenceTime); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3170 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3171 | for (auto&& [id, presentFence] : presentFences) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3172 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3173 | const bool isInternalDisplay = |
| 3174 | mPhysicalDisplays.get(id).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 3175 | |
| 3176 | if (isInternalDisplay) { |
| 3177 | mScheduler->addPresentFence(id, std::move(presentFence)); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3178 | } |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3179 | } |
| 3180 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3181 | const bool hasPacesetterDisplay = |
| 3182 | pacesetterDisplay && getHwComposer().isConnected(pacesetterId); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3183 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3184 | if (!hasSyncFramework) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3185 | if (hasPacesetterDisplay && pacesetterDisplay->isPoweredOn()) { |
| 3186 | mScheduler->enableHardwareVsync(pacesetterId); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3187 | } |
| 3188 | } |
| 3189 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3190 | if (hasPacesetterDisplay && !pacesetterDisplay->isPoweredOn()) { |
Lars Svensson | d9e5469 | 2021-12-21 07:41:57 +0100 | [diff] [blame] | 3191 | getRenderEngine().cleanupPostRender(); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 3192 | return; |
| 3193 | } |
| 3194 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 3195 | // Cleanup any outstanding resources due to rendering a prior frame. |
| 3196 | getRenderEngine().cleanupPostRender(); |
| 3197 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3198 | if (mNumTrustedPresentationListeners > 0) { |
| 3199 | // 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] | 3200 | traverseLegacyLayers([&](Layer* layer) { |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3201 | if (!layer->hasTrustedPresentationListener()) { |
| 3202 | return; |
| 3203 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3204 | const frontend::LayerSnapshot* snapshot = mLayerLifecycleManagerEnabled |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3205 | ? mLayerSnapshotBuilder.getSnapshot(layer->sequence) |
| 3206 | : layer->getLayerSnapshot(); |
| 3207 | std::optional<const DisplayDevice*> displayOpt = std::nullopt; |
| 3208 | if (snapshot) { |
| 3209 | displayOpt = layerStackToDisplay.get(snapshot->outputFilter.layerStack); |
| 3210 | } |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 3211 | const DisplayDevice* display = displayOpt.value_or(nullptr); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3212 | layer->updateTrustedPresentationState(display, snapshot, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 3213 | nanoseconds_to_milliseconds(presentStartTime), |
| 3214 | false); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3215 | }); |
| 3216 | } |
| 3217 | |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3218 | // Even though ATRACE_INT64 already checks if tracing is enabled, it doesn't prevent the |
| 3219 | // side-effect of getTotalSize(), so we check that again here |
| 3220 | if (ATRACE_ENABLED()) { |
Marissa Wall | 22b2de1 | 2019-12-02 18:11:43 -0800 | [diff] [blame] | 3221 | // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3222 | ATRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize()); |
| 3223 | } |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3224 | |
| 3225 | logFrameStats(presentTime); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 3226 | } |
| 3227 | |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3228 | FloatRect SurfaceFlinger::getMaxDisplayBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3229 | const ui::Size maxSize = [this] { |
| 3230 | ftl::FakeGuard guard(mStateLock); |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3231 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3232 | // The LayerTraceGenerator tool runs without displays. |
| 3233 | if (mDisplays.empty()) return ui::Size{5000, 5000}; |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3234 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3235 | return std::accumulate(mDisplays.begin(), mDisplays.end(), ui::kEmptySize, |
| 3236 | [](ui::Size size, const auto& pair) -> ui::Size { |
| 3237 | const auto& display = pair.second; |
| 3238 | return {std::max(size.getWidth(), display->getWidth()), |
| 3239 | std::max(size.getHeight(), display->getHeight())}; |
| 3240 | }); |
| 3241 | }(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3242 | |
| 3243 | // Ignore display bounds for now since they will be computed later. Use a large Rect bound |
| 3244 | // to ensure it's bigger than an actual display will be. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3245 | const float xMax = maxSize.getWidth() * 10.f; |
| 3246 | const float yMax = maxSize.getHeight() * 10.f; |
| 3247 | |
| 3248 | return {-xMax, -yMax, xMax, yMax}; |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | void SurfaceFlinger::computeLayerBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3252 | const FloatRect maxBounds = getMaxDisplayBounds(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3253 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 3254 | layer->computeBounds(maxBounds, ui::Transform(), 0.f /* shadowRadius */); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3255 | } |
| 3256 | } |
| 3257 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3258 | void SurfaceFlinger::commitTransactions() { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 3259 | ATRACE_CALL(); |
| 3260 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3261 | // Keep a copy of the drawing state (that is going to be overwritten |
| 3262 | // by commitTransactionsLocked) outside of mStateLock so that the side |
| 3263 | // effects of the State assignment don't happen with mStateLock held, |
| 3264 | // which can cause deadlocks. |
Mathias Agopian | 7cc6df5 | 2013-06-05 14:30:54 -0700 | [diff] [blame] | 3265 | State drawingState(mDrawingState); |
| 3266 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3267 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 3268 | mDebugInTransaction = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3269 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3270 | // Here we're guaranteed that some transaction flags are set |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3271 | // so we can call commitTransactionsLocked unconditionally. |
| 3272 | // We clear the flags with mStateLock held to guarantee that |
| 3273 | // mCurrentState won't change until the transaction is committed. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3274 | mScheduler->modulateVsync({}, &VsyncModulator::onTransactionCommit); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3275 | commitTransactionsLocked(clearTransactionFlags(eTransactionMask)); |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 3276 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3277 | mDebugInTransaction = 0; |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 3278 | } |
| 3279 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3280 | std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes( |
| 3281 | PhysicalDisplayId displayId) const { |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3282 | std::vector<HWComposer::HWCDisplayMode> hwcModes; |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3283 | std::optional<hal::HWConfigId> activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3284 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3285 | const bool isExternalDisplay = FlagManager::getInstance().connected_display() && |
| 3286 | getHwComposer().getDisplayConnectionType(displayId) == |
| 3287 | ui::DisplayConnectionType::External; |
| 3288 | |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3289 | int attempt = 0; |
| 3290 | constexpr int kMaxAttempts = 3; |
| 3291 | do { |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 3292 | hwcModes = getHwComposer().getModes(displayId, |
| 3293 | scheduler::RefreshRateSelector::kMinSupportedFrameRate |
| 3294 | .getPeriodNsecs()); |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3295 | const auto activeModeHwcIdExp = getHwComposer().getActiveMode(displayId); |
| 3296 | activeModeHwcIdOpt = activeModeHwcIdExp.value_opt(); |
| 3297 | |
| 3298 | if (isExternalDisplay && |
| 3299 | activeModeHwcIdExp.has_error([](status_t error) { return error == NO_INIT; })) { |
| 3300 | constexpr nsecs_t k59HzVsyncPeriod = 16949153; |
| 3301 | constexpr nsecs_t k60HzVsyncPeriod = 16666667; |
| 3302 | |
| 3303 | // DM sets the initial mode for an external display to 1080p@60, but |
| 3304 | // this comes after SF creates its own state (including the |
| 3305 | // DisplayDevice). For now, pick the same mode in order to avoid |
| 3306 | // inconsistent state and unnecessary mode switching. |
| 3307 | // TODO (b/318534874): Let DM decide the initial mode. |
| 3308 | // |
| 3309 | // Try to find 1920x1080 @ 60 Hz |
| 3310 | if (const auto iter = std::find_if(hwcModes.begin(), hwcModes.end(), |
| 3311 | [](const auto& mode) { |
| 3312 | return mode.width == 1920 && |
| 3313 | mode.height == 1080 && |
| 3314 | mode.vsyncPeriod == k60HzVsyncPeriod; |
| 3315 | }); |
| 3316 | iter != hwcModes.end()) { |
| 3317 | activeModeHwcIdOpt = iter->hwcId; |
| 3318 | break; |
| 3319 | } |
| 3320 | |
| 3321 | // Try to find 1920x1080 @ 59-60 Hz |
| 3322 | if (const auto iter = std::find_if(hwcModes.begin(), hwcModes.end(), |
| 3323 | [](const auto& mode) { |
| 3324 | return mode.width == 1920 && |
| 3325 | mode.height == 1080 && |
| 3326 | mode.vsyncPeriod >= k60HzVsyncPeriod && |
| 3327 | mode.vsyncPeriod <= k59HzVsyncPeriod; |
| 3328 | }); |
| 3329 | iter != hwcModes.end()) { |
| 3330 | activeModeHwcIdOpt = iter->hwcId; |
| 3331 | break; |
| 3332 | } |
| 3333 | |
| 3334 | // The display does not support 1080p@60, and this is the last attempt to pick a display |
| 3335 | // mode. Prefer 60 Hz if available, with the closest resolution to 1080p. |
| 3336 | if (attempt + 1 == kMaxAttempts) { |
| 3337 | std::vector<HWComposer::HWCDisplayMode> hwcModeOpts; |
| 3338 | |
| 3339 | for (const auto& mode : hwcModes) { |
| 3340 | if (mode.width <= 1920 && mode.height <= 1080 && |
| 3341 | mode.vsyncPeriod >= k60HzVsyncPeriod && |
| 3342 | mode.vsyncPeriod <= k59HzVsyncPeriod) { |
| 3343 | hwcModeOpts.push_back(mode); |
| 3344 | } |
| 3345 | } |
| 3346 | |
| 3347 | if (const auto iter = std::max_element(hwcModeOpts.begin(), hwcModeOpts.end(), |
| 3348 | [](const auto& a, const auto& b) { |
| 3349 | const auto aSize = a.width * a.height; |
| 3350 | const auto bSize = b.width * b.height; |
| 3351 | if (aSize < bSize) |
| 3352 | return true; |
| 3353 | else if (aSize == bSize) |
| 3354 | return a.vsyncPeriod > b.vsyncPeriod; |
| 3355 | else |
| 3356 | return false; |
| 3357 | }); |
| 3358 | iter != hwcModeOpts.end()) { |
| 3359 | activeModeHwcIdOpt = iter->hwcId; |
| 3360 | break; |
| 3361 | } |
| 3362 | |
| 3363 | // hwcModeOpts was empty, use hwcModes[0] as the last resort |
| 3364 | activeModeHwcIdOpt = hwcModes[0].hwcId; |
| 3365 | } |
| 3366 | } |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3367 | |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3368 | const auto isActiveMode = [activeModeHwcIdOpt](const HWComposer::HWCDisplayMode& mode) { |
| 3369 | return mode.hwcId == activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3370 | }; |
| 3371 | |
| 3372 | if (std::any_of(hwcModes.begin(), hwcModes.end(), isActiveMode)) { |
| 3373 | break; |
| 3374 | } |
| 3375 | } while (++attempt < kMaxAttempts); |
| 3376 | |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3377 | if (attempt == kMaxAttempts) { |
| 3378 | const std::string activeMode = |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3379 | activeModeHwcIdOpt ? std::to_string(*activeModeHwcIdOpt) : "unknown"s; |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3380 | ALOGE("HWC failed to report an active mode that is supported: activeModeHwcId=%s, " |
| 3381 | "hwcModes={%s}", |
| 3382 | activeMode.c_str(), base::Join(hwcModes, ", ").c_str()); |
| 3383 | return {}; |
| 3384 | } |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3385 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3386 | const DisplayModes oldModes = mPhysicalDisplays.get(displayId) |
| 3387 | .transform([](const PhysicalDisplay& display) { |
| 3388 | return display.snapshot().displayModes(); |
| 3389 | }) |
| 3390 | .value_or(DisplayModes{}); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3391 | |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 3392 | DisplayModeId nextModeId = std::accumulate(oldModes.begin(), oldModes.end(), DisplayModeId(-1), |
| 3393 | [](DisplayModeId max, const auto& pair) { |
| 3394 | return std::max(max, pair.first); |
| 3395 | }); |
| 3396 | ++nextModeId; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3397 | |
| 3398 | DisplayModes newModes; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3399 | for (const auto& hwcMode : hwcModes) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 3400 | const auto id = nextModeId++; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3401 | newModes.try_emplace(id, |
| 3402 | DisplayMode::Builder(hwcMode.hwcId) |
| 3403 | .setId(id) |
| 3404 | .setPhysicalDisplayId(displayId) |
| 3405 | .setResolution({hwcMode.width, hwcMode.height}) |
| 3406 | .setVsyncPeriod(hwcMode.vsyncPeriod) |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 3407 | .setVrrConfig(hwcMode.vrrConfig) |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3408 | .setDpiX(hwcMode.dpiX) |
| 3409 | .setDpiY(hwcMode.dpiY) |
| 3410 | .setGroup(hwcMode.configGroup) |
| 3411 | .build()); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3412 | } |
| 3413 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3414 | const bool sameModes = |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3415 | std::equal(newModes.begin(), newModes.end(), oldModes.begin(), oldModes.end(), |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3416 | [](const auto& lhs, const auto& rhs) { |
| 3417 | return equalsExceptDisplayModeId(*lhs.second, *rhs.second); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3418 | }); |
| 3419 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3420 | // Keep IDs if modes have not changed. |
| 3421 | const auto& modes = sameModes ? oldModes : newModes; |
| 3422 | const DisplayModePtr activeMode = |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3423 | std::find_if(modes.begin(), modes.end(), [activeModeHwcIdOpt](const auto& pair) { |
| 3424 | return pair.second->getHwcId() == activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3425 | })->second; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3426 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3427 | if (isExternalDisplay) { |
| 3428 | ALOGI("External display %s initial mode: {%s}", to_string(displayId).c_str(), |
| 3429 | to_string(*activeMode).c_str()); |
| 3430 | } |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3431 | return {modes, activeMode}; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3432 | } |
| 3433 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3434 | bool SurfaceFlinger::configureLocked() { |
| 3435 | std::vector<HotplugEvent> events; |
| 3436 | { |
| 3437 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 3438 | events = std::move(mPendingHotplugEvents); |
| 3439 | } |
| 3440 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3441 | for (const auto [hwcDisplayId, connection] : events) { |
| 3442 | if (auto info = getHwComposer().onHotplug(hwcDisplayId, connection)) { |
| 3443 | const auto displayId = info->id; |
| 3444 | const bool connected = connection == hal::Connection::CONNECTED; |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3445 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3446 | if (const char* const log = |
| 3447 | processHotplug(displayId, hwcDisplayId, connected, std::move(*info))) { |
| 3448 | ALOGI("%s display %s (HAL ID %" PRIu64 ")", log, to_string(displayId).c_str(), |
| 3449 | hwcDisplayId); |
| 3450 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3451 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3452 | } |
| 3453 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3454 | return !events.empty(); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3455 | } |
| 3456 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3457 | const char* SurfaceFlinger::processHotplug(PhysicalDisplayId displayId, |
| 3458 | hal::HWDisplayId hwcDisplayId, bool connected, |
| 3459 | DisplayIdentificationInfo&& info) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3460 | const auto displayOpt = mPhysicalDisplays.get(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3461 | if (!connected) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3462 | LOG_ALWAYS_FATAL_IF(!displayOpt); |
| 3463 | const auto& display = displayOpt->get(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3464 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3465 | if (const ssize_t index = mCurrentState.displays.indexOfKey(display.token()); index >= 0) { |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3466 | mCurrentState.displays.removeItemsAt(index); |
| 3467 | } |
| 3468 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3469 | mPhysicalDisplays.erase(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3470 | return "Disconnecting"; |
| 3471 | } |
| 3472 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3473 | auto [displayModes, activeMode] = loadDisplayModes(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3474 | if (!activeMode) { |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3475 | ALOGE("Failed to hotplug display %s", to_string(displayId).c_str()); |
Huihong Luo | 9f0fc59 | 2024-01-17 12:29:26 -0800 | [diff] [blame] | 3476 | if (FlagManager::getInstance().hotplug2()) { |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3477 | mScheduler->dispatchHotplugError( |
| 3478 | static_cast<int32_t>(DisplayHotplugEvent::ERROR_UNKNOWN)); |
Huihong Luo | 9f0fc59 | 2024-01-17 12:29:26 -0800 | [diff] [blame] | 3479 | } |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3480 | getHwComposer().disconnectDisplay(displayId); |
| 3481 | return nullptr; |
| 3482 | } |
| 3483 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3484 | ui::ColorModes colorModes = getHwComposer().getColorModes(displayId); |
| 3485 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3486 | if (displayOpt) { |
| 3487 | const auto& display = displayOpt->get(); |
| 3488 | const auto& snapshot = display.snapshot(); |
| 3489 | |
| 3490 | std::optional<DeviceProductInfo> deviceProductInfo; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3491 | if (getHwComposer().updatesDeviceProductInfoOnHotplugReconnect()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3492 | deviceProductInfo = std::move(info.deviceProductInfo); |
| 3493 | } else { |
| 3494 | deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3495 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3496 | |
| 3497 | const auto it = |
| 3498 | mPhysicalDisplays.try_replace(displayId, display.token(), displayId, |
| 3499 | snapshot.connectionType(), std::move(displayModes), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3500 | std::move(colorModes), std::move(deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3501 | |
| 3502 | auto& state = mCurrentState.displays.editValueFor(it->second.token()); |
| 3503 | state.sequenceId = DisplayDeviceState{}.sequenceId; // Generate new sequenceId. |
| 3504 | state.physical->activeMode = std::move(activeMode); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3505 | return "Reconnecting"; |
| 3506 | } |
| 3507 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3508 | const sp<IBinder> token = sp<BBinder>::make(); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3509 | const ui::DisplayConnectionType connectionType = |
| 3510 | getHwComposer().getDisplayConnectionType(displayId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3511 | |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3512 | mPhysicalDisplays.try_emplace(displayId, token, displayId, connectionType, |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3513 | std::move(displayModes), std::move(colorModes), |
| 3514 | std::move(info.deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3515 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3516 | DisplayDeviceState state; |
| 3517 | state.physical = {.id = displayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3518 | .hwcDisplayId = hwcDisplayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3519 | .activeMode = std::move(activeMode)}; |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3520 | state.isSecure = connectionType == ui::DisplayConnectionType::Internal; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3521 | state.isProtected = true; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3522 | state.displayName = std::move(info.name); |
| 3523 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3524 | mCurrentState.displays.add(token, state); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3525 | return "Connecting"; |
| 3526 | } |
| 3527 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3528 | void SurfaceFlinger::dispatchDisplayModeChangeEvent(PhysicalDisplayId displayId, |
| 3529 | const scheduler::FrameRateMode& mode) { |
| 3530 | // TODO(b/255635821): Merge code paths and move to Scheduler. |
| 3531 | const auto onDisplayModeChanged = displayId == mActiveDisplayId |
| 3532 | ? &scheduler::Scheduler::onPrimaryDisplayModeChanged |
| 3533 | : &scheduler::Scheduler::onNonPrimaryDisplayModeChanged; |
| 3534 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 3535 | ((*mScheduler).*onDisplayModeChanged)(scheduler::Cycle::Render, mode); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3536 | } |
| 3537 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3538 | sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3539 | const wp<IBinder>& displayToken, |
| 3540 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3541 | const DisplayDeviceState& state, |
| 3542 | const sp<compositionengine::DisplaySurface>& displaySurface, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3543 | const sp<IGraphicBufferProducer>& producer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3544 | DisplayDeviceCreationArgs creationArgs(sp<SurfaceFlinger>::fromExisting(this), getHwComposer(), |
| 3545 | displayToken, compositionDisplay); |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 3546 | creationArgs.sequenceId = state.sequenceId; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3547 | creationArgs.isSecure = state.isSecure; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3548 | creationArgs.isProtected = state.isProtected; |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3549 | creationArgs.displaySurface = displaySurface; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3550 | creationArgs.hasWideColorGamut = false; |
| 3551 | creationArgs.supportedPerFrameMetadata = 0; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 3552 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3553 | if (const auto& physical = state.physical) { |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3554 | creationArgs.activeModeId = physical->activeMode->getId(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3555 | const auto [kernelIdleTimerController, idleTimerTimeoutMs] = |
| 3556 | getKernelIdleTimerProperties(compositionDisplay->getId()); |
| 3557 | |
Ady Abraham | 0c8b723 | 2023-01-27 21:12:16 -0800 | [diff] [blame] | 3558 | using Config = scheduler::RefreshRateSelector::Config; |
| 3559 | const auto enableFrameRateOverride = sysprop::enable_frame_rate_override(true) |
| 3560 | ? Config::FrameRateOverride::Enabled |
| 3561 | : Config::FrameRateOverride::Disabled; |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 3562 | const Config config = |
Ady Abraham | 8ca643a | 2022-10-18 18:26:47 -0700 | [diff] [blame] | 3563 | {.enableFrameRateOverride = enableFrameRateOverride, |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3564 | .frameRateMultipleThreshold = |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 3565 | base::GetIntProperty("debug.sf.frame_rate_multiple_threshold"s, 0), |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3566 | .idleTimerTimeout = idleTimerTimeoutMs, |
| 3567 | .kernelIdleTimerController = kernelIdleTimerController}; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3568 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3569 | creationArgs.refreshRateSelector = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3570 | mPhysicalDisplays.get(physical->id) |
| 3571 | .transform(&PhysicalDisplay::snapshotRef) |
| 3572 | .transform([&](const display::DisplaySnapshot& snapshot) { |
| 3573 | return std::make_shared< |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3574 | scheduler::RefreshRateSelector>(snapshot.displayModes(), |
| 3575 | creationArgs.activeModeId, |
| 3576 | config); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3577 | }) |
| 3578 | .value_or(nullptr); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3579 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3580 | creationArgs.isPrimary = physical->id == getPrimaryDisplayIdLocked(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3581 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 3582 | mPhysicalDisplays.get(physical->id) |
| 3583 | .transform(&PhysicalDisplay::snapshotRef) |
| 3584 | .transform(ftl::unit_fn([&](const display::DisplaySnapshot& snapshot) { |
| 3585 | for (const auto mode : snapshot.colorModes()) { |
| 3586 | creationArgs.hasWideColorGamut |= ui::isWideColorMode(mode); |
| 3587 | creationArgs.hwcColorModes |
| 3588 | .emplace(mode, |
| 3589 | getHwComposer().getRenderIntents(physical->id, mode)); |
| 3590 | } |
| 3591 | })); |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 3592 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3593 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3594 | if (const auto id = HalDisplayId::tryCast(compositionDisplay->getId())) { |
| 3595 | getHwComposer().getHdrCapabilities(*id, &creationArgs.hdrCapabilities); |
| 3596 | creationArgs.supportedPerFrameMetadata = getHwComposer().getSupportedPerFrameMetadata(*id); |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 3597 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3598 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 3599 | auto nativeWindowSurface = getFactory().createNativeWindowSurface(producer); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3600 | auto nativeWindow = nativeWindowSurface->getNativeWindow(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3601 | creationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3602 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3603 | // Make sure that composition can never be stalled by a virtual display |
| 3604 | // 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] | 3605 | // here, in case the display is composed entirely by HWC. |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 3606 | if (state.isVirtual()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3607 | nativeWindow->setSwapInterval(nativeWindow.get(), 0); |
| 3608 | } |
| 3609 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 3610 | creationArgs.physicalOrientation = |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3611 | getPhysicalDisplayOrientation(compositionDisplay->getId(), creationArgs.isPrimary); |
| 3612 | ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 3613 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 3614 | creationArgs.initialPowerMode = state.isVirtual() ? hal::PowerMode::ON : hal::PowerMode::OFF; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3615 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3616 | creationArgs.requestedRefreshRate = state.requestedRefreshRate; |
| 3617 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3618 | sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3619 | |
Ady Abraham | 8565ad2 | 2021-06-22 17:45:44 -0700 | [diff] [blame] | 3620 | nativeWindowSurface->preallocateBuffers(); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3621 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3622 | ui::ColorMode defaultColorMode = ui::ColorMode::NATIVE; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 3623 | Dataspace defaultDataSpace = Dataspace::UNKNOWN; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3624 | if (display->hasWideColorGamut()) { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3625 | defaultColorMode = ui::ColorMode::SRGB; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 3626 | defaultDataSpace = Dataspace::V0_SRGB; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3627 | } |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 3628 | display->getCompositionDisplay()->setColorProfile( |
| 3629 | compositionengine::Output::ColorProfile{defaultColorMode, defaultDataSpace, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 3630 | RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3631 | |
| 3632 | if (const auto& physical = state.physical) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3633 | const auto& mode = *physical->activeMode; |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 3634 | display->setActiveMode(mode.getId(), mode.getVsyncRate(), mode.getVsyncRate()); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 3635 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3636 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3637 | display->setLayerFilter(makeLayerFilterForDisplay(display->getId(), state.layerStack)); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3638 | display->setProjection(state.orientation, state.layerStackSpaceRect, |
| 3639 | state.orientedDisplaySpaceRect); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3640 | display->setDisplayName(state.displayName); |
Vishnu Nair | a119aaa | 2021-09-24 07:19:35 -0700 | [diff] [blame] | 3641 | display->setFlags(state.flags); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3642 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3643 | return display; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3644 | } |
| 3645 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3646 | void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, |
| 3647 | const DisplayDeviceState& state) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3648 | ui::Size resolution(0, 0); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3649 | ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN); |
| 3650 | if (state.physical) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3651 | resolution = state.physical->activeMode->getResolution(); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3652 | pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888); |
| 3653 | } else if (state.surface != nullptr) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3654 | int status = state.surface->query(NATIVE_WINDOW_WIDTH, &resolution.width); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3655 | ALOGE_IF(status != NO_ERROR, "Unable to query width (%d)", status); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3656 | status = state.surface->query(NATIVE_WINDOW_HEIGHT, &resolution.height); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3657 | ALOGE_IF(status != NO_ERROR, "Unable to query height (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3658 | int format; |
| 3659 | status = state.surface->query(NATIVE_WINDOW_FORMAT, &format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3660 | ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3661 | pixelFormat = static_cast<ui::PixelFormat>(format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3662 | } else { |
| 3663 | // Virtual displays without a surface are dormant: |
| 3664 | // they have external state (layer stack, projection, |
| 3665 | // etc.) but no internal state (i.e. a DisplayDevice). |
| 3666 | return; |
| 3667 | } |
| 3668 | |
| 3669 | compositionengine::DisplayCreationArgsBuilder builder; |
| 3670 | if (const auto& physical = state.physical) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3671 | builder.setId(physical->id); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3672 | } else { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 3673 | builder.setId(acquireVirtualDisplay(resolution, pixelFormat)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3674 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3675 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3676 | builder.setPixels(resolution); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3677 | builder.setIsSecure(state.isSecure); |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3678 | builder.setIsProtected(state.isProtected); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 3679 | builder.setPowerAdvisor(mPowerAdvisor.get()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3680 | builder.setName(state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3681 | auto compositionDisplay = getCompositionEngine().createDisplay(builder.build()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3682 | compositionDisplay->setLayerCachingEnabled(mLayerCachingEnabled); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3683 | |
| 3684 | sp<compositionengine::DisplaySurface> displaySurface; |
| 3685 | sp<IGraphicBufferProducer> producer; |
| 3686 | sp<IGraphicBufferProducer> bqProducer; |
| 3687 | sp<IGraphicBufferConsumer> bqConsumer; |
| 3688 | getFactory().createBufferQueue(&bqProducer, &bqConsumer, /*consumerIsSurfaceFlinger =*/false); |
| 3689 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3690 | if (state.isVirtual()) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3691 | const auto displayId = VirtualDisplayId::tryCast(compositionDisplay->getId()); |
| 3692 | LOG_FATAL_IF(!displayId); |
| 3693 | auto surface = sp<VirtualDisplaySurface>::make(getHwComposer(), *displayId, state.surface, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3694 | bqProducer, bqConsumer, state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3695 | displaySurface = surface; |
| 3696 | producer = std::move(surface); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3697 | } else { |
| 3698 | ALOGE_IF(state.surface != nullptr, |
| 3699 | "adding a supported display, but rendering " |
| 3700 | "surface is provided (%p), ignoring it", |
| 3701 | state.surface.get()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3702 | const auto displayId = PhysicalDisplayId::tryCast(compositionDisplay->getId()); |
| 3703 | LOG_FATAL_IF(!displayId); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3704 | displaySurface = |
| 3705 | sp<FramebufferSurface>::make(getHwComposer(), *displayId, bqConsumer, |
| 3706 | state.physical->activeMode->getResolution(), |
| 3707 | ui::Size(maxGraphicsWidth, maxGraphicsHeight)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3708 | producer = bqProducer; |
| 3709 | } |
| 3710 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3711 | LOG_FATAL_IF(!displaySurface); |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3712 | auto display = setupNewDisplayDeviceInternal(displayToken, std::move(compositionDisplay), state, |
| 3713 | displaySurface, producer); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3714 | |
| 3715 | if (mScheduler && !display->isVirtual()) { |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3716 | // TODO(b/241285876): Annotate `processDisplayAdded` instead. |
| 3717 | ftl::FakeGuard guard(kMainThreadContext); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3718 | |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3719 | // For hotplug reconnect, renew the registration since display modes have been reloaded. |
| 3720 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector()); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3721 | } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3722 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3723 | if (display->isVirtual()) { |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 3724 | display->adjustRefreshRate(mScheduler->getPacesetterRefreshRate()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3725 | } |
| 3726 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3727 | mDisplays.try_emplace(displayToken, std::move(display)); |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3728 | |
| 3729 | // For an external display, loadDisplayModes already attempted to select the same mode |
| 3730 | // as DM, but SF still needs to be updated to match. |
| 3731 | // TODO (b/318534874): Let DM decide the initial mode. |
| 3732 | if (const auto& physical = state.physical; |
| 3733 | mScheduler && physical && FlagManager::getInstance().connected_display()) { |
| 3734 | const bool isInternalDisplay = mPhysicalDisplays.get(physical->id) |
| 3735 | .transform(&PhysicalDisplay::isInternal) |
| 3736 | .value_or(false); |
| 3737 | |
| 3738 | if (!isInternalDisplay) { |
| 3739 | auto activeModePtr = physical->activeMode; |
| 3740 | const auto fps = activeModePtr->getPeakFps(); |
| 3741 | |
| 3742 | setDesiredMode( |
| 3743 | {.mode = scheduler::FrameRateMode{fps, |
| 3744 | ftl::as_non_null(std::move(activeModePtr))}, |
| 3745 | .emitEvent = false, |
| 3746 | .force = true}); |
| 3747 | } |
| 3748 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3752 | auto display = getDisplayDeviceLocked(displayToken); |
| 3753 | if (display) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3754 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3755 | |
| 3756 | if (display->isVirtual()) { |
| 3757 | releaseVirtualDisplay(display->getVirtualId()); |
| 3758 | } else { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 3759 | mScheduler->unregisterDisplay(display->getPhysicalId()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3760 | } |
| 3761 | } |
| 3762 | |
| 3763 | mDisplays.erase(displayToken); |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3764 | |
| 3765 | if (display && display->isVirtual()) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 3766 | static_cast<void>(mScheduler->schedule([display = std::move(display)] { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3767 | // Destroy the display without holding the mStateLock. |
| 3768 | // This is a temporary solution until we can manage transaction queues without |
| 3769 | // holding the mStateLock. |
| 3770 | // With blast, the IGBP that is passed to the VirtualDisplaySurface is owned by the |
| 3771 | // client. When the IGBP is disconnected, its buffer cache in SF will be cleared |
| 3772 | // via SurfaceComposerClient::doUncacheBufferTransaction. This call from the client |
| 3773 | // ends up running on the main thread causing a deadlock since setTransactionstate |
| 3774 | // will try to acquire the mStateLock. Instead we extend the lifetime of |
| 3775 | // DisplayDevice and destroy it in the main thread without holding the mStateLock. |
| 3776 | // The display will be disconnected and removed from the mDisplays list so it will |
| 3777 | // not be accessible. |
| 3778 | })); |
| 3779 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3780 | } |
| 3781 | |
| 3782 | void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, |
| 3783 | const DisplayDeviceState& currentState, |
| 3784 | const DisplayDeviceState& drawingState) { |
| 3785 | const sp<IBinder> currentBinder = IInterface::asBinder(currentState.surface); |
| 3786 | const sp<IBinder> drawingBinder = IInterface::asBinder(drawingState.surface); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3787 | |
| 3788 | // Recreate the DisplayDevice if the surface or sequence ID changed. |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3789 | if (currentBinder != drawingBinder || currentState.sequenceId != drawingState.sequenceId) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3790 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3791 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3792 | if (display->isVirtual()) { |
| 3793 | releaseVirtualDisplay(display->getVirtualId()); |
| 3794 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3795 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3796 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3797 | mDisplays.erase(displayToken); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3798 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3799 | if (const auto& physical = currentState.physical) { |
| 3800 | getHwComposer().allocatePhysicalDisplay(physical->hwcDisplayId, physical->id); |
| 3801 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3802 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3803 | processDisplayAdded(displayToken, currentState); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3804 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3805 | if (currentState.physical) { |
Marin Shalamanov | 4c5e301 | 2020-06-04 21:41:42 +0200 | [diff] [blame] | 3806 | const auto display = getDisplayDeviceLocked(displayToken); |
| 3807 | setPowerModeInternal(display, hal::PowerMode::ON); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3808 | |
| 3809 | // TODO(b/175678251) Call a listener instead. |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 3810 | if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 3811 | mScheduler->resetPhaseConfiguration(display->getActiveMode().fps); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3812 | } |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3813 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3814 | return; |
| 3815 | } |
| 3816 | |
| 3817 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3818 | if (currentState.layerStack != drawingState.layerStack) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3819 | display->setLayerFilter( |
| 3820 | makeLayerFilterForDisplay(display->getId(), currentState.layerStack)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3821 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 3822 | if (currentState.flags != drawingState.flags) { |
| 3823 | display->setFlags(currentState.flags); |
| 3824 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3825 | if ((currentState.orientation != drawingState.orientation) || |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3826 | (currentState.layerStackSpaceRect != drawingState.layerStackSpaceRect) || |
| 3827 | (currentState.orientedDisplaySpaceRect != drawingState.orientedDisplaySpaceRect)) { |
| 3828 | display->setProjection(currentState.orientation, currentState.layerStackSpaceRect, |
| 3829 | currentState.orientedDisplaySpaceRect); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3830 | if (display->getId() == mActiveDisplayId) { |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 3831 | mActiveDisplayTransformHint = display->getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 3832 | sActiveDisplayRotationFlags = |
| 3833 | ui::Transform::toRotationFlags(display->getOrientation()); |
Arthur Hung | b6aa9a0 | 2021-06-09 14:23:01 +0800 | [diff] [blame] | 3834 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3835 | } |
| 3836 | if (currentState.width != drawingState.width || |
| 3837 | currentState.height != drawingState.height) { |
| 3838 | display->setDisplaySize(currentState.width, currentState.height); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 3839 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3840 | if (display->getId() == mActiveDisplayId) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 3841 | onActiveDisplaySizeChanged(*display); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3842 | } |
| 3843 | } |
| 3844 | } |
| 3845 | } |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 3846 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3847 | void SurfaceFlinger::processDisplayChangesLocked() { |
| 3848 | // here we take advantage of Vector's copy-on-write semantics to |
| 3849 | // improve performance by skipping the transaction entirely when |
| 3850 | // know that the lists are identical |
| 3851 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays); |
| 3852 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays); |
| 3853 | if (!curr.isIdenticalTo(draw)) { |
| 3854 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3855 | mUpdateInputInfo = true; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3856 | |
Dominik Laskowski | 01f191c | 2024-01-29 11:51:23 -0500 | [diff] [blame] | 3857 | // Apply the current color matrix to any added or changed display. |
| 3858 | mCurrentState.colorMatrixChanged = true; |
| 3859 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3860 | // find the displays that were removed |
| 3861 | // (ie: in drawing state but not in current state) |
| 3862 | // also handle displays that changed |
| 3863 | // (ie: displays that are in both lists) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3864 | for (size_t i = 0; i < draw.size(); i++) { |
| 3865 | const wp<IBinder>& displayToken = draw.keyAt(i); |
| 3866 | const ssize_t j = curr.indexOfKey(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3867 | if (j < 0) { |
| 3868 | // in drawing state but not in current state |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3869 | processDisplayRemoved(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3870 | } else { |
| 3871 | // this display is in both lists. see if something changed. |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3872 | const DisplayDeviceState& currentState = curr[j]; |
| 3873 | const DisplayDeviceState& drawingState = draw[i]; |
| 3874 | processDisplayChanged(displayToken, currentState, drawingState); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3875 | } |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3876 | } |
| 3877 | |
| 3878 | // find displays that were added |
| 3879 | // (ie: in current state but not in drawing state) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3880 | for (size_t i = 0; i < curr.size(); i++) { |
| 3881 | const wp<IBinder>& displayToken = curr.keyAt(i); |
| 3882 | if (draw.indexOfKey(displayToken) < 0) { |
| 3883 | processDisplayAdded(displayToken, curr[i]); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3884 | } |
| 3885 | } |
| 3886 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3887 | |
| 3888 | mDrawingState.displays = mCurrentState.displays; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3889 | } |
| 3890 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3891 | void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { |
| 3892 | // Commit display transactions. |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3893 | const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3894 | mFrontEndDisplayInfosChanged = displayTransactionNeeded; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3895 | if (displayTransactionNeeded && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3896 | processDisplayChangesLocked(); |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 3897 | mFrontEndDisplayInfos.clear(); |
| 3898 | for (const auto& [_, display] : mDisplays) { |
| 3899 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 3900 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3901 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 3902 | mForceTransactionDisplayChange = displayTransactionNeeded; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3903 | |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3904 | if (mSomeChildrenChanged) { |
| 3905 | mVisibleRegionsDirty = true; |
| 3906 | mSomeChildrenChanged = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3907 | mUpdateInputInfo = true; |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3910 | // Update transform hint. |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 3911 | if (transactionFlags & (eTransformHintUpdateNeeded | eDisplayTransactionNeeded)) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3912 | // 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] | 3913 | // |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 3914 | // 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] | 3915 | // the hint is set before we acquire a buffer from the surface texture. |
| 3916 | // |
| 3917 | // NOTE: layer transactions have taken place already, so we use their |
| 3918 | // drawing state. However, SurfaceFlinger's own transaction has not |
| 3919 | // happened yet, so we must use the current state layer list |
| 3920 | // (soon to become the drawing state list). |
| 3921 | // |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3922 | sp<const DisplayDevice> hintDisplay; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3923 | ui::LayerStack layerStack; |
| 3924 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3925 | mCurrentState.traverse([&](Layer* layer) REQUIRES(mStateLock) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3926 | // NOTE: we rely on the fact that layers are sorted by |
| 3927 | // layerStack first (so we don't have to traverse the list |
| 3928 | // of displays for every layer). |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3929 | if (const auto filter = layer->getOutputFilter(); layerStack != filter.layerStack) { |
| 3930 | layerStack = filter.layerStack; |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3931 | hintDisplay = nullptr; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3932 | |
| 3933 | // Find the display that includes the layer. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3934 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3935 | if (!display->getCompositionDisplay()->includesLayer(filter)) { |
| 3936 | continue; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3937 | } |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3938 | |
| 3939 | // Pick the primary display if another display mirrors the layer. |
| 3940 | if (hintDisplay) { |
| 3941 | hintDisplay = nullptr; |
| 3942 | break; |
| 3943 | } |
| 3944 | |
| 3945 | hintDisplay = display; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3946 | } |
| 3947 | } |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 3948 | |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3949 | if (!hintDisplay) { |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3950 | // NOTE: TEMPORARY FIX ONLY. Real fix should cause layers to |
| 3951 | // redraw after transform hint changes. See bug 8508397. |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3952 | // could be null when this layer is using a layerStack |
| 3953 | // that is not visible on any display. Also can occur at |
| 3954 | // screen off/on times. |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3955 | // U Update: Don't provide stale hints to the clients. For |
| 3956 | // special cases where we want the app to draw its |
| 3957 | // first frame before the display is available, we rely |
| 3958 | // on WMS and DMS to provide the right information |
| 3959 | // so the client can calculate the hint. |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3960 | layer->skipReportingTransformHint(); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3961 | } else { |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3962 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3963 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3964 | }); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3965 | } |
| 3966 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3967 | if (mLayersAdded) { |
| 3968 | mLayersAdded = false; |
| 3969 | // Layers have been added. |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3970 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3971 | mUpdateInputInfo = true; |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3972 | } |
| 3973 | |
| 3974 | // some layers might have been removed, so |
| 3975 | // we need to update the regions they're exposing. |
| 3976 | if (mLayersRemoved) { |
| 3977 | mLayersRemoved = false; |
| 3978 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3979 | mUpdateInputInfo = true; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3980 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3981 | if (mLayersPendingRemoval.indexOf(sp<Layer>::fromExisting(layer)) >= 0) { |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3982 | // this layer is not visible anymore |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3983 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3984 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3985 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 3986 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3987 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3988 | } |
| 3989 | |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 3990 | if (transactionFlags & eInputInfoUpdateNeeded) { |
| 3991 | mUpdateInputInfo = true; |
| 3992 | } |
| 3993 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3994 | doCommitTransactions(); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 3995 | } |
| 3996 | |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3997 | void SurfaceFlinger::updateInputFlinger(VsyncId vsyncId, TimePoint frameTime) { |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3998 | if (!mInputFlinger || (!mUpdateInputInfo && mInputWindowCommands.empty())) { |
Vishnu Nair | 42a27b5 | 2021-11-18 15:35:22 -0800 | [diff] [blame] | 3999 | return; |
| 4000 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4001 | ATRACE_CALL(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4002 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4003 | std::vector<WindowInfo> windowInfos; |
| 4004 | std::vector<DisplayInfo> displayInfos; |
| 4005 | bool updateWindowInfo = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4006 | if (mUpdateInputInfo) { |
| 4007 | mUpdateInputInfo = false; |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4008 | updateWindowInfo = true; |
| 4009 | buildWindowInfos(windowInfos, displayInfos); |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4010 | } |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4011 | |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4012 | std::unordered_set<int32_t> visibleWindowIds; |
| 4013 | for (WindowInfo& windowInfo : windowInfos) { |
| 4014 | if (!windowInfo.inputConfig.test(WindowInfo::InputConfig::NOT_VISIBLE)) { |
| 4015 | visibleWindowIds.insert(windowInfo.id); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4016 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4017 | } |
| 4018 | bool visibleWindowsChanged = false; |
| 4019 | if (visibleWindowIds != mVisibleWindowIds) { |
| 4020 | visibleWindowsChanged = true; |
| 4021 | mVisibleWindowIds = std::move(visibleWindowIds); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4022 | } |
| 4023 | |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 4024 | BackgroundExecutor::getInstance().sendCallbacks({[updateWindowInfo, |
| 4025 | windowInfos = std::move(windowInfos), |
| 4026 | displayInfos = std::move(displayInfos), |
| 4027 | inputWindowCommands = |
| 4028 | std::move(mInputWindowCommands), |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4029 | inputFlinger = mInputFlinger, this, |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4030 | visibleWindowsChanged, vsyncId, frameTime]() { |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4031 | ATRACE_NAME("BackgroundExecutor::updateInputFlinger"); |
| 4032 | if (updateWindowInfo) { |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 4033 | mWindowInfosListenerInvoker |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4034 | ->windowInfosChanged(gui::WindowInfosUpdate{std::move(windowInfos), |
| 4035 | std::move(displayInfos), |
| 4036 | ftl::to_underlying(vsyncId), |
| 4037 | frameTime.ns()}, |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4038 | std::move( |
| 4039 | inputWindowCommands.windowInfosReportedListeners), |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4040 | /* forceImmediateCall= */ visibleWindowsChanged || |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4041 | !inputWindowCommands.focusRequests.empty()); |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 4042 | } else { |
| 4043 | // If there are listeners but no changes to input windows, call the listeners |
| 4044 | // immediately. |
| 4045 | for (const auto& listener : inputWindowCommands.windowInfosReportedListeners) { |
| 4046 | if (IInterface::asBinder(listener)->isBinderAlive()) { |
| 4047 | listener->onWindowInfosReported(); |
| 4048 | } |
| 4049 | } |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4050 | } |
| 4051 | for (const auto& focusRequest : inputWindowCommands.focusRequests) { |
| 4052 | inputFlinger->setFocusedWindow(focusRequest); |
| 4053 | } |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 4054 | }}); |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 4055 | |
Arthur Hung | 6cbb975 | 2019-09-05 16:38:18 +0800 | [diff] [blame] | 4056 | mInputWindowCommands.clear(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4057 | } |
| 4058 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4059 | void SurfaceFlinger::persistDisplayBrightness(bool needsComposite) { |
| 4060 | const bool supportsDisplayBrightnessCommand = getHwComposer().getComposer()->isSupported( |
| 4061 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 4062 | if (!supportsDisplayBrightnessCommand) { |
| 4063 | return; |
| 4064 | } |
| 4065 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4066 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4067 | if (const auto brightness = display->getStagedBrightness(); brightness) { |
| 4068 | if (!needsComposite) { |
| 4069 | const status_t error = |
| 4070 | getHwComposer() |
| 4071 | .setDisplayBrightness(display->getPhysicalId(), *brightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 4072 | display->getCompositionDisplay() |
| 4073 | ->getState() |
| 4074 | .displayBrightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4075 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 4076 | .applyImmediately = true}) |
| 4077 | .get(); |
| 4078 | |
| 4079 | ALOGE_IF(error != NO_ERROR, |
| 4080 | "Error setting display brightness for display %s: %d (%s)", |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 4081 | to_string(display->getId()).c_str(), error, strerror(error)); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4082 | } |
| 4083 | display->persistBrightness(needsComposite); |
| 4084 | } |
| 4085 | } |
| 4086 | } |
| 4087 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4088 | void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, |
| 4089 | std::vector<DisplayInfo>& outDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4090 | static size_t sNumWindowInfos = 0; |
| 4091 | outWindowInfos.reserve(sNumWindowInfos); |
| 4092 | sNumWindowInfos = 0; |
| 4093 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4094 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4095 | mLayerSnapshotBuilder.forEachInputSnapshot( |
| 4096 | [&outWindowInfos](const frontend::LayerSnapshot& snapshot) { |
| 4097 | outWindowInfos.push_back(snapshot.inputInfo); |
| 4098 | }); |
| 4099 | } else { |
| 4100 | mDrawingState.traverseInReverseZOrder([&](Layer* layer) { |
| 4101 | if (!layer->needsInputInfo()) return; |
| 4102 | const auto opt = |
| 4103 | mFrontEndDisplayInfos.get(layer->getLayerStack()) |
| 4104 | .transform([](const frontend::DisplayInfo& info) { |
| 4105 | return Layer::InputDisplayArgs{&info.transform, info.isSecure}; |
| 4106 | }); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4107 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4108 | outWindowInfos.push_back(layer->fillInputInfo(opt.value_or(Layer::InputDisplayArgs{}))); |
| 4109 | }); |
| 4110 | } |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 4111 | |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4112 | sNumWindowInfos = outWindowInfos.size(); |
| 4113 | |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 4114 | outDisplayInfos.reserve(mFrontEndDisplayInfos.size()); |
| 4115 | for (const auto& [_, info] : mFrontEndDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4116 | outDisplayInfos.push_back(info.info); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 4117 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 4118 | } |
| 4119 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 4120 | void SurfaceFlinger::updateCursorAsync() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4121 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4122 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 4123 | if (HalDisplayId::tryCast(display->getId())) { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4124 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 4125 | } |
| 4126 | } |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 4127 | |
| 4128 | constexpr bool kCursorOnly = true; |
| 4129 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4130 | mCompositionEngine->updateCursorAsync(refreshArgs); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4131 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4132 | } |
| 4133 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 4134 | void SurfaceFlinger::requestHardwareVsync(PhysicalDisplayId displayId, bool enable) { |
| 4135 | getHwComposer().setVsyncEnabled(displayId, enable ? hal::Vsync::ENABLE : hal::Vsync::DISABLE); |
| 4136 | } |
| 4137 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4138 | void SurfaceFlinger::requestDisplayModes(std::vector<display::DisplayModeRequest> modeRequests) { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 4139 | if (mBootStage != BootStage::FINISHED) { |
| 4140 | ALOGV("Currently in the boot stage, skipping display mode changes"); |
| 4141 | return; |
| 4142 | } |
| 4143 | |
| 4144 | ATRACE_CALL(); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4145 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 4146 | // If this is called from the main thread mStateLock must be locked before |
| 4147 | // 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] | 4148 | // Scheduler::chooseRefreshRateForContent |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 4149 | |
| 4150 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
Marin Shalamanov | a63f9ae | 2021-11-03 15:05:16 +0100 | [diff] [blame] | 4151 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4152 | for (auto& request : modeRequests) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4153 | const auto& modePtr = request.mode.modePtr; |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 4154 | |
| 4155 | const auto displayId = modePtr->getPhysicalDisplayId(); |
| 4156 | const auto display = getDisplayDeviceLocked(displayId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4157 | |
| 4158 | if (!display) continue; |
| 4159 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 4160 | if (ftl::FakeGuard guard(kMainThreadContext); |
| 4161 | !shouldApplyRefreshRateSelectorPolicy(*display)) { |
| 4162 | ALOGV("%s(%s): Skipped applying policy", __func__, to_string(displayId).c_str()); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 4163 | continue; |
| 4164 | } |
| 4165 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4166 | if (display->refreshRateSelector().isModeAllowed(request.mode)) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 4167 | setDesiredMode(std::move(request)); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4168 | } else { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 4169 | ALOGV("%s: Mode %d is disallowed for display %s", __func__, |
| 4170 | ftl::to_underlying(modePtr->getId()), to_string(displayId).c_str()); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4171 | } |
| 4172 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 4173 | } |
| 4174 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 4175 | void SurfaceFlinger::triggerOnFrameRateOverridesChanged() { |
| 4176 | PhysicalDisplayId displayId = [&]() { |
| 4177 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 4178 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 4179 | }(); |
| 4180 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4181 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 4182 | } |
| 4183 | |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 4184 | void SurfaceFlinger::notifyCpuLoadUp() { |
| 4185 | mPowerAdvisor->notifyCpuLoadUp(); |
| 4186 | } |
| 4187 | |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 4188 | void SurfaceFlinger::onChoreographerAttached() { |
| 4189 | ATRACE_CALL(); |
| 4190 | if (mLayerLifecycleManagerEnabled) { |
| 4191 | mUpdateAttachedChoreographer = true; |
| 4192 | scheduleCommit(FrameHint::kNone); |
| 4193 | } |
| 4194 | } |
| 4195 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4196 | void SurfaceFlinger::onExpectedPresentTimePosted(TimePoint expectedPresentTime, |
| 4197 | ftl::NonNull<DisplayModePtr> modePtr, |
| 4198 | Fps renderRate) { |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4199 | const auto vsyncPeriod = modePtr->getVsyncRate().getPeriod(); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4200 | const auto timeoutOpt = [&]() -> std::optional<Period> { |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4201 | const auto vrrConfig = modePtr->getVrrConfig(); |
| 4202 | if (!vrrConfig) return std::nullopt; |
| 4203 | |
| 4204 | const auto notifyExpectedPresentConfig = |
| 4205 | modePtr->getVrrConfig()->notifyExpectedPresentConfig; |
| 4206 | if (!notifyExpectedPresentConfig) return std::nullopt; |
ramindani | cbd7a6d | 2023-12-19 16:00:30 -0800 | [diff] [blame] | 4207 | return Period::fromNs(notifyExpectedPresentConfig->timeoutNs); |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4208 | }(); |
| 4209 | |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4210 | notifyExpectedPresentIfRequired(modePtr->getPhysicalDisplayId(), vsyncPeriod, |
| 4211 | expectedPresentTime, renderRate, timeoutOpt); |
| 4212 | } |
| 4213 | |
| 4214 | void SurfaceFlinger::notifyExpectedPresentIfRequired(PhysicalDisplayId displayId, |
| 4215 | Period vsyncPeriod, |
| 4216 | TimePoint expectedPresentTime, |
| 4217 | Fps frameInterval, |
| 4218 | std::optional<Period> timeoutOpt) { |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4219 | auto& data = mNotifyExpectedPresentMap[displayId]; |
| 4220 | const auto lastExpectedPresentTimestamp = data.lastExpectedPresentTimestamp; |
| 4221 | const auto lastFrameInterval = data.lastFrameInterval; |
| 4222 | data.lastFrameInterval = frameInterval; |
| 4223 | data.lastExpectedPresentTimestamp = expectedPresentTime; |
| 4224 | const auto threshold = Duration::fromNs(vsyncPeriod.ns() / 2); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4225 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4226 | const constexpr nsecs_t kOneSecondNs = |
| 4227 | std::chrono::duration_cast<std::chrono::nanoseconds>(1s).count(); |
| 4228 | const auto timeout = |
| 4229 | Period::fromNs(timeoutOpt && timeoutOpt->ns() > 0 ? timeoutOpt->ns() : kOneSecondNs); |
| 4230 | const bool frameIntervalIsOnCadence = |
| 4231 | isFrameIntervalOnCadence(expectedPresentTime, lastExpectedPresentTimestamp, |
| 4232 | lastFrameInterval, timeout, threshold); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4233 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4234 | const bool expectedPresentWithinTimeout = |
| 4235 | isExpectedPresentWithinTimeout(expectedPresentTime, lastExpectedPresentTimestamp, |
| 4236 | timeoutOpt, threshold); |
| 4237 | if (expectedPresentWithinTimeout && frameIntervalIsOnCadence) { |
| 4238 | return; |
| 4239 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4240 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4241 | auto hintStatus = data.hintStatus.load(); |
| 4242 | if (!expectedPresentWithinTimeout) { |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4243 | if ((hintStatus != NotifyExpectedPresentHintStatus::Sent && |
| 4244 | hintStatus != NotifyExpectedPresentHintStatus::ScheduleOnTx) || |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4245 | (timeoutOpt && timeoutOpt->ns() == 0)) { |
| 4246 | // Send the hint immediately if timeout, as the hint gets |
| 4247 | // delayed otherwise, as the frame is scheduled close |
| 4248 | // to the actual present. |
| 4249 | if (data.hintStatus |
| 4250 | .compare_exchange_strong(hintStatus, |
| 4251 | NotifyExpectedPresentHintStatus::ScheduleOnTx)) { |
| 4252 | scheduleNotifyExpectedPresentHint(displayId); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4253 | return; |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4254 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4255 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4256 | } |
| 4257 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4258 | if (hintStatus == NotifyExpectedPresentHintStatus::Sent && |
| 4259 | data.hintStatus.compare_exchange_strong(hintStatus, |
| 4260 | NotifyExpectedPresentHintStatus::ScheduleOnTx)) { |
| 4261 | return; |
| 4262 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4263 | if (hintStatus != NotifyExpectedPresentHintStatus::Start) { |
| 4264 | return; |
| 4265 | } |
| 4266 | data.hintStatus.store(NotifyExpectedPresentHintStatus::ScheduleOnPresent); |
| 4267 | mScheduler->scheduleFrame(); |
| 4268 | } |
| 4269 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4270 | void SurfaceFlinger::scheduleNotifyExpectedPresentHint(PhysicalDisplayId displayId, |
| 4271 | VsyncId vsyncId) { |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4272 | auto itr = mNotifyExpectedPresentMap.find(displayId); |
| 4273 | if (itr == mNotifyExpectedPresentMap.end()) { |
| 4274 | return; |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4275 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4276 | |
| 4277 | const char* const whence = __func__; |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4278 | const auto sendHint = [=, this]() { |
| 4279 | auto& data = mNotifyExpectedPresentMap.at(displayId); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4280 | TimePoint expectedPresentTime = data.lastExpectedPresentTimestamp; |
| 4281 | if (ftl::to_underlying(vsyncId) != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 4282 | const auto predictionOpt = mFrameTimeline->getTokenManager()->getPredictionsForToken( |
| 4283 | ftl::to_underlying(vsyncId)); |
| 4284 | const auto expectedPresentTimeOnPredictor = TimePoint::fromNs( |
| 4285 | predictionOpt ? predictionOpt->presentTime : expectedPresentTime.ns()); |
| 4286 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 4287 | const auto expectedPresentTimeOnScheduler = scheduledFrameResultOpt.has_value() |
| 4288 | ? scheduledFrameResultOpt->vsyncTime |
| 4289 | : TimePoint::fromNs(0); |
| 4290 | expectedPresentTime = |
| 4291 | std::max(expectedPresentTimeOnPredictor, expectedPresentTimeOnScheduler); |
| 4292 | } |
| 4293 | |
| 4294 | if (expectedPresentTime < TimePoint::now()) { |
| 4295 | expectedPresentTime = |
| 4296 | mScheduler->getVsyncSchedule()->vsyncDeadlineAfter(TimePoint::now()); |
| 4297 | if (mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration > |
| 4298 | mScheduler->getVsyncSchedule(displayId)->period()) { |
| 4299 | expectedPresentTime += mScheduler->getVsyncSchedule(displayId)->period(); |
| 4300 | } |
| 4301 | } |
| 4302 | const auto status = getHwComposer().notifyExpectedPresent(displayId, expectedPresentTime, |
| 4303 | data.lastFrameInterval); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4304 | if (status != NO_ERROR) { |
| 4305 | ALOGE("%s failed to notifyExpectedPresentHint for display %" PRId64, whence, |
| 4306 | displayId.value); |
| 4307 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4308 | }; |
| 4309 | |
| 4310 | if (itr->second.hintStatus == NotifyExpectedPresentHintStatus::ScheduleOnTx) { |
| 4311 | return static_cast<void>(mScheduler->schedule([=, |
| 4312 | this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 4313 | auto& data = mNotifyExpectedPresentMap.at(displayId); |
| 4314 | auto scheduleHintOnTx = NotifyExpectedPresentHintStatus::ScheduleOnTx; |
| 4315 | if (data.hintStatus.compare_exchange_strong(scheduleHintOnTx, |
| 4316 | NotifyExpectedPresentHintStatus::Sent)) { |
| 4317 | sendHint(); |
| 4318 | } |
| 4319 | })); |
| 4320 | } |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4321 | auto scheduleHintOnPresent = NotifyExpectedPresentHintStatus::ScheduleOnPresent; |
| 4322 | if (itr->second.hintStatus.compare_exchange_strong(scheduleHintOnPresent, |
| 4323 | NotifyExpectedPresentHintStatus::Sent)) { |
| 4324 | sendHint(); |
| 4325 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | void SurfaceFlinger::sendNotifyExpectedPresentHint(PhysicalDisplayId displayId) { |
| 4329 | if (auto itr = mNotifyExpectedPresentMap.find(displayId); |
| 4330 | itr == mNotifyExpectedPresentMap.end() || |
| 4331 | itr->second.hintStatus != NotifyExpectedPresentHintStatus::ScheduleOnPresent) { |
| 4332 | return; |
| 4333 | } |
| 4334 | scheduleNotifyExpectedPresentHint(displayId); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4335 | } |
| 4336 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 4337 | void SurfaceFlinger::initScheduler(const sp<const DisplayDevice>& display) { |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4338 | using namespace scheduler; |
| 4339 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 4340 | LOG_ALWAYS_FATAL_IF(mScheduler); |
| 4341 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4342 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 4343 | const Fps activeRefreshRate = activeMode.fps; |
Ady Abraham | 9e16a48 | 2019-12-03 17:19:41 -0800 | [diff] [blame] | 4344 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4345 | FeatureFlags features; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4346 | |
Ady Abraham | 3f84c50 | 2023-11-30 18:18:06 -0800 | [diff] [blame] | 4347 | const auto defaultContentDetectionValue = |
| 4348 | FlagManager::getInstance().enable_fro_dependent_features() && |
| 4349 | sysprop::enable_frame_rate_override(true); |
| 4350 | if (sysprop::use_content_detection_for_refresh_rate(defaultContentDetectionValue)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4351 | features |= Feature::kContentDetection; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 4352 | if (FlagManager::getInstance().enable_small_area_detection()) { |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 4353 | features |= Feature::kSmallDirtyContentDetection; |
| 4354 | } |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4355 | } |
| 4356 | if (base::GetBoolProperty("debug.sf.show_predicted_vsync"s, false)) { |
| 4357 | features |= Feature::kTracePredictedVsync; |
| 4358 | } |
| 4359 | if (!base::GetBoolProperty("debug.sf.vsync_reactor_ignore_present_fences"s, false) && |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 4360 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4361 | features |= Feature::kPresentFences; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4362 | } |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4363 | if (display->refreshRateSelector().kernelIdleTimerController()) { |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4364 | features |= Feature::kKernelIdleTimer; |
| 4365 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4366 | if (mBackpressureGpuComposition) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4367 | features |= Feature::kBackpressureGpuComposition; |
| 4368 | } |
Leon Scroggins III | 0bd0d4c | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 4369 | if (getHwComposer().getComposer()->isSupported( |
| 4370 | Hwc2::Composer::OptionalFeature::ExpectedPresentTime)) { |
| 4371 | features |= Feature::kExpectedPresentTime; |
| 4372 | } |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4373 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4374 | mScheduler = std::make_unique<Scheduler>(static_cast<ICompositor&>(*this), |
| 4375 | static_cast<ISchedulerCallback&>(*this), features, |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4376 | getFactory(), activeRefreshRate, *mTimeStats); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4377 | |
| 4378 | // The pacesetter must be registered before EventThread creation below. |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4379 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector()); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4380 | if (FlagManager::getInstance().vrr_config()) { |
| 4381 | mScheduler->setRenderRate(display->getPhysicalId(), activeMode.fps); |
| 4382 | } |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4383 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 4384 | const auto configs = mScheduler->getVsyncConfiguration().getCurrentConfigs(); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4385 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4386 | mScheduler->createEventThread(scheduler::Cycle::Render, mFrameTimeline->getTokenManager(), |
| 4387 | /* workDuration */ configs.late.appWorkDuration, |
| 4388 | /* readyDuration */ configs.late.sfWorkDuration); |
| 4389 | mScheduler->createEventThread(scheduler::Cycle::LastComposite, |
| 4390 | mFrameTimeline->getTokenManager(), |
| 4391 | /* workDuration */ activeRefreshRate.getPeriod(), |
| 4392 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4393 | |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 4394 | // Dispatch after EventThread creation, since registerDisplay above skipped dispatch. |
| 4395 | mScheduler->dispatchHotplug(display->getPhysicalId(), scheduler::Scheduler::Hotplug::Connected); |
| 4396 | |
Leon Scroggins III | a7be94e | 2024-01-23 12:24:30 -0500 | [diff] [blame] | 4397 | mScheduler->initVsync(*mFrameTimeline->getTokenManager(), configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4398 | |
| 4399 | mRegionSamplingThread = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4400 | sp<RegionSamplingThread>::make(*this, |
| 4401 | RegionSamplingThread::EnvironmentTimingTunables()); |
Andy Yu | aef688b | 2024-01-23 17:14:23 -0800 | [diff] [blame] | 4402 | mFpsReporter = sp<FpsReporter>::make(*mFrameTimeline); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4403 | |
| 4404 | // Timer callbacks may fire, so do this last. |
| 4405 | mScheduler->startTimers(); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4406 | } |
| 4407 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4408 | void SurfaceFlinger::doCommitTransactions() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 4409 | ATRACE_CALL(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4410 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4411 | if (!mLayersPendingRemoval.isEmpty()) { |
| 4412 | // Notify removed layers now that they can't be drawn from |
| 4413 | for (const auto& l : mLayersPendingRemoval) { |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4414 | // Ensure any buffers set to display on any children are released. |
| 4415 | if (l->isRemovedFromCurrentState()) { |
| 4416 | l->latchAndReleaseBuffer(); |
| 4417 | } |
| 4418 | |
chaviw | 6852bff | 2022-04-19 17:35:11 -0500 | [diff] [blame] | 4419 | // If a layer has a parent, we allow it to out-live it's handle |
| 4420 | // with the idea that the parent holds a reference and will eventually |
| 4421 | // be cleaned up. However no one cleans up the top-level so we do so |
| 4422 | // here. |
| 4423 | if (l->isAtRoot()) { |
| 4424 | l->setIsAtRoot(false); |
| 4425 | mCurrentState.layersSortedByZ.remove(l); |
| 4426 | } |
| 4427 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4428 | // If the layer has been removed and has no parent, then it will not be reachable |
| 4429 | // when traversing layers on screen. Add the layer to the offscreenLayers set to |
| 4430 | // ensure we can copy its current to drawing state. |
| 4431 | if (!l->getParent()) { |
| 4432 | mOffscreenLayers.emplace(l.get()); |
| 4433 | } |
| 4434 | } |
| 4435 | mLayersPendingRemoval.clear(); |
| 4436 | } |
| 4437 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4438 | mDrawingState = mCurrentState; |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4439 | mCurrentState.colorMatrixChanged = false; |
| 4440 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4441 | if (mVisibleRegionsDirty) { |
| 4442 | for (const auto& rootLayer : mDrawingState.layersSortedByZ) { |
| 4443 | rootLayer->commitChildList(); |
| 4444 | } |
Andrei Stanciu | dadac5a | 2020-08-05 17:02:34 +0300 | [diff] [blame] | 4445 | } |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4446 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4447 | commitOffscreenLayers(); |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4448 | if (mLayerMirrorRoots.size() > 0) { |
| 4449 | std::deque<Layer*> pendingUpdates; |
| 4450 | pendingUpdates.insert(pendingUpdates.end(), mLayerMirrorRoots.begin(), |
| 4451 | mLayerMirrorRoots.end()); |
| 4452 | std::vector<Layer*> needsUpdating; |
| 4453 | for (Layer* cloneRoot : mLayerMirrorRoots) { |
| 4454 | pendingUpdates.pop_front(); |
| 4455 | if (cloneRoot->isRemovedFromCurrentState()) { |
| 4456 | continue; |
| 4457 | } |
| 4458 | if (cloneRoot->updateMirrorInfo(pendingUpdates)) { |
| 4459 | } else { |
| 4460 | needsUpdating.push_back(cloneRoot); |
| 4461 | } |
| 4462 | } |
| 4463 | for (Layer* cloneRoot : needsUpdating) { |
| 4464 | cloneRoot->updateMirrorInfo({}); |
| 4465 | } |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4466 | } |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4467 | } |
| 4468 | |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4469 | void SurfaceFlinger::commitOffscreenLayers() { |
| 4470 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4471 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, [](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4472 | if (layer->clearTransactionFlags(eTransactionNeeded)) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4473 | layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4474 | layer->commitChildList(); |
| 4475 | } |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4476 | }); |
| 4477 | } |
| 4478 | } |
| 4479 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4480 | void SurfaceFlinger::invalidateLayerStack(const ui::LayerFilter& layerFilter, const Region& dirty) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4481 | for (const auto& [token, displayDevice] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4482 | auto display = displayDevice->getCompositionDisplay(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4483 | if (display->includesLayer(layerFilter)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4484 | display->editState().dirtyRegion.orSelf(dirty); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 4485 | } |
| 4486 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 4487 | } |
| 4488 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4489 | bool SurfaceFlinger::latchBuffers() { |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 4490 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 4491 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4492 | const nsecs_t latchTime = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4493 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4494 | bool visibleRegions = false; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4495 | bool frameQueued = false; |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4496 | bool newDataLatched = false; |
Eric Penner | 51c59cd | 2014-07-28 19:51:58 -0700 | [diff] [blame] | 4497 | |
| 4498 | // Store the set of layers that need updates. This set must not change as |
| 4499 | // buffers are being latched, as this could result in a deadlock. |
| 4500 | // Example: Two producers share the same command stream and: |
| 4501 | // 1.) Layer 0 is latched |
| 4502 | // 2.) Layer 0 gets a new frame |
| 4503 | // 2.) Layer 1 gets a new frame |
| 4504 | // 3.) Layer 1 is latched. |
| 4505 | // Display is now waiting on Layer 1's frame, which is behind layer 0's |
| 4506 | // 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] | 4507 | mDrawingState.traverse([&](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4508 | if (layer->clearTransactionFlags(eTransactionNeeded) || mForceTransactionDisplayChange) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4509 | const uint32_t flags = layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4510 | if (flags & Layer::eVisibleRegion) { |
| 4511 | mVisibleRegionsDirty = true; |
| 4512 | } |
| 4513 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4514 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4515 | if (layer->hasReadyFrame() || layer->willReleaseBufferOnLatch()) { |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4516 | frameQueued = true; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4517 | mLayersWithQueuedFrames.emplace(sp<Layer>::fromExisting(layer)); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4518 | } else { |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 4519 | layer->useEmptyDamage(); |
Vishnu Nair | c09c023 | 2023-03-02 03:22:35 +0000 | [diff] [blame] | 4520 | if (!layer->hasBuffer()) { |
| 4521 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 4522 | // instead of a missed frame. This is used to identify scenarios where we |
| 4523 | // could not latch a buffer or apply a transaction due to backpressure. |
| 4524 | // We only update the latch time for buffer less layers here, the latch time |
| 4525 | // is updated for buffer layers when the buffer is latched. |
| 4526 | layer->updateLastLatchTime(latchTime); |
| 4527 | } |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4528 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4529 | }); |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4530 | mForceTransactionDisplayChange = false; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4531 | |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4532 | // The client can continue submitting buffers for offscreen layers, but they will not |
| 4533 | // be shown on screen. Therefore, we need to latch and release buffers of offscreen |
| 4534 | // layers to ensure dequeueBuffer doesn't block indefinitely. |
| 4535 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4536 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4537 | [&](Layer* l) { l->latchAndReleaseBuffer(); }); |
| 4538 | } |
| 4539 | |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4540 | if (!mLayersWithQueuedFrames.empty()) { |
| 4541 | // mStateLock is needed for latchBuffer as LayerRejecter::reject() |
| 4542 | // writes to Layer current state. See also b/119481871 |
| 4543 | Mutex::Autolock lock(mStateLock); |
| 4544 | |
Alec Mouri | 2f7d9ae | 2020-11-30 19:32:33 -0800 | [diff] [blame] | 4545 | for (const auto& layer : mLayersWithQueuedFrames) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4546 | if (layer->willReleaseBufferOnLatch()) { |
| 4547 | mLayersWithBuffersRemoved.emplace(layer); |
| 4548 | } |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 4549 | if (layer->latchBuffer(visibleRegions, latchTime)) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4550 | mLayersPendingRefresh.push_back(layer); |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4551 | newDataLatched = true; |
| 4552 | } |
Vishnu Nair | 1b70019 | 2022-02-04 10:09:47 -0800 | [diff] [blame] | 4553 | layer->useSurfaceDamage(); |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4554 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4555 | } |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 4556 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 4557 | mVisibleRegionsDirty |= visibleRegions; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4558 | |
| 4559 | // If we will need to wake up at some time in the future to deal with a |
| 4560 | // queued frame that shouldn't be displayed during this vsync period, wake |
| 4561 | // up during the next vsync period to check again. |
Chia-I Wu | a36bf92 | 2017-06-30 12:51:05 -0700 | [diff] [blame] | 4562 | if (frameQueued && (mLayersWithQueuedFrames.empty() || !newDataLatched)) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4563 | scheduleCommit(FrameHint::kNone); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4564 | } |
| 4565 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 4566 | // enter boot animation on first buffer latch |
| 4567 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 4568 | ALOGI("Enter boot animation"); |
| 4569 | mBootStage = BootStage::BOOTANIMATION; |
| 4570 | } |
| 4571 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4572 | if (mLayerMirrorRoots.size() > 0) { |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4573 | mDrawingState.traverse([&](Layer* layer) { layer->updateCloneBufferInfo(); }); |
| 4574 | } |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 4575 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4576 | // 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] | 4577 | return !mLayersWithQueuedFrames.empty() && newDataLatched; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4578 | } |
| 4579 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4580 | status_t SurfaceFlinger::addClientLayer(LayerCreationArgs& args, const sp<IBinder>& handle, |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4581 | const sp<Layer>& layer, const wp<Layer>& parent, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4582 | uint32_t* outTransformHint) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4583 | if (mNumLayers >= MAX_LAYERS) { |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4584 | ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(), |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4585 | MAX_LAYERS); |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 4586 | static_cast<void>(mScheduler->schedule([=, this] { |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4587 | ALOGE("Dumping layer keeping > 20 children alive:"); |
| 4588 | bool leakingParentLayerFound = false; |
| 4589 | mDrawingState.traverse([&](Layer* layer) { |
| 4590 | if (leakingParentLayerFound) { |
| 4591 | return; |
| 4592 | } |
| 4593 | if (layer->getChildrenCount() > 20) { |
| 4594 | leakingParentLayerFound = true; |
| 4595 | sp<Layer> parent = sp<Layer>::fromExisting(layer); |
| 4596 | while (parent) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4597 | ALOGE("Parent Layer: %s%s", parent->getName().c_str(), |
| 4598 | (parent->isHandleAlive() ? "handleAlive" : "")); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4599 | parent = parent->getParent(); |
| 4600 | } |
| 4601 | // Sample up to 100 layers |
| 4602 | ALOGE("Dumping random sampling of child layers total(%zu): ", |
| 4603 | layer->getChildrenCount()); |
| 4604 | int sampleSize = (layer->getChildrenCount() / 100) + 1; |
| 4605 | layer->traverseChildren([&](Layer* layer) { |
| 4606 | if (rand() % sampleSize == 0) { |
jiayongqiang | c476a34 | 2023-12-06 17:04:54 +0800 | [diff] [blame] | 4607 | ALOGE("Child Layer: %s%s", layer->getName().c_str(), |
| 4608 | (layer->isHandleAlive() ? "handleAlive" : "")); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4609 | } |
| 4610 | }); |
| 4611 | } |
| 4612 | }); |
| 4613 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4614 | int numLayers = 0; |
| 4615 | mDrawingState.traverse([&](Layer* layer) { numLayers++; }); |
| 4616 | |
| 4617 | ALOGE("Dumping random sampling of on-screen layers total(%u):", numLayers); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4618 | mDrawingState.traverse([&](Layer* layer) { |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4619 | // Aim to dump about 200 layers to avoid totally trashing |
| 4620 | // logcat. On the other hand, if there really are 4096 layers |
| 4621 | // something has gone totally wrong its probably the most |
| 4622 | // useful information in logcat. |
| 4623 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4624 | ALOGE("Layer: %s%s", layer->getName().c_str(), |
| 4625 | (layer->isHandleAlive() ? "handleAlive" : "")); |
| 4626 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4627 | } |
| 4628 | }); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4629 | ALOGE("Dumping random sampling of off-screen layers total(%zu): ", |
| 4630 | mOffscreenLayers.size()); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4631 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 4632 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4633 | ALOGE("Offscreen-layer: %s%s", offscreenLayer->getName().c_str(), |
| 4634 | (offscreenLayer->isHandleAlive() ? "handleAlive" : "")); |
| 4635 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4636 | } |
| 4637 | } |
| 4638 | })); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4639 | return NO_MEMORY; |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4640 | } |
| 4641 | |
Vishnu Nair | 86e1190 | 2022-09-06 16:03:27 +0000 | [diff] [blame] | 4642 | layer->updateTransformHint(mActiveDisplayTransformHint); |
| 4643 | if (outTransformHint) { |
| 4644 | *outTransformHint = mActiveDisplayTransformHint; |
| 4645 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4646 | args.parentId = LayerHandle::getLayerId(args.parentHandle.promote()); |
| 4647 | args.layerIdToMirror = LayerHandle::getLayerId(args.mirrorLayerHandle.promote()); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4648 | { |
| 4649 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4650 | mCreatedLayers.emplace_back(layer, parent, args.addToRoot); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4651 | mNewLayers.emplace_back(std::make_unique<frontend::RequestedLayerState>(args)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 4652 | args.mirrorLayerHandle.clear(); |
| 4653 | args.parentHandle.clear(); |
| 4654 | mNewLayerArgs.emplace_back(std::move(args)); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4655 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4656 | |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4657 | setTransactionFlags(eTransactionNeeded); |
| 4658 | return NO_ERROR; |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 4659 | } |
| 4660 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4661 | uint32_t SurfaceFlinger::getTransactionFlags() const { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 4662 | return mTransactionFlags; |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 4663 | } |
| 4664 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4665 | uint32_t SurfaceFlinger::clearTransactionFlags(uint32_t mask) { |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4666 | uint32_t transactionFlags = mTransactionFlags.fetch_and(~mask); |
| 4667 | ATRACE_INT("mTransactionFlags", transactionFlags); |
| 4668 | return transactionFlags & mask; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4669 | } |
| 4670 | |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4671 | void SurfaceFlinger::setTransactionFlags(uint32_t mask, TransactionSchedule schedule, |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4672 | const sp<IBinder>& applyToken, FrameHint frameHint) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4673 | mScheduler->modulateVsync({}, &VsyncModulator::setTransactionSchedule, schedule, applyToken); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4674 | uint32_t transactionFlags = mTransactionFlags.fetch_or(mask); |
| 4675 | ATRACE_INT("mTransactionFlags", transactionFlags); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4676 | |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4677 | if (const bool scheduled = transactionFlags & mask; !scheduled) { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4678 | scheduleCommit(frameHint); |
Ady Abraham | 27bcb55 | 2023-01-21 04:34:22 +0000 | [diff] [blame] | 4679 | } else if (frameHint == FrameHint::kActive) { |
| 4680 | // Even if the next frame is already scheduled, we should reset the idle timer |
| 4681 | // as a new activity just happened. |
| 4682 | mScheduler->resetIdleTimer(); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4683 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4684 | } |
| 4685 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4686 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyTimelineCheck( |
| 4687 | const TransactionHandler::TransactionFlushState& flushState) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 4688 | const auto& transaction = *flushState.transaction; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4689 | |
| 4690 | const TimePoint desiredPresentTime = TimePoint::fromNs(transaction.desiredPresentTime); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 4691 | const TimePoint expectedPresentTime = mScheduler->expectedPresentTimeForPacesetter(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4692 | |
| 4693 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4694 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4695 | // Do not present if the desiredPresentTime has not passed unless it is more than |
| 4696 | // one second in the future. We ignore timestamps more than 1 second in the future |
| 4697 | // for stability reasons. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4698 | if (!transaction.isAutoTimestamp && desiredPresentTime >= expectedPresentTime && |
| 4699 | desiredPresentTime < expectedPresentTime + 1s) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4700 | ATRACE_FORMAT("not current desiredPresentTime: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4701 | desiredPresentTime, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4702 | return TransactionReadiness::NotReady; |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4703 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4704 | |
Ady Abraham | 9633f8e | 2024-03-04 19:38:12 +0000 | [diff] [blame] | 4705 | if (!mScheduler->isVsyncValid(expectedPresentTime, transaction.originUid)) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4706 | ATRACE_FORMAT("!isVsyncValid expectedPresentTime: %" PRId64 " uid: %d", expectedPresentTime, |
| 4707 | transaction.originUid); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4708 | return TransactionReadiness::NotReady; |
| 4709 | } |
| 4710 | |
| 4711 | // If the client didn't specify desiredPresentTime, use the vsyncId to determine the |
| 4712 | // expected present time of this transaction. |
Ady Abraham | 9633f8e | 2024-03-04 19:38:12 +0000 | [diff] [blame] | 4713 | if (transaction.isAutoTimestamp && |
| 4714 | frameIsEarly(expectedPresentTime, VsyncId{transaction.frameTimelineInfo.vsyncId})) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4715 | ATRACE_FORMAT("frameIsEarly vsyncId: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4716 | transaction.frameTimelineInfo.vsyncId, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4717 | return TransactionReadiness::NotReady; |
| 4718 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4719 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4720 | return TransactionReadiness::Ready; |
| 4721 | } |
| 4722 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4723 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheckLegacy( |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4724 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4725 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4726 | auto ready = TransactionReadiness::Ready; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4727 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const ResolvedComposerState& |
| 4728 | resolvedState) -> bool { |
| 4729 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 4730 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4731 | const auto& transaction = *flushState.transaction; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4732 | const auto& s = resolvedState.state; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4733 | // check for barrier frames |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4734 | if (s.bufferData->hasBarrier) { |
| 4735 | // The current producerId is already a newer producer than the buffer that has a |
| 4736 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4737 | // 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] | 4738 | if (layer->getDrawingState().barrierProducerId > s.bufferData->producerId) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4739 | layer->callReleaseBufferCallback(s.bufferData->releaseBufferListener, |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4740 | resolvedState.externalTexture->getBuffer(), |
Chavi Weingarten | c8bcb68 | 2023-03-06 22:20:42 +0000 | [diff] [blame] | 4741 | s.bufferData->frameNumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4742 | s.bufferData->acquireFence); |
| 4743 | // Delete the entire state at this point and not just release the buffer because |
| 4744 | // 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] | 4745 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", |
| 4746 | layer->getDebugName(), layer->getDrawingState().barrierProducerId, |
| 4747 | s.bufferData->producerId); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4748 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4749 | } |
| 4750 | |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 4751 | if (layer->getDrawingState().barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4752 | const bool willApplyBarrierFrame = |
| 4753 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4754 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4755 | s.bufferData->barrierFrameNumber)); |
| 4756 | if (!willApplyBarrierFrame) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4757 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4758 | layer->getDebugName(), |
| 4759 | layer->getDrawingState().barrierFrameNumber, |
| 4760 | s.bufferData->barrierFrameNumber); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4761 | ready = TransactionReadiness::NotReadyBarrier; |
| 4762 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4763 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4764 | } |
| 4765 | } |
| 4766 | |
| 4767 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4768 | // the transaction in the queue. |
| 4769 | const bool hasPendingBuffer = |
| 4770 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4771 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4772 | ATRACE_FORMAT("hasPendingBuffer %s", layer->getDebugName()); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4773 | ready = TransactionReadiness::NotReady; |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4774 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4775 | } |
| 4776 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4777 | const bool acquireFenceAvailable = s.bufferData && |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4778 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4779 | s.bufferData->acquireFence; |
Ying Wei | 1fd9bfc | 2023-06-29 16:47:00 +0000 | [diff] [blame] | 4780 | const bool fenceSignaled = !acquireFenceAvailable || |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4781 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4782 | if (!fenceSignaled) { |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4783 | // check fence status |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4784 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(s, transaction.states.size(), |
| 4785 | flushState.firstTransaction) && |
| 4786 | layer->isSimpleBufferUpdate(s); |
| 4787 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4788 | if (allowLatchUnsignaled) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4789 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", |
| 4790 | layer->getDebugName()); |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4791 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4792 | } else { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4793 | ready = TransactionReadiness::NotReady; |
| 4794 | auto& listener = s.bufferData->releaseBufferListener; |
| 4795 | if (listener && |
| 4796 | (flushState.queueProcessTime - transaction.postTime) > |
| 4797 | std::chrono::nanoseconds(4s).count()) { |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 4798 | mTransactionHandler |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 4799 | .onTransactionQueueStalled(transaction.id, |
| 4800 | {.pid = layer->getOwnerPid(), |
| 4801 | .layerId = static_cast<uint32_t>( |
| 4802 | layer->getSequence()), |
| 4803 | .layerName = layer->getDebugName(), |
| 4804 | .bufferId = s.bufferData->getId(), |
| 4805 | .frameNumber = s.bufferData->frameNumber}); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4806 | } |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4807 | ATRACE_FORMAT("fence unsignaled %s", layer->getDebugName()); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4808 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4809 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4810 | } |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4811 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4812 | }); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4813 | return ready; |
| 4814 | } |
| 4815 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4816 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheck( |
| 4817 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4818 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4819 | auto ready = TransactionReadiness::Ready; |
| 4820 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const ResolvedComposerState& |
| 4821 | resolvedState) -> bool { |
| 4822 | const frontend::RequestedLayerState* layer = |
| 4823 | mLayerLifecycleManager.getLayerFromId(resolvedState.layerId); |
| 4824 | const auto& transaction = *flushState.transaction; |
| 4825 | const auto& s = resolvedState.state; |
| 4826 | // check for barrier frames |
| 4827 | if (s.bufferData->hasBarrier) { |
| 4828 | // The current producerId is already a newer producer than the buffer that has a |
| 4829 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4830 | // don't wait on the barrier since we know that's stale information. |
| 4831 | if (layer->barrierProducerId > s.bufferData->producerId) { |
| 4832 | if (s.bufferData->releaseBufferListener) { |
| 4833 | uint32_t currentMaxAcquiredBufferCount = |
| 4834 | getMaxAcquiredBufferCountForCurrentRefreshRate(layer->ownerUid.val()); |
| 4835 | ATRACE_FORMAT_INSTANT("callReleaseBufferCallback %s - %" PRIu64, |
| 4836 | layer->name.c_str(), s.bufferData->frameNumber); |
| 4837 | s.bufferData->releaseBufferListener |
| 4838 | ->onReleaseBuffer({resolvedState.externalTexture->getBuffer()->getId(), |
| 4839 | s.bufferData->frameNumber}, |
| 4840 | s.bufferData->acquireFence |
| 4841 | ? s.bufferData->acquireFence |
| 4842 | : Fence::NO_FENCE, |
| 4843 | currentMaxAcquiredBufferCount); |
| 4844 | } |
| 4845 | |
| 4846 | // Delete the entire state at this point and not just release the buffer because |
| 4847 | // everything associated with the Layer in this Transaction is now out of date. |
| 4848 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", layer->name.c_str(), |
| 4849 | layer->barrierProducerId, s.bufferData->producerId); |
| 4850 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4851 | } |
| 4852 | |
| 4853 | if (layer->barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
| 4854 | const bool willApplyBarrierFrame = |
| 4855 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4856 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4857 | s.bufferData->barrierFrameNumber)); |
| 4858 | if (!willApplyBarrierFrame) { |
| 4859 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4860 | layer->name.c_str(), layer->barrierFrameNumber, |
| 4861 | s.bufferData->barrierFrameNumber); |
| 4862 | ready = TransactionReadiness::NotReadyBarrier; |
| 4863 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4864 | } |
| 4865 | } |
| 4866 | } |
| 4867 | |
| 4868 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4869 | // the transaction in the queue. |
| 4870 | const bool hasPendingBuffer = |
| 4871 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4872 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
| 4873 | ATRACE_FORMAT("hasPendingBuffer %s", layer->name.c_str()); |
| 4874 | ready = TransactionReadiness::NotReady; |
| 4875 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4876 | } |
| 4877 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4878 | const bool acquireFenceAvailable = s.bufferData && |
| 4879 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4880 | s.bufferData->acquireFence; |
Ying Wei | 1fd9bfc | 2023-06-29 16:47:00 +0000 | [diff] [blame] | 4881 | const bool fenceSignaled = !acquireFenceAvailable || |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4882 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
| 4883 | if (!fenceSignaled) { |
| 4884 | // check fence status |
| 4885 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(s, transaction.states.size(), |
| 4886 | flushState.firstTransaction) && |
| 4887 | layer->isSimpleBufferUpdate(s); |
| 4888 | if (allowLatchUnsignaled) { |
| 4889 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", layer->name.c_str()); |
| 4890 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4891 | } else { |
| 4892 | ready = TransactionReadiness::NotReady; |
| 4893 | auto& listener = s.bufferData->releaseBufferListener; |
| 4894 | if (listener && |
| 4895 | (flushState.queueProcessTime - transaction.postTime) > |
| 4896 | std::chrono::nanoseconds(4s).count()) { |
| 4897 | mTransactionHandler |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 4898 | .onTransactionQueueStalled(transaction.id, |
| 4899 | {.pid = layer->ownerPid.val(), |
| 4900 | .layerId = layer->id, |
| 4901 | .layerName = layer->name, |
| 4902 | .bufferId = s.bufferData->getId(), |
| 4903 | .frameNumber = s.bufferData->frameNumber}); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4904 | } |
| 4905 | ATRACE_FORMAT("fence unsignaled %s", layer->name.c_str()); |
| 4906 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4907 | } |
| 4908 | } |
| 4909 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
| 4910 | }); |
| 4911 | return ready; |
| 4912 | } |
| 4913 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4914 | void SurfaceFlinger::addTransactionReadyFilters() { |
| 4915 | mTransactionHandler.addTransactionReadyFilter( |
| 4916 | std::bind(&SurfaceFlinger::transactionReadyTimelineCheck, this, std::placeholders::_1)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4917 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4918 | mTransactionHandler.addTransactionReadyFilter( |
| 4919 | std::bind(&SurfaceFlinger::transactionReadyBufferCheck, this, |
| 4920 | std::placeholders::_1)); |
| 4921 | } else { |
| 4922 | mTransactionHandler.addTransactionReadyFilter( |
| 4923 | std::bind(&SurfaceFlinger::transactionReadyBufferCheckLegacy, this, |
| 4924 | std::placeholders::_1)); |
| 4925 | } |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4926 | } |
| 4927 | |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4928 | // For tests only |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4929 | bool SurfaceFlinger::flushTransactionQueues(VsyncId vsyncId) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4930 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4931 | std::vector<TransactionState> transactions = mTransactionHandler.flushTransactions(); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4932 | return applyTransactions(transactions, vsyncId); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4933 | } |
| 4934 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4935 | bool SurfaceFlinger::applyTransactions(std::vector<TransactionState>& transactions, |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4936 | VsyncId vsyncId) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 4937 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4938 | return applyTransactionsLocked(transactions, vsyncId); |
| 4939 | } |
| 4940 | |
| 4941 | bool SurfaceFlinger::applyTransactionsLocked(std::vector<TransactionState>& transactions, |
| 4942 | VsyncId vsyncId) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4943 | bool needsTraversal = false; |
| 4944 | // Now apply all transactions. |
Robert Carr | ff7663b | 2022-02-08 12:46:49 -0800 | [diff] [blame] | 4945 | for (auto& transaction : transactions) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4946 | needsTraversal |= |
| 4947 | applyTransactionState(transaction.frameTimelineInfo, transaction.states, |
| 4948 | transaction.displays, transaction.flags, |
| 4949 | transaction.inputWindowCommands, |
| 4950 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4951 | std::move(transaction.uncacheBufferIds), transaction.postTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4952 | transaction.hasListenerCallbacks, |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4953 | transaction.listenerCallbacks, transaction.originPid, |
| 4954 | transaction.originUid, transaction.id); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4955 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4956 | return needsTraversal; |
Marissa Wall | e6e3c0d | 2019-03-29 10:28:30 -0700 | [diff] [blame] | 4957 | } |
| 4958 | |
| 4959 | bool SurfaceFlinger::transactionFlushNeeded() { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4960 | return mTransactionHandler.hasPendingTransactions(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4961 | } |
| 4962 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4963 | bool SurfaceFlinger::frameIsEarly(TimePoint expectedPresentTime, VsyncId vsyncId) const { |
| 4964 | const auto prediction = |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 4965 | mFrameTimeline->getTokenManager()->getPredictionsForToken(ftl::to_underlying(vsyncId)); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4966 | if (!prediction) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4967 | return false; |
| 4968 | } |
| 4969 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4970 | const auto predictedPresentTime = TimePoint::fromNs(prediction->presentTime); |
| 4971 | |
Rachel Lee | 0655a91 | 2023-04-20 19:54:18 -0700 | [diff] [blame] | 4972 | if (std::chrono::abs(predictedPresentTime - expectedPresentTime) >= |
| 4973 | scheduler::VsyncConfig::kEarlyLatchMaxThreshold) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4974 | return false; |
| 4975 | } |
| 4976 | |
Ady Abraham | 3db8a3c | 2023-11-20 17:53:47 -0800 | [diff] [blame] | 4977 | const Duration earlyLatchVsyncThreshold = mScheduler->getVsyncSchedule()->minFramePeriod() / 2; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4978 | |
| 4979 | return predictedPresentTime >= expectedPresentTime && |
| 4980 | predictedPresentTime - expectedPresentTime >= earlyLatchVsyncThreshold; |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4981 | } |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4982 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4983 | bool SurfaceFlinger::shouldLatchUnsignaled(const layer_state_t& state, size_t numStates, |
| 4984 | bool firstTransaction) const { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4985 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Disabled) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4986 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::Disabled)", __func__); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4987 | return false; |
| 4988 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4989 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4990 | // We only want to latch unsignaled when a single layer is updated in this |
| 4991 | // transaction (i.e. not a blast sync transaction). |
| 4992 | if (numStates != 1) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4993 | ATRACE_FORMAT_INSTANT("%s: false (numStates=%zu)", __func__, numStates); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4994 | return false; |
| 4995 | } |
| 4996 | |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4997 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::AutoSingleLayer) { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4998 | if (!firstTransaction) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4999 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; not first " |
| 5000 | "transaction)", |
| 5001 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 5002 | return false; |
| 5003 | } |
| 5004 | |
| 5005 | // We don't want to latch unsignaled if are in early / client composition |
| 5006 | // as it leads to jank due to RenderEngine waiting for unsignaled buffer |
| 5007 | // or window animations being slow. |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 5008 | if (mScheduler->vsyncModulator().isVsyncConfigEarly()) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 5009 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; " |
| 5010 | "isVsyncConfigEarly)", |
| 5011 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 5012 | return false; |
| 5013 | } |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5014 | } |
| 5015 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5016 | return true; |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5017 | } |
| 5018 | |
chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 5019 | status_t SurfaceFlinger::setTransactionState( |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5020 | const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 5021 | const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5022 | InputWindowCommands inputWindowCommands, int64_t desiredPresentTime, bool isAutoTimestamp, |
| 5023 | const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 5024 | const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId, |
| 5025 | const std::vector<uint64_t>& mergedTransactionIds) { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 5026 | ATRACE_CALL(); |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 5027 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5028 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5029 | const int originPid = ipc->getCallingPid(); |
| 5030 | const int originUid = ipc->getCallingUid(); |
| 5031 | uint32_t permissions = LayerStatePermissions::getTransactionPermissions(originPid, originUid); |
| 5032 | for (auto composerState : states) { |
| 5033 | composerState.state.sanitize(permissions); |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 5034 | } |
| 5035 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5036 | for (DisplayState display : displays) { |
| 5037 | display.sanitize(permissions); |
| 5038 | } |
| 5039 | |
| 5040 | if (!inputWindowCommands.empty() && |
| 5041 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) == 0) { |
| 5042 | ALOGE("Only privileged callers are allowed to send input commands."); |
| 5043 | inputWindowCommands.clear(); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 5044 | } |
| 5045 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 5046 | if (flags & (eEarlyWakeupStart | eEarlyWakeupEnd)) { |
| 5047 | const bool hasPermission = |
| 5048 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) || |
| 5049 | callingThreadHasPermission(sWakeupSurfaceFlinger); |
| 5050 | if (!hasPermission) { |
| 5051 | ALOGE("Caller needs permission android.permission.WAKEUP_SURFACE_FLINGER to use " |
| 5052 | "eEarlyWakeup[Start|End] flags"); |
| 5053 | flags &= ~(eEarlyWakeupStart | eEarlyWakeupEnd); |
| 5054 | } |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 5055 | } |
| 5056 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 5057 | const int64_t postTime = systemTime(); |
| 5058 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5059 | std::vector<uint64_t> uncacheBufferIds; |
| 5060 | uncacheBufferIds.reserve(uncacheBuffers.size()); |
| 5061 | for (const auto& uncacheBuffer : uncacheBuffers) { |
| 5062 | sp<GraphicBuffer> buffer = ClientCache::getInstance().erase(uncacheBuffer); |
| 5063 | if (buffer != nullptr) { |
| 5064 | uncacheBufferIds.push_back(buffer->getId()); |
| 5065 | } |
| 5066 | } |
| 5067 | |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5068 | std::vector<ResolvedComposerState> resolvedStates; |
| 5069 | resolvedStates.reserve(states.size()); |
| 5070 | for (auto& state : states) { |
| 5071 | resolvedStates.emplace_back(std::move(state)); |
| 5072 | auto& resolvedState = resolvedStates.back(); |
| 5073 | if (resolvedState.state.hasBufferChanges() && resolvedState.state.hasValidBuffer() && |
| 5074 | resolvedState.state.surface) { |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 5075 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 5076 | std::string layerName = (layer) ? |
| 5077 | layer->getDebugName() : std::to_string(resolvedState.state.layerId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5078 | resolvedState.externalTexture = |
| 5079 | getExternalTextureFromBufferData(*resolvedState.state.bufferData, |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 5080 | layerName.c_str(), transactionId); |
Patrick Williams | 38d920e | 2023-08-31 17:31:18 -0500 | [diff] [blame] | 5081 | if (resolvedState.externalTexture) { |
| 5082 | resolvedState.state.bufferData->buffer = resolvedState.externalTexture->getBuffer(); |
| 5083 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5084 | mBufferCountTracker.increment(resolvedState.state.surface->localBinder()); |
| 5085 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 5086 | resolvedState.layerId = LayerHandle::getLayerId(resolvedState.state.surface); |
| 5087 | if (resolvedState.state.what & layer_state_t::eReparent) { |
| 5088 | resolvedState.parentId = |
| 5089 | getLayerIdFromSurfaceControl(resolvedState.state.parentSurfaceControlForChild); |
| 5090 | } |
| 5091 | if (resolvedState.state.what & layer_state_t::eRelativeLayerChanged) { |
| 5092 | resolvedState.relativeParentId = |
| 5093 | getLayerIdFromSurfaceControl(resolvedState.state.relativeLayerSurfaceControl); |
| 5094 | } |
| 5095 | if (resolvedState.state.what & layer_state_t::eInputInfoChanged) { |
| 5096 | wp<IBinder>& touchableRegionCropHandle = |
| 5097 | resolvedState.state.windowInfoHandle->editInfo()->touchableRegionCropHandle; |
| 5098 | resolvedState.touchCropId = |
| 5099 | LayerHandle::getLayerId(touchableRegionCropHandle.promote()); |
| 5100 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5101 | } |
| 5102 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5103 | TransactionState state{frameTimelineInfo, |
| 5104 | resolvedStates, |
| 5105 | displays, |
| 5106 | flags, |
| 5107 | applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5108 | std::move(inputWindowCommands), |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5109 | desiredPresentTime, |
| 5110 | isAutoTimestamp, |
| 5111 | std::move(uncacheBufferIds), |
| 5112 | postTime, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5113 | hasListenerCallbacks, |
| 5114 | listenerCallbacks, |
| 5115 | originPid, |
| 5116 | originUid, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 5117 | transactionId, |
| 5118 | mergedTransactionIds}; |
Vishnu Nair | 83df034 | 2021-03-30 11:50:44 -0700 | [diff] [blame] | 5119 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 5120 | if (mTransactionTracing) { |
| 5121 | mTransactionTracing->addQueuedTransaction(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5122 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5123 | |
| 5124 | const auto schedule = [](uint32_t flags) { |
| 5125 | if (flags & eEarlyWakeupEnd) return TransactionSchedule::EarlyEnd; |
| 5126 | if (flags & eEarlyWakeupStart) return TransactionSchedule::EarlyStart; |
| 5127 | return TransactionSchedule::Late; |
| 5128 | }(state.flags); |
| 5129 | |
| 5130 | const auto frameHint = state.isFrameActive() ? FrameHint::kActive : FrameHint::kNone; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5131 | mTransactionHandler.queueTransaction(std::move(state)); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 5132 | for (const auto& [displayId, data] : mNotifyExpectedPresentMap) { |
| 5133 | if (data.hintStatus.load() == NotifyExpectedPresentHintStatus::ScheduleOnTx) { |
| 5134 | scheduleNotifyExpectedPresentHint(displayId, VsyncId{frameTimelineInfo.vsyncId}); |
| 5135 | } |
| 5136 | } |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 5137 | setTransactionFlags(eTransactionFlushNeeded, schedule, applyToken, frameHint); |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 5138 | return NO_ERROR; |
| 5139 | } |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 5140 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5141 | bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5142 | std::vector<ResolvedComposerState>& states, |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 5143 | Vector<DisplayState>& displays, uint32_t flags, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5144 | const InputWindowCommands& inputWindowCommands, |
| 5145 | const int64_t desiredPresentTime, bool isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5146 | const std::vector<uint64_t>& uncacheBufferIds, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5147 | const int64_t postTime, bool hasListenerCallbacks, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5148 | const std::vector<ListenerCallbacks>& listenerCallbacks, |
| 5149 | int originPid, int originUid, uint64_t transactionId) { |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 5150 | uint32_t transactionFlags = 0; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5151 | if (!mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5152 | for (DisplayState& display : displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5153 | transactionFlags |= setDisplayStateLocked(display); |
| 5154 | } |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 5155 | } |
| 5156 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5157 | // start and end registration for listeners w/ no surface so they can get their callback. Note |
| 5158 | // that listeners with SurfaceControls will start registration during setClientStateLocked |
| 5159 | // below. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5160 | for (const auto& listener : listenerCallbacks) { |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5161 | mTransactionCallbackInvoker.addEmptyTransaction(listener); |
Marissa Wall | d600d57 | 2019-03-26 15:38:50 -0700 | [diff] [blame] | 5162 | } |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 5163 | nsecs_t now = systemTime(); |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5164 | uint32_t clientStateFlags = 0; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5165 | for (auto& resolvedState : states) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5166 | if (mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5167 | clientStateFlags |= |
| 5168 | setClientStateLocked(frameTimelineInfo, resolvedState, desiredPresentTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5169 | isAutoTimestamp, postTime, transactionId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5170 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5171 | } else /*mLayerLifecycleManagerEnabled*/ { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5172 | clientStateFlags |= updateLayerCallbacksAndStats(frameTimelineInfo, resolvedState, |
| 5173 | desiredPresentTime, isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5174 | postTime, transactionId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5175 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5176 | if ((flags & eAnimation) && resolvedState.state.surface) { |
| 5177 | if (const auto layer = LayerHandle::getLayer(resolvedState.state.surface)) { |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5178 | const auto layerProps = scheduler::LayerProps{ |
| 5179 | .visible = layer->isVisible(), |
| 5180 | .bounds = layer->getBounds(), |
| 5181 | .transform = layer->getTransform(), |
| 5182 | .setFrameRateVote = layer->getFrameRateForLayerTree(), |
| 5183 | .frameRateSelectionPriority = layer->getFrameRateSelectionPriority(), |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 5184 | .isFrontBuffered = layer->isFrontBuffered(), |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5185 | }; |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 5186 | layer->recordLayerHistoryAnimationTx(layerProps, now); |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 5187 | } |
| 5188 | } |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 5189 | } |
| 5190 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5191 | transactionFlags |= clientStateFlags; |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5192 | transactionFlags |= addInputWindowCommands(inputWindowCommands); |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5193 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5194 | for (uint64_t uncacheBufferId : uncacheBufferIds) { |
| 5195 | mBufferIdsToUncache.push_back(uncacheBufferId); |
Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 5196 | } |
| 5197 | |
Jorim Jaggi | bdcf09c | 2017-08-08 15:22:08 +0200 | [diff] [blame] | 5198 | // If a synchronous transaction is explicitly requested without any changes, force a transaction |
| 5199 | // anyway. This can be used as a flush mechanism for previous async transactions. |
| 5200 | // Empty animation transaction can be used to simulate back-pressure, so also force a |
| 5201 | // transaction for empty animation transactions. |
Vishnu Nair | 1523dad | 2022-09-29 16:05:18 -0700 | [diff] [blame] | 5202 | if (transactionFlags == 0 && (flags & eAnimation)) { |
Robert Carr | 2a7dbb4 | 2016-05-24 11:41:28 -0700 | [diff] [blame] | 5203 | transactionFlags = eTransactionNeeded; |
| 5204 | } |
| 5205 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5206 | bool needsTraversal = false; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 5207 | if (transactionFlags) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5208 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 5209 | // 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] | 5210 | if (transactionFlags & eTraversalNeeded) { |
| 5211 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5212 | needsTraversal = true; |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 5213 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5214 | if (transactionFlags) { |
| 5215 | setTransactionFlags(transactionFlags); |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 5216 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5217 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5218 | |
| 5219 | return needsTraversal; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5220 | } |
| 5221 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5222 | bool SurfaceFlinger::applyAndCommitDisplayTransactionStates( |
| 5223 | std::vector<TransactionState>& transactions) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5224 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5225 | bool needsTraversal = false; |
| 5226 | uint32_t transactionFlags = 0; |
| 5227 | for (auto& transaction : transactions) { |
| 5228 | for (DisplayState& display : transaction.displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5229 | transactionFlags |= setDisplayStateLocked(display); |
| 5230 | } |
| 5231 | } |
| 5232 | |
| 5233 | if (transactionFlags) { |
| 5234 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 5235 | // so we don't have to wake up again next frame to perform an unnecessary traversal. |
| 5236 | if (transactionFlags & eTraversalNeeded) { |
| 5237 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
| 5238 | needsTraversal = true; |
| 5239 | } |
| 5240 | if (transactionFlags) { |
| 5241 | setTransactionFlags(transactionFlags); |
| 5242 | } |
| 5243 | } |
| 5244 | |
| 5245 | mFrontEndDisplayInfosChanged = mTransactionFlags & eDisplayTransactionNeeded; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5246 | if (mFrontEndDisplayInfosChanged && !mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5247 | processDisplayChangesLocked(); |
| 5248 | mFrontEndDisplayInfos.clear(); |
| 5249 | for (const auto& [_, display] : mDisplays) { |
| 5250 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 5251 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5252 | needsTraversal = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5253 | } |
| 5254 | |
| 5255 | return needsTraversal; |
| 5256 | } |
| 5257 | |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5258 | uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s) { |
| 5259 | const ssize_t index = mCurrentState.displays.indexOfKey(s.token); |
| 5260 | if (index < 0) return 0; |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 5261 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5262 | uint32_t flags = 0; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5263 | DisplayDeviceState& state = mCurrentState.displays.editValueAt(index); |
| 5264 | |
| 5265 | const uint32_t what = s.what; |
| 5266 | if (what & DisplayState::eSurfaceChanged) { |
| 5267 | if (IInterface::asBinder(state.surface) != IInterface::asBinder(s.surface)) { |
| 5268 | state.surface = s.surface; |
| 5269 | flags |= eDisplayTransactionNeeded; |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 5270 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5271 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5272 | if (what & DisplayState::eLayerStackChanged) { |
| 5273 | if (state.layerStack != s.layerStack) { |
| 5274 | state.layerStack = s.layerStack; |
| 5275 | flags |= eDisplayTransactionNeeded; |
| 5276 | } |
| 5277 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 5278 | if (what & DisplayState::eFlagsChanged) { |
| 5279 | if (state.flags != s.flags) { |
| 5280 | state.flags = s.flags; |
| 5281 | flags |= eDisplayTransactionNeeded; |
| 5282 | } |
| 5283 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5284 | if (what & DisplayState::eDisplayProjectionChanged) { |
| 5285 | if (state.orientation != s.orientation) { |
| 5286 | state.orientation = s.orientation; |
| 5287 | flags |= eDisplayTransactionNeeded; |
| 5288 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5289 | if (state.orientedDisplaySpaceRect != s.orientedDisplaySpaceRect) { |
| 5290 | state.orientedDisplaySpaceRect = s.orientedDisplaySpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5291 | flags |= eDisplayTransactionNeeded; |
| 5292 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5293 | if (state.layerStackSpaceRect != s.layerStackSpaceRect) { |
| 5294 | state.layerStackSpaceRect = s.layerStackSpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5295 | flags |= eDisplayTransactionNeeded; |
| 5296 | } |
| 5297 | } |
| 5298 | if (what & DisplayState::eDisplaySizeChanged) { |
| 5299 | if (state.width != s.width) { |
| 5300 | state.width = s.width; |
| 5301 | flags |= eDisplayTransactionNeeded; |
| 5302 | } |
| 5303 | if (state.height != s.height) { |
| 5304 | state.height = s.height; |
| 5305 | flags |= eDisplayTransactionNeeded; |
| 5306 | } |
| 5307 | } |
| 5308 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5309 | return flags; |
| 5310 | } |
| 5311 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5312 | bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5313 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5314 | const int pid = ipc->getCallingPid(); |
| 5315 | const int uid = ipc->getCallingUid(); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5316 | if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) && |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5317 | (usePermissionCache ? !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid) |
| 5318 | : !checkPermission(sAccessSurfaceFlinger, pid, uid))) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5319 | return false; |
| 5320 | } |
| 5321 | return true; |
| 5322 | } |
| 5323 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5324 | uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5325 | ResolvedComposerState& composerState, |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5326 | int64_t desiredPresentTime, bool isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5327 | int64_t postTime, uint64_t transactionId) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5328 | layer_state_t& s = composerState.state; |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5329 | |
| 5330 | std::vector<ListenerCallbacks> filteredListeners; |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5331 | for (auto& listener : s.listeners) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5332 | // Starts a registration but separates the callback ids according to callback type. This |
| 5333 | // allows the callback invoker to send on latch callbacks earlier. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5334 | // note that startRegistration will not re-register if the listener has |
| 5335 | // already be registered for a prior surface control |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5336 | |
| 5337 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5338 | if (!onCommitCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5339 | filteredListeners.push_back(onCommitCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5340 | } |
| 5341 | |
| 5342 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5343 | if (!onCompleteCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5344 | filteredListeners.push_back(onCompleteCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5345 | } |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5346 | } |
| 5347 | |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 5348 | const uint64_t what = s.what; |
| 5349 | uint32_t flags = 0; |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 5350 | sp<Layer> layer = nullptr; |
| 5351 | if (s.surface) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5352 | layer = LayerHandle::getLayer(s.surface); |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 5353 | } else { |
| 5354 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5355 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5356 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5357 | if (layer == nullptr) { |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5358 | for (auto& [listener, callbackIds] : s.listeners) { |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 5359 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5360 | callbackIds, |
| 5361 | s.surface), |
| 5362 | std::vector<JankData>()); |
Marissa Wall | 88e2048 | 2019-06-24 10:49:42 -0700 | [diff] [blame] | 5363 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5364 | return 0; |
| 5365 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 5366 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5367 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 5368 | ui::LayerStack oldLayerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5369 | |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 5370 | // Only set by BLAST adapter layers |
| 5371 | if (what & layer_state_t::eProducerDisconnect) { |
| 5372 | layer->onDisconnect(); |
| 5373 | } |
| 5374 | |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5375 | if (what & layer_state_t::ePositionChanged) { |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 5376 | if (layer->setPosition(s.x, s.y)) { |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5377 | flags |= eTraversalNeeded; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5378 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5379 | } |
| 5380 | if (what & layer_state_t::eLayerChanged) { |
| 5381 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5382 | const auto& p = layer->getParent(); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5383 | if (p == nullptr) { |
chaviw | 64f7b42 | 2017-07-12 10:31:58 -0700 | [diff] [blame] | 5384 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5385 | if (layer->setLayer(s.z) && idx >= 0) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5386 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5387 | mCurrentState.layersSortedByZ.add(layer); |
| 5388 | // we need traversal (state changed) |
| 5389 | // AND transaction (list changed) |
| 5390 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5391 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5392 | } else { |
| 5393 | if (p->setChildLayer(layer, s.z)) { |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 5394 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5395 | } |
| 5396 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5397 | } |
| 5398 | if (what & layer_state_t::eRelativeLayerChanged) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5399 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5400 | const auto& p = layer->getParent(); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5401 | const auto& relativeHandle = s.relativeLayerSurfaceControl ? |
| 5402 | s.relativeLayerSurfaceControl->getHandle() : nullptr; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5403 | if (p == nullptr) { |
| 5404 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5405 | if (layer->setRelativeLayer(relativeHandle, s.z) && |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5406 | idx >= 0) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5407 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5408 | mCurrentState.layersSortedByZ.add(layer); |
| 5409 | // we need traversal (state changed) |
| 5410 | // AND transaction (list changed) |
| 5411 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5412 | } |
| 5413 | } else { |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5414 | if (p->setChildRelativeLayer(layer, relativeHandle, s.z)) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5415 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5416 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5417 | } |
| 5418 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5419 | if (what & layer_state_t::eAlphaChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5420 | if (layer->setAlpha(s.color.a)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5421 | } |
| 5422 | if (what & layer_state_t::eColorChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5423 | if (layer->setColor(s.color.rgb)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5424 | } |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 5425 | if (what & layer_state_t::eColorTransformChanged) { |
| 5426 | if (layer->setColorTransform(s.colorTransform)) { |
| 5427 | flags |= eTraversalNeeded; |
| 5428 | } |
| 5429 | } |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5430 | if (what & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5431 | if (layer->setBackgroundColor(s.bgColor.rgb, s.bgColor.a, s.bgColorDataspace)) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5432 | flags |= eTraversalNeeded; |
| 5433 | } |
| 5434 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5435 | if (what & layer_state_t::eMatrixChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5436 | if (layer->setMatrix(s.matrix)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5437 | } |
| 5438 | if (what & layer_state_t::eTransparentRegionChanged) { |
| 5439 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 5440 | flags |= eTraversalNeeded; |
| 5441 | } |
| 5442 | if (what & layer_state_t::eFlagsChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5443 | if (layer->setFlags(s.flags, s.mask)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5444 | } |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 5445 | if (what & layer_state_t::eCornerRadiusChanged) { |
| 5446 | if (layer->setCornerRadius(s.cornerRadius)) |
| 5447 | flags |= eTraversalNeeded; |
| 5448 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5449 | if (what & layer_state_t::eBackgroundBlurRadiusChanged && mSupportsBlur) { |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5450 | if (layer->setBackgroundBlurRadius(s.backgroundBlurRadius)) flags |= eTraversalNeeded; |
| 5451 | } |
Galia Peycheva | e11d575 | 2021-01-22 13:50:16 +0000 | [diff] [blame] | 5452 | if (what & layer_state_t::eBlurRegionsChanged) { |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5453 | if (layer->setBlurRegions(s.blurRegions)) flags |= eTraversalNeeded; |
| 5454 | } |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 5455 | if (what & layer_state_t::eRenderBorderChanged) { |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 5456 | if (layer->enableBorder(s.borderEnabled, s.borderWidth, s.borderColor)) { |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 5457 | flags |= eTraversalNeeded; |
| 5458 | } |
| 5459 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5460 | if (what & layer_state_t::eLayerStackChanged) { |
| 5461 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 5462 | // We only allow setting layer stacks for top level layers, |
| 5463 | // everything else inherits layer stack from its parent. |
| 5464 | if (layer->hasParent()) { |
| 5465 | 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] | 5466 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5467 | } else if (idx < 0) { |
| 5468 | ALOGE("Attempt to set layer stack on layer without parent (%s) that " |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5469 | "that also does not appear in the top level layer list. Something" |
| 5470 | " has gone wrong.", |
| 5471 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5472 | } else if (layer->setLayerStack(s.layerStack)) { |
| 5473 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5474 | mCurrentState.layersSortedByZ.add(layer); |
| 5475 | // we need traversal (state changed) |
| 5476 | // AND transaction (list changed) |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5477 | flags |= eTransactionNeeded | eTraversalNeeded | eTransformHintUpdateNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5478 | } |
| 5479 | } |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5480 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5481 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5482 | } |
| 5483 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5484 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5485 | flags |= eTraversalNeeded; |
| 5486 | } |
| 5487 | if (what & layer_state_t::eCropChanged) { |
| 5488 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5489 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5490 | if (what & layer_state_t::eDataspaceChanged) { |
| 5491 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5492 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5493 | if (what & layer_state_t::eSurfaceDamageRegionChanged) { |
| 5494 | if (layer->setSurfaceDamageRegion(s.surfaceDamageRegion)) flags |= eTraversalNeeded; |
| 5495 | } |
| 5496 | if (what & layer_state_t::eApiChanged) { |
| 5497 | if (layer->setApi(s.api)) flags |= eTraversalNeeded; |
| 5498 | } |
| 5499 | if (what & layer_state_t::eSidebandStreamChanged) { |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 5500 | if (layer->setSidebandStream(s.sidebandStream, frameTimelineInfo, postTime)) |
| 5501 | flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5502 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5503 | if (what & layer_state_t::eInputInfoChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5504 | layer->setInputInfo(*s.windowInfoHandle->getInfo()); |
| 5505 | flags |= eTraversalNeeded; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5506 | } |
Vishnu Nair | adf632b | 2021-01-07 14:05:08 -0800 | [diff] [blame] | 5507 | std::optional<nsecs_t> dequeueBufferTimestamp; |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5508 | if (what & layer_state_t::eMetadataChanged) { |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5509 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5510 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5511 | if (const int32_t gameMode = s.metadata.getInt32(gui::METADATA_GAME_MODE, -1); |
| 5512 | gameMode != -1) { |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5513 | // The transaction will be received on the Task layer and needs to be applied to all |
| 5514 | // child layers. Child layers that are added at a later point will obtain the game mode |
| 5515 | // info through addChild(). |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5516 | layer->setGameModeForTree(static_cast<GameMode>(gameMode)); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5517 | } |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5518 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 5519 | if (layer->setMetadata(s.metadata)) { |
| 5520 | flags |= eTraversalNeeded; |
| 5521 | mLayerMetadataSnapshotNeeded = true; |
| 5522 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5523 | } |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 5524 | if (what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 5525 | if (layer->setColorSpaceAgnostic(s.colorSpaceAgnostic)) { |
| 5526 | flags |= eTraversalNeeded; |
| 5527 | } |
| 5528 | } |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 5529 | if (what & layer_state_t::eShadowRadiusChanged) { |
| 5530 | if (layer->setShadowRadius(s.shadowRadius)) flags |= eTraversalNeeded; |
| 5531 | } |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 5532 | if (what & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 5533 | const auto compatibility = |
| 5534 | Layer::FrameRate::convertCompatibility(s.defaultFrameRateCompatibility); |
| 5535 | |
| 5536 | if (layer->setDefaultFrameRateCompatibility(compatibility)) { |
| 5537 | flags |= eTraversalNeeded; |
| 5538 | } |
| 5539 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5540 | if (what & layer_state_t::eFrameRateSelectionPriority) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5541 | if (layer->setFrameRateSelectionPriority(s.frameRateSelectionPriority)) { |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5542 | flags |= eTraversalNeeded; |
| 5543 | } |
| 5544 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5545 | if (what & layer_state_t::eFrameRateChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5546 | const auto compatibility = |
| 5547 | Layer::FrameRate::convertCompatibility(s.frameRateCompatibility); |
| 5548 | const auto strategy = |
| 5549 | Layer::FrameRate::convertChangeFrameRateStrategy(s.changeFrameRateStrategy); |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 5550 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 5551 | if (layer->setFrameRate(Layer::FrameRate::FrameRateVote(Fps::fromValue(s.frameRate), |
| 5552 | compatibility, strategy))) { |
| 5553 | flags |= eTraversalNeeded; |
| 5554 | } |
| 5555 | } |
| 5556 | if (what & layer_state_t::eFrameRateCategoryChanged) { |
| 5557 | const FrameRateCategory category = Layer::FrameRate::convertCategory(s.frameRateCategory); |
Rachel Lee | 67afbea | 2023-09-28 15:35:07 -0700 | [diff] [blame] | 5558 | if (layer->setFrameRateCategory(category, s.frameRateCategorySmoothSwitchOnly)) { |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 5559 | flags |= eTraversalNeeded; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 5560 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5561 | } |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 5562 | if (what & layer_state_t::eFrameRateSelectionStrategyChanged) { |
| 5563 | const scheduler::LayerInfo::FrameRateSelectionStrategy strategy = |
| 5564 | scheduler::LayerInfo::convertFrameRateSelectionStrategy( |
| 5565 | s.frameRateSelectionStrategy); |
| 5566 | if (layer->setFrameRateSelectionStrategy(strategy)) { |
| 5567 | flags |= eTraversalNeeded; |
| 5568 | } |
| 5569 | } |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5570 | if (what & layer_state_t::eFixedTransformHintChanged) { |
| 5571 | if (layer->setFixedTransformHint(s.fixedTransformHint)) { |
| 5572 | flags |= eTraversalNeeded | eTransformHintUpdateNeeded; |
| 5573 | } |
| 5574 | } |
Vishnu Nair | cf26a0a | 2020-11-13 12:56:20 -0800 | [diff] [blame] | 5575 | if (what & layer_state_t::eAutoRefreshChanged) { |
| 5576 | layer->setAutoRefresh(s.autoRefresh); |
| 5577 | } |
Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 5578 | if (what & layer_state_t::eDimmingEnabledChanged) { |
| 5579 | if (layer->setDimmingEnabled(s.dimmingEnabled)) flags |= eTraversalNeeded; |
| 5580 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5581 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 5582 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5583 | flags |= eTraversalNeeded; |
| 5584 | } |
| 5585 | } |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 5586 | if (what & layer_state_t::eDesiredHdrHeadroomChanged) { |
| 5587 | if (layer->setDesiredHdrHeadroom(s.desiredHdrSdrRatio)) { |
| 5588 | flags |= eTraversalNeeded; |
| 5589 | } |
| 5590 | } |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 5591 | if (what & layer_state_t::eCachingHintChanged) { |
| 5592 | if (layer->setCachingHint(s.cachingHint)) { |
| 5593 | flags |= eTraversalNeeded; |
| 5594 | } |
| 5595 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5596 | if (what & layer_state_t::eHdrMetadataChanged) { |
| 5597 | if (layer->setHdrMetadata(s.hdrMetadata)) flags |= eTraversalNeeded; |
| 5598 | } |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5599 | if (what & layer_state_t::eTrustedOverlayChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5600 | if (layer->setTrustedOverlay(s.isTrustedOverlay)) { |
| 5601 | flags |= eTraversalNeeded; |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5602 | } |
| 5603 | } |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 5604 | if (what & layer_state_t::eStretchChanged) { |
| 5605 | if (layer->setStretchEffect(s.stretchEffect)) { |
| 5606 | flags |= eTraversalNeeded; |
| 5607 | } |
| 5608 | } |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 5609 | if (what & layer_state_t::eBufferCropChanged) { |
| 5610 | if (layer->setBufferCrop(s.bufferCrop)) { |
| 5611 | flags |= eTraversalNeeded; |
| 5612 | } |
| 5613 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 5614 | if (what & layer_state_t::eDestinationFrameChanged) { |
| 5615 | if (layer->setDestinationFrame(s.destinationFrame)) { |
| 5616 | flags |= eTraversalNeeded; |
| 5617 | } |
| 5618 | } |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5619 | if (what & layer_state_t::eDropInputModeChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5620 | if (layer->setDropInputMode(s.dropInputMode)) { |
| 5621 | flags |= eTraversalNeeded; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 5622 | mUpdateInputInfo = true; |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5623 | } |
| 5624 | } |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5625 | // This has to happen after we reparent children because when we reparent to null we remove |
| 5626 | // child layers from current state and remove its relative z. If the children are reparented in |
| 5627 | // the same transaction, then we have to make sure we reparent the children first so we do not |
| 5628 | // lose its relative z order. |
| 5629 | if (what & layer_state_t::eReparent) { |
| 5630 | bool hadParent = layer->hasParent(); |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5631 | auto parentHandle = (s.parentSurfaceControlForChild) |
| 5632 | ? s.parentSurfaceControlForChild->getHandle() |
| 5633 | : nullptr; |
| 5634 | if (layer->reparent(parentHandle)) { |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5635 | if (!hadParent) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 5636 | layer->setIsAtRoot(false); |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5637 | mCurrentState.layersSortedByZ.remove(layer); |
| 5638 | } |
| 5639 | flags |= eTransactionNeeded | eTraversalNeeded; |
| 5640 | } |
| 5641 | } |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5642 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5643 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5644 | for (auto& [listener, callbackIds] : filteredListeners) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 5645 | callbackHandles.emplace_back( |
| 5646 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5647 | } |
| 5648 | } |
Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 5649 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5650 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5651 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5652 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 5653 | frameTimelineInfo)) { |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5654 | flags |= eTraversalNeeded; |
| 5655 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5656 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5657 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 5658 | } |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 5659 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5660 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5661 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5662 | } |
| 5663 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5664 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5665 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5666 | s.trustedPresentationListener)) { |
| 5667 | flags |= eTraversalNeeded; |
| 5668 | } |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5669 | } |
| 5670 | |
Pascal Muetschard | b39918f | 2023-01-27 11:36:11 +0100 | [diff] [blame] | 5671 | if (what & layer_state_t::eFlushJankData) { |
| 5672 | // Do nothing. Processing the transaction completed listeners currently cause the flush. |
| 5673 | } |
| 5674 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5675 | if (layer->setTransactionCompletedListeners(callbackHandles, |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5676 | layer->willPresentCurrentTransaction() || |
| 5677 | layer->willReleaseBufferOnLatch())) { |
Vishnu Nair | d691322 | 2023-02-01 22:56:21 +0000 | [diff] [blame] | 5678 | flags |= eTraversalNeeded; |
| 5679 | } |
| 5680 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5681 | // Do not put anything that updates layer state or modifies flags after |
| 5682 | // setTransactionCompletedListener |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5683 | |
| 5684 | // 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] | 5685 | if (((flags & eTransformHintUpdateNeeded) == 0) && |
| 5686 | oldLayerStack != layer->getLayerStack(LayerVector::StateSet::Current)) { |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5687 | flags |= eTransformHintUpdateNeeded; |
| 5688 | } |
| 5689 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5690 | return flags; |
| 5691 | } |
| 5692 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5693 | uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& frameTimelineInfo, |
| 5694 | ResolvedComposerState& composerState, |
| 5695 | int64_t desiredPresentTime, |
| 5696 | bool isAutoTimestamp, int64_t postTime, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5697 | uint64_t transactionId) { |
| 5698 | layer_state_t& s = composerState.state; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5699 | |
| 5700 | std::vector<ListenerCallbacks> filteredListeners; |
| 5701 | for (auto& listener : s.listeners) { |
| 5702 | // Starts a registration but separates the callback ids according to callback type. This |
| 5703 | // allows the callback invoker to send on latch callbacks earlier. |
| 5704 | // note that startRegistration will not re-register if the listener has |
| 5705 | // already be registered for a prior surface control |
| 5706 | |
| 5707 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5708 | if (!onCommitCallbacks.callbackIds.empty()) { |
| 5709 | filteredListeners.push_back(onCommitCallbacks); |
| 5710 | } |
| 5711 | |
| 5712 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5713 | if (!onCompleteCallbacks.callbackIds.empty()) { |
| 5714 | filteredListeners.push_back(onCompleteCallbacks); |
| 5715 | } |
| 5716 | } |
| 5717 | |
| 5718 | const uint64_t what = s.what; |
| 5719 | uint32_t flags = 0; |
| 5720 | sp<Layer> layer = nullptr; |
| 5721 | if (s.surface) { |
| 5722 | layer = LayerHandle::getLayer(s.surface); |
| 5723 | } else { |
| 5724 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5725 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5726 | } |
| 5727 | if (layer == nullptr) { |
| 5728 | for (auto& [listener, callbackIds] : s.listeners) { |
| 5729 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5730 | callbackIds, |
| 5731 | s.surface), |
| 5732 | std::vector<JankData>()); |
| 5733 | } |
| 5734 | return 0; |
| 5735 | } |
| 5736 | if (what & layer_state_t::eProducerDisconnect) { |
| 5737 | layer->onDisconnect(); |
| 5738 | } |
| 5739 | std::optional<nsecs_t> dequeueBufferTimestamp; |
| 5740 | if (what & layer_state_t::eMetadataChanged) { |
| 5741 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
| 5742 | } |
| 5743 | |
| 5744 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5745 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5746 | for (auto& [listener, callbackIds] : filteredListeners) { |
| 5747 | callbackHandles.emplace_back( |
| 5748 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
| 5749 | } |
| 5750 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5751 | // TODO(b/238781169) remove after screenshot refactor, currently screenshots |
| 5752 | // requires to read drawing state from binder thread. So we need to fix that |
| 5753 | // before removing this. |
Vishnu Nair | aeaf9d7 | 2023-09-12 15:47:41 -0700 | [diff] [blame] | 5754 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5755 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
| 5756 | } |
| 5757 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5758 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5759 | flags |= eTraversalNeeded; |
| 5760 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5761 | if (what & layer_state_t::eCropChanged) { |
| 5762 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5763 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5764 | if (what & layer_state_t::eSidebandStreamChanged) { |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 5765 | if (layer->setSidebandStream(s.sidebandStream, frameTimelineInfo, postTime)) |
| 5766 | flags |= eTraversalNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5767 | } |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 5768 | if (what & layer_state_t::eDataspaceChanged) { |
| 5769 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5770 | } |
Vishnu Nair | c5e3416 | 2023-08-22 13:21:20 -0700 | [diff] [blame] | 5771 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
| 5772 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
| 5773 | flags |= eTraversalNeeded; |
| 5774 | } |
| 5775 | } |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 5776 | if (what & layer_state_t::eDesiredHdrHeadroomChanged) { |
| 5777 | if (layer->setDesiredHdrHeadroom(s.desiredHdrSdrRatio)) { |
| 5778 | flags |= eTraversalNeeded; |
| 5779 | } |
| 5780 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5781 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 5782 | std::optional<ui::Transform::RotationFlags> transformHint = std::nullopt; |
| 5783 | frontend::LayerSnapshot* snapshot = mLayerSnapshotBuilder.getSnapshot(layer->sequence); |
| 5784 | if (snapshot) { |
| 5785 | transformHint = snapshot->transformHint; |
| 5786 | } |
| 5787 | layer->setTransformHint(transformHint); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5788 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5789 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
| 5790 | frameTimelineInfo)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5791 | flags |= eTraversalNeeded; |
| 5792 | } |
| 5793 | mLayersWithQueuedFrames.emplace(layer); |
| 5794 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5795 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
| 5796 | } |
| 5797 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5798 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5799 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5800 | } |
| 5801 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5802 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5803 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5804 | s.trustedPresentationListener)) { |
| 5805 | flags |= eTraversalNeeded; |
| 5806 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5807 | } |
| 5808 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5809 | const auto& requestedLayerState = mLayerLifecycleManager.getLayerFromId(layer->getSequence()); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5810 | bool willPresentCurrentTransaction = requestedLayerState && |
| 5811 | (requestedLayerState->hasReadyFrame() || |
| 5812 | requestedLayerState->willReleaseBufferOnLatch()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5813 | if (layer->setTransactionCompletedListeners(callbackHandles, willPresentCurrentTransaction)) |
| 5814 | flags |= eTraversalNeeded; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5815 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5816 | return flags; |
| 5817 | } |
| 5818 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5819 | uint32_t SurfaceFlinger::addInputWindowCommands(const InputWindowCommands& inputWindowCommands) { |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5820 | bool hasChanges = mInputWindowCommands.merge(inputWindowCommands); |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 5821 | return hasChanges ? eTraversalNeeded : 0; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5822 | } |
| 5823 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5824 | status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5825 | const sp<IBinder>& mirrorFromHandle, |
| 5826 | gui::CreateSurfaceResult& outResult) { |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5827 | if (!mirrorFromHandle) { |
| 5828 | return NAME_NOT_FOUND; |
| 5829 | } |
| 5830 | |
| 5831 | sp<Layer> mirrorLayer; |
| 5832 | sp<Layer> mirrorFrom; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5833 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5834 | { |
| 5835 | Mutex::Autolock _l(mStateLock); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5836 | mirrorFrom = LayerHandle::getLayer(mirrorFromHandle); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5837 | if (!mirrorFrom) { |
| 5838 | return NAME_NOT_FOUND; |
| 5839 | } |
Vishnu Nair | b21272e | 2022-07-01 22:47:33 +0000 | [diff] [blame] | 5840 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5841 | mirrorArgs.mirrorLayerHandle = mirrorFromHandle; |
| 5842 | mirrorArgs.addToRoot = false; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5843 | status_t result = createEffectLayer(mirrorArgs, &outResult.handle, &mirrorLayer); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5844 | if (result != NO_ERROR) { |
| 5845 | return result; |
| 5846 | } |
| 5847 | |
Vishnu Nair | de17725 | 2023-04-21 12:44:10 -0700 | [diff] [blame] | 5848 | mirrorLayer->setClonedChild(mirrorFrom->createClone(mirrorLayer->getSequence())); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5849 | } |
| 5850 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5851 | outResult.layerId = mirrorLayer->sequence; |
| 5852 | outResult.layerName = String16(mirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5853 | return addClientLayer(mirrorArgs, outResult.handle, mirrorLayer /* layer */, |
| 5854 | nullptr /* parent */, nullptr /* outTransformHint */); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5855 | } |
| 5856 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5857 | status_t SurfaceFlinger::mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5858 | gui::CreateSurfaceResult& outResult) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5859 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5860 | const int uid = ipc->getCallingUid(); |
| 5861 | if (uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM && uid != AID_SHELL) { |
| 5862 | ALOGE("Permission denied when trying to mirror display"); |
| 5863 | return PERMISSION_DENIED; |
| 5864 | } |
| 5865 | |
| 5866 | ui::LayerStack layerStack; |
| 5867 | sp<Layer> rootMirrorLayer; |
| 5868 | status_t result = 0; |
| 5869 | |
| 5870 | { |
| 5871 | Mutex::Autolock lock(mStateLock); |
| 5872 | |
| 5873 | const auto display = getDisplayDeviceLocked(displayId); |
| 5874 | if (!display) { |
| 5875 | return NAME_NOT_FOUND; |
| 5876 | } |
| 5877 | |
| 5878 | layerStack = display->getLayerStack(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5879 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5880 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5881 | mirrorArgs.addToRoot = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5882 | mirrorArgs.layerStackToMirror = layerStack; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5883 | result = createEffectLayer(mirrorArgs, &outResult.handle, &rootMirrorLayer); |
| 5884 | outResult.layerId = rootMirrorLayer->sequence; |
| 5885 | outResult.layerName = String16(rootMirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5886 | result |= addClientLayer(mirrorArgs, outResult.handle, rootMirrorLayer /* layer */, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5887 | nullptr /* parent */, nullptr /* outTransformHint */); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5888 | } |
| 5889 | |
| 5890 | if (result != NO_ERROR) { |
| 5891 | return result; |
| 5892 | } |
| 5893 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5894 | if (mLegacyFrontEndEnabled) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5895 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5896 | mMirrorDisplays.emplace_back(layerStack, outResult.handle, args.client); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5897 | } |
| 5898 | |
| 5899 | setTransactionFlags(eTransactionFlushNeeded); |
| 5900 | return NO_ERROR; |
| 5901 | } |
| 5902 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5903 | status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, gui::CreateSurfaceResult& outResult) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5904 | status_t result = NO_ERROR; |
| 5905 | |
| 5906 | sp<Layer> layer; |
| 5907 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5908 | switch (args.flags & ISurfaceComposerClient::eFXSurfaceMask) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5909 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 5910 | case ISurfaceComposerClient::eFXSurfaceContainer: |
| 5911 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 5912 | args.flags |= ISurfaceComposerClient::eNoColorFill; |
Siarhei Vishniakou | 8d66013 | 2024-01-11 16:48:44 -0800 | [diff] [blame] | 5913 | [[fallthrough]]; |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 5914 | case ISurfaceComposerClient::eFXSurfaceEffect: { |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5915 | result = createBufferStateLayer(args, &outResult.handle, &layer); |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5916 | std::atomic<int32_t>* pendingBufferCounter = layer->getPendingBufferCounter(); |
| 5917 | if (pendingBufferCounter) { |
| 5918 | std::string counterName = layer->getPendingBufferCounterName(); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5919 | mBufferCountTracker.add(outResult.handle->localBinder(), counterName, |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5920 | pendingBufferCounter); |
| 5921 | } |
| 5922 | } break; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5923 | default: |
| 5924 | result = BAD_VALUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5925 | break; |
| 5926 | } |
| 5927 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5928 | if (result != NO_ERROR) { |
| 5929 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5930 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5931 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5932 | args.addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess(); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5933 | // We can safely promote the parent layer in binder thread because we have a strong reference |
| 5934 | // to the layer's handle inside this scope. |
| 5935 | sp<Layer> parent = LayerHandle::getLayer(args.parentHandle.promote()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5936 | if (args.parentHandle != nullptr && parent == nullptr) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5937 | ALOGE("Invalid parent handle %p", args.parentHandle.promote().get()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5938 | args.addToRoot = false; |
Garfield Tan | dbc93d7 | 2021-10-26 18:28:57 -0700 | [diff] [blame] | 5939 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5940 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5941 | uint32_t outTransformHint; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5942 | result = addClientLayer(args, outResult.handle, layer, parent, &outTransformHint); |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 5943 | if (result != NO_ERROR) { |
| 5944 | return result; |
| 5945 | } |
| 5946 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5947 | outResult.transformHint = static_cast<int32_t>(outTransformHint); |
| 5948 | outResult.layerId = layer->sequence; |
| 5949 | outResult.layerName = String16(layer->getDebugName()); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5950 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5951 | } |
| 5952 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5953 | status_t SurfaceFlinger::createBufferStateLayer(LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5954 | sp<Layer>* outLayer) { |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5955 | *outLayer = getFactory().createBufferStateLayer(args); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5956 | *handle = (*outLayer)->getHandle(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5957 | return NO_ERROR; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 5958 | } |
| 5959 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5960 | status_t SurfaceFlinger::createEffectLayer(const LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5961 | sp<Layer>* outLayer) { |
| 5962 | *outLayer = getFactory().createEffectLayer(args); |
| 5963 | *handle = (*outLayer)->getHandle(); |
| 5964 | return NO_ERROR; |
| 5965 | } |
| 5966 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5967 | void SurfaceFlinger::markLayerPendingRemovalLocked(const sp<Layer>& layer) { |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5968 | mLayersPendingRemoval.add(layer); |
| 5969 | mLayersRemoved = true; |
| 5970 | setTransactionFlags(eTransactionNeeded); |
| 5971 | } |
| 5972 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5973 | void SurfaceFlinger::onHandleDestroyed(BBinder* handle, sp<Layer>& layer, uint32_t layerId) { |
| 5974 | { |
| 5975 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | 606d9d0 | 2023-08-19 14:20:18 -0700 | [diff] [blame] | 5976 | mDestroyedHandles.emplace_back(layerId, layer->getDebugName()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5977 | } |
| 5978 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 5979 | mTransactionHandler.onLayerDestroyed(layerId); |
| 5980 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5981 | Mutex::Autolock lock(mStateLock); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5982 | markLayerPendingRemovalLocked(layer); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 5983 | layer->onHandleDestroyed(); |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 5984 | mBufferCountTracker.remove(handle); |
Robert Carr | 695d528 | 2018-12-18 15:27:58 -0800 | [diff] [blame] | 5985 | layer.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5986 | |
| 5987 | setTransactionFlags(eTransactionFlushNeeded); |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 5988 | } |
| 5989 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 5990 | void SurfaceFlinger::initializeDisplays() { |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5991 | TransactionState state; |
| 5992 | state.inputWindowCommands = mInputWindowCommands; |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5993 | const nsecs_t now = systemTime(); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5994 | state.desiredPresentTime = now; |
| 5995 | state.postTime = now; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5996 | state.originPid = mPid; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5997 | state.originUid = static_cast<int>(getuid()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5998 | const uint64_t transactionId = (static_cast<uint64_t>(mPid) << 32) | mUniqueTransactionId++; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5999 | state.id = transactionId; |
| 6000 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6001 | auto layerStack = ui::DEFAULT_LAYER_STACK.id; |
| 6002 | for (const auto& [id, display] : FTL_FAKE_GUARD(mStateLock, mPhysicalDisplays)) { |
| 6003 | state.displays.push(DisplayState(display.token(), ui::LayerStack::fromValue(layerStack++))); |
| 6004 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 6005 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6006 | std::vector<TransactionState> transactions; |
| 6007 | transactions.emplace_back(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 6008 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6009 | if (mLegacyFrontEndEnabled) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6010 | applyTransactions(transactions, VsyncId{0}); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6011 | } else { |
| 6012 | applyAndCommitDisplayTransactionStates(transactions); |
| 6013 | } |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 6014 | |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6015 | { |
| 6016 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6017 | |
| 6018 | // In case of a restart, ensure all displays are off. |
| 6019 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6020 | setPowerModeInternal(getDisplayDeviceLocked(id), hal::PowerMode::OFF); |
| 6021 | } |
| 6022 | |
| 6023 | // Power on all displays. The primary display is first, so becomes the active display. Also, |
| 6024 | // the DisplayCapability set of a display is populated on its first powering on. Do this now |
| 6025 | // before responding to any Binder query from DisplayManager about display capabilities. |
| 6026 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6027 | setPowerModeInternal(getDisplayDeviceLocked(id), hal::PowerMode::ON); |
| 6028 | } |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6029 | } |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 6030 | } |
| 6031 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6032 | void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6033 | if (display->isVirtual()) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6034 | // TODO(b/241285876): This code path should not be reachable, so enforce this at compile |
| 6035 | // time. |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 6036 | ALOGE("%s: Invalid operation on virtual display", __func__); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6037 | return; |
| 6038 | } |
| 6039 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6040 | const auto displayId = display->getPhysicalId(); |
| 6041 | 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] | 6042 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6043 | const auto currentMode = display->getPowerMode(); |
| 6044 | if (currentMode == mode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6045 | return; |
| 6046 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6047 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6048 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 6049 | .transform(&PhysicalDisplay::isInternal) |
| 6050 | .value_or(false); |
| 6051 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 6052 | const auto activeDisplay = getDisplayDeviceLocked(mActiveDisplayId); |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 6053 | |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6054 | ALOGW_IF(display != activeDisplay && isInternalDisplay && activeDisplay && |
| 6055 | activeDisplay->isPoweredOn(), |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 6056 | "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] | 6057 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6058 | display->setPowerMode(mode); |
| 6059 | |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 6060 | const auto activeMode = display->refreshRateSelector().getActiveMode().modePtr; |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6061 | if (currentMode == hal::PowerMode::OFF) { |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 6062 | // Turn on the display |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6063 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 6064 | // Activate the display (which involves a modeset to the active mode) when the inner or |
| 6065 | // outer display of a foldable is powered on. This condition relies on the above |
| 6066 | // DisplayDevice::setPowerMode. If `display` and `activeDisplay` are the same display, |
| 6067 | // then the `activeDisplay->isPoweredOn()` below is true, such that the display is not |
| 6068 | // activated every time it is powered on. |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6069 | // |
| 6070 | // TODO(b/255635821): Remove the concept of active display. |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 6071 | if (isInternalDisplay && (!activeDisplay || !activeDisplay->isPoweredOn())) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 6072 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 6073 | } |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6074 | |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6075 | if (displayId == mActiveDisplayId) { |
| 6076 | // TODO(b/281692563): Merge the syscalls. For now, keep uclamp in a separate syscall and |
| 6077 | // set it before SCHED_FIFO due to b/190237315. |
| 6078 | if (setSchedAttr(true) != NO_ERROR) { |
| 6079 | ALOGW("Failed to set uclamp.min after powering on active display: %s", |
| 6080 | strerror(errno)); |
| 6081 | } |
| 6082 | if (setSchedFifo(true) != NO_ERROR) { |
| 6083 | ALOGW("Failed to set SCHED_FIFO after powering on active display: %s", |
| 6084 | strerror(errno)); |
| 6085 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 6086 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6087 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6088 | getHwComposer().setPowerMode(displayId, mode); |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6089 | if (mode != hal::PowerMode::DOZE_SUSPEND && |
| 6090 | (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present())) { |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6091 | const bool enable = |
| 6092 | mScheduler->getVsyncSchedule(displayId)->getPendingHardwareVsyncState(); |
| 6093 | requestHardwareVsync(displayId, enable); |
| 6094 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6095 | if (displayId == mActiveDisplayId) { |
| 6096 | mScheduler->enableSyntheticVsync(false); |
| 6097 | } |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6098 | |
| 6099 | constexpr bool kAllowToEnable = true; |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 6100 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, activeMode.get()); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6101 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6102 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6103 | mVisibleRegionsDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6104 | scheduleComposite(FrameHint::kActive); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6105 | } else if (mode == hal::PowerMode::OFF) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6106 | const bool currentModeNotDozeSuspend = (currentMode != hal::PowerMode::DOZE_SUSPEND); |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 6107 | // Turn off the display |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6108 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 6109 | if (const auto display = getActivatableDisplay()) { |
| 6110 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
| 6111 | } else { |
| 6112 | if (setSchedFifo(false) != NO_ERROR) { |
| 6113 | ALOGW("Failed to set SCHED_OTHER after powering off active display: %s", |
| 6114 | strerror(errno)); |
| 6115 | } |
| 6116 | if (setSchedAttr(false) != NO_ERROR) { |
| 6117 | ALOGW("Failed set uclamp.min after powering off active display: %s", |
| 6118 | strerror(errno)); |
| 6119 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6120 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6121 | if (currentModeNotDozeSuspend) { |
| 6122 | if (!FlagManager::getInstance().multithreaded_present()) { |
| 6123 | mScheduler->disableHardwareVsync(displayId, true); |
| 6124 | } |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 6125 | mScheduler->enableSyntheticVsync(); |
| 6126 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6127 | } |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 6128 | } |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6129 | if (currentModeNotDozeSuspend && FlagManager::getInstance().multithreaded_present()) { |
| 6130 | constexpr bool kDisallow = true; |
| 6131 | mScheduler->disableHardwareVsync(displayId, kDisallow); |
| 6132 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6133 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6134 | // We must disable VSYNC *before* turning off the display. The call to |
| 6135 | // disableHardwareVsync, above, schedules a task to turn it off after |
| 6136 | // this method returns. But by that point, the display is OFF, so the |
| 6137 | // call just updates the pending state, without actually disabling |
| 6138 | // VSYNC. |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6139 | requestHardwareVsync(displayId, false); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6140 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6141 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6142 | mVisibleRegionsDirty = true; |
| 6143 | // from this point on, SF will stop drawing on this display |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6144 | } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6145 | // Update display while dozing |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6146 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6147 | if (currentMode == hal::PowerMode::DOZE_SUSPEND && |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6148 | (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present())) { |
| 6149 | if (displayId == mActiveDisplayId) { |
| 6150 | ALOGI("Force repainting for DOZE_SUSPEND -> DOZE or ON."); |
| 6151 | mVisibleRegionsDirty = true; |
| 6152 | scheduleRepaint(); |
| 6153 | mScheduler->enableSyntheticVsync(false); |
| 6154 | } |
| 6155 | constexpr bool kAllowToEnable = true; |
| 6156 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, activeMode.get()); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6157 | } |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6158 | } else if (mode == hal::PowerMode::DOZE_SUSPEND) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6159 | // Leave display going to doze |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6160 | if (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present()) { |
| 6161 | constexpr bool kDisallow = true; |
| 6162 | mScheduler->disableHardwareVsync(displayId, kDisallow); |
| 6163 | } |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6164 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6165 | mScheduler->enableSyntheticVsync(); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6166 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6167 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6168 | } else { |
Matthew Bouyack | 38d4961 | 2017-05-12 12:49:32 -0700 | [diff] [blame] | 6169 | ALOGE("Attempting to set unknown power mode: %d\n", mode); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6170 | getHwComposer().setPowerMode(displayId, mode); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6171 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6172 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6173 | if (displayId == mActiveDisplayId) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 6174 | mTimeStats->setPowerMode(mode); |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 6175 | mScheduler->setActiveDisplayPowerModeForRefreshRateStats(mode); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 6176 | } |
| 6177 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6178 | mScheduler->setDisplayPowerMode(displayId, mode); |
| 6179 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6180 | 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] | 6181 | } |
| 6182 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6183 | void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) { |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 6184 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 6185 | kMainThreadContext) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 6186 | const auto display = getDisplayDeviceLocked(displayToken); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6187 | if (!display) { |
| 6188 | ALOGE("Attempt to set power mode %d for invalid display token %p", mode, |
| 6189 | displayToken.get()); |
| 6190 | } else if (display->isVirtual()) { |
| 6191 | ALOGW("Attempt to set power mode %d for virtual display", mode); |
| 6192 | } else { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6193 | setPowerModeInternal(display, static_cast<hal::PowerMode>(mode)); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6194 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6195 | }); |
| 6196 | |
| 6197 | future.wait(); |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 6198 | } |
| 6199 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 6200 | status_t SurfaceFlinger::doDump(int fd, const DumpArgs& args, bool asProto) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6201 | std::string result; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 6202 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 6203 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6204 | const int pid = ipc->getCallingPid(); |
| 6205 | const int uid = ipc->getCallingUid(); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 6206 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 6207 | if ((uid != AID_SHELL) && |
| 6208 | !PermissionCache::checkPermission(sDump, pid, uid)) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6209 | StringAppendF(&result, "Permission Denial: can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 6210 | pid, uid); |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6211 | write(fd, result.c_str(), result.size()); |
| 6212 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6213 | } |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 6214 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6215 | if (asProto && args.empty()) { |
| 6216 | perfetto::protos::LayersTraceFileProto traceFileProto = |
| 6217 | mLayerTracing.createTraceFileProto(); |
| 6218 | perfetto::protos::LayersSnapshotProto* layersTrace = traceFileProto.add_entry(); |
| 6219 | perfetto::protos::LayersProto layersProto = dumpProtoFromMainThread(); |
| 6220 | layersTrace->mutable_layers()->Swap(&layersProto); |
| 6221 | auto displayProtos = dumpDisplayProto(); |
| 6222 | layersTrace->mutable_displays()->Swap(&displayProtos); |
| 6223 | result.append(traceFileProto.SerializeAsString()); |
| 6224 | write(fd, result.c_str(), result.size()); |
| 6225 | return NO_ERROR; |
| 6226 | } |
| 6227 | |
| 6228 | static const std::unordered_map<std::string, Dumper> dumpers = { |
| 6229 | {"--comp-displays"s, dumper(&SurfaceFlinger::dumpCompositionDisplays)}, |
| 6230 | {"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)}, |
| 6231 | {"--displays"s, dumper(&SurfaceFlinger::dumpDisplays)}, |
| 6232 | {"--edid"s, argsDumper(&SurfaceFlinger::dumpRawDisplayIdentificationData)}, |
| 6233 | {"--events"s, dumper(&SurfaceFlinger::dumpEvents)}, |
| 6234 | {"--frametimeline"s, argsDumper(&SurfaceFlinger::dumpFrameTimeline)}, |
| 6235 | {"--frontend"s, mainThreadDumper(&SurfaceFlinger::dumpFrontEnd)}, |
| 6236 | {"--hdrinfo"s, dumper(&SurfaceFlinger::dumpHdrInfo)}, |
| 6237 | {"--hwclayers"s, mainThreadDumper(&SurfaceFlinger::dumpHwcLayersMinidump)}, |
| 6238 | {"--latency"s, argsDumper(&SurfaceFlinger::dumpStatsLocked)}, |
| 6239 | {"--latency-clear"s, argsDumper(&SurfaceFlinger::clearStatsLocked)}, |
| 6240 | {"--list"s, dumper(&SurfaceFlinger::listLayersLocked)}, |
| 6241 | {"--planner"s, argsDumper(&SurfaceFlinger::dumpPlannerInfo)}, |
| 6242 | {"--scheduler"s, dumper(&SurfaceFlinger::dumpScheduler)}, |
| 6243 | {"--timestats"s, protoDumper(&SurfaceFlinger::dumpTimeStats)}, |
| 6244 | {"--vsync"s, dumper(&SurfaceFlinger::dumpVsync)}, |
| 6245 | {"--wide-color"s, dumper(&SurfaceFlinger::dumpWideColorInfo)}, |
| 6246 | }; |
| 6247 | |
| 6248 | const auto flag = args.empty() ? ""s : std::string(String8(args[0])); |
| 6249 | if (const auto it = dumpers.find(flag); it != dumpers.end()) { |
| 6250 | (it->second)(args, asProto, result); |
| 6251 | write(fd, result.c_str(), result.size()); |
| 6252 | return NO_ERROR; |
| 6253 | } |
| 6254 | |
| 6255 | // Traversal of drawing state must happen on the main thread. |
| 6256 | // Otherwise, SortedVector may have shared ownership during concurrent |
| 6257 | // traversals, which can result in use-after-frees. |
| 6258 | std::string compositionLayers; |
| 6259 | mScheduler |
| 6260 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 6261 | dumpVisibleFrontEnd(compositionLayers); |
| 6262 | }) |
| 6263 | .get(); |
| 6264 | dumpAll(args, compositionLayers, result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6265 | write(fd, result.c_str(), result.size()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6266 | return NO_ERROR; |
| 6267 | } |
| 6268 | |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 6269 | status_t SurfaceFlinger::dumpCritical(int fd, const DumpArgs&, bool asProto) { |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 6270 | return doDump(fd, DumpArgs(), asProto); |
| 6271 | } |
| 6272 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6273 | void SurfaceFlinger::listLayersLocked(std::string& result) const { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6274 | mCurrentState.traverseInZOrder( |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 6275 | [&](Layer* layer) { StringAppendF(&result, "%s\n", layer->getDebugName()); }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6276 | } |
| 6277 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6278 | void SurfaceFlinger::dumpStatsLocked(const DumpArgs& args, std::string& result) const { |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 6279 | StringAppendF(&result, "%" PRId64 "\n", getVsyncPeriodFromHWC()); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6280 | if (args.size() < 2) return; |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 6281 | |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6282 | const auto name = String8(args[1]); |
| 6283 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 6284 | if (layer->getName() == name.c_str()) { |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6285 | layer->dumpFrameStats(result); |
| 6286 | } |
| 6287 | }); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6288 | } |
| 6289 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6290 | void SurfaceFlinger::clearStatsLocked(const DumpArgs& args, std::string&) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 6291 | const bool clearAll = args.size() < 2; |
| 6292 | const auto name = clearAll ? String8() : String8(args[1]); |
| 6293 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 6294 | mCurrentState.traverse([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 6295 | if (clearAll || layer->getName() == name.c_str()) { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 6296 | layer->clearFrameStats(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6297 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 6298 | }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6299 | } |
| 6300 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6301 | void SurfaceFlinger::dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const { |
| 6302 | mTimeStats->parseArgs(asProto, args, result); |
| 6303 | } |
| 6304 | |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 6305 | void SurfaceFlinger::dumpFrameTimeline(const DumpArgs& args, std::string& result) const { |
| 6306 | mFrameTimeline->parseArgs(args, result); |
| 6307 | } |
| 6308 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6309 | void SurfaceFlinger::logFrameStats(TimePoint now) { |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6310 | static TimePoint sTimestamp = now; |
| 6311 | if (now - sTimestamp < 30min) return; |
| 6312 | sTimestamp = now; |
| 6313 | |
| 6314 | ATRACE_CALL(); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6315 | mDrawingState.traverse([&](Layer* layer) { layer->logFrameStats(); }); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 6316 | } |
| 6317 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6318 | void SurfaceFlinger::appendSfConfigString(std::string& result) const { |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 6319 | result.append(" [sf"); |
Fabien Sanglard | c93afd5 | 2017-03-13 13:02:42 -0700 | [diff] [blame] | 6320 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6321 | StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); |
| 6322 | StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 6323 | StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%zu", |
| 6324 | getHwComposer().getMaxVirtualDisplayDimension()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6325 | StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6326 | StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6327 | maxFrameBufferAcquiredBuffers); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 6328 | result.append("]"); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6329 | } |
| 6330 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6331 | void SurfaceFlinger::dumpScheduler(std::string& result) const { |
| 6332 | utils::Dumper dumper{result}; |
| 6333 | |
| 6334 | mScheduler->dump(dumper); |
| 6335 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6336 | // TODO(b/241285876): Move to DisplayModeController. |
| 6337 | dumper.dump("debugDisplayModeSetByBackdoor"sv, mDebugDisplayModeSetByBackdoor); |
| 6338 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6339 | |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6340 | StringAppendF(&result, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6341 | " present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64 |
| 6342 | " ns\n\n", |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6343 | dispSyncPresentTimeOffset, getVsyncPeriodFromHWC()); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6344 | } |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6345 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6346 | void SurfaceFlinger::dumpEvents(std::string& result) const { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 6347 | mScheduler->dump(scheduler::Cycle::Render, result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6348 | } |
| 6349 | |
| 6350 | void SurfaceFlinger::dumpVsync(std::string& result) const { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 6351 | mScheduler->dumpVsync(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6352 | } |
| 6353 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 6354 | void SurfaceFlinger::dumpPlannerInfo(const DumpArgs& args, std::string& result) const { |
| 6355 | for (const auto& [token, display] : mDisplays) { |
| 6356 | const auto compositionDisplay = display->getCompositionDisplay(); |
| 6357 | compositionDisplay->dumpPlannerInfo(args, result); |
| 6358 | } |
| 6359 | } |
| 6360 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6361 | void SurfaceFlinger::dumpCompositionDisplays(std::string& result) const { |
| 6362 | for (const auto& [token, display] : mDisplays) { |
| 6363 | display->getCompositionDisplay()->dump(result); |
| 6364 | result += '\n'; |
| 6365 | } |
| 6366 | } |
| 6367 | |
| 6368 | void SurfaceFlinger::dumpDisplays(std::string& result) const { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6369 | utils::Dumper dumper{result}; |
| 6370 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6371 | for (const auto& [id, display] : mPhysicalDisplays) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6372 | utils::Dumper::Section section(dumper, ftl::Concat("Display ", id.value).str()); |
| 6373 | |
| 6374 | display.snapshot().dump(dumper); |
| 6375 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6376 | if (const auto device = getDisplayDeviceLocked(id)) { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6377 | device->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6378 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6379 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6380 | |
| 6381 | for (const auto& [token, display] : mDisplays) { |
| 6382 | if (display->isVirtual()) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6383 | const auto displayId = display->getId(); |
| 6384 | utils::Dumper::Section section(dumper, |
| 6385 | ftl::Concat("Virtual Display ", displayId.value).str()); |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6386 | display->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6387 | } |
| 6388 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6389 | } |
| 6390 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6391 | void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 6392 | for (const auto& [token, display] : mDisplays) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6393 | const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6394 | if (!displayId) { |
| 6395 | continue; |
| 6396 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6397 | const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId); |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6398 | if (!hwcDisplayId) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6399 | continue; |
| 6400 | } |
| 6401 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6402 | StringAppendF(&result, |
| 6403 | "Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), |
| 6404 | *hwcDisplayId); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6405 | uint8_t port; |
| 6406 | DisplayIdentificationData data; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6407 | if (!getHwComposer().getDisplayIdentificationData(*hwcDisplayId, &port, &data)) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6408 | result.append("no identification data\n"); |
| 6409 | continue; |
| 6410 | } |
| 6411 | |
| 6412 | if (!isEdid(data)) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6413 | result.append("unknown identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6414 | continue; |
| 6415 | } |
| 6416 | |
| 6417 | const auto edid = parseEdid(data); |
| 6418 | if (!edid) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6419 | result.append("invalid EDID\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6420 | continue; |
| 6421 | } |
| 6422 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6423 | StringAppendF(&result, "port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6424 | result.append(edid->displayName.data(), edid->displayName.length()); |
| 6425 | result.append("\"\n"); |
| 6426 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6427 | } |
| 6428 | |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6429 | void SurfaceFlinger::dumpRawDisplayIdentificationData(const DumpArgs& args, |
| 6430 | std::string& result) const { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 6431 | hal::HWDisplayId hwcDisplayId; |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6432 | uint8_t port; |
| 6433 | DisplayIdentificationData data; |
| 6434 | |
| 6435 | if (args.size() > 1 && base::ParseUint(String8(args[1]), &hwcDisplayId) && |
| 6436 | getHwComposer().getDisplayIdentificationData(hwcDisplayId, &port, &data)) { |
| 6437 | result.append(reinterpret_cast<const char*>(data.data()), data.size()); |
| 6438 | } |
| 6439 | } |
| 6440 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6441 | void SurfaceFlinger::dumpWideColorInfo(std::string& result) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6442 | StringAppendF(&result, "Device supports wide color: %d\n", mSupportsWideColor); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6443 | StringAppendF(&result, "DisplayColorSetting: %s\n", |
| 6444 | decodeDisplayColorSetting(mDisplayColorSetting).c_str()); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6445 | |
| 6446 | // TODO: print out if wide-color mode is active or not |
| 6447 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6448 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6449 | StringAppendF(&result, "Display %s color modes:\n", to_string(id).c_str()); |
| 6450 | for (const auto mode : display.snapshot().colorModes()) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6451 | StringAppendF(&result, " %s (%d)\n", decodeColorMode(mode).c_str(), mode); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6452 | } |
| 6453 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6454 | if (const auto display = getDisplayDeviceLocked(id)) { |
| 6455 | ui::ColorMode currentMode = display->getCompositionDisplay()->getState().colorMode; |
| 6456 | StringAppendF(&result, " Current color mode: %s (%d)\n", |
| 6457 | decodeColorMode(currentMode).c_str(), currentMode); |
| 6458 | } |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6459 | } |
| 6460 | result.append("\n"); |
| 6461 | } |
| 6462 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6463 | void SurfaceFlinger::dumpHdrInfo(std::string& result) const { |
| 6464 | for (const auto& [displayId, listener] : mHdrLayerInfoListeners) { |
| 6465 | StringAppendF(&result, "HDR events for display %" PRIu64 "\n", displayId.value); |
| 6466 | listener->dump(result); |
| 6467 | result.append("\n"); |
| 6468 | } |
| 6469 | } |
| 6470 | |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6471 | void SurfaceFlinger::dumpFrontEnd(std::string& result) { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6472 | std::ostringstream out; |
| 6473 | out << "\nComposition list\n"; |
| 6474 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6475 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 6476 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 6477 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 6478 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6479 | } |
| 6480 | out << " " << *snapshot << "\n"; |
| 6481 | } |
| 6482 | |
| 6483 | out << "\nInput list\n"; |
| 6484 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6485 | mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6486 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 6487 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 6488 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6489 | } |
| 6490 | out << " " << snapshot << "\n"; |
| 6491 | }); |
| 6492 | |
| 6493 | out << "\nLayer Hierarchy\n" |
| 6494 | << mLayerHierarchyBuilder.getHierarchy().dump() << "\nOffscreen Hierarchy\n" |
| 6495 | << mLayerHierarchyBuilder.getOffscreenHierarchy().dump() << "\n\n"; |
| 6496 | result.append(out.str()); |
| 6497 | } |
| 6498 | |
| 6499 | void SurfaceFlinger::dumpVisibleFrontEnd(std::string& result) { |
| 6500 | if (!mLayerLifecycleManagerEnabled) { |
| 6501 | StringAppendF(&result, "Composition layers\n"); |
| 6502 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 6503 | auto* compositionState = layer->getCompositionState(); |
| 6504 | if (!compositionState || !compositionState->isVisible) return; |
| 6505 | android::base::StringAppendF(&result, "* Layer %p (%s)\n", layer, |
| 6506 | layer->getDebugName() ? layer->getDebugName() |
| 6507 | : "<unknown>"); |
| 6508 | compositionState->dump(result); |
| 6509 | }); |
| 6510 | |
| 6511 | StringAppendF(&result, "Offscreen Layers\n"); |
| 6512 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6513 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
| 6514 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
| 6515 | } |
| 6516 | } else { |
| 6517 | std::ostringstream out; |
| 6518 | out << "\nComposition list\n"; |
| 6519 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6520 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 6521 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 6522 | if (snapshot->hasSomethingToDraw()) { |
| 6523 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 6524 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 6525 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6526 | } |
| 6527 | out << " " << *snapshot << "\n"; |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6528 | } |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6529 | }); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6530 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6531 | out << "\nInput list\n"; |
| 6532 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6533 | mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6534 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 6535 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 6536 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6537 | } |
| 6538 | out << " " << snapshot << "\n"; |
| 6539 | }); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6540 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6541 | out << "\nLayer Hierarchy\n" |
| 6542 | << mLayerHierarchyBuilder.getHierarchy() << "\nOffscreen Hierarchy\n" |
| 6543 | << mLayerHierarchyBuilder.getOffscreenHierarchy() << "\n\n"; |
| 6544 | result = out.str(); |
| 6545 | dumpHwcLayersMinidump(result); |
| 6546 | } |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6547 | } |
| 6548 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6549 | perfetto::protos::LayersProto SurfaceFlinger::dumpDrawingStateProto(uint32_t traceFlags) const { |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 6550 | std::unordered_set<uint64_t> stackIdsToSkip; |
| 6551 | |
| 6552 | // Determine if virtual layers display should be skipped |
| 6553 | if ((traceFlags & LayerTracing::TRACE_VIRTUAL_DISPLAYS) == 0) { |
| 6554 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 6555 | if (display->isVirtual()) { |
| 6556 | stackIdsToSkip.insert(display->getLayerStack().id); |
| 6557 | } |
| 6558 | } |
| 6559 | } |
| 6560 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6561 | if (mLegacyFrontEndEnabled) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6562 | perfetto::protos::LayersProto layersProto; |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 6563 | for (const sp<Layer>& layer : mDrawingState.layersSortedByZ) { |
| 6564 | if (stackIdsToSkip.find(layer->getLayerStack().id) != stackIdsToSkip.end()) { |
| 6565 | continue; |
| 6566 | } |
| 6567 | layer->writeToProto(layersProto, traceFlags); |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 6568 | } |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 6569 | return layersProto; |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 6570 | } |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 6571 | |
Vishnu Nair | 22be349 | 2023-04-20 10:08:21 -0700 | [diff] [blame] | 6572 | return LayerProtoFromSnapshotGenerator(mLayerSnapshotBuilder, mFrontEndDisplayInfos, |
| 6573 | mLegacyLayers, traceFlags) |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 6574 | .generate(mLayerHierarchyBuilder.getHierarchy()); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6575 | } |
| 6576 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6577 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> |
| 6578 | SurfaceFlinger::dumpDisplayProto() const { |
| 6579 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> displays; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6580 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6581 | perfetto::protos::DisplayProto* displayProto = displays.Add(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6582 | displayProto->set_id(display->getId().value); |
| 6583 | displayProto->set_name(display->getDisplayName()); |
| 6584 | displayProto->set_layer_stack(display->getLayerStack().id); |
DoÄŸancan Emek | fc4b6ed | 2023-07-26 15:24:04 +0000 | [diff] [blame] | 6585 | |
| 6586 | if (!display->isVirtual()) { |
| 6587 | const auto dpi = display->refreshRateSelector().getActiveMode().modePtr->getDpi(); |
| 6588 | displayProto->set_dpi_x(dpi.x); |
| 6589 | displayProto->set_dpi_y(dpi.y); |
| 6590 | } |
| 6591 | |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6592 | LayerProtoHelper::writeSizeToProto(display->getWidth(), display->getHeight(), |
| 6593 | [&]() { return displayProto->mutable_size(); }); |
| 6594 | LayerProtoHelper::writeToProto(display->getLayerStackSpaceRect(), [&]() { |
| 6595 | return displayProto->mutable_layer_stack_space_rect(); |
| 6596 | }); |
| 6597 | LayerProtoHelper::writeTransformToProto(display->getTransform(), |
| 6598 | displayProto->mutable_transform()); |
Vishnu Nair | 791d48a | 2021-12-02 16:55:13 -0800 | [diff] [blame] | 6599 | displayProto->set_is_virtual(display->isVirtual()); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6600 | } |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 6601 | return displays; |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6602 | } |
| 6603 | |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 6604 | void SurfaceFlinger::dumpHwc(std::string& result) const { |
| 6605 | getHwComposer().dump(result); |
| 6606 | } |
| 6607 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6608 | void SurfaceFlinger::dumpOffscreenLayersProto(perfetto::protos::LayersProto& layersProto, |
| 6609 | uint32_t traceFlags) const { |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6610 | // Add a fake invisible root layer to the proto output and parent all the offscreen layers to |
| 6611 | // it. |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6612 | perfetto::protos::LayerProto* rootProto = layersProto.add_layers(); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6613 | const int32_t offscreenRootLayerId = INT32_MAX - 2; |
| 6614 | rootProto->set_id(offscreenRootLayerId); |
| 6615 | rootProto->set_name("Offscreen Root"); |
Vishnu Nair | d5aeb61 | 2019-09-20 14:39:39 -0700 | [diff] [blame] | 6616 | rootProto->set_parent(-1); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6617 | |
| 6618 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6619 | // Add layer as child of the fake root |
| 6620 | rootProto->add_children(offscreenLayer->sequence); |
| 6621 | |
| 6622 | // Add layer |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6623 | auto* layerProto = offscreenLayer->writeToProto(layersProto, traceFlags); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6624 | layerProto->set_parent(offscreenRootLayerId); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6625 | } |
| 6626 | } |
| 6627 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6628 | perfetto::protos::LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) { |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 6629 | return mScheduler->schedule([=, this] { return dumpDrawingStateProto(traceFlags); }).get(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 6630 | } |
| 6631 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6632 | void SurfaceFlinger::dumpOffscreenLayers(std::string& result) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6633 | auto future = mScheduler->schedule([this] { |
| 6634 | std::string result; |
| 6635 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6636 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
Vishnu Nair | 76554eb | 2022-12-09 03:38:36 +0000 | [diff] [blame] | 6637 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6638 | } |
| 6639 | return result; |
| 6640 | }); |
| 6641 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6642 | result.append("Offscreen Layers:\n"); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6643 | result.append(future.get()); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6644 | } |
| 6645 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6646 | void SurfaceFlinger::dumpHwcLayersMinidumpLockedLegacy(std::string& result) const { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6647 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6648 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6649 | if (!displayId) { |
| 6650 | continue; |
| 6651 | } |
| 6652 | |
| 6653 | 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] | 6654 | displayId == mActiveDisplayId ? "active" : "inactive"); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6655 | Layer::miniDumpHeader(result); |
| 6656 | |
| 6657 | const DisplayDevice& ref = *display; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6658 | mDrawingState.traverseInZOrder([&](Layer* layer) { layer->miniDumpLegacy(result, ref); }); |
| 6659 | result.append("\n"); |
| 6660 | } |
| 6661 | } |
| 6662 | |
| 6663 | void SurfaceFlinger::dumpHwcLayersMinidump(std::string& result) const { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6664 | if (!mLayerLifecycleManagerEnabled) { |
| 6665 | return dumpHwcLayersMinidumpLockedLegacy(result); |
| 6666 | } |
| 6667 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6668 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6669 | if (!displayId) { |
| 6670 | continue; |
| 6671 | } |
| 6672 | |
| 6673 | StringAppendF(&result, "Display %s (%s) HWC layers:\n", to_string(*displayId).c_str(), |
| 6674 | displayId == mActiveDisplayId ? "active" : "inactive"); |
| 6675 | Layer::miniDumpHeader(result); |
| 6676 | |
| 6677 | const DisplayDevice& ref = *display; |
| 6678 | mLayerSnapshotBuilder.forEachVisibleSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6679 | if (!snapshot.hasSomethingToDraw() || |
| 6680 | ref.getLayerStack() != snapshot.outputFilter.layerStack) { |
| 6681 | return; |
| 6682 | } |
| 6683 | auto it = mLegacyLayers.find(snapshot.sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 6684 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 6685 | "Couldnt find layer object for %s", |
| 6686 | snapshot.getDebugString().c_str()); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6687 | it->second->miniDump(result, snapshot, ref); |
| 6688 | }); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6689 | result.append("\n"); |
| 6690 | } |
| 6691 | } |
| 6692 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6693 | void SurfaceFlinger::dumpAll(const DumpArgs& args, const std::string& compositionLayers, |
| 6694 | std::string& result) const { |
| 6695 | TimedLock lock(mStateLock, s2ns(1), __func__); |
| 6696 | if (!lock.locked()) { |
| 6697 | StringAppendF(&result, "Dumping without lock after timeout: %s (%d)\n", |
| 6698 | strerror(-lock.status), lock.status); |
| 6699 | } |
| 6700 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6701 | const bool colorize = !args.empty() && args[0] == String16("--color"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6702 | Colorizer colorizer(colorize); |
| 6703 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6704 | // figure out if we're stuck somewhere |
| 6705 | const nsecs_t now = systemTime(); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6706 | const nsecs_t inTransaction(mDebugInTransaction); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6707 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 6708 | |
| 6709 | /* |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6710 | * Dump library configuration. |
| 6711 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6712 | |
| 6713 | colorizer.bold(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6714 | result.append("Build configuration:"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6715 | colorizer.reset(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6716 | appendSfConfigString(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6717 | result.append("\n"); |
| 6718 | |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6719 | result.append("\nDisplay identification data:\n"); |
| 6720 | dumpDisplayIdentificationData(result); |
| 6721 | |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6722 | result.append("\nWide-Color information:\n"); |
| 6723 | dumpWideColorInfo(result); |
| 6724 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6725 | dumpHdrInfo(result); |
| 6726 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6727 | colorizer.bold(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6728 | result.append("Sync configuration: "); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6729 | colorizer.reset(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6730 | result.append(SyncFeatures::getInstance().toString()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6731 | result.append("\n\n"); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6732 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6733 | colorizer.bold(result); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6734 | result.append("Scheduler:\n"); |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6735 | colorizer.reset(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6736 | dumpScheduler(result); |
| 6737 | dumpEvents(result); |
| 6738 | dumpVsync(result); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 6739 | result.append("\n"); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6740 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6741 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6742 | * Dump the visible layer list |
| 6743 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6744 | colorizer.bold(result); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6745 | StringAppendF(&result, "SurfaceFlinger New Frontend Enabled:%s\n", |
| 6746 | mLayerLifecycleManagerEnabled ? "true" : "false"); |
| 6747 | StringAppendF(&result, "Active Layers - layers with client handles (count = %zu)\n", |
| 6748 | mNumLayers.load()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6749 | colorizer.reset(result); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6750 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 6751 | result.append(compositionLayers); |
Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 6752 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6753 | colorizer.bold(result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6754 | StringAppendF(&result, "Displays (%zu entries)\n", mDisplays.size()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6755 | colorizer.reset(result); |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6756 | dumpDisplays(result); |
| 6757 | dumpCompositionDisplays(result); |
| 6758 | result.push_back('\n'); |
Lloyd Pique | c3cb729 | 2019-05-17 15:25:14 -0700 | [diff] [blame] | 6759 | |
| 6760 | mCompositionEngine->dump(result); |
| 6761 | |
| 6762 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6763 | * Dump SurfaceFlinger global state |
| 6764 | */ |
| 6765 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6766 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6767 | result.append("SurfaceFlinger global state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6768 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6769 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 6770 | getRenderEngine().dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6771 | |
Robert Carr | beba6f0 | 2021-02-10 21:06:27 -0800 | [diff] [blame] | 6772 | result.append("ClientCache state:\n"); |
| 6773 | ClientCache::getInstance().dump(result); |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 6774 | DebugEGLImageTracker::getInstance()->dump(result); |
| 6775 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6776 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 6777 | display->getCompositionDisplay()->getState().undefinedRegion.dump(result, |
| 6778 | "undefinedRegion"); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 6779 | StringAppendF(&result, " orientation=%s, isPoweredOn=%d\n", |
| 6780 | toCString(display->getOrientation()), display->isPoweredOn()); |
Lloyd Pique | 2ae2b3b | 2017-12-14 17:18:17 -0800 | [diff] [blame] | 6781 | } |
Carlos Martinez Romero | 779dc1f | 2022-10-27 23:23:30 +0000 | [diff] [blame] | 6782 | StringAppendF(&result, " transaction-flags : %08x\n", mTransactionFlags.load()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6783 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 6784 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6785 | std::string fps, xDpi, yDpi; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 6786 | if (const auto activeModePtr = |
| 6787 | display->refreshRateSelector().getActiveMode().modePtr.get()) { |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 6788 | fps = to_string(activeModePtr->getVsyncRate()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6789 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6790 | const auto dpi = activeModePtr->getDpi(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6791 | xDpi = base::StringPrintf("%.2f", dpi.x); |
| 6792 | yDpi = base::StringPrintf("%.2f", dpi.y); |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6793 | } else { |
| 6794 | fps = "unknown"; |
| 6795 | xDpi = "unknown"; |
| 6796 | yDpi = "unknown"; |
| 6797 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6798 | StringAppendF(&result, |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6799 | " refresh-rate : %s\n" |
| 6800 | " x-dpi : %s\n" |
| 6801 | " y-dpi : %s\n", |
| 6802 | fps.c_str(), xDpi.c_str(), yDpi.c_str()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6803 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6804 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6805 | StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6806 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6807 | result.append("\nTransaction tracing: "); |
| 6808 | if (mTransactionTracing) { |
| 6809 | result.append("enabled\n"); |
| 6810 | mTransactionTracing->dump(result); |
| 6811 | } else { |
| 6812 | result.append("disabled\n"); |
| 6813 | } |
| 6814 | result.push_back('\n'); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6815 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6816 | if (mLegacyFrontEndEnabled) { |
| 6817 | dumpHwcLayersMinidumpLockedLegacy(result); |
| 6818 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6819 | |
Ady Abraham | 2790e9f | 2021-04-28 13:14:20 -0700 | [diff] [blame] | 6820 | { |
| 6821 | DumpArgs plannerArgs; |
| 6822 | plannerArgs.add(); // first argument is ignored |
| 6823 | plannerArgs.add(String16("--layers")); |
| 6824 | dumpPlannerInfo(plannerArgs, result); |
| 6825 | } |
| 6826 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6827 | /* |
| 6828 | * Dump HWComposer state |
| 6829 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6830 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6831 | result.append("h/w composer state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6832 | colorizer.reset(result); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6833 | const bool hwcDisabled = mDebugDisableHWC || mDebugFlashDelay; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6834 | StringAppendF(&result, " h/w composer %s\n", hwcDisabled ? "disabled" : "enabled"); |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 6835 | dumpHwc(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6836 | |
| 6837 | /* |
| 6838 | * Dump gralloc state |
| 6839 | */ |
| 6840 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 6841 | alloc.dump(result); |
Karthik Ravi Shankar | 171155a | 2017-06-28 15:40:24 -0700 | [diff] [blame] | 6842 | |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6843 | /* |
| 6844 | * Dump flag/property manager state |
| 6845 | */ |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 6846 | FlagManager::getInstance().dump(result); |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6847 | |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 6848 | result.append(mTimeStats->miniDump()); |
| 6849 | result.append("\n"); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 6850 | |
| 6851 | result.append("Window Infos:\n"); |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 6852 | auto windowInfosDebug = mWindowInfosListenerInvoker->getDebugInfo(); |
| 6853 | StringAppendF(&result, " max send vsync id: %" PRId64 "\n", |
| 6854 | ftl::to_underlying(windowInfosDebug.maxSendDelayVsyncId)); |
| 6855 | StringAppendF(&result, " max send delay (ns): %" PRId64 " ns\n", |
| 6856 | windowInfosDebug.maxSendDelayDuration); |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 6857 | StringAppendF(&result, " unsent messages: %zu\n", windowInfosDebug.pendingMessageCount); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 6858 | result.append("\n"); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6859 | } |
| 6860 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6861 | mat4 SurfaceFlinger::calculateColorMatrix(float saturation) { |
| 6862 | if (saturation == 1) { |
| 6863 | return mat4(); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6864 | } |
| 6865 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6866 | float3 luminance{0.213f, 0.715f, 0.072f}; |
| 6867 | luminance *= 1.0f - saturation; |
| 6868 | mat4 saturationMatrix = mat4(vec4{luminance.r + saturation, luminance.r, luminance.r, 0.0f}, |
| 6869 | vec4{luminance.g, luminance.g + saturation, luminance.g, 0.0f}, |
| 6870 | vec4{luminance.b, luminance.b, luminance.b + saturation, 0.0f}, |
| 6871 | vec4{0.0f, 0.0f, 0.0f, 1.0f}); |
| 6872 | return saturationMatrix; |
| 6873 | } |
| 6874 | |
| 6875 | void SurfaceFlinger::updateColorMatrixLocked() { |
| 6876 | mat4 colorMatrix = |
| 6877 | mClientColorMatrix * calculateColorMatrix(mGlobalSaturationFactor) * mDaltonizer(); |
| 6878 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6879 | if (mCurrentState.colorMatrix != colorMatrix) { |
| 6880 | mCurrentState.colorMatrix = colorMatrix; |
| 6881 | mCurrentState.colorMatrixChanged = true; |
| 6882 | setTransactionFlags(eTransactionNeeded); |
| 6883 | } |
| 6884 | } |
| 6885 | |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6886 | status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6887 | #pragma clang diagnostic push |
| 6888 | #pragma clang diagnostic error "-Wswitch-enum" |
| 6889 | switch (static_cast<ISurfaceComposerTag>(code)) { |
| 6890 | // These methods should at minimum make sure that the client requested |
| 6891 | // access to SF. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6892 | case GET_HDR_CAPABILITIES: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6893 | case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6894 | case GET_GAME_CONTENT_TYPE_SUPPORT: |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6895 | case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6896 | // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary |
| 6897 | // permission dynamically. Don't use the permission cache for this check. |
| 6898 | bool usePermissionCache = code != OVERRIDE_HDR_TYPES; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6899 | if (!callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 6900 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6901 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", |
| 6902 | ipc->getCallingPid(), ipc->getCallingUid()); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6903 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6904 | } |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 6905 | return OK; |
| 6906 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6907 | // The following calls are currently used by clients that do not |
| 6908 | // request necessary permissions. However, they do not expose any secret |
| 6909 | // information, so it is OK to pass them. |
Peiyong Lin | d1fedb4 | 2019-03-11 17:48:41 -0700 | [diff] [blame] | 6910 | case GET_ACTIVE_COLOR_MODE: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6911 | case GET_ACTIVE_DISPLAY_MODE: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6912 | case GET_DISPLAY_COLOR_MODES: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6913 | case GET_DISPLAY_MODES: |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 6914 | case GET_SCHEDULING_POLICY: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6915 | // Calling setTransactionState is safe, because you need to have been |
| 6916 | // granted a reference to Client* and Handle* to do anything with it. |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6917 | case SET_TRANSACTION_STATE: { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 6918 | // This is not sensitive information, so should not require permission control. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6919 | return OK; |
| 6920 | } |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 6921 | case BOOT_FINISHED: |
| 6922 | // Used by apps to hook Choreographer to SurfaceFlinger. |
| 6923 | case CREATE_DISPLAY_EVENT_CONNECTION: |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6924 | case CREATE_CONNECTION: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6925 | case CREATE_DISPLAY: |
| 6926 | case DESTROY_DISPLAY: |
| 6927 | case GET_PRIMARY_PHYSICAL_DISPLAY_ID: |
| 6928 | case GET_PHYSICAL_DISPLAY_IDS: |
| 6929 | case GET_PHYSICAL_DISPLAY_TOKEN: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6930 | case AUTHENTICATE_SURFACE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6931 | case SET_POWER_MODE: |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 6932 | case GET_SUPPORTED_FRAME_TIMESTAMPS: |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6933 | case GET_DISPLAY_STATE: |
| 6934 | case GET_DISPLAY_STATS: |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 6935 | case GET_STATIC_DISPLAY_INFO: |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 6936 | case GET_DYNAMIC_DISPLAY_INFO: |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 6937 | case GET_DISPLAY_NATIVE_PRIMARIES: |
| 6938 | case SET_ACTIVE_COLOR_MODE: |
| 6939 | case SET_BOOT_DISPLAY_MODE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6940 | case CLEAR_BOOT_DISPLAY_MODE: |
| 6941 | case GET_BOOT_DISPLAY_MODE_SUPPORT: |
| 6942 | case SET_AUTO_LOW_LATENCY_MODE: |
| 6943 | case SET_GAME_CONTENT_TYPE: |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6944 | case CAPTURE_LAYERS: |
| 6945 | case CAPTURE_DISPLAY: |
| 6946 | case CAPTURE_DISPLAY_BY_ID: |
Huihong Luo | 4ed1c91 | 2022-02-22 14:30:01 -0800 | [diff] [blame] | 6947 | case CLEAR_ANIMATION_FRAME_STATS: |
| 6948 | case GET_ANIMATION_FRAME_STATS: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6949 | case OVERRIDE_HDR_TYPES: |
| 6950 | case ON_PULL_ATOM: |
| 6951 | case ENABLE_VSYNC_INJECTIONS: |
| 6952 | case INJECT_VSYNC: |
| 6953 | case GET_LAYER_DEBUG_INFO: |
| 6954 | case GET_COLOR_MANAGEMENT: |
| 6955 | case GET_COMPOSITION_PREFERENCE: |
| 6956 | case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: |
| 6957 | case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6958 | case GET_DISPLAYED_CONTENT_SAMPLE: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6959 | case GET_PROTECTED_CONTENT_SUPPORT: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6960 | case IS_WIDE_COLOR_DISPLAY: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6961 | case ADD_REGION_SAMPLING_LISTENER: |
| 6962 | case REMOVE_REGION_SAMPLING_LISTENER: |
| 6963 | case ADD_FPS_LISTENER: |
| 6964 | case REMOVE_FPS_LISTENER: |
| 6965 | case ADD_TUNNEL_MODE_ENABLED_LISTENER: |
| 6966 | case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: |
| 6967 | case ADD_WINDOW_INFOS_LISTENER: |
| 6968 | case REMOVE_WINDOW_INFOS_LISTENER: |
| 6969 | case SET_DESIRED_DISPLAY_MODE_SPECS: |
| 6970 | case GET_DESIRED_DISPLAY_MODE_SPECS: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6971 | case GET_DISPLAY_BRIGHTNESS_SUPPORT: |
| 6972 | case SET_DISPLAY_BRIGHTNESS: |
| 6973 | case ADD_HDR_LAYER_INFO_LISTENER: |
| 6974 | case REMOVE_HDR_LAYER_INFO_LISTENER: |
| 6975 | case NOTIFY_POWER_BOOST: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6976 | case SET_GLOBAL_SHADOW_SETTINGS: |
| 6977 | case GET_DISPLAY_DECORATION_SUPPORT: |
| 6978 | case SET_FRAME_RATE: |
| 6979 | case SET_OVERRIDE_FRAME_RATE: |
| 6980 | case SET_FRAME_TIMELINE_INFO: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6981 | case ADD_TRANSACTION_TRACE_LISTENER: |
| 6982 | case GET_GPU_CONTEXT_PRIORITY: |
| 6983 | case GET_MAX_ACQUIRED_BUFFER_COUNT: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6984 | LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6985 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6986 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6987 | |
| 6988 | // These codes are used for the IBinder protocol to either interrogate the recipient |
| 6989 | // side of the transaction for its canonical interface descriptor or to dump its state. |
| 6990 | // We let them pass by default. |
| 6991 | if (code == IBinder::INTERFACE_TRANSACTION || code == IBinder::DUMP_TRANSACTION || |
| 6992 | code == IBinder::PING_TRANSACTION || code == IBinder::SHELL_COMMAND_TRANSACTION || |
| 6993 | code == IBinder::SYSPROPS_TRANSACTION) { |
| 6994 | return OK; |
| 6995 | } |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 6996 | // Numbers from 1000 to 1045 are currently used for backdoors. The code |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6997 | // 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] | 6998 | if (code >= 1000 && code <= 1045) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6999 | ALOGV("Accessing SurfaceFlinger through backdoor code: %u", code); |
| 7000 | return OK; |
| 7001 | } |
| 7002 | ALOGE("Permission Denial: SurfaceFlinger did not recognize request code: %u", code); |
| 7003 | return PERMISSION_DENIED; |
| 7004 | #pragma clang diagnostic pop |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 7005 | } |
| 7006 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7007 | status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 7008 | uint32_t flags) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7009 | if (const status_t error = CheckTransactCodeCredentials(code); error != OK) { |
| 7010 | return error; |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 7011 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 7012 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7013 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 7014 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 7015 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Romain Guy | 8c6bbd6 | 2017-06-05 13:51:43 -0700 | [diff] [blame] | 7016 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7017 | const int uid = ipc->getCallingUid(); |
| 7018 | if (CC_UNLIKELY(uid != AID_SYSTEM |
| 7019 | && !PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 7020 | const int pid = ipc->getCallingPid(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 7021 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 7022 | "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] | 7023 | return PERMISSION_DENIED; |
| 7024 | } |
| 7025 | int n; |
| 7026 | switch (code) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7027 | case 1000: // Unused. |
| 7028 | case 1001: |
| 7029 | return NAME_NOT_FOUND; |
| 7030 | case 1002: // Toggle flashing on surface damage. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7031 | sfdo_setDebugFlash(data.readInt32()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7032 | return NO_ERROR; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 7033 | case 1004: // Force composite ahead of next VSYNC. |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 7034 | case 1006: |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7035 | sfdo_scheduleComposite(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7036 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7037 | case 1005: { // Force commit ahead of next VSYNC. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7038 | sfdo_scheduleCommit(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 7039 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7040 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7041 | case 1007: // Unused. |
| 7042 | return NAME_NOT_FOUND; |
| 7043 | case 1008: // Toggle forced GPU composition. |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 7044 | sfdo_forceClientComposition(data.readInt32() != 0); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 7045 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7046 | case 1009: // Toggle use of transform hint. |
| 7047 | mDebugDisableTransformHint = data.readInt32() != 0; |
| 7048 | scheduleRepaint(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 7049 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7050 | case 1010: // Interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 7051 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7052 | reply->writeInt32(0); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7053 | reply->writeInt32(mDebugFlashDelay); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 7054 | reply->writeInt32(0); |
Dianne Hackborn | 12839be | 2012-02-06 21:21:05 -0800 | [diff] [blame] | 7055 | reply->writeInt32(mDebugDisableHWC); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7056 | return NO_ERROR; |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 7057 | case 1013: // Unused. |
| 7058 | return NAME_NOT_FOUND; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7059 | case 1014: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7060 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7061 | // daltonize |
| 7062 | n = data.readInt32(); |
| 7063 | switch (n % 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7064 | case 1: |
| 7065 | mDaltonizer.setType(ColorBlindnessType::Protanomaly); |
| 7066 | break; |
| 7067 | case 2: |
| 7068 | mDaltonizer.setType(ColorBlindnessType::Deuteranomaly); |
| 7069 | break; |
| 7070 | case 3: |
| 7071 | mDaltonizer.setType(ColorBlindnessType::Tritanomaly); |
| 7072 | break; |
| 7073 | default: |
| 7074 | mDaltonizer.setType(ColorBlindnessType::None); |
| 7075 | break; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7076 | } |
| 7077 | if (n >= 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7078 | mDaltonizer.setMode(ColorBlindnessMode::Correction); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7079 | } else { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7080 | mDaltonizer.setMode(ColorBlindnessMode::Simulation); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7081 | } |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7082 | |
| 7083 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7084 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7085 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7086 | case 1015: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7087 | Mutex::Autolock _l(mStateLock); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7088 | // apply a color matrix |
| 7089 | n = data.readInt32(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7090 | if (n) { |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7091 | // color matrix is sent as a column-major mat4 matrix |
Alan Viverette | 794c5ba | 2013-10-03 16:40:52 -0700 | [diff] [blame] | 7092 | for (size_t i = 0 ; i < 4; i++) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7093 | for (size_t j = 0; j < 4; j++) { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7094 | mClientColorMatrix[i][j] = data.readFloat(); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7095 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7096 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7097 | } else { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7098 | mClientColorMatrix = mat4(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7099 | } |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 7100 | |
| 7101 | // Check that supplied matrix's last row is {0,0,0,1} so we can avoid |
| 7102 | // the division by w in the fragment shader |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7103 | float4 lastRow(transpose(mClientColorMatrix)[3]); |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 7104 | if (any(greaterThan(abs(lastRow - float4{0, 0, 0, 1}), float4{1e-4f}))) { |
| 7105 | ALOGE("The color transform's last row must be (0, 0, 0, 1)"); |
| 7106 | } |
| 7107 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7108 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7109 | return NO_ERROR; |
| 7110 | } |
Dominik Laskowski | 8d32ddc | 2019-08-07 11:25:35 -0700 | [diff] [blame] | 7111 | case 1016: { // Unused. |
| 7112 | return NAME_NOT_FOUND; |
Ruchi Kandoi | f52b3c8 | 2014-04-24 16:42:35 -0700 | [diff] [blame] | 7113 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 7114 | case 1017: { |
| 7115 | n = data.readInt32(); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 7116 | mForceFullDamage = n != 0; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 7117 | return NO_ERROR; |
| 7118 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7119 | case 1018: { // Set the render deadline as a duration until VSYNC. |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7120 | n = data.readInt32(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7121 | mScheduler->setDuration(scheduler::Cycle::Render, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7122 | return NO_ERROR; |
| 7123 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7124 | 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] | 7125 | n = data.readInt32(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7126 | mScheduler->setDuration(scheduler::Cycle::LastComposite, |
| 7127 | std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7128 | return NO_ERROR; |
| 7129 | } |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 7130 | case 1020: { // Unused |
| 7131 | return NAME_NOT_FOUND; |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 7132 | } |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 7133 | case 1021: { // Disable HWC virtual displays |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 7134 | const bool enable = data.readInt32() != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7135 | static_cast<void>( |
| 7136 | mScheduler->schedule([this, enable] { enableHalVirtualDisplays(enable); })); |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 7137 | return NO_ERROR; |
| 7138 | } |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7139 | case 1022: { // Set saturation boost |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7140 | Mutex::Autolock _l(mStateLock); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7141 | mGlobalSaturationFactor = std::max(0.0f, std::min(data.readFloat(), 2.0f)); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7142 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7143 | updateColorMatrixLocked(); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7144 | return NO_ERROR; |
| 7145 | } |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7146 | case 1023: { // Set color mode. |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7147 | mDisplayColorSetting = static_cast<DisplayColorSetting>(data.readInt32()); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7148 | |
| 7149 | if (int32_t colorMode; data.readInt32(&colorMode) == NO_ERROR) { |
| 7150 | mForceColorMode = static_cast<ui::ColorMode>(colorMode); |
Daniel Solomon | 7c7ede2 | 2019-07-11 16:35:40 -0700 | [diff] [blame] | 7151 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7152 | scheduleRepaint(); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 7153 | return NO_ERROR; |
| 7154 | } |
Peiyong Lin | 4bac91c | 2018-10-25 09:48:33 -0700 | [diff] [blame] | 7155 | // Deprecate, use 1030 to check whether the device is color managed. |
| 7156 | case 1024: { |
| 7157 | return NAME_NOT_FOUND; |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 7158 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7159 | // Deprecated, use perfetto to start/stop the layer tracing |
| 7160 | case 1025: { |
| 7161 | return NAME_NOT_FOUND; |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 7162 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7163 | // Deprecated, execute "adb shell perfetto --query" to see the ongoing tracing sessions |
| 7164 | case 1026: { |
| 7165 | return NAME_NOT_FOUND; |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 7166 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7167 | // Is a DisplayColorSetting supported? |
| 7168 | case 1027: { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7169 | const auto display = getDefaultDisplayDevice(); |
| 7170 | if (!display) { |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7171 | return NAME_NOT_FOUND; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7172 | } |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7173 | |
| 7174 | DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32()); |
| 7175 | switch (setting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7176 | case DisplayColorSetting::kManaged: |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7177 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7178 | reply->writeBool(true); |
| 7179 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7180 | case DisplayColorSetting::kEnhanced: |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7181 | reply->writeBool(display->hasRenderIntent(RenderIntent::ENHANCE)); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7182 | break; |
| 7183 | default: // vendor display color setting |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7184 | reply->writeBool( |
| 7185 | display->hasRenderIntent(static_cast<RenderIntent>(setting))); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7186 | break; |
| 7187 | } |
| 7188 | return NO_ERROR; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7189 | } |
Alec Mouri | 9c58bcd | 2020-09-09 18:57:07 -0700 | [diff] [blame] | 7190 | case 1028: { // Unused. |
| 7191 | return NAME_NOT_FOUND; |
Steven Thomas | 97f1f4c | 2018-06-01 12:04:16 -0700 | [diff] [blame] | 7192 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7193 | // Deprecated, use perfetto to set the active layer tracing buffer size |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 7194 | case 1029: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7195 | return NAME_NOT_FOUND; |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 7196 | } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 7197 | // Is device color managed? |
| 7198 | case 1030: { |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 7199 | // ColorDisplayManager stil calls this |
| 7200 | reply->writeBool(true); |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 7201 | return NO_ERROR; |
| 7202 | } |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7203 | // Override default composition data space |
| 7204 | // adb shell service call SurfaceFlinger 1031 i32 1 DATASPACE_NUMBER DATASPACE_NUMBER \ |
| 7205 | // && adb shell stop zygote && adb shell start zygote |
| 7206 | // to restore: adb shell service call SurfaceFlinger 1031 i32 0 && \ |
| 7207 | // adb shell stop zygote && adb shell start zygote |
| 7208 | case 1031: { |
| 7209 | Mutex::Autolock _l(mStateLock); |
| 7210 | n = data.readInt32(); |
| 7211 | if (n) { |
| 7212 | n = data.readInt32(); |
| 7213 | if (n) { |
| 7214 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 7215 | if (!validateCompositionDataspace(dataspace)) { |
| 7216 | return BAD_VALUE; |
| 7217 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7218 | mDefaultCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7219 | } |
| 7220 | n = data.readInt32(); |
| 7221 | if (n) { |
| 7222 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 7223 | if (!validateCompositionDataspace(dataspace)) { |
| 7224 | return BAD_VALUE; |
| 7225 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7226 | mWideColorGamutCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7227 | } |
| 7228 | } else { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7229 | // restore composition data space. |
| 7230 | mDefaultCompositionDataspace = defaultCompositionDataspace; |
| 7231 | mWideColorGamutCompositionDataspace = wideColorGamutCompositionDataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7232 | } |
| 7233 | return NO_ERROR; |
| 7234 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7235 | // Deprecated, use perfetto to set layer trace flags |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 7236 | case 1033: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7237 | return NAME_NOT_FOUND; |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 7238 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 7239 | case 1034: { |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7240 | n = data.readInt32(); |
| 7241 | if (n == 0 || n == 1) { |
| 7242 | sfdo_enableRefreshRateOverlay(static_cast<bool>(n)); |
| 7243 | } else { |
| 7244 | Mutex::Autolock lock(mStateLock); |
| 7245 | reply->writeBool(isRefreshRateOverlayEnabled()); |
| 7246 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 7247 | return NO_ERROR; |
| 7248 | } |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 7249 | case 1035: { |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7250 | // Parameters: |
| 7251 | // - (required) i32 mode id. |
| 7252 | // - (optional) i64 display id. Using default display if not provided. |
| 7253 | // - (optional) f min render rate. Using mode's fps is not provided. |
| 7254 | // - (optional) f max render rate. Using mode's fps is not provided. |
| 7255 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 7256 | const int modeId = data.readInt32(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 7257 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7258 | const auto display = [&]() -> sp<IBinder> { |
| 7259 | uint64_t value; |
| 7260 | if (data.readUint64(&value) != NO_ERROR) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7261 | return getDefaultDisplayDevice()->getDisplayToken().promote(); |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7262 | } |
| 7263 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7264 | if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(value)) { |
| 7265 | return getPhysicalDisplayToken(*id); |
| 7266 | } |
| 7267 | |
| 7268 | ALOGE("Invalid physical display ID"); |
| 7269 | return nullptr; |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7270 | }(); |
| 7271 | |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7272 | const auto getFps = [&] { |
| 7273 | float value; |
| 7274 | if (data.readFloat(&value) == NO_ERROR) { |
| 7275 | return Fps::fromValue(value); |
| 7276 | } |
| 7277 | |
| 7278 | return Fps(); |
| 7279 | }; |
| 7280 | |
| 7281 | const auto minFps = getFps(); |
| 7282 | const auto maxFps = getFps(); |
| 7283 | |
Shiyong Li | 2bcece9 | 2021-08-30 20:38:50 +0000 | [diff] [blame] | 7284 | mDebugDisplayModeSetByBackdoor = false; |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7285 | const status_t result = |
| 7286 | setActiveModeFromBackdoor(display, DisplayModeId{modeId}, minFps, maxFps); |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7287 | mDebugDisplayModeSetByBackdoor = result == NO_ERROR; |
| 7288 | return result; |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 7289 | } |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7290 | // Turn on/off frame rate flexibility mode. When turned on it overrides the display |
| 7291 | // manager frame rate policy a new policy which allows switching between all refresh |
| 7292 | // rates. |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7293 | case 1036: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7294 | if (data.readInt32() > 0) { // turn on |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7295 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7296 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7297 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7298 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7299 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7300 | // This is a little racy, but not in a way that hurts anything. As |
| 7301 | // we grab the defaultMode from the display manager policy, we could |
| 7302 | // be setting a new display manager policy, leaving us using a stale |
| 7303 | // defaultMode. The defaultMode doesn't matter for the override |
| 7304 | // policy though, since we set allowGroupSwitching to true, so it's |
| 7305 | // not a problem. |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7306 | scheduler::RefreshRateSelector::OverridePolicy overridePolicy; |
| 7307 | overridePolicy.defaultMode = display->refreshRateSelector() |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7308 | .getDisplayManagerPolicy() |
| 7309 | .defaultMode; |
| 7310 | overridePolicy.allowGroupSwitching = true; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7311 | return setDesiredDisplayModeSpecsInternal(display, overridePolicy); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7312 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7313 | .get(); |
| 7314 | } else { // turn off |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7315 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7316 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7317 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7318 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7319 | return setDesiredDisplayModeSpecsInternal( |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7320 | display, |
| 7321 | scheduler::RefreshRateSelector::NoOverridePolicy{}); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7322 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7323 | .get(); |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7324 | } |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7325 | } |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 7326 | // Inject a hotplug connected event for the primary display. This will deallocate and |
| 7327 | // reallocate the display state including framebuffers. |
| 7328 | case 1037: { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7329 | const hal::HWDisplayId hwcId = |
| 7330 | (Mutex::Autolock(mStateLock), getHwComposer().getPrimaryHwcDisplayId()); |
| 7331 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 7332 | onComposerHalHotplugEvent(hwcId, DisplayHotplugEvent::CONNECTED); |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 7333 | return NO_ERROR; |
| 7334 | } |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 7335 | // Modify the max number of display frames stored within FrameTimeline |
| 7336 | case 1038: { |
| 7337 | n = data.readInt32(); |
| 7338 | if (n < 0 || n > MAX_ALLOWED_DISPLAY_FRAMES) { |
| 7339 | ALOGW("Invalid max size. Maximum allowed is %d", MAX_ALLOWED_DISPLAY_FRAMES); |
| 7340 | return BAD_VALUE; |
| 7341 | } |
| 7342 | if (n == 0) { |
| 7343 | // restore to default |
| 7344 | mFrameTimeline->reset(); |
| 7345 | return NO_ERROR; |
| 7346 | } |
| 7347 | mFrameTimeline->setMaxDisplayFrames(n); |
| 7348 | return NO_ERROR; |
| 7349 | } |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 7350 | case 1039: { |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 7351 | PhysicalDisplayId displayId = [&]() { |
| 7352 | Mutex::Autolock lock(mStateLock); |
| 7353 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 7354 | }(); |
| 7355 | |
| 7356 | auto inUid = static_cast<uid_t>(data.readInt32()); |
| 7357 | const auto refreshRate = data.readFloat(); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 7358 | mScheduler->setPreferredRefreshRateForUid(FrameRateOverride{inUid, refreshRate}); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7359 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 7360 | return NO_ERROR; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 7361 | } |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7362 | // Toggle caching feature |
| 7363 | // First argument is an int32 - nonzero enables caching and zero disables caching |
| 7364 | // Second argument is an optional uint64 - if present, then limits enabling/disabling |
| 7365 | // caching to a particular physical display |
| 7366 | case 1040: { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7367 | auto future = mScheduler->schedule([&] { |
| 7368 | n = data.readInt32(); |
| 7369 | std::optional<PhysicalDisplayId> inputId = std::nullopt; |
| 7370 | if (uint64_t inputDisplayId; data.readUint64(&inputDisplayId) == NO_ERROR) { |
| 7371 | inputId = DisplayId::fromValue<PhysicalDisplayId>(inputDisplayId); |
| 7372 | if (!inputId || getPhysicalDisplayToken(*inputId)) { |
| 7373 | ALOGE("No display with id: %" PRIu64, inputDisplayId); |
| 7374 | return NAME_NOT_FOUND; |
| 7375 | } |
| 7376 | } |
| 7377 | { |
| 7378 | Mutex::Autolock lock(mStateLock); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7379 | mLayerCachingEnabled = n != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7380 | for (const auto& [_, display] : mDisplays) { |
| 7381 | if (!inputId || *inputId == display->getPhysicalId()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7382 | display->enableLayerCaching(mLayerCachingEnabled); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7383 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7384 | } |
| 7385 | } |
| 7386 | return OK; |
| 7387 | }); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7388 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7389 | if (const status_t error = future.get(); error != OK) { |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7390 | return error; |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7391 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7392 | scheduleRepaint(); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7393 | return NO_ERROR; |
| 7394 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 7395 | case 1041: { // Transaction tracing |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7396 | if (mTransactionTracing) { |
Vishnu Nair | 640261c | 2023-09-21 21:22:51 -0700 | [diff] [blame] | 7397 | int arg = data.readInt32(); |
| 7398 | if (arg == -1) { |
Vishnu Nair | 50858e6 | 2023-10-13 23:28:24 +0000 | [diff] [blame] | 7399 | mScheduler->schedule([&]() { mTransactionTracing.reset(); }).get(); |
Vishnu Nair | 640261c | 2023-09-21 21:22:51 -0700 | [diff] [blame] | 7400 | } else if (arg > 0) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7401 | // Transaction tracing is always running but allow the user to temporarily |
| 7402 | // increase the buffer when actively debugging. |
| 7403 | mTransactionTracing->setBufferSize( |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 7404 | TransactionTracing::LEGACY_ACTIVE_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7405 | } else { |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 7406 | TransactionTraceWriter::getInstance().invoke("", /* overwrite= */ true); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7407 | mTransactionTracing->setBufferSize( |
| 7408 | TransactionTracing::CONTINUOUS_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7409 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 7410 | } |
| 7411 | reply->writeInt32(NO_ERROR); |
| 7412 | return NO_ERROR; |
| 7413 | } |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 7414 | case 1042: { // Write transaction trace to file |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7415 | if (mTransactionTracing) { |
| 7416 | mTransactionTracing->writeToFile(); |
| 7417 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7418 | reply->writeInt32(NO_ERROR); |
| 7419 | return NO_ERROR; |
| 7420 | } |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 7421 | // hdr sdr ratio overlay |
| 7422 | case 1043: { |
| 7423 | auto future = mScheduler->schedule( |
| 7424 | [&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 7425 | n = data.readInt32(); |
| 7426 | mHdrSdrRatioOverlay = n != 0; |
| 7427 | switch (n) { |
| 7428 | case 0: |
| 7429 | case 1: |
| 7430 | enableHdrSdrRatioOverlay(mHdrSdrRatioOverlay); |
| 7431 | break; |
| 7432 | default: |
| 7433 | reply->writeBool(isHdrSdrRatioOverlayEnabled()); |
| 7434 | } |
| 7435 | }); |
| 7436 | future.wait(); |
| 7437 | return NO_ERROR; |
| 7438 | } |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 7439 | |
| 7440 | case 1044: { // Enable/Disable mirroring from one display to another |
| 7441 | /* |
| 7442 | * Mirror one display onto another. |
| 7443 | * Ensure the source and destination displays are on. |
| 7444 | * Commands: |
| 7445 | * 0: Mirror one display to another |
| 7446 | * 1: Disable mirroring to a previously mirrored display |
| 7447 | * 2: Disable mirroring on previously mirrored displays |
| 7448 | * |
| 7449 | * Ex: |
| 7450 | * Get the display ids: |
| 7451 | * adb shell dumpsys SurfaceFlinger --display-id |
| 7452 | * Mirror first display to the second: |
| 7453 | * adb shell service call SurfaceFlinger 1044 i64 0 i64 4619827677550801152 i64 |
| 7454 | * 4619827677550801153 |
| 7455 | * Stop mirroring: |
| 7456 | * adb shell service call SurfaceFlinger 1044 i64 1 |
| 7457 | */ |
| 7458 | |
| 7459 | int64_t arg0 = data.readInt64(); |
| 7460 | |
| 7461 | switch (arg0) { |
| 7462 | case 0: { |
| 7463 | // Mirror arg1 to arg2 |
| 7464 | int64_t arg1 = data.readInt64(); |
| 7465 | int64_t arg2 = data.readInt64(); |
| 7466 | // Enable mirroring for one display |
| 7467 | const auto display1id = DisplayId::fromValue(arg1); |
| 7468 | auto mirrorRoot = SurfaceComposerClient::getDefault()->mirrorDisplay( |
| 7469 | display1id.value()); |
| 7470 | auto id2 = DisplayId::fromValue<PhysicalDisplayId>(arg2); |
| 7471 | const auto token2 = getPhysicalDisplayToken(*id2); |
| 7472 | ui::LayerStack layerStack; |
| 7473 | { |
| 7474 | Mutex::Autolock lock(mStateLock); |
| 7475 | sp<DisplayDevice> display = getDisplayDeviceLocked(token2); |
| 7476 | layerStack = display->getLayerStack(); |
| 7477 | } |
| 7478 | SurfaceComposerClient::Transaction t; |
| 7479 | t.setDisplayLayerStack(token2, layerStack); |
| 7480 | t.setLayer(mirrorRoot, INT_MAX); // Top-most layer |
| 7481 | t.setLayerStack(mirrorRoot, layerStack); |
| 7482 | t.apply(); |
| 7483 | |
| 7484 | mMirrorMapForDebug.emplace_or_replace(arg2, mirrorRoot); |
| 7485 | break; |
| 7486 | } |
| 7487 | |
| 7488 | case 1: { |
| 7489 | // Disable mirroring for arg1 |
| 7490 | int64_t arg1 = data.readInt64(); |
| 7491 | mMirrorMapForDebug.erase(arg1); |
| 7492 | break; |
| 7493 | } |
| 7494 | |
| 7495 | case 2: { |
| 7496 | // Disable mirroring for all displays |
| 7497 | mMirrorMapForDebug.clear(); |
| 7498 | break; |
| 7499 | } |
| 7500 | |
| 7501 | default: |
| 7502 | return BAD_VALUE; |
| 7503 | } |
| 7504 | return NO_ERROR; |
| 7505 | } |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7506 | // Inject jank |
| 7507 | // First argument is a float that describes the fraction of frame duration to jank by. |
| 7508 | // Second argument is a delay in ms for triggering the jank. This is useful for working |
| 7509 | // with tools that steal the adb connection. This argument is optional. |
| 7510 | case 1045: { |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 7511 | if (FlagManager::getInstance().vrr_config()) { |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7512 | float jankAmount = data.readFloat(); |
| 7513 | int32_t jankDelayMs = 0; |
| 7514 | if (data.readInt32(&jankDelayMs) != NO_ERROR) { |
| 7515 | jankDelayMs = 0; |
| 7516 | } |
| 7517 | |
| 7518 | const auto jankDelayDuration = Duration(std::chrono::milliseconds(jankDelayMs)); |
| 7519 | |
| 7520 | const bool jankAmountValid = jankAmount > 0.0 && jankAmount < 100.0; |
| 7521 | |
| 7522 | if (!jankAmountValid) { |
| 7523 | ALOGD("Ignoring invalid jank amount: %f", jankAmount); |
| 7524 | reply->writeInt32(BAD_VALUE); |
| 7525 | return BAD_VALUE; |
| 7526 | } |
| 7527 | |
| 7528 | (void)mScheduler->scheduleDelayed( |
| 7529 | [&, jankAmount]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 7530 | mScheduler->injectPacesetterDelay(jankAmount); |
| 7531 | scheduleComposite(FrameHint::kActive); |
| 7532 | }, |
| 7533 | jankDelayDuration.ns()); |
| 7534 | reply->writeInt32(NO_ERROR); |
| 7535 | return NO_ERROR; |
| 7536 | } |
| 7537 | return err; |
| 7538 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7539 | } |
| 7540 | } |
| 7541 | return err; |
| 7542 | } |
| 7543 | |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7544 | void SurfaceFlinger::kernelTimerChanged(bool expired) { |
| 7545 | static bool updateOverlay = |
| 7546 | property_get_bool("debug.sf.kernel_idle_timer_update_overlay", true); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7547 | if (!updateOverlay) return; |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7548 | |
| 7549 | // Update the overlay on the main thread to avoid race conditions with |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 7550 | // RefreshRateSelector::getActiveMode |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 7551 | static_cast<void>(mScheduler->schedule([=, this] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7552 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7553 | if (!display) { |
| 7554 | ALOGW("%s: default display is null", __func__); |
| 7555 | return; |
| 7556 | } |
Adrian Salido | a942af8 | 2022-02-17 19:22:31 -0800 | [diff] [blame] | 7557 | if (!display->isRefreshRateOverlayEnabled()) return; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7558 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7559 | const auto desiredModeIdOpt = |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 7560 | display->getDesiredMode().transform([](const display::DisplayModeRequest& request) { |
| 7561 | return request.mode.modePtr->getId(); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7562 | }); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7563 | |
| 7564 | const bool timerExpired = mKernelIdleTimerEnabled && expired; |
| 7565 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7566 | if (display->onKernelTimerChanged(desiredModeIdOpt, timerExpired)) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 7567 | mScheduler->scheduleFrame(); |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7568 | } |
| 7569 | })); |
| 7570 | } |
| 7571 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7572 | std::pair<std::optional<KernelIdleTimerController>, std::chrono::milliseconds> |
| 7573 | SurfaceFlinger::getKernelIdleTimerProperties(DisplayId displayId) { |
| 7574 | const bool isKernelIdleTimerHwcSupported = getHwComposer().getComposer()->isSupported( |
| 7575 | android::Hwc2::Composer::OptionalFeature::KernelIdleTimer); |
| 7576 | const auto timeout = getIdleTimerTimeout(displayId); |
| 7577 | if (isKernelIdleTimerHwcSupported) { |
| 7578 | if (const auto id = PhysicalDisplayId::tryCast(displayId); |
| 7579 | getHwComposer().hasDisplayIdleTimerCapability(*id)) { |
| 7580 | // In order to decide if we can use the HWC api for idle timer |
| 7581 | // we query DisplayCapability::DISPLAY_IDLE_TIMER directly on the composer |
| 7582 | // without relying on hasDisplayCapability. |
| 7583 | // hasDisplayCapability relies on DisplayCapabilities |
| 7584 | // which are updated after we set the PowerMode::ON. |
| 7585 | // DISPLAY_IDLE_TIMER is a display driver property |
| 7586 | // and is available before the PowerMode::ON |
| 7587 | return {KernelIdleTimerController::HwcApi, timeout}; |
| 7588 | } |
| 7589 | return {std::nullopt, timeout}; |
| 7590 | } |
| 7591 | if (getKernelIdleTimerSyspropConfig(displayId)) { |
| 7592 | return {KernelIdleTimerController::Sysprop, timeout}; |
| 7593 | } |
| 7594 | |
| 7595 | return {std::nullopt, timeout}; |
| 7596 | } |
| 7597 | |
| 7598 | void SurfaceFlinger::updateKernelIdleTimer(std::chrono::milliseconds timeout, |
| 7599 | KernelIdleTimerController controller, |
| 7600 | PhysicalDisplayId displayId) { |
| 7601 | switch (controller) { |
| 7602 | case KernelIdleTimerController::HwcApi: { |
| 7603 | getHwComposer().setIdleTimerEnabled(displayId, timeout); |
| 7604 | break; |
| 7605 | } |
| 7606 | case KernelIdleTimerController::Sysprop: { |
| 7607 | base::SetProperty(KERNEL_IDLE_TIMER_PROP, timeout > 0ms ? "true" : "false"); |
| 7608 | break; |
| 7609 | } |
| 7610 | } |
| 7611 | } |
| 7612 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7613 | void SurfaceFlinger::toggleKernelIdleTimer() { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7614 | using KernelIdleTimerAction = scheduler::RefreshRateSelector::KernelIdleTimerAction; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7615 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7616 | const auto display = getDefaultDisplayDeviceLocked(); |
| 7617 | if (!display) { |
| 7618 | ALOGW("%s: default display is null", __func__); |
| 7619 | return; |
| 7620 | } |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7621 | |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7622 | // If the support for kernel idle timer is disabled for the active display, |
| 7623 | // don't do anything. |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7624 | const std::optional<KernelIdleTimerController> kernelIdleTimerController = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7625 | display->refreshRateSelector().kernelIdleTimerController(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7626 | if (!kernelIdleTimerController.has_value()) { |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7627 | return; |
| 7628 | } |
| 7629 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7630 | const KernelIdleTimerAction action = display->refreshRateSelector().getIdleTimerAction(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7631 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7632 | switch (action) { |
| 7633 | case KernelIdleTimerAction::TurnOff: |
| 7634 | if (mKernelIdleTimerEnabled) { |
| 7635 | ATRACE_INT("KernelIdleTimer", 0); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7636 | std::chrono::milliseconds constexpr kTimerDisabledTimeout = 0ms; |
| 7637 | updateKernelIdleTimer(kTimerDisabledTimeout, kernelIdleTimerController.value(), |
| 7638 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7639 | mKernelIdleTimerEnabled = false; |
| 7640 | } |
| 7641 | break; |
| 7642 | case KernelIdleTimerAction::TurnOn: |
| 7643 | if (!mKernelIdleTimerEnabled) { |
| 7644 | ATRACE_INT("KernelIdleTimer", 1); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7645 | const std::chrono::milliseconds timeout = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7646 | display->refreshRateSelector().getIdleTimerTimeout(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7647 | updateKernelIdleTimer(timeout, kernelIdleTimerController.value(), |
| 7648 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7649 | mKernelIdleTimerEnabled = true; |
| 7650 | } |
| 7651 | break; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7652 | } |
| 7653 | } |
| 7654 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7655 | // A simple RAII class to disconnect from an ANativeWindow* when it goes out of scope |
| 7656 | class WindowDisconnector { |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7657 | public: |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7658 | WindowDisconnector(ANativeWindow* window, int api) : mWindow(window), mApi(api) {} |
| 7659 | ~WindowDisconnector() { |
| 7660 | native_window_api_disconnect(mWindow, mApi); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7661 | } |
| 7662 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7663 | private: |
| 7664 | ANativeWindow* mWindow; |
| 7665 | const int mApi; |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7666 | }; |
| 7667 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7668 | static bool hasCaptureBlackoutContentPermission() { |
| 7669 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7670 | const int pid = ipc->getCallingPid(); |
| 7671 | const int uid = ipc->getCallingUid(); |
| 7672 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 7673 | PermissionCache::checkPermission(sCaptureBlackoutContent, pid, uid); |
| 7674 | } |
| 7675 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7676 | static status_t validateScreenshotPermissions(const CaptureArgs& captureArgs) { |
| 7677 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7678 | const int pid = ipc->getCallingPid(); |
| 7679 | const int uid = ipc->getCallingUid(); |
| 7680 | if (uid == AID_GRAPHICS || PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 7681 | return OK; |
| 7682 | } |
| 7683 | |
| 7684 | // If the caller doesn't have the correct permissions but is only attempting to screenshot |
| 7685 | // itself, we allow it to continue. |
| 7686 | if (captureArgs.uid == uid) { |
| 7687 | return OK; |
| 7688 | } |
| 7689 | |
| 7690 | ALOGE("Permission Denial: can't take screenshot pid=%d, uid=%d", pid, uid); |
| 7691 | return PERMISSION_DENIED; |
| 7692 | } |
| 7693 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7694 | status_t SurfaceFlinger::setSchedFifo(bool enabled) { |
| 7695 | static constexpr int kFifoPriority = 2; |
| 7696 | static constexpr int kOtherPriority = 0; |
| 7697 | |
| 7698 | struct sched_param param = {0}; |
| 7699 | int sched_policy; |
| 7700 | if (enabled) { |
| 7701 | sched_policy = SCHED_FIFO; |
| 7702 | param.sched_priority = kFifoPriority; |
| 7703 | } else { |
| 7704 | sched_policy = SCHED_OTHER; |
| 7705 | param.sched_priority = kOtherPriority; |
| 7706 | } |
| 7707 | |
| 7708 | if (sched_setscheduler(0, sched_policy, ¶m) != 0) { |
| 7709 | return -errno; |
| 7710 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7711 | |
| 7712 | return NO_ERROR; |
| 7713 | } |
| 7714 | |
| 7715 | status_t SurfaceFlinger::setSchedAttr(bool enabled) { |
| 7716 | static const unsigned int kUclampMin = |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 7717 | base::GetUintProperty<unsigned int>("ro.surface_flinger.uclamp.min"s, 0U); |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7718 | |
| 7719 | if (!kUclampMin) { |
| 7720 | // uclamp.min set to 0 (default), skip setting |
| 7721 | return NO_ERROR; |
| 7722 | } |
| 7723 | |
| 7724 | // Currently, there is no wrapper in bionic: b/183240349. |
| 7725 | struct sched_attr { |
| 7726 | uint32_t size; |
| 7727 | uint32_t sched_policy; |
| 7728 | uint64_t sched_flags; |
| 7729 | int32_t sched_nice; |
| 7730 | uint32_t sched_priority; |
| 7731 | uint64_t sched_runtime; |
| 7732 | uint64_t sched_deadline; |
| 7733 | uint64_t sched_period; |
| 7734 | uint32_t sched_util_min; |
| 7735 | uint32_t sched_util_max; |
| 7736 | }; |
| 7737 | |
| 7738 | sched_attr attr = {}; |
| 7739 | attr.size = sizeof(attr); |
| 7740 | |
| 7741 | attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP); |
| 7742 | attr.sched_util_min = enabled ? kUclampMin : 0; |
| 7743 | attr.sched_util_max = 1024; |
| 7744 | |
| 7745 | if (syscall(__NR_sched_setattr, 0, &attr, 0)) { |
| 7746 | return -errno; |
| 7747 | } |
| 7748 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7749 | return NO_ERROR; |
| 7750 | } |
| 7751 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7752 | namespace { |
| 7753 | |
| 7754 | ui::Dataspace pickBestDataspace(ui::Dataspace requestedDataspace, const DisplayDevice* display, |
| 7755 | bool capturingHdrLayers, bool hintForSeamlessTransition) { |
| 7756 | if (requestedDataspace != ui::Dataspace::UNKNOWN || display == nullptr) { |
| 7757 | return requestedDataspace; |
| 7758 | } |
| 7759 | |
| 7760 | const auto& state = display->getCompositionDisplay()->getState(); |
| 7761 | |
| 7762 | const auto dataspaceForColorMode = ui::pickDataspaceFor(state.colorMode); |
| 7763 | |
Alec Mouri | 2964072 | 2023-05-16 23:22:41 +0000 | [diff] [blame] | 7764 | // TODO: Enable once HDR screenshots are ready. |
| 7765 | if constexpr (/* DISABLES CODE */ (false)) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7766 | // For now since we only support 8-bit screenshots, just use HLG and |
| 7767 | // assume that 1.0 >= display max luminance. This isn't quite as future |
| 7768 | // proof as PQ is, but is good enough. |
| 7769 | // Consider using PQ once we support 16-bit screenshots and we're able |
| 7770 | // to consistently supply metadata to image encoders. |
| 7771 | return ui::Dataspace::BT2020_HLG; |
| 7772 | } |
| 7773 | |
| 7774 | return dataspaceForColorMode; |
| 7775 | } |
| 7776 | |
| 7777 | } // namespace |
| 7778 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7779 | static void invokeScreenCaptureError(const status_t status, |
| 7780 | const sp<IScreenCaptureListener>& captureListener) { |
| 7781 | ScreenCaptureResults captureResults; |
| 7782 | captureResults.fenceResult = base::unexpected(status); |
| 7783 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7784 | } |
| 7785 | |
| 7786 | void SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, |
| 7787 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7788 | ATRACE_CALL(); |
| 7789 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7790 | status_t validate = validateScreenshotPermissions(args); |
| 7791 | if (validate != OK) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7792 | invokeScreenCaptureError(validate, captureListener); |
| 7793 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7794 | } |
| 7795 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7796 | if (!args.displayToken) { |
| 7797 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7798 | return; |
| 7799 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7800 | |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 7801 | if (args.captureSecureLayers && !hasCaptureBlackoutContentPermission()) { |
| 7802 | ALOGE("Attempting to capture secure layers without CAPTURE_BLACKOUT_CONTENT"); |
| 7803 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 7804 | return; |
| 7805 | } |
| 7806 | |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7807 | wp<const DisplayDevice> displayWeak; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7808 | ui::LayerStack layerStack; |
| 7809 | ui::Size reqSize(args.width, args.height); |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7810 | std::unordered_set<uint32_t> excludeLayerIds; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7811 | { |
| 7812 | Mutex::Autolock lock(mStateLock); |
| 7813 | sp<DisplayDevice> display = getDisplayDeviceLocked(args.displayToken); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7814 | if (!display) { |
| 7815 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7816 | return; |
| 7817 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7818 | displayWeak = display; |
| 7819 | layerStack = display->getLayerStack(); |
| 7820 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7821 | // 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] | 7822 | if (args.width == 0 || args.height == 0) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7823 | reqSize = display->getLayerStackSpaceRect().getSize(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7824 | } |
| 7825 | |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7826 | for (const auto& handle : args.excludeHandles) { |
| 7827 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7828 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7829 | excludeLayerIds.emplace(excludeLayer); |
| 7830 | } else { |
| 7831 | ALOGW("Invalid layer handle passed as excludeLayer to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7832 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7833 | return; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7834 | } |
| 7835 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7836 | } |
| 7837 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7838 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
Alec Mouri | c44a1ff | 2023-05-19 23:49:05 +0000 | [diff] [blame] | 7839 | return DisplayRenderArea::create(displayWeak, args.sourceCrop, reqSize, args.dataspace, |
Melody Hsu | 70a63e5 | 2023-11-17 19:49:12 +0000 | [diff] [blame] | 7840 | args.hintForSeamlessTransition, args.captureSecureLayers); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7841 | }); |
| 7842 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7843 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7844 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7845 | getLayerSnapshots = |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7846 | getLayerSnapshotsForScreenshots(layerStack, args.uid, std::move(excludeLayerIds)); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7847 | } else { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7848 | auto traverseLayers = [this, args, excludeLayerIds, |
| 7849 | layerStack](const LayerVector::Visitor& visitor) { |
| 7850 | traverseLayersInLayerStack(layerStack, args.uid, std::move(excludeLayerIds), visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7851 | }; |
| 7852 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7853 | } |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 7854 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7855 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, args.pixelFormat, |
| 7856 | args.allowProtected, args.grayscale, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7857 | } |
| 7858 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7859 | void SurfaceFlinger::captureDisplay(DisplayId displayId, const CaptureArgs& args, |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7860 | const sp<IScreenCaptureListener>& captureListener) { |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7861 | ui::LayerStack layerStack; |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7862 | wp<const DisplayDevice> displayWeak; |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7863 | ui::Size size; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7864 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7865 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7866 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7867 | const auto display = getDisplayDeviceLocked(displayId); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7868 | if (!display) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7869 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7870 | return; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7871 | } |
| 7872 | |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7873 | displayWeak = display; |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7874 | layerStack = display->getLayerStack(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7875 | size = display->getLayerStackSpaceRect().getSize(); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7876 | } |
| 7877 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7878 | size.width *= args.frameScaleX; |
| 7879 | size.height *= args.frameScaleY; |
| 7880 | |
| 7881 | // We could query a real value for this but it'll be a long, long time until we support |
| 7882 | // displays that need upwards of 1GB per buffer so... |
| 7883 | constexpr auto kMaxTextureSize = 16384; |
| 7884 | if (size.width <= 0 || size.height <= 0 || size.width >= kMaxTextureSize || |
| 7885 | size.height >= kMaxTextureSize) { |
| 7886 | ALOGE("capture display resolved to invalid size %d x %d", size.width, size.height); |
| 7887 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7888 | return; |
| 7889 | } |
| 7890 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7891 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7892 | return DisplayRenderArea::create(displayWeak, Rect(), size, args.dataspace, |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7893 | args.hintForSeamlessTransition, |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7894 | false /* captureSecureLayers */); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7895 | }); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7896 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7897 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7898 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7899 | getLayerSnapshots = getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID, |
| 7900 | /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7901 | } else { |
| 7902 | auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7903 | traverseLayersInLayerStack(layerStack, CaptureArgs::UNSET_UID, {}, visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7904 | }; |
| 7905 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7906 | } |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7907 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7908 | if (captureListener == nullptr) { |
| 7909 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7910 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7911 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7912 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7913 | |
| 7914 | constexpr bool kAllowProtected = false; |
| 7915 | constexpr bool kGrayscale = false; |
| 7916 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7917 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, size, args.pixelFormat, |
| 7918 | kAllowProtected, kGrayscale, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7919 | } |
| 7920 | |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 7921 | ScreenCaptureResults SurfaceFlinger::captureLayersSync(const LayerCaptureArgs& args) { |
| 7922 | sp<SyncScreenCaptureListener> captureListener = sp<SyncScreenCaptureListener>::make(); |
| 7923 | captureLayers(args, captureListener); |
| 7924 | return captureListener->waitForResults(); |
| 7925 | } |
| 7926 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7927 | void SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, |
| 7928 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7929 | ATRACE_CALL(); |
| 7930 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7931 | status_t validate = validateScreenshotPermissions(args); |
| 7932 | if (validate != OK) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7933 | invokeScreenCaptureError(validate, captureListener); |
| 7934 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7935 | } |
| 7936 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7937 | ui::Size reqSize; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7938 | sp<Layer> parent; |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7939 | Rect crop(args.sourceCrop); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7940 | std::unordered_set<uint32_t> excludeLayerIds; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7941 | ui::Dataspace dataspace = args.dataspace; |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7942 | |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 7943 | if (args.captureSecureLayers && !hasCaptureBlackoutContentPermission()) { |
| 7944 | ALOGE("Attempting to capture secure layers without CAPTURE_BLACKOUT_CONTENT"); |
| 7945 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 7946 | return; |
| 7947 | } |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7948 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7949 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7950 | Mutex::Autolock lock(mStateLock); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7951 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 7952 | parent = LayerHandle::getLayer(args.layerHandle); |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7953 | if (parent == nullptr) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7954 | ALOGE("captureLayers called with an invalid or removed parent"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7955 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7956 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7957 | } |
| 7958 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 7959 | Rect parentSourceBounds = parent->getCroppedBufferSize(parent->getDrawingState()); |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7960 | if (args.sourceCrop.width() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7961 | crop.left = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7962 | crop.right = parentSourceBounds.getWidth(); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7963 | } |
| 7964 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7965 | if (args.sourceCrop.height() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7966 | crop.top = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7967 | crop.bottom = parentSourceBounds.getHeight(); |
| 7968 | } |
| 7969 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7970 | if (crop.isEmpty() || args.frameScaleX <= 0.0f || args.frameScaleY <= 0.0f) { |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7971 | // Error out if the layer has no source bounds (i.e. they are boundless) and a source |
| 7972 | // crop was not specified, or an invalid frame scale was provided. |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7973 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7974 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7975 | } |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7976 | reqSize = ui::Size(crop.width() * args.frameScaleX, crop.height() * args.frameScaleY); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7977 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7978 | for (const auto& handle : args.excludeHandles) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7979 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7980 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7981 | excludeLayerIds.emplace(excludeLayer); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7982 | } else { |
| 7983 | ALOGW("Invalid layer handle passed as excludeLayer to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7984 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7985 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7986 | } |
| 7987 | } |
| 7988 | } // mStateLock |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7989 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7990 | // really small crop or frameScale |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7991 | if (reqSize.width <= 0 || reqSize.height <= 0) { |
| 7992 | ALOGW("Failed to captureLayes: crop or scale too small"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7993 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7994 | return; |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7995 | } |
| 7996 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7997 | bool childrenOnly = args.childrenOnly; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 7998 | RenderAreaFuture renderAreaFuture = ftl::defer([=, this]() -> std::unique_ptr<RenderArea> { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7999 | ui::Transform layerTransform; |
| 8000 | Rect layerBufferSize; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8001 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8002 | frontend::LayerSnapshot* snapshot = |
| 8003 | mLayerSnapshotBuilder.getSnapshot(parent->getSequence()); |
| 8004 | if (!snapshot) { |
| 8005 | ALOGW("Couldn't find layer snapshot for %d", parent->getSequence()); |
| 8006 | } else { |
| 8007 | layerTransform = snapshot->localTransform; |
| 8008 | layerBufferSize = snapshot->bufferSize; |
| 8009 | } |
| 8010 | } else { |
| 8011 | layerTransform = parent->getTransform(); |
| 8012 | layerBufferSize = parent->getBufferSize(parent->getDrawingState()); |
| 8013 | } |
| 8014 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 8015 | return std::make_unique<LayerRenderArea>(*this, parent, crop, reqSize, dataspace, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8016 | childrenOnly, args.captureSecureLayers, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8017 | layerTransform, layerBufferSize, |
| 8018 | args.hintForSeamlessTransition); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 8019 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8020 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8021 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8022 | std::optional<FloatRect> parentCrop = std::nullopt; |
| 8023 | if (args.childrenOnly) { |
| 8024 | parentCrop = crop.isEmpty() ? FloatRect(0, 0, reqSize.width, reqSize.height) |
| 8025 | : crop.toFloatRect(); |
| 8026 | } |
| 8027 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8028 | getLayerSnapshots = getLayerSnapshotsForScreenshots(parent->sequence, args.uid, |
| 8029 | std::move(excludeLayerIds), |
| 8030 | args.childrenOnly, parentCrop); |
| 8031 | } else { |
| 8032 | auto traverseLayers = [parent, args, excludeLayerIds](const LayerVector::Visitor& visitor) { |
| 8033 | parent->traverseChildrenInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
| 8034 | if (!layer->isVisible()) { |
| 8035 | return; |
| 8036 | } else if (args.childrenOnly && layer == parent.get()) { |
| 8037 | return; |
| 8038 | } else if (args.uid != CaptureArgs::UNSET_UID && args.uid != layer->getOwnerUid()) { |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 8039 | return; |
| 8040 | } |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 8041 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8042 | auto p = sp<Layer>::fromExisting(layer); |
| 8043 | while (p != nullptr) { |
| 8044 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 8045 | return; |
| 8046 | } |
| 8047 | p = p->getParent(); |
| 8048 | } |
| 8049 | |
| 8050 | visitor(layer); |
| 8051 | }); |
| 8052 | }; |
| 8053 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 8054 | } |
Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 8055 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 8056 | if (captureListener == nullptr) { |
| 8057 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8058 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8059 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 8060 | } |
| 8061 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8062 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, args.pixelFormat, |
| 8063 | args.allowProtected, args.grayscale, captureListener); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8064 | } |
| 8065 | |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame^] | 8066 | bool SurfaceFlinger::layersHasProtectedLayer( |
| 8067 | const std::vector<std::pair<Layer*, sp<LayerFE>>>& layers) const { |
| 8068 | bool protectedLayerFound = false; |
| 8069 | for (auto& [_, layerFe] : layers) { |
| 8070 | protectedLayerFound |= |
| 8071 | (layerFe->mSnapshot->isVisible && layerFe->mSnapshot->hasProtectedContent); |
| 8072 | if (protectedLayerFound) { |
| 8073 | break; |
| 8074 | } |
| 8075 | } |
| 8076 | return protectedLayerFound; |
| 8077 | } |
| 8078 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8079 | void SurfaceFlinger::captureScreenCommon(RenderAreaFuture renderAreaFuture, |
| 8080 | GetLayerSnapshotsFunction getLayerSnapshots, |
| 8081 | ui::Size bufferSize, ui::PixelFormat reqPixelFormat, |
| 8082 | bool allowProtected, bool grayscale, |
| 8083 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8084 | ATRACE_CALL(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 8085 | |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 8086 | if (exceedsMaxRenderTargetSize(bufferSize.getWidth(), bufferSize.getHeight())) { |
| 8087 | ALOGE("Attempted to capture screen with size (%" PRId32 ", %" PRId32 |
| 8088 | ") that exceeds render target size limit.", |
| 8089 | bufferSize.getWidth(), bufferSize.getHeight()); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8090 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8091 | return; |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 8092 | } |
| 8093 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 8094 | // Loop over all visible layers to see whether there's any protected layer. A protected layer is |
| 8095 | // typically a layer with DRM contents, or have the GRALLOC_USAGE_PROTECTED set on the buffer. |
| 8096 | // A protected layer has no implication on whether it's secure, which is explicitly set by |
| 8097 | // application to avoid being screenshot or drawn via unsecure display. |
| 8098 | const bool supportsProtected = getRenderEngine().supportsProtectedContent(); |
| 8099 | bool hasProtectedLayer = false; |
| 8100 | if (allowProtected && supportsProtected) { |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame^] | 8101 | // Snapshots must be taken from the main thread. |
| 8102 | auto layers = mScheduler->schedule([=]() { return getLayerSnapshots(); }).get(); |
| 8103 | hasProtectedLayer = layersHasProtectedLayer(layers); |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 8104 | } |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8105 | const bool isProtected = hasProtectedLayer && allowProtected && supportsProtected; |
Richard Liu | cbcb895 | 2020-04-08 10:51:55 +0000 | [diff] [blame] | 8106 | const uint32_t usage = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER | |
| 8107 | GRALLOC_USAGE_HW_TEXTURE | |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8108 | (isProtected ? GRALLOC_USAGE_PROTECTED |
| 8109 | : GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8110 | sp<GraphicBuffer> buffer = |
| 8111 | getFactory().createGraphicBuffer(bufferSize.getWidth(), bufferSize.getHeight(), |
| 8112 | static_cast<android_pixel_format>(reqPixelFormat), |
| 8113 | 1 /* layerCount */, usage, "screenshot"); |
Alec Mouri | 7013b6f | 2021-02-12 11:16:54 -0800 | [diff] [blame] | 8114 | |
| 8115 | const status_t bufferStatus = buffer->initCheck(); |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 8116 | if (bufferStatus != OK) { |
| 8117 | // Animations may end up being really janky, but don't crash here. |
| 8118 | // Otherwise an irreponsible process may cause an SF crash by allocating |
| 8119 | // too much. |
| 8120 | ALOGE("%s: Buffer failed to allocate: %d", __func__, bufferStatus); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8121 | invokeScreenCaptureError(bufferStatus, captureListener); |
| 8122 | return; |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 8123 | } |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8124 | const std::shared_ptr<renderengine::ExternalTexture> texture = std::make_shared< |
| 8125 | renderengine::impl::ExternalTexture>(buffer, getRenderEngine(), |
| 8126 | renderengine::impl::ExternalTexture::Usage:: |
| 8127 | WRITEABLE); |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame^] | 8128 | auto futureFence = |
| 8129 | captureScreenshot(std::move(renderAreaFuture), getLayerSnapshots, texture, |
| 8130 | false /* regionSampling */, grayscale, isProtected, captureListener); |
| 8131 | futureFence.get(); |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 8132 | } |
| 8133 | |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame^] | 8134 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenshot( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8135 | RenderAreaFuture renderAreaFuture, GetLayerSnapshotsFunction getLayerSnapshots, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 8136 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8137 | bool grayscale, bool isProtected, const sp<IScreenCaptureListener>& captureListener) { |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 8138 | ATRACE_CALL(); |
| 8139 | |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame^] | 8140 | auto takeScreenshotFn = [=, this, renderAreaFuture = std::move(renderAreaFuture)]() REQUIRES( |
| 8141 | kMainThreadContext) mutable -> ftl::SharedFuture<FenceResult> { |
| 8142 | ScreenCaptureResults captureResults; |
| 8143 | std::shared_ptr<RenderArea> renderArea = renderAreaFuture.get(); |
| 8144 | if (!renderArea) { |
| 8145 | ALOGW("Skipping screen capture because of invalid render area."); |
| 8146 | if (captureListener) { |
| 8147 | captureResults.fenceResult = base::unexpected(NO_MEMORY); |
| 8148 | captureListener->onScreenCaptureCompleted(captureResults); |
| 8149 | } |
| 8150 | return ftl::yield<FenceResult>(base::unexpected(NO_ERROR)).share(); |
| 8151 | } |
| 8152 | |
| 8153 | ftl::SharedFuture<FenceResult> renderFuture; |
| 8154 | renderArea->render([&]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 8155 | renderFuture = renderScreenImpl(renderArea, getLayerSnapshots, buffer, regionSampling, |
| 8156 | grayscale, isProtected, captureResults); |
| 8157 | }); |
| 8158 | |
| 8159 | if (captureListener) { |
| 8160 | // Defer blocking on renderFuture back to the Binder thread. |
| 8161 | return ftl::Future(std::move(renderFuture)) |
| 8162 | .then([captureListener, captureResults = std::move(captureResults)]( |
| 8163 | FenceResult fenceResult) mutable -> FenceResult { |
| 8164 | captureResults.fenceResult = std::move(fenceResult); |
Nolan Scobie | 1d2deb2 | 2022-11-18 12:57:47 -0500 | [diff] [blame] | 8165 | captureListener->onScreenCaptureCompleted(captureResults); |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame^] | 8166 | return base::unexpected(NO_ERROR); |
| 8167 | }) |
| 8168 | .share(); |
| 8169 | } |
| 8170 | return renderFuture; |
| 8171 | }; |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 8172 | |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame^] | 8173 | auto future = |
| 8174 | mScheduler->schedule(FTL_FAKE_GUARD(kMainThreadContext, std::move(takeScreenshotFn))); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 8175 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8176 | // Flatten nested futures. |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 8177 | auto chain = ftl::Future(std::move(future)).then([](ftl::SharedFuture<FenceResult> future) { |
| 8178 | return future; |
| 8179 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8180 | |
| 8181 | return chain.share(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 8182 | } |
| 8183 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 8184 | ftl::SharedFuture<FenceResult> SurfaceFlinger::renderScreenImpl( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8185 | std::shared_ptr<const RenderArea> renderArea, GetLayerSnapshotsFunction getLayerSnapshots, |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 8186 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8187 | bool grayscale, bool isProtected, ScreenCaptureResults& captureResults) { |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 8188 | ATRACE_CALL(); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8189 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8190 | auto layers = getLayerSnapshots(); |
Alec Mouri | b4814de | 2023-09-11 22:09:03 +0000 | [diff] [blame] | 8191 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8192 | for (auto& [_, layerFE] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8193 | frontend::LayerSnapshot* snapshot = layerFE->mSnapshot.get(); |
| 8194 | captureResults.capturedSecureLayers |= (snapshot->isVisible && snapshot->isSecure); |
| 8195 | captureResults.capturedHdrLayers |= isHdrLayer(*snapshot); |
| 8196 | layerFE->mSnapshot->geomLayerTransform = |
| 8197 | renderArea->getTransform() * layerFE->mSnapshot->geomLayerTransform; |
Patrick Williams | c6e0cce | 2023-02-28 23:04:45 -0600 | [diff] [blame] | 8198 | layerFE->mSnapshot->geomInverseLayerTransform = |
| 8199 | layerFE->mSnapshot->geomLayerTransform.inverse(); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8200 | } |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8201 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8202 | auto capturedBuffer = buffer; |
| 8203 | |
| 8204 | auto requestedDataspace = renderArea->getReqDataSpace(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8205 | auto parent = renderArea->getParentLayer(); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 8206 | auto renderIntent = RenderIntent::TONE_MAP_COLORIMETRIC; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 8207 | auto sdrWhitePointNits = DisplayDevice::sDefaultMaxLumiance; |
| 8208 | auto displayBrightnessNits = DisplayDevice::sDefaultMaxLumiance; |
| 8209 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8210 | captureResults.capturedDataspace = requestedDataspace; |
| 8211 | |
| 8212 | { |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8213 | Mutex::Autolock lock(mStateLock); |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8214 | const DisplayDevice* display = nullptr; |
| 8215 | if (parent) { |
| 8216 | display = findDisplay([layerStack = parent->getLayerStack()](const auto& display) { |
| 8217 | return display.getLayerStack() == layerStack; |
| 8218 | }).get(); |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8219 | } |
| 8220 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8221 | if (display == nullptr) { |
| 8222 | display = renderArea->getDisplayDevice().get(); |
| 8223 | } |
| 8224 | |
| 8225 | if (display == nullptr) { |
| 8226 | display = getDefaultDisplayDeviceLocked().get(); |
| 8227 | } |
| 8228 | |
| 8229 | if (display != nullptr) { |
| 8230 | const auto& state = display->getCompositionDisplay()->getState(); |
| 8231 | captureResults.capturedDataspace = |
| 8232 | pickBestDataspace(requestedDataspace, display, captureResults.capturedHdrLayers, |
| 8233 | renderArea->getHintForSeamlessTransition()); |
| 8234 | sdrWhitePointNits = state.sdrWhitePointNits; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8235 | |
Alec Mouri | b4814de | 2023-09-11 22:09:03 +0000 | [diff] [blame] | 8236 | // TODO(b/298219334): Clean this up once we verify this doesn't break anything |
| 8237 | static constexpr bool kScreenshotsDontDim = true; |
| 8238 | |
| 8239 | if (kScreenshotsDontDim && !captureResults.capturedHdrLayers) { |
| 8240 | displayBrightnessNits = sdrWhitePointNits; |
| 8241 | } else { |
| 8242 | displayBrightnessNits = state.displayBrightnessNits; |
| 8243 | // Only clamp the display brightness if this is not a seamless transition. Otherwise |
| 8244 | // for seamless transitions it's important to match the current display state as the |
| 8245 | // buffer will be shown under these same conditions, and we want to avoid any |
| 8246 | // flickers |
| 8247 | if (sdrWhitePointNits > 1.0f && !renderArea->getHintForSeamlessTransition()) { |
| 8248 | // Restrict the amount of HDR "headroom" in the screenshot to avoid over-dimming |
| 8249 | // the SDR portion. 2.0 chosen by experimentation |
| 8250 | constexpr float kMaxScreenshotHeadroom = 2.0f; |
| 8251 | displayBrightnessNits = std::min(sdrWhitePointNits * kMaxScreenshotHeadroom, |
| 8252 | displayBrightnessNits); |
| 8253 | } |
Alec Mouri | 5e488f8 | 2023-09-15 01:27:49 +0000 | [diff] [blame] | 8254 | } |
Alec Mouri | ffb3221 | 2023-09-16 19:29:15 +0000 | [diff] [blame] | 8255 | |
| 8256 | // Screenshots leaving the device should be colorimetric |
| 8257 | if (requestedDataspace == ui::Dataspace::UNKNOWN && |
| 8258 | renderArea->getHintForSeamlessTransition()) { |
Alec Mouri | 5e488f8 | 2023-09-15 01:27:49 +0000 | [diff] [blame] | 8259 | renderIntent = state.renderIntent; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8260 | } |
| 8261 | } |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8262 | } |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8263 | |
| 8264 | captureResults.buffer = capturedBuffer->getBuffer(); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8265 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8266 | ui::LayerStack layerStack{ui::DEFAULT_LAYER_STACK}; |
| 8267 | if (!layers.empty()) { |
| 8268 | const sp<LayerFE>& layerFE = layers.back().second; |
| 8269 | layerStack = layerFE->getCompositionState()->outputFilter.layerStack; |
Yichi Chen | 40773d9 | 2020-04-01 10:10:18 +0800 | [diff] [blame] | 8270 | } |
Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 8271 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8272 | auto copyLayerFEs = [&layers]() { |
| 8273 | std::vector<sp<compositionengine::LayerFE>> layerFEs; |
| 8274 | layerFEs.reserve(layers.size()); |
| 8275 | for (const auto& [_, layerFE] : layers) { |
| 8276 | layerFEs.push_back(layerFE); |
| 8277 | } |
| 8278 | return layerFEs; |
| 8279 | }; |
| 8280 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8281 | auto present = [this, buffer = capturedBuffer, dataspace = captureResults.capturedDataspace, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8282 | sdrWhitePointNits, displayBrightnessNits, grayscale, isProtected, |
| 8283 | layerFEs = copyLayerFEs(), layerStack, regionSampling, |
| 8284 | renderArea = std::move(renderArea), renderIntent]() -> FenceResult { |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8285 | std::unique_ptr<compositionengine::CompositionEngine> compositionEngine = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8286 | mFactory.createCompositionEngine(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8287 | compositionEngine->setRenderEngine(mRenderEngine.get()); |
| 8288 | |
| 8289 | compositionengine::Output::ColorProfile colorProfile{.dataspace = dataspace, |
| 8290 | .renderIntent = renderIntent}; |
| 8291 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8292 | float targetBrightness = 1.0f; |
| 8293 | if (dataspace == ui::Dataspace::BT2020_HLG) { |
| 8294 | const float maxBrightnessNits = displayBrightnessNits / sdrWhitePointNits * 203; |
| 8295 | // With a low dimming ratio, don't fit the entire curve. Otherwise mixed content |
| 8296 | // will appear way too bright. |
| 8297 | if (maxBrightnessNits < 1000.f) { |
| 8298 | targetBrightness = 1000.f / maxBrightnessNits; |
| 8299 | } |
| 8300 | } |
| 8301 | |
Alec Mouri | ffb3221 | 2023-09-16 19:29:15 +0000 | [diff] [blame] | 8302 | // Screenshots leaving the device must not dim in gamma space. |
| 8303 | const bool dimInGammaSpaceForEnhancedScreenshots = mDimInGammaSpaceForEnhancedScreenshots && |
| 8304 | renderArea->getHintForSeamlessTransition(); |
| 8305 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8306 | std::shared_ptr<ScreenCaptureOutput> output = createScreenCaptureOutput( |
| 8307 | ScreenCaptureOutputArgs{.compositionEngine = *compositionEngine, |
| 8308 | .colorProfile = colorProfile, |
| 8309 | .renderArea = *renderArea, |
| 8310 | .layerStack = layerStack, |
| 8311 | .buffer = std::move(buffer), |
| 8312 | .sdrWhitePointNits = sdrWhitePointNits, |
| 8313 | .displayBrightnessNits = displayBrightnessNits, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8314 | .targetBrightness = targetBrightness, |
Alec Mouri | 7dae9c1 | 2023-07-13 19:40:53 +0000 | [diff] [blame] | 8315 | .regionSampling = regionSampling, |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 8316 | .treat170mAsSrgb = mTreat170mAsSrgb, |
| 8317 | .dimInGammaSpaceForEnhancedScreenshots = |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8318 | dimInGammaSpaceForEnhancedScreenshots, |
| 8319 | .isProtected = isProtected}); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8320 | |
| 8321 | const float colorSaturation = grayscale ? 0 : 1; |
| 8322 | compositionengine::CompositionRefreshArgs refreshArgs{ |
| 8323 | .outputs = {output}, |
| 8324 | .layers = std::move(layerFEs), |
| 8325 | .updatingOutputGeometryThisFrame = true, |
| 8326 | .updatingGeometryThisFrame = true, |
| 8327 | .colorTransformMatrix = calculateColorMatrix(colorSaturation), |
| 8328 | }; |
| 8329 | compositionEngine->present(refreshArgs); |
| 8330 | |
| 8331 | return output->getRenderSurface()->getClientTargetAcquireFence(); |
| 8332 | }; |
| 8333 | |
| 8334 | // If RenderEngine is threaded, we can safely call CompositionEngine::present off the main |
| 8335 | // thread as the RenderEngine::drawLayers call will run on RenderEngine's thread. Otherwise, |
| 8336 | // we need RenderEngine to run on the main thread so we call CompositionEngine::present |
| 8337 | // immediately. |
| 8338 | // |
| 8339 | // TODO(b/196334700) Once we use RenderEngineThreaded everywhere we can always defer the call |
| 8340 | // to CompositionEngine::present. |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 8341 | auto presentFuture = mRenderEngine->isThreaded() ? ftl::defer(std::move(present)).share() |
| 8342 | : ftl::yield(present()).share(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8343 | |
| 8344 | for (auto& [layer, layerFE] : layers) { |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 8345 | layer->onLayerDisplayed(presentFuture, ui::INVALID_LAYER_STACK, |
| 8346 | [layerFE = std::move(layerFE)](FenceResult) { |
| 8347 | if (FlagManager::getInstance() |
| 8348 | .screenshot_fence_preservation()) { |
| 8349 | const auto compositionResult = |
| 8350 | layerFE->stealCompositionResult(); |
| 8351 | const auto& fences = compositionResult.releaseFences; |
| 8352 | // CompositionEngine may choose to cull layers that |
| 8353 | // aren't visible, so pass a non-fence. |
| 8354 | return fences.empty() ? Fence::NO_FENCE |
| 8355 | : fences.back().first.get(); |
| 8356 | } else { |
| 8357 | return layerFE->stealCompositionResult() |
| 8358 | .releaseFences.back() |
| 8359 | .first.get(); |
| 8360 | } |
| 8361 | }); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8362 | } |
| 8363 | |
| 8364 | return presentFuture; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 8365 | } |
| 8366 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8367 | void SurfaceFlinger::traverseLegacyLayers(const LayerVector::Visitor& visitor) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8368 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8369 | for (auto& layer : mLegacyLayers) { |
| 8370 | visitor(layer.second.get()); |
| 8371 | } |
| 8372 | } else { |
| 8373 | mDrawingState.traverse(visitor); |
| 8374 | } |
| 8375 | } |
| 8376 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 8377 | // --------------------------------------------------------------------------- |
| 8378 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 8379 | void SurfaceFlinger::State::traverse(const LayerVector::Visitor& visitor) const { |
| 8380 | layersSortedByZ.traverse(visitor); |
| 8381 | } |
| 8382 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 8383 | void SurfaceFlinger::State::traverseInZOrder(const LayerVector::Visitor& visitor) const { |
| 8384 | layersSortedByZ.traverseInZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 8385 | } |
| 8386 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 8387 | void SurfaceFlinger::State::traverseInReverseZOrder(const LayerVector::Visitor& visitor) const { |
| 8388 | layersSortedByZ.traverseInReverseZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 8389 | } |
| 8390 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8391 | void SurfaceFlinger::traverseLayersInLayerStack(ui::LayerStack layerStack, const int32_t uid, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8392 | std::unordered_set<uint32_t> excludeLayerIds, |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 8393 | const LayerVector::Visitor& visitor) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8394 | // We loop through the first level of layers without traversing, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 8395 | // as we need to determine which layers belong to the requested display. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8396 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 8397 | if (layer->getLayerStack() != layerStack) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8398 | continue; |
| 8399 | } |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 8400 | // relative layers are traversed in Layer::traverseInZOrder |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8401 | layer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 8402 | if (layer->isInternalDisplayOverlay()) { |
Adrian Roos | 8acf5a0 | 2018-01-17 21:28:19 +0100 | [diff] [blame] | 8403 | return; |
| 8404 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8405 | if (!layer->isVisible()) { |
| 8406 | return; |
| 8407 | } |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8408 | if (uid != CaptureArgs::UNSET_UID && layer->getOwnerUid() != uid) { |
| 8409 | return; |
| 8410 | } |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8411 | |
| 8412 | if (!excludeLayerIds.empty()) { |
| 8413 | auto p = sp<Layer>::fromExisting(layer); |
| 8414 | while (p != nullptr) { |
| 8415 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 8416 | return; |
| 8417 | } |
| 8418 | p = p->getParent(); |
| 8419 | } |
| 8420 | } |
| 8421 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8422 | visitor(layer); |
| 8423 | }); |
| 8424 | } |
| 8425 | } |
| 8426 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8427 | ftl::Optional<scheduler::FrameRateMode> SurfaceFlinger::getPreferredDisplayMode( |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8428 | PhysicalDisplayId displayId, DisplayModeId defaultModeId) const { |
| 8429 | if (const auto schedulerMode = mScheduler->getPreferredDisplayMode(); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8430 | schedulerMode.modePtr->getPhysicalDisplayId() == displayId) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8431 | return schedulerMode; |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8432 | } |
| 8433 | |
| 8434 | return mPhysicalDisplays.get(displayId) |
| 8435 | .transform(&PhysicalDisplay::snapshotRef) |
| 8436 | .and_then([&](const display::DisplaySnapshot& snapshot) { |
| 8437 | return snapshot.displayModes().get(defaultModeId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 8438 | }) |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8439 | .transform([](const DisplayModePtr& modePtr) { |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 8440 | return scheduler::FrameRateMode{modePtr->getPeakFps(), ftl::as_non_null(modePtr)}; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8441 | }); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8442 | } |
| 8443 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8444 | status_t SurfaceFlinger::setDesiredDisplayModeSpecsInternal( |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 8445 | const sp<DisplayDevice>& display, |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8446 | const scheduler::RefreshRateSelector::PolicyVariant& policy) { |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8447 | const auto displayId = display->getPhysicalId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8448 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8449 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 8450 | Mutex::Autolock lock(mStateLock); |
| 8451 | |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 8452 | if (mDebugDisplayModeSetByBackdoor) { |
| 8453 | // ignore this request as mode is overridden by backdoor |
| 8454 | return NO_ERROR; |
| 8455 | } |
| 8456 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8457 | auto& selector = display->refreshRateSelector(); |
| 8458 | using SetPolicyResult = scheduler::RefreshRateSelector::SetPolicyResult; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8459 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8460 | switch (selector.setPolicy(policy)) { |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8461 | case SetPolicyResult::Invalid: |
| 8462 | return BAD_VALUE; |
| 8463 | case SetPolicyResult::Unchanged: |
| 8464 | return NO_ERROR; |
| 8465 | case SetPolicyResult::Changed: |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8466 | break; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8467 | } |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8468 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 8469 | if (!shouldApplyRefreshRateSelectorPolicy(*display)) { |
| 8470 | ALOGV("%s(%s): Skipped applying policy", __func__, to_string(displayId).c_str()); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8471 | return NO_ERROR; |
| 8472 | } |
| 8473 | |
| 8474 | return applyRefreshRateSelectorPolicy(displayId, selector); |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8475 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8476 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 8477 | bool SurfaceFlinger::shouldApplyRefreshRateSelectorPolicy(const DisplayDevice& display) const { |
| 8478 | if (display.isPoweredOn() || mPhysicalDisplays.size() == 1) return true; |
| 8479 | |
| 8480 | LOG_ALWAYS_FATAL_IF(display.isVirtual()); |
| 8481 | const auto displayId = display.getPhysicalId(); |
| 8482 | |
| 8483 | // The display is powered off, and this is a multi-display device. If the display is the |
| 8484 | // inactive internal display of a dual-display foldable, then the policy will be applied |
| 8485 | // when it becomes active upon powering on. |
| 8486 | // |
| 8487 | // TODO(b/255635711): Remove this function (i.e. returning `false` as a special case) once |
| 8488 | // concurrent mode setting across multiple (potentially powered off) displays is supported. |
| 8489 | // |
| 8490 | return displayId == mActiveDisplayId || |
| 8491 | !mPhysicalDisplays.get(displayId) |
| 8492 | .transform(&PhysicalDisplay::isInternal) |
| 8493 | .value_or(false); |
| 8494 | } |
| 8495 | |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8496 | status_t SurfaceFlinger::applyRefreshRateSelectorPolicy( |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8497 | PhysicalDisplayId displayId, const scheduler::RefreshRateSelector& selector, bool force) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8498 | const scheduler::RefreshRateSelector::Policy currentPolicy = selector.getCurrentPolicy(); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8499 | ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str()); |
Adrian Salido | ab6ef6c | 2019-08-28 10:02:49 -0700 | [diff] [blame] | 8500 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 8501 | // TODO(b/140204874): Leave the event in until we do proper testing with all apps that might |
| 8502 | // be depending in this callback. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8503 | if (const auto activeMode = selector.getActiveMode(); displayId == mActiveDisplayId) { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8504 | mScheduler->onPrimaryDisplayModeChanged(scheduler::Cycle::Render, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8505 | toggleKernelIdleTimer(); |
| 8506 | } else { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8507 | mScheduler->onNonPrimaryDisplayModeChanged(scheduler::Cycle::Render, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8508 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 8509 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8510 | auto preferredModeOpt = getPreferredDisplayMode(displayId, currentPolicy.defaultMode); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8511 | if (!preferredModeOpt) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8512 | ALOGE("%s: Preferred mode is unknown", __func__); |
| 8513 | return NAME_NOT_FOUND; |
| 8514 | } |
| 8515 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8516 | auto preferredMode = std::move(*preferredModeOpt); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8517 | const auto preferredModeId = preferredMode.modePtr->getId(); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 8518 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8519 | const Fps preferredFps = preferredMode.fps; |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8520 | ALOGV("Switching to Scheduler preferred mode %d (%s)", ftl::to_underlying(preferredModeId), |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8521 | to_string(preferredFps).c_str()); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8522 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8523 | if (!selector.isModeAllowed(preferredMode)) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8524 | ALOGE("%s: Preferred mode %d is disallowed", __func__, ftl::to_underlying(preferredModeId)); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8525 | return INVALID_OPERATION; |
Dominik Laskowski | 4f1dd8c | 2019-04-17 15:54:30 -0700 | [diff] [blame] | 8526 | } |
| 8527 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 8528 | setDesiredMode({std::move(preferredMode), .emitEvent = true, .force = force}); |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 8529 | |
| 8530 | // Update the frameRateOverride list as the display render rate might have changed |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8531 | if (mScheduler->updateFrameRateOverrides(scheduler::GlobalSignals{}, preferredFps)) { |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 8532 | triggerOnFrameRateOverridesChanged(); |
| 8533 | } |
| 8534 | |
Ady Abraham | d9b3ea6 | 2019-02-26 14:08:03 -0800 | [diff] [blame] | 8535 | return NO_ERROR; |
| 8536 | } |
| 8537 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8538 | namespace { |
| 8539 | FpsRange translate(const gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange& aidlRange) { |
| 8540 | return FpsRange{Fps::fromValue(aidlRange.min), Fps::fromValue(aidlRange.max)}; |
| 8541 | } |
| 8542 | |
| 8543 | FpsRanges translate(const gui::DisplayModeSpecs::RefreshRateRanges& aidlRanges) { |
| 8544 | return FpsRanges{translate(aidlRanges.physical), translate(aidlRanges.render)}; |
| 8545 | } |
| 8546 | |
| 8547 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange translate(const FpsRange& range) { |
| 8548 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange aidlRange; |
| 8549 | aidlRange.min = range.min.getValue(); |
| 8550 | aidlRange.max = range.max.getValue(); |
| 8551 | return aidlRange; |
| 8552 | } |
| 8553 | |
| 8554 | gui::DisplayModeSpecs::RefreshRateRanges translate(const FpsRanges& ranges) { |
| 8555 | gui::DisplayModeSpecs::RefreshRateRanges aidlRanges; |
| 8556 | aidlRanges.physical = translate(ranges.physical); |
| 8557 | aidlRanges.render = translate(ranges.render); |
| 8558 | return aidlRanges; |
| 8559 | } |
| 8560 | |
| 8561 | } // namespace |
| 8562 | |
| 8563 | status_t SurfaceFlinger::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 8564 | const gui::DisplayModeSpecs& specs) { |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8565 | ATRACE_CALL(); |
| 8566 | |
| 8567 | if (!displayToken) { |
| 8568 | return BAD_VALUE; |
| 8569 | } |
| 8570 | |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 8571 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8572 | const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayToken)); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8573 | if (!display) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8574 | ALOGE("Attempt to set desired display modes for invalid display token %p", |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8575 | displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8576 | return NAME_NOT_FOUND; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8577 | } else if (display->isVirtual()) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8578 | ALOGW("Attempt to set desired display modes for virtual display"); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8579 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8580 | } else { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8581 | using Policy = scheduler::RefreshRateSelector::DisplayManagerPolicy; |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8582 | const Policy policy{DisplayModeId(specs.defaultMode), translate(specs.primaryRanges), |
| 8583 | translate(specs.appRequestRanges), specs.allowGroupSwitching}; |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 8584 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8585 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8586 | } |
| 8587 | }); |
| 8588 | |
| 8589 | return future.get(); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8590 | } |
| 8591 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 8592 | status_t SurfaceFlinger::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8593 | gui::DisplayModeSpecs* outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8594 | ATRACE_CALL(); |
| 8595 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8596 | if (!displayToken || !outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8597 | return BAD_VALUE; |
| 8598 | } |
| 8599 | |
| 8600 | Mutex::Autolock lock(mStateLock); |
| 8601 | const auto display = getDisplayDeviceLocked(displayToken); |
| 8602 | if (!display) { |
| 8603 | return NAME_NOT_FOUND; |
| 8604 | } |
| 8605 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8606 | if (display->isVirtual()) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 8607 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8608 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8609 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8610 | scheduler::RefreshRateSelector::Policy policy = |
| 8611 | display->refreshRateSelector().getDisplayManagerPolicy(); |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8612 | outSpecs->defaultMode = ftl::to_underlying(policy.defaultMode); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8613 | outSpecs->allowGroupSwitching = policy.allowGroupSwitching; |
| 8614 | outSpecs->primaryRanges = translate(policy.primaryRanges); |
| 8615 | outSpecs->appRequestRanges = translate(policy.appRequestRanges); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8616 | return NO_ERROR; |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8617 | } |
| 8618 | |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 8619 | void SurfaceFlinger::onLayerFirstRef(Layer* layer) { |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8620 | mNumLayers++; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8621 | if (!layer->isRemovedFromCurrentState()) { |
| 8622 | mScheduler->registerLayer(layer); |
| 8623 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8624 | } |
| 8625 | |
| 8626 | void SurfaceFlinger::onLayerDestroyed(Layer* layer) { |
| 8627 | mNumLayers--; |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8628 | removeHierarchyFromOffscreenLayers(layer); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8629 | if (!layer->isRemovedFromCurrentState()) { |
| 8630 | mScheduler->deregisterLayer(layer); |
| 8631 | } |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 8632 | if (mTransactionTracing) { |
| 8633 | mTransactionTracing->onLayerRemoved(layer->getSequence()); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 8634 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 8635 | mScheduler->onLayerDestroyed(layer); |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8636 | } |
| 8637 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8638 | void SurfaceFlinger::onLayerUpdate() { |
| 8639 | scheduleCommit(FrameHint::kActive); |
| 8640 | } |
| 8641 | |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8642 | // WARNING: ONLY CALL THIS FROM LAYER DTOR |
| 8643 | // Here we add children in the current state to offscreen layers and remove the |
| 8644 | // layer itself from the offscreen layer list. Since |
| 8645 | // this is the dtor, it is safe to access the current state. This keeps us |
| 8646 | // from dangling children layers such that they are not reachable from the |
| 8647 | // Drawing state nor the offscreen layer list |
| 8648 | // See b/141111965 |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8649 | void SurfaceFlinger::removeHierarchyFromOffscreenLayers(Layer* layer) { |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8650 | for (auto& child : layer->getCurrentChildren()) { |
| 8651 | mOffscreenLayers.emplace(child.get()); |
| 8652 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8653 | mOffscreenLayers.erase(layer); |
| 8654 | } |
| 8655 | |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8656 | void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) { |
| 8657 | mOffscreenLayers.erase(layer); |
| 8658 | } |
| 8659 | |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 8660 | status_t SurfaceFlinger::setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, |
| 8661 | float lightPosY, float lightPosZ, |
| 8662 | float lightRadius) { |
| 8663 | Mutex::Autolock _l(mStateLock); |
| 8664 | mCurrentState.globalShadowSettings.ambientColor = vec4(ambientColor); |
| 8665 | mCurrentState.globalShadowSettings.spotColor = vec4(spotColor); |
| 8666 | mCurrentState.globalShadowSettings.lightPos.y = lightPosY; |
| 8667 | mCurrentState.globalShadowSettings.lightPos.z = lightPosZ; |
| 8668 | mCurrentState.globalShadowSettings.lightRadius = lightRadius; |
| 8669 | |
| 8670 | // these values are overridden when calculating the shadow settings for a layer. |
| 8671 | mCurrentState.globalShadowSettings.lightPos.x = 0.f; |
| 8672 | mCurrentState.globalShadowSettings.length = 0.f; |
Vishnu Nair | b13bb95 | 2019-11-15 10:24:08 -0800 | [diff] [blame] | 8673 | return NO_ERROR; |
| 8674 | } |
| 8675 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8676 | const std::unordered_map<std::string, uint32_t>& SurfaceFlinger::getGenericLayerMetadataKeyMap() |
| 8677 | const { |
| 8678 | // TODO(b/149500060): Remove this fixed/static mapping. Please prefer taking |
| 8679 | // on the work to remove the table in that bug rather than adding more to |
| 8680 | // it. |
| 8681 | static const std::unordered_map<std::string, uint32_t> genericLayerMetadataKeyMap{ |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8682 | {"org.chromium.arc.V1_0.TaskId", gui::METADATA_TASK_ID}, |
| 8683 | {"org.chromium.arc.V1_0.CursorInfo", gui::METADATA_MOUSE_CURSOR}, |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8684 | }; |
| 8685 | return genericLayerMetadataKeyMap; |
| 8686 | } |
| 8687 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8688 | status_t SurfaceFlinger::setGameModeFrameRateOverride(uid_t uid, float frameRate) { |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 8689 | PhysicalDisplayId displayId = [&]() { |
| 8690 | Mutex::Autolock lock(mStateLock); |
| 8691 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 8692 | }(); |
| 8693 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8694 | mScheduler->setGameModeFrameRateForUid(FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8695 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 8696 | return NO_ERROR; |
| 8697 | } |
| 8698 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8699 | status_t SurfaceFlinger::setGameDefaultFrameRateOverride(uid_t uid, float frameRate) { |
| 8700 | if (FlagManager::getInstance().game_default_frame_rate()) { |
| 8701 | mScheduler->setGameDefaultFrameRateForUid( |
| 8702 | FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
| 8703 | } |
| 8704 | return NO_ERROR; |
| 8705 | } |
| 8706 | |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8707 | status_t SurfaceFlinger::updateSmallAreaDetection( |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 8708 | std::vector<std::pair<int32_t, float>>& appIdThresholdMappings) { |
| 8709 | mScheduler->updateSmallAreaDetection(appIdThresholdMappings); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8710 | return NO_ERROR; |
| 8711 | } |
| 8712 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 8713 | status_t SurfaceFlinger::setSmallAreaDetectionThreshold(int32_t appId, float threshold) { |
| 8714 | mScheduler->setSmallAreaDetectionThreshold(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8715 | return NO_ERROR; |
| 8716 | } |
| 8717 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8718 | void SurfaceFlinger::enableRefreshRateOverlay(bool enable) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 8719 | bool setByHwc = getHwComposer().hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8720 | for (const auto& [id, display] : mPhysicalDisplays) { |
Sally Qi | de329f2 | 2023-09-26 16:21:39 -0700 | [diff] [blame] | 8721 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal || |
| 8722 | FlagManager::getInstance().refresh_rate_overlay_on_external_display()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8723 | if (const auto device = getDisplayDeviceLocked(id)) { |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 8724 | const auto enableOverlay = [&](const bool setByHwc) FTL_FAKE_GUARD( |
| 8725 | kMainThreadContext) { |
| 8726 | device->enableRefreshRateOverlay(enable, setByHwc, mRefreshRateOverlaySpinner, |
| 8727 | mRefreshRateOverlayRenderRate, |
| 8728 | mRefreshRateOverlayShowInMiddle); |
| 8729 | }; |
| 8730 | enableOverlay(setByHwc); |
| 8731 | if (setByHwc) { |
| 8732 | const auto status = |
| 8733 | getHwComposer().setRefreshRateChangedCallbackDebugEnabled(id, enable); |
| 8734 | if (status != NO_ERROR) { |
| 8735 | ALOGE("Error updating the refresh rate changed callback debug enabled"); |
| 8736 | enableOverlay(/*setByHwc*/ false); |
| 8737 | } |
| 8738 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8739 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8740 | } |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 8741 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8742 | } |
| 8743 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 8744 | void SurfaceFlinger::enableHdrSdrRatioOverlay(bool enable) { |
| 8745 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 8746 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal) { |
| 8747 | if (const auto device = getDisplayDeviceLocked(id)) { |
| 8748 | device->enableHdrSdrRatioOverlay(enable); |
| 8749 | } |
| 8750 | } |
| 8751 | } |
| 8752 | } |
| 8753 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8754 | int SurfaceFlinger::getGpuContextPriority() { |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 8755 | return getRenderEngine().getContextPriority(); |
Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 8756 | } |
| 8757 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8758 | int SurfaceFlinger::calculateMaxAcquiredBufferCount(Fps refreshRate, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8759 | std::chrono::nanoseconds presentLatency) { |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8760 | auto pipelineDepth = presentLatency.count() / refreshRate.getPeriodNsecs(); |
| 8761 | if (presentLatency.count() % refreshRate.getPeriodNsecs()) { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8762 | pipelineDepth++; |
| 8763 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8764 | return std::max(minAcquiredBuffers, static_cast<int64_t>(pipelineDepth - 1)); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8765 | } |
| 8766 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8767 | status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 8768 | Fps maxRefreshRate = 60_Hz; |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8769 | |
| 8770 | if (!getHwComposer().isHeadless()) { |
| 8771 | if (const auto display = getDefaultDisplayDevice()) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8772 | maxRefreshRate = display->refreshRateSelector().getSupportedRefreshRateRange().max; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8773 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8774 | } |
| 8775 | |
| 8776 | *buffers = getMaxAcquiredBufferCountForRefreshRate(maxRefreshRate); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8777 | return NO_ERROR; |
| 8778 | } |
| 8779 | |
rnlee | ed20fa4 | 2021-08-10 18:00:03 -0700 | [diff] [blame] | 8780 | uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 8781 | Fps refreshRate = 60_Hz; |
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 | if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) { |
| 8784 | refreshRate = *frameRateOverride; |
| 8785 | } else if (!getHwComposer().isHeadless()) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8786 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked())) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8787 | refreshRate = display->refreshRateSelector().getActiveMode().fps; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8788 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8789 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8790 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8791 | return getMaxAcquiredBufferCountForRefreshRate(refreshRate); |
| 8792 | } |
| 8793 | |
| 8794 | int SurfaceFlinger::getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 8795 | const auto vsyncConfig = |
| 8796 | mScheduler->getVsyncConfiguration().getConfigsForRefreshRate(refreshRate).late; |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8797 | const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration; |
| 8798 | return calculateMaxAcquiredBufferCount(refreshRate, presentLatency); |
| 8799 | } |
| 8800 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 8801 | void SurfaceFlinger::handleLayerCreatedLocked(const LayerCreatedState& state, VsyncId vsyncId) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8802 | sp<Layer> layer = state.layer.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8803 | if (!layer) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8804 | ALOGD("Layer was destroyed soon after creation %p", state.layer.unsafe_get()); |
| 8805 | return; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8806 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 8807 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8808 | |
| 8809 | sp<Layer> parent; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8810 | bool addToRoot = state.addToRoot; |
| 8811 | if (state.initialParent != nullptr) { |
| 8812 | parent = state.initialParent.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8813 | if (parent == nullptr) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8814 | ALOGD("Parent was destroyed soon after creation %p", state.initialParent.unsafe_get()); |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 8815 | addToRoot = false; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8816 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8817 | } |
| 8818 | |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 8819 | if (parent == nullptr && addToRoot) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 8820 | layer->setIsAtRoot(true); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8821 | mCurrentState.layersSortedByZ.add(layer); |
| 8822 | } else if (parent == nullptr) { |
| 8823 | layer->onRemovedFromCurrentState(); |
| 8824 | } else if (parent->isRemovedFromCurrentState()) { |
| 8825 | parent->addChild(layer); |
| 8826 | layer->onRemovedFromCurrentState(); |
| 8827 | } else { |
| 8828 | parent->addChild(layer); |
| 8829 | } |
| 8830 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 8831 | ui::LayerStack layerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 8832 | sp<const DisplayDevice> hintDisplay; |
| 8833 | // Find the display that includes the layer. |
| 8834 | for (const auto& [token, display] : mDisplays) { |
| 8835 | if (display->getLayerStack() == layerStack) { |
| 8836 | hintDisplay = display; |
| 8837 | break; |
| 8838 | } |
| 8839 | } |
| 8840 | |
| 8841 | if (hintDisplay) { |
| 8842 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
| 8843 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8844 | } |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8845 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8846 | void SurfaceFlinger::sample() { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8847 | if (!mLumaSampling || !mRegionSamplingThread) { |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8848 | return; |
| 8849 | } |
| 8850 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 8851 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 8852 | const auto scheduleFrameTimeOpt = scheduledFrameResultOpt |
| 8853 | ? std::optional{scheduledFrameResultOpt->callbackTime} |
| 8854 | : std::nullopt; |
| 8855 | mRegionSamplingThread->onCompositionComplete(scheduleFrameTimeOpt); |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8856 | } |
| 8857 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8858 | void SurfaceFlinger::onActiveDisplaySizeChanged(const DisplayDevice& activeDisplay) { |
| 8859 | mScheduler->onActiveDisplayAreaChanged(activeDisplay.getWidth() * activeDisplay.getHeight()); |
| 8860 | getRenderEngine().onActiveDisplaySizeChanged(activeDisplay.getSize()); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8861 | } |
| 8862 | |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 8863 | sp<DisplayDevice> SurfaceFlinger::getActivatableDisplay() const { |
| 8864 | if (mPhysicalDisplays.size() == 1) return nullptr; |
| 8865 | |
| 8866 | // TODO(b/255635821): Choose the pacesetter display, considering both internal and external |
| 8867 | // displays. For now, pick the other internal display, assuming a dual-display foldable. |
| 8868 | return findDisplay([this](const DisplayDevice& display) REQUIRES(mStateLock) { |
| 8869 | const auto idOpt = PhysicalDisplayId::tryCast(display.getId()); |
| 8870 | return idOpt && *idOpt != mActiveDisplayId && display.isPoweredOn() && |
| 8871 | mPhysicalDisplays.get(*idOpt) |
| 8872 | .transform(&PhysicalDisplay::isInternal) |
| 8873 | .value_or(false); |
| 8874 | }); |
| 8875 | } |
| 8876 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8877 | void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveDisplayPtr, |
| 8878 | const DisplayDevice& activeDisplay) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8879 | ATRACE_CALL(); |
| 8880 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8881 | // 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] | 8882 | // because DM is about to send its policy via setDesiredDisplayModeSpecs. |
| 8883 | bool forceApplyPolicy = false; |
| 8884 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8885 | if (inactiveDisplayPtr) { |
| 8886 | inactiveDisplayPtr->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false); |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 8887 | forceApplyPolicy = true; |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 8888 | } |
| 8889 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8890 | mActiveDisplayId = activeDisplay.getPhysicalId(); |
| 8891 | activeDisplay.getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 8892 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 8893 | mScheduler->resetPhaseConfiguration(activeDisplay.getActiveMode().fps); |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 8894 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8895 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8896 | mScheduler->setModeChangePending(false); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8897 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 8898 | mScheduler->setPacesetterDisplay(mActiveDisplayId); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 8899 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8900 | onActiveDisplaySizeChanged(activeDisplay); |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8901 | mActiveDisplayTransformHint = activeDisplay.getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 8902 | sActiveDisplayRotationFlags = ui::Transform::toRotationFlags(activeDisplay.getOrientation()); |
Ady Abraham | 85d692d | 2021-09-28 14:08:54 -0700 | [diff] [blame] | 8903 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 8904 | // 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] | 8905 | // that case, its preferred mode has not been propagated to HWC (via setDesiredMode). In either |
| 8906 | // case, the Scheduler's cachedModeChangedParams must be initialized to the newly active mode, |
| 8907 | // 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] | 8908 | applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay.refreshRateSelector(), |
| 8909 | forceApplyPolicy); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8910 | } |
| 8911 | |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 8912 | status_t SurfaceFlinger::addWindowInfosListener(const sp<IWindowInfosListener>& windowInfosListener, |
| 8913 | gui::WindowInfosListenerInfo* outInfo) { |
| 8914 | mWindowInfosListenerInvoker->addWindowInfosListener(windowInfosListener, outInfo); |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 8915 | setTransactionFlags(eInputInfoUpdateNeeded); |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 8916 | return NO_ERROR; |
| 8917 | } |
| 8918 | |
| 8919 | status_t SurfaceFlinger::removeWindowInfosListener( |
| 8920 | const sp<IWindowInfosListener>& windowInfosListener) const { |
| 8921 | mWindowInfosListenerInvoker->removeWindowInfosListener(windowInfosListener); |
| 8922 | return NO_ERROR; |
| 8923 | } |
| 8924 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 8925 | status_t SurfaceFlinger::getStalledTransactionInfo( |
| 8926 | int pid, std::optional<TransactionHandler::StalledTransactionInfo>& result) { |
| 8927 | result = mTransactionHandler.getStalledTransactionInfo(pid); |
| 8928 | return NO_ERROR; |
| 8929 | } |
| 8930 | |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 8931 | void SurfaceFlinger::updateHdcpLevels(hal::HWDisplayId hwcDisplayId, int32_t connectedLevel, |
| 8932 | int32_t maxLevel) { |
| 8933 | if (!FlagManager::getInstance().connected_display()) { |
| 8934 | return; |
| 8935 | } |
| 8936 | |
| 8937 | Mutex::Autolock lock(mStateLock); |
| 8938 | |
| 8939 | const auto idOpt = getHwComposer().toPhysicalDisplayId(hwcDisplayId); |
| 8940 | if (!idOpt) { |
| 8941 | ALOGE("No display found for HDCP level changed event: connected=%d, max=%d for " |
| 8942 | "display=%" PRIu64, |
| 8943 | connectedLevel, maxLevel, hwcDisplayId); |
| 8944 | return; |
| 8945 | } |
| 8946 | |
| 8947 | const bool isInternalDisplay = |
| 8948 | mPhysicalDisplays.get(*idOpt).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 8949 | if (isInternalDisplay) { |
| 8950 | ALOGW("Unexpected HDCP level changed for internal display: connected=%d, max=%d for " |
| 8951 | "display=%" PRIu64, |
| 8952 | connectedLevel, maxLevel, hwcDisplayId); |
| 8953 | return; |
| 8954 | } |
| 8955 | |
| 8956 | static_cast<void>(mScheduler->schedule([this, displayId = *idOpt, connectedLevel, maxLevel]() { |
| 8957 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayId))) { |
| 8958 | Mutex::Autolock lock(mStateLock); |
| 8959 | display->setSecure(connectedLevel >= 2 /* HDCP_V1 */); |
| 8960 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8961 | mScheduler->onHdcpLevelsChanged(scheduler::Cycle::Render, displayId, connectedLevel, |
| 8962 | maxLevel); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 8963 | })); |
| 8964 | } |
| 8965 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8966 | std::shared_ptr<renderengine::ExternalTexture> SurfaceFlinger::getExternalTextureFromBufferData( |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8967 | BufferData& bufferData, const char* layerName, uint64_t transactionId) { |
| 8968 | if (bufferData.buffer && |
| 8969 | exceedsMaxRenderTargetSize(bufferData.buffer->getWidth(), bufferData.buffer->getHeight())) { |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 8970 | std::string errorMessage = |
| 8971 | base::StringPrintf("Attempted to create an ExternalTexture with size (%u, %u) for " |
| 8972 | "layer %s that exceeds render target size limit of %u.", |
| 8973 | bufferData.buffer->getWidth(), bufferData.buffer->getHeight(), |
| 8974 | layerName, static_cast<uint32_t>(mMaxRenderTargetSize)); |
| 8975 | ALOGD("%s", errorMessage.c_str()); |
| 8976 | if (bufferData.releaseBufferListener) { |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 8977 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
| 8978 | String8(errorMessage.c_str())); |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 8979 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8980 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8981 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8982 | |
| 8983 | bool cachedBufferChanged = |
| 8984 | bufferData.flags.test(BufferData::BufferDataChange::cachedBufferChanged); |
| 8985 | if (cachedBufferChanged && bufferData.buffer) { |
| 8986 | auto result = ClientCache::getInstance().add(bufferData.cachedBuffer, bufferData.buffer); |
| 8987 | if (result.ok()) { |
| 8988 | return result.value(); |
| 8989 | } |
| 8990 | |
| 8991 | if (result.error() == ClientCache::AddError::CacheFull) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 8992 | ALOGE("Attempted to create an ExternalTexture for layer %s but CacheFull", layerName); |
| 8993 | |
| 8994 | if (bufferData.releaseBufferListener) { |
| 8995 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 8996 | String8("Buffer processing hung due to full buffer cache")); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 8997 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8998 | } |
| 8999 | |
| 9000 | return nullptr; |
| 9001 | } |
| 9002 | |
| 9003 | if (cachedBufferChanged) { |
| 9004 | return ClientCache::getInstance().get(bufferData.cachedBuffer); |
| 9005 | } |
| 9006 | |
| 9007 | if (bufferData.buffer) { |
| 9008 | return std::make_shared< |
| 9009 | renderengine::impl::ExternalTexture>(bufferData.buffer, getRenderEngine(), |
| 9010 | renderengine::impl::ExternalTexture::Usage:: |
| 9011 | READABLE); |
| 9012 | } |
| 9013 | |
| 9014 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 9015 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9016 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 9017 | bool SurfaceFlinger::commitMirrorDisplays(VsyncId vsyncId) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9018 | std::vector<MirrorDisplayState> mirrorDisplays; |
| 9019 | { |
| 9020 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
| 9021 | mirrorDisplays = std::move(mMirrorDisplays); |
| 9022 | mMirrorDisplays.clear(); |
| 9023 | if (mirrorDisplays.size() == 0) { |
| 9024 | return false; |
| 9025 | } |
| 9026 | } |
| 9027 | |
| 9028 | sp<IBinder> unused; |
| 9029 | for (const auto& mirrorDisplay : mirrorDisplays) { |
| 9030 | // Set mirror layer's default layer stack to -1 so it doesn't end up rendered on a display |
| 9031 | // accidentally. |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 9032 | sp<Layer> rootMirrorLayer = LayerHandle::getLayer(mirrorDisplay.rootHandle); |
Qi Jing | b8e4c13 | 2023-08-25 23:01:47 +0000 | [diff] [blame] | 9033 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(rootMirrorLayer); |
| 9034 | bool ret = rootMirrorLayer->setLayerStack(ui::LayerStack::fromValue(-1)); |
| 9035 | if (idx >= 0 && ret) { |
| 9036 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 9037 | mCurrentState.layersSortedByZ.add(rootMirrorLayer); |
| 9038 | } |
| 9039 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9040 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 9041 | if (layer->getLayerStack() != mirrorDisplay.layerStack || |
| 9042 | layer->isInternalDisplayOverlay()) { |
| 9043 | continue; |
| 9044 | } |
| 9045 | |
| 9046 | LayerCreationArgs mirrorArgs(this, mirrorDisplay.client, "MirrorLayerParent", |
| 9047 | ISurfaceComposerClient::eNoColorFill, |
| 9048 | gui::LayerMetadata()); |
| 9049 | sp<Layer> childMirror; |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 9050 | { |
| 9051 | Mutex::Autolock lock(mStateLock); |
| 9052 | createEffectLayer(mirrorArgs, &unused, &childMirror); |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 9053 | MUTEX_ALIAS(mStateLock, childMirror->mFlinger->mStateLock); |
Vishnu Nair | de17725 | 2023-04-21 12:44:10 -0700 | [diff] [blame] | 9054 | childMirror->setClonedChild(layer->createClone(childMirror->getSequence())); |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 9055 | childMirror->reparent(mirrorDisplay.rootHandle); |
| 9056 | } |
| 9057 | // lock on mStateLock needs to be released before binder handle gets destroyed |
| 9058 | unused.clear(); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9059 | } |
| 9060 | } |
| 9061 | return true; |
| 9062 | } |
| 9063 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9064 | bool SurfaceFlinger::commitCreatedLayers(VsyncId vsyncId, |
| 9065 | std::vector<LayerCreatedState>& createdLayers) { |
| 9066 | if (createdLayers.size() == 0) { |
| 9067 | return false; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9068 | } |
| 9069 | |
| 9070 | Mutex::Autolock _l(mStateLock); |
| 9071 | for (const auto& createdLayer : createdLayers) { |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 9072 | handleLayerCreatedLocked(createdLayer, vsyncId); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9073 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9074 | mLayersAdded = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9075 | return mLayersAdded; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9076 | } |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9077 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 9078 | void SurfaceFlinger::updateLayerMetadataSnapshot() { |
| 9079 | LayerMetadata parentMetadata; |
| 9080 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 9081 | layer->updateMetadataSnapshot(parentMetadata); |
| 9082 | } |
| 9083 | |
| 9084 | std::unordered_set<Layer*> visited; |
| 9085 | mDrawingState.traverse([&visited](Layer* layer) { |
| 9086 | if (visited.find(layer) != visited.end()) { |
| 9087 | return; |
| 9088 | } |
| 9089 | |
| 9090 | // If the layer isRelativeOf, then either it's relative metadata will be set |
| 9091 | // recursively when updateRelativeMetadataSnapshot is called on its relative parent or |
| 9092 | // it's relative parent has been deleted. Clear the layer's relativeLayerMetadata to ensure |
| 9093 | // that layers with deleted relative parents don't hold stale relativeLayerMetadata. |
| 9094 | if (layer->getDrawingState().isRelativeOf) { |
| 9095 | layer->editLayerSnapshot()->relativeLayerMetadata = {}; |
| 9096 | return; |
| 9097 | } |
| 9098 | |
| 9099 | layer->updateRelativeMetadataSnapshot({}, visited); |
| 9100 | }); |
| 9101 | } |
| 9102 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9103 | void SurfaceFlinger::moveSnapshotsFromCompositionArgs( |
| 9104 | compositionengine::CompositionRefreshArgs& refreshArgs, |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 9105 | const std::vector<std::pair<Layer*, LayerFE*>>& layers) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9106 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9107 | std::vector<std::unique_ptr<frontend::LayerSnapshot>>& snapshots = |
| 9108 | mLayerSnapshotBuilder.getSnapshots(); |
| 9109 | for (auto [_, layerFE] : layers) { |
| 9110 | auto i = layerFE->mSnapshot->globalZ; |
| 9111 | snapshots[i] = std::move(layerFE->mSnapshot); |
| 9112 | } |
| 9113 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9114 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9115 | for (auto [layer, layerFE] : layers) { |
| 9116 | layer->updateLayerSnapshot(std::move(layerFE->mSnapshot)); |
| 9117 | } |
| 9118 | } |
| 9119 | } |
| 9120 | |
| 9121 | std::vector<std::pair<Layer*, LayerFE*>> SurfaceFlinger::moveSnapshotsToCompositionArgs( |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 9122 | compositionengine::CompositionRefreshArgs& refreshArgs, bool cursorOnly) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9123 | std::vector<std::pair<Layer*, LayerFE*>> layers; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9124 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9125 | nsecs_t currentTime = systemTime(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9126 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 9127 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 9128 | if (cursorOnly && |
| 9129 | snapshot->compositionType != |
| 9130 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) { |
| 9131 | return; |
| 9132 | } |
| 9133 | |
| 9134 | if (!snapshot->hasSomethingToDraw()) { |
| 9135 | return; |
| 9136 | } |
| 9137 | |
| 9138 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 9139 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 9140 | "Couldnt find layer object for %s", |
| 9141 | snapshot->getDebugString().c_str()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9142 | auto& legacyLayer = it->second; |
| 9143 | sp<LayerFE> layerFE = legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9144 | snapshot->fps = getLayerFramerate(currentTime, snapshot->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9145 | layerFE->mSnapshot = std::move(snapshot); |
| 9146 | refreshArgs.layers.push_back(layerFE); |
| 9147 | layers.emplace_back(legacyLayer.get(), layerFE.get()); |
| 9148 | }); |
| 9149 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9150 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 9151 | auto moveSnapshots = [&layers, &refreshArgs, cursorOnly](Layer* layer) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9152 | if (const auto& layerFE = layer->getCompositionEngineLayerFE()) { |
| 9153 | if (cursorOnly && |
| 9154 | layer->getLayerSnapshot()->compositionType != |
| 9155 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) |
| 9156 | return; |
| 9157 | layer->updateSnapshot(refreshArgs.updatingGeometryThisFrame); |
| 9158 | layerFE->mSnapshot = layer->stealLayerSnapshot(); |
| 9159 | refreshArgs.layers.push_back(layerFE); |
| 9160 | layers.emplace_back(layer, layerFE.get()); |
| 9161 | } |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 9162 | }; |
| 9163 | |
| 9164 | if (cursorOnly || !mVisibleRegionsDirty) { |
| 9165 | // for hot path avoid traversals by walking though the previous composition list |
| 9166 | for (sp<Layer> layer : mPreviouslyComposedLayers) { |
| 9167 | moveSnapshots(layer.get()); |
| 9168 | } |
| 9169 | } else { |
| 9170 | mPreviouslyComposedLayers.clear(); |
| 9171 | mDrawingState.traverseInZOrder( |
| 9172 | [&moveSnapshots](Layer* layer) { moveSnapshots(layer); }); |
| 9173 | mPreviouslyComposedLayers.reserve(layers.size()); |
| 9174 | for (auto [layer, _] : layers) { |
| 9175 | mPreviouslyComposedLayers.push_back(sp<Layer>::fromExisting(layer)); |
| 9176 | } |
| 9177 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9178 | } |
| 9179 | |
| 9180 | return layers; |
| 9181 | } |
| 9182 | |
| 9183 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9184 | SurfaceFlinger::getLayerSnapshotsForScreenshots( |
| 9185 | std::optional<ui::LayerStack> layerStack, uint32_t uid, |
| 9186 | std::function<bool(const frontend::LayerSnapshot&, bool& outStopTraversal)> |
| 9187 | snapshotFilterFn) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9188 | return [&, layerStack, uid]() { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9189 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers; |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9190 | bool stopTraversal = false; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9191 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 9192 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9193 | if (stopTraversal) { |
| 9194 | return; |
| 9195 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9196 | if (layerStack && snapshot->outputFilter.layerStack != *layerStack) { |
| 9197 | return; |
| 9198 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 9199 | if (uid != CaptureArgs::UNSET_UID && snapshot->uid != gui::Uid(uid)) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9200 | return; |
| 9201 | } |
| 9202 | if (!snapshot->hasSomethingToDraw()) { |
| 9203 | return; |
| 9204 | } |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9205 | if (snapshotFilterFn && !snapshotFilterFn(*snapshot, stopTraversal)) { |
| 9206 | return; |
| 9207 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9208 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9209 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 9210 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 9211 | "Couldnt find layer object for %s", |
| 9212 | snapshot->getDebugString().c_str()); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9213 | Layer* legacyLayer = (it == mLegacyLayers.end()) ? nullptr : it->second.get(); |
| 9214 | sp<LayerFE> layerFE = getFactory().createLayerFE(snapshot->name); |
| 9215 | layerFE->mSnapshot = std::make_unique<frontend::LayerSnapshot>(*snapshot); |
| 9216 | layers.emplace_back(legacyLayer, std::move(layerFE)); |
| 9217 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9218 | |
| 9219 | return layers; |
| 9220 | }; |
| 9221 | } |
| 9222 | |
| 9223 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9224 | SurfaceFlinger::getLayerSnapshotsForScreenshots(std::optional<ui::LayerStack> layerStack, |
| 9225 | uint32_t uid, |
| 9226 | std::unordered_set<uint32_t> excludeLayerIds) { |
| 9227 | return [&, layerStack, uid, excludeLayerIds = std::move(excludeLayerIds)]() { |
| 9228 | if (excludeLayerIds.empty()) { |
| 9229 | auto getLayerSnapshotsFn = |
| 9230 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 9231 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9232 | return layers; |
| 9233 | } |
| 9234 | |
| 9235 | frontend::LayerSnapshotBuilder::Args |
| 9236 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 9237 | .layerLifecycleManager = mLayerLifecycleManager, |
| 9238 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
| 9239 | .displays = mFrontEndDisplayInfos, |
| 9240 | .displayChanges = true, |
| 9241 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9242 | .supportsBlur = mSupportsBlur, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9243 | .forceFullDamage = mForceFullDamage, |
| 9244 | .excludeLayerIds = std::move(excludeLayerIds), |
| 9245 | .supportedLayerGenericMetadata = |
| 9246 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 9247 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 9248 | .skipRoundCornersWhenProtected = |
| 9249 | !getRenderEngine().supportsProtectedContent()}; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9250 | mLayerSnapshotBuilder.update(args); |
| 9251 | |
| 9252 | auto getLayerSnapshotsFn = |
| 9253 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 9254 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9255 | |
| 9256 | args.excludeLayerIds.clear(); |
| 9257 | mLayerSnapshotBuilder.update(args); |
| 9258 | |
| 9259 | return layers; |
| 9260 | }; |
| 9261 | } |
| 9262 | |
| 9263 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9264 | SurfaceFlinger::getLayerSnapshotsForScreenshots(uint32_t rootLayerId, uint32_t uid, |
| 9265 | std::unordered_set<uint32_t> excludeLayerIds, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 9266 | bool childrenOnly, |
| 9267 | const std::optional<FloatRect>& parentCrop) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9268 | return [&, rootLayerId, uid, excludeLayerIds = std::move(excludeLayerIds), childrenOnly, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9269 | parentCrop]() { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9270 | auto root = mLayerHierarchyBuilder.getPartialHierarchy(rootLayerId, childrenOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9271 | frontend::LayerSnapshotBuilder::Args |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9272 | args{.root = root, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9273 | .layerLifecycleManager = mLayerLifecycleManager, |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9274 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9275 | .displays = mFrontEndDisplayInfos, |
| 9276 | .displayChanges = true, |
| 9277 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9278 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9279 | .forceFullDamage = mForceFullDamage, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 9280 | .parentCrop = parentCrop, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9281 | .excludeLayerIds = std::move(excludeLayerIds), |
| 9282 | .supportedLayerGenericMetadata = |
| 9283 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 9284 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 9285 | .skipRoundCornersWhenProtected = |
| 9286 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | c54fdb0 | 2023-11-21 17:19:58 -0800 | [diff] [blame] | 9287 | // The layer may not exist if it was just created and a screenshot was requested immediately |
| 9288 | // after. In this case, the hierarchy will be empty so we will not render any layers. |
| 9289 | args.rootSnapshot.isSecure = mLayerLifecycleManager.getLayerFromId(rootLayerId) && |
| 9290 | mLayerLifecycleManager.isLayerSecure(rootLayerId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9291 | mLayerSnapshotBuilder.update(args); |
| 9292 | |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9293 | auto getLayerSnapshotsFn = |
| 9294 | getLayerSnapshotsForScreenshots({}, uid, /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9295 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9296 | args.root = mLayerHierarchyBuilder.getHierarchy(); |
| 9297 | args.parentCrop.reset(); |
| 9298 | args.excludeLayerIds.clear(); |
| 9299 | mLayerSnapshotBuilder.update(args); |
| 9300 | return layers; |
| 9301 | }; |
| 9302 | } |
| 9303 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9304 | frontend::Update SurfaceFlinger::flushLifecycleUpdates() { |
| 9305 | frontend::Update update; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9306 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 9307 | // Locking: |
| 9308 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 9309 | // we must keep a copy of the transactions (specifically the composer |
| 9310 | // states) around outside the scope of the lock. |
| 9311 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 9312 | // transactions with layers still in the createdLayer queue, flush the transactions |
| 9313 | // before committing the created layers. |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 9314 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9315 | update.transactions = mTransactionHandler.flushTransactions(); |
| 9316 | { |
| 9317 | // TODO(b/238781169) lockless queue this and keep order. |
| 9318 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 9319 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 9320 | mCreatedLayers.clear(); |
| 9321 | update.newLayers = std::move(mNewLayers); |
| 9322 | mNewLayers.clear(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9323 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 9324 | mNewLayerArgs.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9325 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 9326 | mDestroyedHandles.clear(); |
| 9327 | } |
| 9328 | return update; |
| 9329 | } |
| 9330 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9331 | void SurfaceFlinger::doActiveLayersTracingIfNeeded(bool isCompositionComputed, |
| 9332 | bool visibleRegionDirty, TimePoint time, |
| 9333 | VsyncId vsyncId) { |
| 9334 | if (!mLayerTracing.isActiveTracingStarted()) { |
| 9335 | return; |
| 9336 | } |
| 9337 | if (isCompositionComputed != |
| 9338 | mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_COMPOSITION)) { |
| 9339 | return; |
| 9340 | } |
| 9341 | if (!visibleRegionDirty && |
| 9342 | !mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_BUFFERS)) { |
| 9343 | return; |
| 9344 | } |
| 9345 | auto snapshot = takeLayersSnapshotProto(mLayerTracing.getActiveTracingFlags(), time, vsyncId, |
| 9346 | visibleRegionDirty); |
| 9347 | mLayerTracing.addProtoSnapshotToOstream(std::move(snapshot), LayerTracing::Mode::MODE_ACTIVE); |
| 9348 | } |
| 9349 | |
| 9350 | perfetto::protos::LayersSnapshotProto SurfaceFlinger::takeLayersSnapshotProto( |
| 9351 | uint32_t traceFlags, TimePoint time, VsyncId vsyncId, bool visibleRegionDirty) { |
| 9352 | ATRACE_CALL(); |
| 9353 | perfetto::protos::LayersSnapshotProto snapshot; |
| 9354 | snapshot.set_elapsed_realtime_nanos(time.ns()); |
| 9355 | snapshot.set_vsync_id(ftl::to_underlying(vsyncId)); |
| 9356 | snapshot.set_where(visibleRegionDirty ? "visibleRegionsDirty" : "bufferLatched"); |
| 9357 | snapshot.set_excludes_composition_state((traceFlags & LayerTracing::Flag::TRACE_COMPOSITION) == |
| 9358 | 0); |
| 9359 | |
| 9360 | auto layers = dumpDrawingStateProto(traceFlags); |
| 9361 | if (traceFlags & LayerTracing::Flag::TRACE_EXTRA) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9362 | dumpOffscreenLayersProto(layers); |
| 9363 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9364 | *snapshot.mutable_layers() = std::move(layers); |
| 9365 | |
| 9366 | if (traceFlags & LayerTracing::Flag::TRACE_HWC) { |
| 9367 | std::string hwcDump; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9368 | dumpHwc(hwcDump); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9369 | snapshot.set_hwc_blob(std::move(hwcDump)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9370 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9371 | |
| 9372 | *snapshot.mutable_displays() = dumpDisplayProto(); |
| 9373 | |
| 9374 | return snapshot; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9375 | } |
| 9376 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 9377 | // sfdo functions |
| 9378 | |
| 9379 | void SurfaceFlinger::sfdo_enableRefreshRateOverlay(bool active) { |
| 9380 | auto future = mScheduler->schedule( |
| 9381 | [&]() FTL_FAKE_GUARD(mStateLock) |
| 9382 | FTL_FAKE_GUARD(kMainThreadContext) { enableRefreshRateOverlay(active); }); |
| 9383 | future.wait(); |
| 9384 | } |
| 9385 | |
| 9386 | void SurfaceFlinger::sfdo_setDebugFlash(int delay) { |
| 9387 | if (delay > 0) { |
| 9388 | mDebugFlashDelay = delay; |
| 9389 | } else { |
| 9390 | mDebugFlashDelay = mDebugFlashDelay ? 0 : 1; |
| 9391 | } |
| 9392 | scheduleRepaint(); |
| 9393 | } |
| 9394 | |
| 9395 | void SurfaceFlinger::sfdo_scheduleComposite() { |
| 9396 | scheduleComposite(SurfaceFlinger::FrameHint::kActive); |
| 9397 | } |
| 9398 | |
| 9399 | void SurfaceFlinger::sfdo_scheduleCommit() { |
| 9400 | Mutex::Autolock lock(mStateLock); |
| 9401 | setTransactionFlags(eTransactionNeeded | eDisplayTransactionNeeded | eTraversalNeeded); |
| 9402 | } |
| 9403 | |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 9404 | void SurfaceFlinger::sfdo_forceClientComposition(bool enabled) { |
| 9405 | mDebugDisableHWC = enabled; |
| 9406 | scheduleRepaint(); |
| 9407 | } |
| 9408 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9409 | // gui::ISurfaceComposer |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9410 | |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9411 | binder::Status SurfaceComposerAIDL::bootFinished() { |
| 9412 | status_t status = checkAccessPermission(); |
| 9413 | if (status != OK) { |
| 9414 | return binderStatusFromStatusT(status); |
| 9415 | } |
| 9416 | mFlinger->bootFinished(); |
| 9417 | return binder::Status::ok(); |
| 9418 | } |
| 9419 | |
| 9420 | binder::Status SurfaceComposerAIDL::createDisplayEventConnection( |
| 9421 | VsyncSource vsyncSource, EventRegistration eventRegistration, |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 9422 | const sp<IBinder>& layerHandle, sp<IDisplayEventConnection>* outConnection) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9423 | sp<IDisplayEventConnection> conn = |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 9424 | mFlinger->createDisplayEventConnection(vsyncSource, eventRegistration, layerHandle); |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9425 | if (conn == nullptr) { |
| 9426 | *outConnection = nullptr; |
| 9427 | return binderStatusFromStatusT(BAD_VALUE); |
| 9428 | } else { |
| 9429 | *outConnection = conn; |
| 9430 | return binder::Status::ok(); |
| 9431 | } |
| 9432 | } |
| 9433 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9434 | binder::Status SurfaceComposerAIDL::createConnection(sp<gui::ISurfaceComposerClient>* outClient) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 9435 | const sp<Client> client = sp<Client>::make(mFlinger); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9436 | if (client->initCheck() == NO_ERROR) { |
| 9437 | *outClient = client; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 9438 | if (FlagManager::getInstance().misc1()) { |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 9439 | const int policy = SCHED_FIFO; |
| 9440 | client->setMinSchedulerPolicy(policy, sched_get_priority_min(policy)); |
| 9441 | } |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9442 | return binder::Status::ok(); |
| 9443 | } else { |
| 9444 | *outClient = nullptr; |
| 9445 | return binderStatusFromStatusT(BAD_VALUE); |
| 9446 | } |
| 9447 | } |
| 9448 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9449 | binder::Status SurfaceComposerAIDL::createDisplay(const std::string& displayName, bool secure, |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 9450 | float requestedRefreshRate, |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9451 | sp<IBinder>* outDisplay) { |
| 9452 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9453 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9454 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9455 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9456 | String8 displayName8 = String8::format("%s", displayName.c_str()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 9457 | *outDisplay = mFlinger->createDisplay(displayName8, secure, requestedRefreshRate); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9458 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9459 | } |
| 9460 | |
| 9461 | binder::Status SurfaceComposerAIDL::destroyDisplay(const sp<IBinder>& display) { |
| 9462 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9463 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9464 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9465 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9466 | mFlinger->destroyDisplay(display); |
| 9467 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9468 | } |
| 9469 | |
| 9470 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) { |
| 9471 | std::vector<PhysicalDisplayId> physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); |
| 9472 | std::vector<int64_t> displayIds; |
| 9473 | displayIds.reserve(physicalDisplayIds.size()); |
| 9474 | for (auto item : physicalDisplayIds) { |
| 9475 | displayIds.push_back(static_cast<int64_t>(item.value)); |
| 9476 | } |
| 9477 | *outDisplayIds = displayIds; |
| 9478 | return binder::Status::ok(); |
| 9479 | } |
| 9480 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9481 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, |
| 9482 | sp<IBinder>* outDisplay) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9483 | status_t status = checkAccessPermission(); |
| 9484 | if (status != OK) { |
| 9485 | return binderStatusFromStatusT(status); |
| 9486 | } |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9487 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 9488 | *outDisplay = mFlinger->getPhysicalDisplayToken(*id); |
| 9489 | return binder::Status::ok(); |
| 9490 | } |
| 9491 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9492 | binder::Status SurfaceComposerAIDL::setPowerMode(const sp<IBinder>& display, int mode) { |
| 9493 | status_t status = checkAccessPermission(); |
| 9494 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9495 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9496 | } |
| 9497 | mFlinger->setPowerMode(display, mode); |
| 9498 | return binder::Status::ok(); |
| 9499 | } |
| 9500 | |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 9501 | binder::Status SurfaceComposerAIDL::getSupportedFrameTimestamps( |
| 9502 | std::vector<FrameEvent>* outSupported) { |
| 9503 | status_t status; |
| 9504 | if (!outSupported) { |
| 9505 | status = UNEXPECTED_NULL; |
| 9506 | } else { |
| 9507 | outSupported->clear(); |
| 9508 | status = mFlinger->getSupportedFrameTimestamps(outSupported); |
| 9509 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9510 | return binderStatusFromStatusT(status); |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 9511 | } |
| 9512 | |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9513 | binder::Status SurfaceComposerAIDL::getDisplayStats(const sp<IBinder>& display, |
| 9514 | gui::DisplayStatInfo* outStatInfo) { |
| 9515 | DisplayStatInfo statInfo; |
| 9516 | status_t status = mFlinger->getDisplayStats(display, &statInfo); |
| 9517 | if (status == NO_ERROR) { |
| 9518 | outStatInfo->vsyncTime = static_cast<long>(statInfo.vsyncTime); |
| 9519 | outStatInfo->vsyncPeriod = static_cast<long>(statInfo.vsyncPeriod); |
| 9520 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9521 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9522 | } |
| 9523 | |
| 9524 | binder::Status SurfaceComposerAIDL::getDisplayState(const sp<IBinder>& display, |
| 9525 | gui::DisplayState* outState) { |
| 9526 | ui::DisplayState state; |
| 9527 | status_t status = mFlinger->getDisplayState(display, &state); |
| 9528 | if (status == NO_ERROR) { |
| 9529 | outState->layerStack = state.layerStack.id; |
| 9530 | outState->orientation = static_cast<gui::Rotation>(state.orientation); |
| 9531 | outState->layerStackSpaceRect.width = state.layerStackSpaceRect.width; |
| 9532 | outState->layerStackSpaceRect.height = state.layerStackSpaceRect.height; |
| 9533 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9534 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9535 | } |
| 9536 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9537 | binder::Status SurfaceComposerAIDL::getStaticDisplayInfo(int64_t displayId, |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9538 | gui::StaticDisplayInfo* outInfo) { |
| 9539 | using Tag = gui::DeviceProductInfo::ManufactureOrModelDate::Tag; |
| 9540 | ui::StaticDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9541 | |
| 9542 | status_t status = mFlinger->getStaticDisplayInfo(displayId, &info); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9543 | if (status == NO_ERROR) { |
| 9544 | // convert ui::StaticDisplayInfo to gui::StaticDisplayInfo |
| 9545 | outInfo->connectionType = static_cast<gui::DisplayConnectionType>(info.connectionType); |
| 9546 | outInfo->density = info.density; |
| 9547 | outInfo->secure = info.secure; |
| 9548 | outInfo->installOrientation = static_cast<gui::Rotation>(info.installOrientation); |
| 9549 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9550 | if (const std::optional<DeviceProductInfo> dpi = info.deviceProductInfo) { |
| 9551 | gui::DeviceProductInfo dinfo; |
| 9552 | dinfo.name = std::move(dpi->name); |
| 9553 | dinfo.manufacturerPnpId = std::vector<uint8_t>(dpi->manufacturerPnpId.begin(), |
| 9554 | dpi->manufacturerPnpId.end()); |
| 9555 | dinfo.productId = dpi->productId; |
| 9556 | dinfo.relativeAddress = |
| 9557 | std::vector<uint8_t>(dpi->relativeAddress.begin(), dpi->relativeAddress.end()); |
| 9558 | if (const auto* model = |
| 9559 | std::get_if<DeviceProductInfo::ModelYear>(&dpi->manufactureOrModelDate)) { |
| 9560 | gui::DeviceProductInfo::ModelYear modelYear; |
| 9561 | modelYear.year = model->year; |
| 9562 | dinfo.manufactureOrModelDate.set<Tag::modelYear>(modelYear); |
| 9563 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureYear>( |
| 9564 | &dpi->manufactureOrModelDate)) { |
| 9565 | gui::DeviceProductInfo::ManufactureYear date; |
| 9566 | date.modelYear.year = manufacture->year; |
| 9567 | dinfo.manufactureOrModelDate.set<Tag::manufactureYear>(date); |
| 9568 | } else if (const auto* manufacture = |
| 9569 | std::get_if<DeviceProductInfo::ManufactureWeekAndYear>( |
| 9570 | &dpi->manufactureOrModelDate)) { |
| 9571 | gui::DeviceProductInfo::ManufactureWeekAndYear date; |
| 9572 | date.manufactureYear.modelYear.year = manufacture->year; |
| 9573 | date.week = manufacture->week; |
| 9574 | dinfo.manufactureOrModelDate.set<Tag::manufactureWeekAndYear>(date); |
| 9575 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9576 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9577 | outInfo->deviceProductInfo = dinfo; |
| 9578 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9579 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9580 | return binderStatusFromStatusT(status); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9581 | } |
| 9582 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9583 | void SurfaceComposerAIDL::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo& info, |
| 9584 | gui::DynamicDisplayInfo*& outInfo) { |
| 9585 | // convert ui::DynamicDisplayInfo to gui::DynamicDisplayInfo |
| 9586 | outInfo->supportedDisplayModes.clear(); |
| 9587 | outInfo->supportedDisplayModes.reserve(info.supportedDisplayModes.size()); |
| 9588 | for (const auto& mode : info.supportedDisplayModes) { |
| 9589 | gui::DisplayMode outMode; |
| 9590 | outMode.id = mode.id; |
| 9591 | outMode.resolution.width = mode.resolution.width; |
| 9592 | outMode.resolution.height = mode.resolution.height; |
| 9593 | outMode.xDpi = mode.xDpi; |
| 9594 | outMode.yDpi = mode.yDpi; |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 9595 | outMode.peakRefreshRate = mode.peakRefreshRate; |
Alec Mouri | d122a1c | 2023-09-30 01:36:33 +0000 | [diff] [blame] | 9596 | outMode.vsyncRate = mode.vsyncRate; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9597 | outMode.appVsyncOffset = mode.appVsyncOffset; |
| 9598 | outMode.sfVsyncOffset = mode.sfVsyncOffset; |
| 9599 | outMode.presentationDeadline = mode.presentationDeadline; |
| 9600 | outMode.group = mode.group; |
| 9601 | std::transform(mode.supportedHdrTypes.begin(), mode.supportedHdrTypes.end(), |
| 9602 | std::back_inserter(outMode.supportedHdrTypes), |
| 9603 | [](const ui::Hdr& value) { return static_cast<int32_t>(value); }); |
| 9604 | outInfo->supportedDisplayModes.push_back(outMode); |
| 9605 | } |
| 9606 | |
| 9607 | outInfo->activeDisplayModeId = info.activeDisplayModeId; |
| 9608 | outInfo->renderFrameRate = info.renderFrameRate; |
| 9609 | |
| 9610 | outInfo->supportedColorModes.clear(); |
| 9611 | outInfo->supportedColorModes.reserve(info.supportedColorModes.size()); |
| 9612 | for (const auto& cmode : info.supportedColorModes) { |
| 9613 | outInfo->supportedColorModes.push_back(static_cast<int32_t>(cmode)); |
| 9614 | } |
| 9615 | |
| 9616 | outInfo->activeColorMode = static_cast<int32_t>(info.activeColorMode); |
| 9617 | |
| 9618 | gui::HdrCapabilities& hdrCapabilities = outInfo->hdrCapabilities; |
| 9619 | hdrCapabilities.supportedHdrTypes.clear(); |
| 9620 | hdrCapabilities.supportedHdrTypes.reserve(info.hdrCapabilities.getSupportedHdrTypes().size()); |
| 9621 | for (const auto& hdr : info.hdrCapabilities.getSupportedHdrTypes()) { |
| 9622 | hdrCapabilities.supportedHdrTypes.push_back(static_cast<int32_t>(hdr)); |
| 9623 | } |
| 9624 | hdrCapabilities.maxLuminance = info.hdrCapabilities.getDesiredMaxLuminance(); |
| 9625 | hdrCapabilities.maxAverageLuminance = info.hdrCapabilities.getDesiredMaxAverageLuminance(); |
| 9626 | hdrCapabilities.minLuminance = info.hdrCapabilities.getDesiredMinLuminance(); |
| 9627 | |
| 9628 | outInfo->autoLowLatencyModeSupported = info.autoLowLatencyModeSupported; |
| 9629 | outInfo->gameContentTypeSupported = info.gameContentTypeSupported; |
| 9630 | outInfo->preferredBootDisplayMode = info.preferredBootDisplayMode; |
| 9631 | } |
| 9632 | |
| 9633 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromToken( |
| 9634 | const sp<IBinder>& display, gui::DynamicDisplayInfo* outInfo) { |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9635 | ui::DynamicDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9636 | status_t status = mFlinger->getDynamicDisplayInfoFromToken(display, &info); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9637 | if (status == NO_ERROR) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9638 | getDynamicDisplayInfoInternal(info, outInfo); |
| 9639 | } |
| 9640 | return binderStatusFromStatusT(status); |
| 9641 | } |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 9642 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9643 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromId(int64_t displayId, |
| 9644 | gui::DynamicDisplayInfo* outInfo) { |
| 9645 | ui::DynamicDisplayInfo info; |
| 9646 | status_t status = mFlinger->getDynamicDisplayInfoFromId(displayId, &info); |
| 9647 | if (status == NO_ERROR) { |
| 9648 | getDynamicDisplayInfoInternal(info, outInfo); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9649 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9650 | return binderStatusFromStatusT(status); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9651 | } |
| 9652 | |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9653 | binder::Status SurfaceComposerAIDL::getDisplayNativePrimaries(const sp<IBinder>& display, |
| 9654 | gui::DisplayPrimaries* outPrimaries) { |
| 9655 | ui::DisplayPrimaries primaries; |
| 9656 | status_t status = mFlinger->getDisplayNativePrimaries(display, primaries); |
| 9657 | if (status == NO_ERROR) { |
| 9658 | outPrimaries->red.X = primaries.red.X; |
| 9659 | outPrimaries->red.Y = primaries.red.Y; |
| 9660 | outPrimaries->red.Z = primaries.red.Z; |
| 9661 | |
| 9662 | outPrimaries->green.X = primaries.green.X; |
| 9663 | outPrimaries->green.Y = primaries.green.Y; |
| 9664 | outPrimaries->green.Z = primaries.green.Z; |
| 9665 | |
| 9666 | outPrimaries->blue.X = primaries.blue.X; |
| 9667 | outPrimaries->blue.Y = primaries.blue.Y; |
| 9668 | outPrimaries->blue.Z = primaries.blue.Z; |
| 9669 | |
| 9670 | outPrimaries->white.X = primaries.white.X; |
| 9671 | outPrimaries->white.Y = primaries.white.Y; |
| 9672 | outPrimaries->white.Z = primaries.white.Z; |
| 9673 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9674 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9675 | } |
| 9676 | |
| 9677 | binder::Status SurfaceComposerAIDL::setActiveColorMode(const sp<IBinder>& display, int colorMode) { |
| 9678 | status_t status = checkAccessPermission(); |
| 9679 | if (status == OK) { |
| 9680 | status = mFlinger->setActiveColorMode(display, static_cast<ui::ColorMode>(colorMode)); |
| 9681 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9682 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9683 | } |
| 9684 | |
| 9685 | binder::Status SurfaceComposerAIDL::setBootDisplayMode(const sp<IBinder>& display, |
| 9686 | int displayModeId) { |
| 9687 | status_t status = checkAccessPermission(); |
| 9688 | if (status == OK) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 9689 | status = mFlinger->setBootDisplayMode(display, DisplayModeId{displayModeId}); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 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 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9694 | binder::Status SurfaceComposerAIDL::clearBootDisplayMode(const sp<IBinder>& display) { |
| 9695 | status_t status = checkAccessPermission(); |
| 9696 | if (status == OK) { |
| 9697 | status = mFlinger->clearBootDisplayMode(display); |
| 9698 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9699 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9700 | } |
| 9701 | |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 9702 | binder::Status SurfaceComposerAIDL::getOverlaySupport(gui::OverlayProperties* outProperties) { |
| 9703 | status_t status = checkAccessPermission(); |
| 9704 | if (status == OK) { |
| 9705 | status = mFlinger->getOverlaySupport(outProperties); |
| 9706 | } |
| 9707 | return binderStatusFromStatusT(status); |
| 9708 | } |
| 9709 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9710 | binder::Status SurfaceComposerAIDL::getBootDisplayModeSupport(bool* outMode) { |
| 9711 | status_t status = checkAccessPermission(); |
| 9712 | if (status == OK) { |
| 9713 | status = mFlinger->getBootDisplayModeSupport(outMode); |
| 9714 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9715 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9716 | } |
| 9717 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9718 | binder::Status SurfaceComposerAIDL::getHdrConversionCapabilities( |
| 9719 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) { |
| 9720 | status_t status = checkAccessPermission(); |
| 9721 | if (status == OK) { |
| 9722 | status = mFlinger->getHdrConversionCapabilities(hdrConversionCapabilities); |
| 9723 | } |
| 9724 | return binderStatusFromStatusT(status); |
| 9725 | } |
| 9726 | |
| 9727 | binder::Status SurfaceComposerAIDL::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 9728 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 9729 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9730 | status_t status = checkAccessPermission(); |
| 9731 | if (status == OK) { |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 9732 | status = mFlinger->setHdrConversionStrategy(hdrConversionStrategy, |
| 9733 | outPreferredHdrOutputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9734 | } |
| 9735 | return binderStatusFromStatusT(status); |
| 9736 | } |
| 9737 | |
| 9738 | binder::Status SurfaceComposerAIDL::getHdrOutputConversionSupport(bool* outMode) { |
| 9739 | status_t status = checkAccessPermission(); |
| 9740 | if (status == OK) { |
| 9741 | status = mFlinger->getHdrOutputConversionSupport(outMode); |
| 9742 | } |
| 9743 | return binderStatusFromStatusT(status); |
| 9744 | } |
| 9745 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9746 | binder::Status SurfaceComposerAIDL::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) { |
| 9747 | status_t status = checkAccessPermission(); |
| 9748 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9749 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9750 | } |
| 9751 | mFlinger->setAutoLowLatencyMode(display, on); |
| 9752 | return binder::Status::ok(); |
| 9753 | } |
| 9754 | |
| 9755 | binder::Status SurfaceComposerAIDL::setGameContentType(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->setGameContentType(display, on); |
| 9761 | return binder::Status::ok(); |
| 9762 | } |
| 9763 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9764 | binder::Status SurfaceComposerAIDL::captureDisplay( |
| 9765 | const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9766 | mFlinger->captureDisplay(args, captureListener); |
| 9767 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9768 | } |
| 9769 | |
| 9770 | binder::Status SurfaceComposerAIDL::captureDisplayById( |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 9771 | int64_t displayId, const CaptureArgs& args, |
| 9772 | const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9773 | // status_t status; |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9774 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9775 | const int uid = ipc->getCallingUid(); |
| 9776 | if (uid == AID_ROOT || uid == AID_GRAPHICS || uid == AID_SYSTEM || uid == AID_SHELL) { |
| 9777 | std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId)); |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 9778 | mFlinger->captureDisplay(*id, args, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9779 | } else { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9780 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9781 | } |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9782 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9783 | } |
| 9784 | |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 9785 | binder::Status SurfaceComposerAIDL::captureLayersSync(const LayerCaptureArgs& args, |
| 9786 | ScreenCaptureResults* outResults) { |
| 9787 | *outResults = mFlinger->captureLayersSync(args); |
| 9788 | return binderStatusFromStatusT(NO_ERROR); |
| 9789 | } |
| 9790 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9791 | binder::Status SurfaceComposerAIDL::captureLayers( |
| 9792 | const LayerCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9793 | mFlinger->captureLayers(args, captureListener); |
| 9794 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9795 | } |
| 9796 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9797 | binder::Status SurfaceComposerAIDL::overrideHdrTypes(const sp<IBinder>& display, |
| 9798 | const std::vector<int32_t>& hdrTypes) { |
| 9799 | // overrideHdrTypes is used by CTS tests, which acquire the necessary |
| 9800 | // permission dynamically. Don't use the permission cache for this check. |
| 9801 | status_t status = checkAccessPermission(false); |
| 9802 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9803 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9804 | } |
| 9805 | |
| 9806 | std::vector<ui::Hdr> hdrTypesVector; |
| 9807 | for (int32_t i : hdrTypes) { |
| 9808 | hdrTypesVector.push_back(static_cast<ui::Hdr>(i)); |
| 9809 | } |
| 9810 | status = mFlinger->overrideHdrTypes(display, hdrTypesVector); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9811 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9812 | } |
| 9813 | |
| 9814 | binder::Status SurfaceComposerAIDL::onPullAtom(int32_t atomId, gui::PullAtomData* outPullData) { |
| 9815 | status_t status; |
| 9816 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 9817 | if (uid != AID_SYSTEM) { |
| 9818 | status = PERMISSION_DENIED; |
| 9819 | } else { |
| 9820 | status = mFlinger->onPullAtom(atomId, &outPullData->data, &outPullData->success); |
| 9821 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9822 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9823 | } |
| 9824 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9825 | binder::Status SurfaceComposerAIDL::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
| 9826 | if (!outLayers) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9827 | return binderStatusFromStatusT(UNEXPECTED_NULL); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9828 | } |
| 9829 | |
| 9830 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9831 | const int pid = ipc->getCallingPid(); |
| 9832 | const int uid = ipc->getCallingUid(); |
| 9833 | if ((uid != AID_SHELL) && !PermissionCache::checkPermission(sDump, pid, uid)) { |
| 9834 | 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] | 9835 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9836 | } |
| 9837 | status_t status = mFlinger->getLayerDebugInfo(outLayers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9838 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9839 | } |
| 9840 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9841 | binder::Status SurfaceComposerAIDL::getCompositionPreference(gui::CompositionPreference* outPref) { |
| 9842 | ui::Dataspace dataspace; |
| 9843 | ui::PixelFormat pixelFormat; |
| 9844 | ui::Dataspace wideColorGamutDataspace; |
| 9845 | ui::PixelFormat wideColorGamutPixelFormat; |
| 9846 | status_t status = |
| 9847 | mFlinger->getCompositionPreference(&dataspace, &pixelFormat, &wideColorGamutDataspace, |
| 9848 | &wideColorGamutPixelFormat); |
| 9849 | if (status == NO_ERROR) { |
| 9850 | outPref->defaultDataspace = static_cast<int32_t>(dataspace); |
| 9851 | outPref->defaultPixelFormat = static_cast<int32_t>(pixelFormat); |
| 9852 | outPref->wideColorGamutDataspace = static_cast<int32_t>(wideColorGamutDataspace); |
| 9853 | outPref->wideColorGamutPixelFormat = static_cast<int32_t>(wideColorGamutPixelFormat); |
| 9854 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9855 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9856 | } |
| 9857 | |
| 9858 | binder::Status SurfaceComposerAIDL::getDisplayedContentSamplingAttributes( |
| 9859 | const sp<IBinder>& display, gui::ContentSamplingAttributes* outAttrs) { |
| 9860 | status_t status = checkAccessPermission(); |
| 9861 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9862 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9863 | } |
| 9864 | |
| 9865 | ui::PixelFormat format; |
| 9866 | ui::Dataspace dataspace; |
| 9867 | uint8_t componentMask; |
| 9868 | status = mFlinger->getDisplayedContentSamplingAttributes(display, &format, &dataspace, |
| 9869 | &componentMask); |
| 9870 | if (status == NO_ERROR) { |
| 9871 | outAttrs->format = static_cast<int32_t>(format); |
| 9872 | outAttrs->dataspace = static_cast<int32_t>(dataspace); |
| 9873 | outAttrs->componentMask = static_cast<int8_t>(componentMask); |
| 9874 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9875 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9876 | } |
| 9877 | |
| 9878 | binder::Status SurfaceComposerAIDL::setDisplayContentSamplingEnabled(const sp<IBinder>& display, |
| 9879 | bool enable, |
| 9880 | int8_t componentMask, |
| 9881 | int64_t maxFrames) { |
| 9882 | status_t status = checkAccessPermission(); |
| 9883 | if (status == OK) { |
| 9884 | status = mFlinger->setDisplayContentSamplingEnabled(display, enable, |
| 9885 | static_cast<uint8_t>(componentMask), |
| 9886 | static_cast<uint64_t>(maxFrames)); |
| 9887 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9888 | return binderStatusFromStatusT(status); |
| 9889 | } |
| 9890 | |
| 9891 | binder::Status SurfaceComposerAIDL::getDisplayedContentSample(const sp<IBinder>& display, |
| 9892 | int64_t maxFrames, int64_t timestamp, |
| 9893 | gui::DisplayedFrameStats* outStats) { |
| 9894 | if (!outStats) { |
| 9895 | return binderStatusFromStatusT(BAD_VALUE); |
| 9896 | } |
| 9897 | |
| 9898 | status_t status = checkAccessPermission(); |
| 9899 | if (status != OK) { |
| 9900 | return binderStatusFromStatusT(status); |
| 9901 | } |
| 9902 | |
| 9903 | DisplayedFrameStats stats; |
| 9904 | status = mFlinger->getDisplayedContentSample(display, static_cast<uint64_t>(maxFrames), |
| 9905 | static_cast<uint64_t>(timestamp), &stats); |
| 9906 | if (status == NO_ERROR) { |
| 9907 | // convert from ui::DisplayedFrameStats to gui::DisplayedFrameStats |
| 9908 | outStats->numFrames = static_cast<int64_t>(stats.numFrames); |
| 9909 | outStats->component_0_sample.reserve(stats.component_0_sample.size()); |
| 9910 | for (const auto& s : stats.component_0_sample) { |
| 9911 | outStats->component_0_sample.push_back(static_cast<int64_t>(s)); |
| 9912 | } |
| 9913 | outStats->component_1_sample.reserve(stats.component_1_sample.size()); |
| 9914 | for (const auto& s : stats.component_1_sample) { |
| 9915 | outStats->component_1_sample.push_back(static_cast<int64_t>(s)); |
| 9916 | } |
| 9917 | outStats->component_2_sample.reserve(stats.component_2_sample.size()); |
| 9918 | for (const auto& s : stats.component_2_sample) { |
| 9919 | outStats->component_2_sample.push_back(static_cast<int64_t>(s)); |
| 9920 | } |
| 9921 | outStats->component_3_sample.reserve(stats.component_3_sample.size()); |
| 9922 | for (const auto& s : stats.component_3_sample) { |
| 9923 | outStats->component_3_sample.push_back(static_cast<int64_t>(s)); |
| 9924 | } |
| 9925 | } |
| 9926 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9927 | } |
| 9928 | |
| 9929 | binder::Status SurfaceComposerAIDL::getProtectedContentSupport(bool* outSupported) { |
| 9930 | status_t status = mFlinger->getProtectedContentSupport(outSupported); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9931 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9932 | } |
| 9933 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9934 | binder::Status SurfaceComposerAIDL::isWideColorDisplay(const sp<IBinder>& token, |
| 9935 | bool* outIsWideColorDisplay) { |
| 9936 | status_t status = mFlinger->isWideColorDisplay(token, outIsWideColorDisplay); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9937 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9938 | } |
| 9939 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9940 | binder::Status SurfaceComposerAIDL::addRegionSamplingListener( |
| 9941 | const gui::ARect& samplingArea, const sp<IBinder>& stopLayerHandle, |
| 9942 | const sp<gui::IRegionSamplingListener>& listener) { |
| 9943 | status_t status = checkReadFrameBufferPermission(); |
| 9944 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9945 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9946 | } |
| 9947 | android::Rect rect; |
| 9948 | rect.left = samplingArea.left; |
| 9949 | rect.top = samplingArea.top; |
| 9950 | rect.right = samplingArea.right; |
| 9951 | rect.bottom = samplingArea.bottom; |
| 9952 | status = mFlinger->addRegionSamplingListener(rect, stopLayerHandle, listener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9953 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9954 | } |
| 9955 | |
| 9956 | binder::Status SurfaceComposerAIDL::removeRegionSamplingListener( |
| 9957 | const sp<gui::IRegionSamplingListener>& listener) { |
| 9958 | status_t status = checkReadFrameBufferPermission(); |
| 9959 | if (status == OK) { |
| 9960 | status = mFlinger->removeRegionSamplingListener(listener); |
| 9961 | } |
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::addFpsListener(int32_t taskId, |
| 9966 | const sp<gui::IFpsListener>& listener) { |
| 9967 | status_t status = checkReadFrameBufferPermission(); |
| 9968 | if (status == OK) { |
| 9969 | status = mFlinger->addFpsListener(taskId, 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::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 9975 | status_t status = checkReadFrameBufferPermission(); |
| 9976 | if (status == OK) { |
| 9977 | status = mFlinger->removeFpsListener(listener); |
| 9978 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9979 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9980 | } |
| 9981 | |
| 9982 | binder::Status SurfaceComposerAIDL::addTunnelModeEnabledListener( |
| 9983 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 9984 | status_t status = checkAccessPermission(); |
| 9985 | if (status == OK) { |
| 9986 | status = mFlinger->addTunnelModeEnabledListener(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::removeTunnelModeEnabledListener( |
| 9992 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 9993 | status_t status = checkAccessPermission(); |
| 9994 | if (status == OK) { |
| 9995 | status = mFlinger->removeTunnelModeEnabledListener(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 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 10000 | binder::Status SurfaceComposerAIDL::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 10001 | const gui::DisplayModeSpecs& specs) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10002 | status_t status = checkAccessPermission(); |
| 10003 | if (status == OK) { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 10004 | status = mFlinger->setDesiredDisplayModeSpecs(displayToken, specs); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 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 | |
| 10009 | binder::Status SurfaceComposerAIDL::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 10010 | gui::DisplayModeSpecs* outSpecs) { |
| 10011 | if (!outSpecs) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10012 | return binderStatusFromStatusT(BAD_VALUE); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10013 | } |
| 10014 | |
| 10015 | status_t status = checkAccessPermission(); |
| 10016 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10017 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10018 | } |
| 10019 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 10020 | status = mFlinger->getDesiredDisplayModeSpecs(displayToken, outSpecs); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10021 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10022 | } |
| 10023 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10024 | binder::Status SurfaceComposerAIDL::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 10025 | bool* outSupport) { |
| 10026 | status_t status = mFlinger->getDisplayBrightnessSupport(displayToken, outSupport); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10027 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10028 | } |
| 10029 | |
| 10030 | binder::Status SurfaceComposerAIDL::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 10031 | const gui::DisplayBrightness& brightness) { |
| 10032 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10033 | if (status == OK) { |
| 10034 | status = mFlinger->setDisplayBrightness(displayToken, brightness); |
| 10035 | } |
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::addHdrLayerInfoListener( |
| 10040 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 10041 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10042 | if (status == OK) { |
| 10043 | status = mFlinger->addHdrLayerInfoListener(displayToken, listener); |
| 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::removeHdrLayerInfoListener( |
| 10049 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 10050 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10051 | if (status == OK) { |
| 10052 | status = mFlinger->removeHdrLayerInfoListener(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::notifyPowerBoost(int boostId) { |
| 10058 | status_t status = checkAccessPermission(); |
| 10059 | if (status == OK) { |
| 10060 | status = mFlinger->notifyPowerBoost(boostId); |
| 10061 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10062 | return binderStatusFromStatusT(status); |
| 10063 | } |
| 10064 | |
| 10065 | binder::Status SurfaceComposerAIDL::setGlobalShadowSettings(const gui::Color& ambientColor, |
| 10066 | const gui::Color& spotColor, |
| 10067 | float lightPosY, float lightPosZ, |
| 10068 | float lightRadius) { |
| 10069 | status_t status = checkAccessPermission(); |
| 10070 | if (status != OK) { |
| 10071 | return binderStatusFromStatusT(status); |
| 10072 | } |
| 10073 | |
| 10074 | half4 ambientColorHalf = {ambientColor.r, ambientColor.g, ambientColor.b, ambientColor.a}; |
| 10075 | half4 spotColorHalf = {spotColor.r, spotColor.g, spotColor.b, spotColor.a}; |
| 10076 | status = mFlinger->setGlobalShadowSettings(ambientColorHalf, spotColorHalf, lightPosY, |
| 10077 | lightPosZ, lightRadius); |
| 10078 | return binderStatusFromStatusT(status); |
| 10079 | } |
| 10080 | |
| 10081 | binder::Status SurfaceComposerAIDL::getDisplayDecorationSupport( |
| 10082 | const sp<IBinder>& displayToken, std::optional<gui::DisplayDecorationSupport>* outSupport) { |
| 10083 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport> support; |
| 10084 | status_t status = mFlinger->getDisplayDecorationSupport(displayToken, &support); |
| 10085 | if (status != NO_ERROR) { |
| 10086 | ALOGE("getDisplayDecorationSupport failed with error %d", status); |
| 10087 | return binderStatusFromStatusT(status); |
| 10088 | } |
| 10089 | |
| 10090 | if (!support || !support.has_value()) { |
| 10091 | outSupport->reset(); |
| 10092 | } else { |
| 10093 | outSupport->emplace(); |
| 10094 | outSupport->value().format = static_cast<int32_t>(support->format); |
| 10095 | outSupport->value().alphaInterpretation = |
| 10096 | static_cast<int32_t>(support->alphaInterpretation); |
| 10097 | } |
| 10098 | |
| 10099 | return binder::Status::ok(); |
| 10100 | } |
| 10101 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10102 | binder::Status SurfaceComposerAIDL::setGameModeFrameRateOverride(int32_t uid, float frameRate) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10103 | status_t status; |
| 10104 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10105 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10106 | status = mFlinger->setGameModeFrameRateOverride(uid, frameRate); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10107 | } else { |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10108 | ALOGE("setGameModeFrameRateOverride() permission denied for uid: %d", c_uid); |
| 10109 | status = PERMISSION_DENIED; |
| 10110 | } |
| 10111 | return binderStatusFromStatusT(status); |
| 10112 | } |
| 10113 | |
| 10114 | binder::Status SurfaceComposerAIDL::setGameDefaultFrameRateOverride(int32_t uid, float frameRate) { |
| 10115 | status_t status; |
| 10116 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10117 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 10118 | status = mFlinger->setGameDefaultFrameRateOverride(uid, frameRate); |
| 10119 | } else { |
| 10120 | ALOGE("setGameDefaultFrameRateOverride() permission denied for uid: %d", c_uid); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10121 | status = PERMISSION_DENIED; |
| 10122 | } |
| 10123 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10124 | } |
| 10125 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 10126 | binder::Status SurfaceComposerAIDL::enableRefreshRateOverlay(bool active) { |
| 10127 | mFlinger->sfdo_enableRefreshRateOverlay(active); |
| 10128 | return binder::Status::ok(); |
| 10129 | } |
| 10130 | |
| 10131 | binder::Status SurfaceComposerAIDL::setDebugFlash(int delay) { |
| 10132 | mFlinger->sfdo_setDebugFlash(delay); |
| 10133 | return binder::Status::ok(); |
| 10134 | } |
| 10135 | |
| 10136 | binder::Status SurfaceComposerAIDL::scheduleComposite() { |
| 10137 | mFlinger->sfdo_scheduleComposite(); |
| 10138 | return binder::Status::ok(); |
| 10139 | } |
| 10140 | |
| 10141 | binder::Status SurfaceComposerAIDL::scheduleCommit() { |
| 10142 | mFlinger->sfdo_scheduleCommit(); |
| 10143 | return binder::Status::ok(); |
| 10144 | } |
| 10145 | |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 10146 | binder::Status SurfaceComposerAIDL::forceClientComposition(bool enabled) { |
| 10147 | mFlinger->sfdo_forceClientComposition(enabled); |
| 10148 | return binder::Status::ok(); |
| 10149 | } |
| 10150 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10151 | binder::Status SurfaceComposerAIDL::updateSmallAreaDetection(const std::vector<int32_t>& appIds, |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10152 | const std::vector<float>& thresholds) { |
| 10153 | status_t status; |
| 10154 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10155 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10156 | if (appIds.size() != thresholds.size()) return binderStatusFromStatusT(BAD_VALUE); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10157 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10158 | std::vector<std::pair<int32_t, float>> mappings; |
| 10159 | const size_t size = appIds.size(); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10160 | mappings.reserve(size); |
| 10161 | for (int i = 0; i < size; i++) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10162 | auto row = std::make_pair(appIds[i], thresholds[i]); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10163 | mappings.push_back(row); |
| 10164 | } |
| 10165 | status = mFlinger->updateSmallAreaDetection(mappings); |
| 10166 | } else { |
| 10167 | ALOGE("updateSmallAreaDetection() permission denied for uid: %d", c_uid); |
| 10168 | status = PERMISSION_DENIED; |
| 10169 | } |
| 10170 | return binderStatusFromStatusT(status); |
| 10171 | } |
| 10172 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10173 | binder::Status SurfaceComposerAIDL::setSmallAreaDetectionThreshold(int32_t appId, float threshold) { |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10174 | status_t status; |
| 10175 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10176 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10177 | status = mFlinger->setSmallAreaDetectionThreshold(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10178 | } else { |
| 10179 | ALOGE("setSmallAreaDetectionThreshold() permission denied for uid: %d", c_uid); |
| 10180 | status = PERMISSION_DENIED; |
| 10181 | } |
| 10182 | return binderStatusFromStatusT(status); |
| 10183 | } |
| 10184 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10185 | binder::Status SurfaceComposerAIDL::getGpuContextPriority(int32_t* outPriority) { |
| 10186 | *outPriority = mFlinger->getGpuContextPriority(); |
| 10187 | return binder::Status::ok(); |
| 10188 | } |
| 10189 | |
| 10190 | binder::Status SurfaceComposerAIDL::getMaxAcquiredBufferCount(int32_t* buffers) { |
| 10191 | status_t status = mFlinger->getMaxAcquiredBufferCount(buffers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10192 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10193 | } |
| 10194 | |
| 10195 | binder::Status SurfaceComposerAIDL::addWindowInfosListener( |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 10196 | const sp<gui::IWindowInfosListener>& windowInfosListener, |
| 10197 | gui::WindowInfosListenerInfo* outInfo) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10198 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10199 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10200 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10201 | // TODO(b/270566761) update permissions check so that only system_server and shell can add |
| 10202 | // WindowInfosListeners |
| 10203 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 10204 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 10205 | status = mFlinger->addWindowInfosListener(windowInfosListener, outInfo); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10206 | } else { |
| 10207 | status = PERMISSION_DENIED; |
| 10208 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10209 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10210 | } |
| 10211 | |
| 10212 | binder::Status SurfaceComposerAIDL::removeWindowInfosListener( |
| 10213 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 10214 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10215 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10216 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10217 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 10218 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10219 | status = mFlinger->removeWindowInfosListener(windowInfosListener); |
| 10220 | } else { |
| 10221 | status = PERMISSION_DENIED; |
| 10222 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10223 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10224 | } |
| 10225 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 10226 | binder::Status SurfaceComposerAIDL::getStalledTransactionInfo( |
| 10227 | int pid, std::optional<gui::StalledTransactionInfo>* outInfo) { |
| 10228 | const int callingPid = IPCThreadState::self()->getCallingPid(); |
| 10229 | const int callingUid = IPCThreadState::self()->getCallingUid(); |
| 10230 | if (!checkPermission(sAccessSurfaceFlinger, callingPid, callingUid)) { |
| 10231 | return binderStatusFromStatusT(PERMISSION_DENIED); |
| 10232 | } |
| 10233 | |
| 10234 | std::optional<TransactionHandler::StalledTransactionInfo> stalledTransactionInfo; |
| 10235 | status_t status = mFlinger->getStalledTransactionInfo(pid, stalledTransactionInfo); |
| 10236 | if (stalledTransactionInfo) { |
| 10237 | gui::StalledTransactionInfo result; |
| 10238 | result.layerName = String16{stalledTransactionInfo->layerName.c_str()}, |
| 10239 | result.bufferId = stalledTransactionInfo->bufferId, |
| 10240 | result.frameNumber = stalledTransactionInfo->frameNumber, |
| 10241 | outInfo->emplace(std::move(result)); |
| 10242 | } else { |
| 10243 | outInfo->reset(); |
| 10244 | } |
| 10245 | return binderStatusFromStatusT(status); |
| 10246 | } |
| 10247 | |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 10248 | binder::Status SurfaceComposerAIDL::getSchedulingPolicy(gui::SchedulingPolicy* outPolicy) { |
| 10249 | return gui::getSchedulingPolicy(outPolicy); |
| 10250 | } |
| 10251 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 10252 | status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { |
| 10253 | if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
| 10254 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10255 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", ipc->getCallingPid(), |
| 10256 | ipc->getCallingUid()); |
| 10257 | return PERMISSION_DENIED; |
| 10258 | } |
| 10259 | return OK; |
| 10260 | } |
| 10261 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10262 | status_t SurfaceComposerAIDL::checkControlDisplayBrightnessPermission() { |
| 10263 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10264 | const int pid = ipc->getCallingPid(); |
| 10265 | const int uid = ipc->getCallingUid(); |
Rheygine Medel | 9e9281e | 2022-09-22 10:13:56 -0700 | [diff] [blame] | 10266 | if ((uid != AID_GRAPHICS) && (uid != AID_SYSTEM) && |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10267 | !PermissionCache::checkPermission(sControlDisplayBrightness, pid, uid)) { |
| 10268 | ALOGE("Permission Denial: can't control brightness pid=%d, uid=%d", pid, uid); |
| 10269 | return PERMISSION_DENIED; |
| 10270 | } |
| 10271 | return OK; |
| 10272 | } |
| 10273 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10274 | status_t SurfaceComposerAIDL::checkReadFrameBufferPermission() { |
| 10275 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10276 | const int pid = ipc->getCallingPid(); |
| 10277 | const int uid = ipc->getCallingUid(); |
| 10278 | if ((uid != AID_GRAPHICS) && !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 10279 | ALOGE("Permission Denial: can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 10280 | return PERMISSION_DENIED; |
| 10281 | } |
| 10282 | return OK; |
| 10283 | } |
| 10284 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 10285 | void SurfaceFlinger::forceFutureUpdate(int delayInMs) { |
| 10286 | static_cast<void>(mScheduler->scheduleDelayed([&]() { scheduleRepaint(); }, ms2ns(delayInMs))); |
| 10287 | } |
| 10288 | |
Vishnu Nair | 2f65e97 | 2023-04-04 16:36:28 +0000 | [diff] [blame] | 10289 | const DisplayDevice* SurfaceFlinger::getDisplayFromLayerStack(ui::LayerStack layerStack) { |
| 10290 | for (const auto& [_, display] : mDisplays) { |
| 10291 | if (display->getLayerStack() == layerStack) { |
| 10292 | return display.get(); |
| 10293 | } |
| 10294 | } |
| 10295 | return nullptr; |
| 10296 | } |
| 10297 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 10298 | } // namespace android |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 10299 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 10300 | #if defined(__gl_h_) |
| 10301 | #error "don't include gl/gl.h in this file" |
| 10302 | #endif |
| 10303 | |
| 10304 | #if defined(__gl2_h_) |
| 10305 | #error "don't include gl2/gl2.h in this file" |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 10306 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 10307 | |
| 10308 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 10309 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |