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> |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 119 | #include <ui/DisplayIdentification.h> |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 120 | #include "BackgroundExecutor.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 121 | #include "Client.h" |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 122 | #include "ClientCache.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 123 | #include "Colorizer.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 124 | #include "DisplayDevice.h" |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 125 | #include "DisplayHardware/ComposerHal.h" |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 126 | #include "DisplayHardware/FramebufferSurface.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 127 | #include "DisplayHardware/HWComposer.h" |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 128 | #include "DisplayHardware/Hal.h" |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 129 | #include "DisplayHardware/PowerAdvisor.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 130 | #include "DisplayHardware/VirtualDisplaySurface.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 131 | #include "DisplayRenderArea.h" |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 132 | #include "Effects/Daltonizer.h" |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 133 | #include "FpsReporter.h" |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 134 | #include "FrameTimeline/FrameTimeline.h" |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 135 | #include "FrameTracer/FrameTracer.h" |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 136 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 137 | #include "FrontEnd/LayerHandle.h" |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 138 | #include "FrontEnd/LayerLifecycleManager.h" |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 139 | #include "FrontEnd/LayerLog.h" |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 140 | #include "FrontEnd/LayerSnapshot.h" |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 141 | #include "HdrLayerInfoReporter.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 142 | #include "Layer.h" |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 143 | #include "LayerProtoHelper.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 144 | #include "LayerRenderArea.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 145 | #include "LayerVector.h" |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 146 | #include "MutexUtils.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 147 | #include "NativeWindowSurface.h" |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 148 | #include "RegionSamplingThread.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 149 | #include "Scheduler/EventThread.h" |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 150 | #include "Scheduler/LayerHistory.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 151 | #include "Scheduler/Scheduler.h" |
Ady Abraham | c581d3c | 2020-08-06 17:34:27 -0700 | [diff] [blame] | 152 | #include "Scheduler/VsyncConfiguration.h" |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 153 | #include "Scheduler/VsyncModulator.h" |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 154 | #include "ScreenCaptureOutput.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 155 | #include "StartPropertySetThread.h" |
| 156 | #include "SurfaceFlingerProperties.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 157 | #include "TimeStats/TimeStats.h" |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 158 | #include "TunnelModeEnabledReporter.h" |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 159 | #include "Utils/Dumper.h" |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 160 | #include "WindowInfosListenerInvoker.h" |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 161 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 162 | #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 163 | #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 164 | #include <aidl/android/hardware/graphics/composer3/RenderIntent.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 165 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 166 | #undef NO_THREAD_SAFETY_ANALYSIS |
| 167 | #define NO_THREAD_SAFETY_ANALYSIS \ |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 168 | _Pragma("GCC error \"Prefer <ftl/fake_guard.h> or MutexUtils.h helpers.\"") |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 169 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 170 | // To enable layer borders in the system, change the below flag to true. |
| 171 | #undef DOES_CONTAIN_BORDER |
| 172 | #define DOES_CONTAIN_BORDER false |
| 173 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | namespace android { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 175 | using namespace std::chrono_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 176 | using namespace std::string_literals; |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 177 | using namespace std::string_view_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 178 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 179 | using namespace hardware::configstore; |
| 180 | using namespace hardware::configstore::V1_0; |
| 181 | using namespace sysprop; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 182 | using ftl::Flags; |
| 183 | using namespace ftl::flag_operators; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 184 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 185 | using aidl::android::hardware::graphics::common::DisplayDecorationSupport; |
| 186 | using aidl::android::hardware::graphics::composer3::Capability; |
| 187 | using aidl::android::hardware::graphics::composer3::DisplayCapability; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 188 | using CompositionStrategyPredictionState = android::compositionengine::impl:: |
| 189 | OutputCompositionState::CompositionStrategyPredictionState; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 190 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 191 | using base::StringAppendF; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 192 | using display::PhysicalDisplay; |
| 193 | using display::PhysicalDisplays; |
Vishnu Nair | af6d297 | 2022-11-18 06:26:38 +0000 | [diff] [blame] | 194 | using frontend::TransactionHandler; |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 195 | using gui::DisplayInfo; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 196 | using gui::GameMode; |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 197 | using gui::IDisplayEventConnection; |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 198 | using gui::IWindowInfosListener; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 199 | using gui::LayerMetadata; |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 200 | using gui::WindowInfo; |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 201 | using gui::aidl_utils::binderStatusFromStatusT; |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 202 | using scheduler::VsyncModulator; |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 203 | using ui::Dataspace; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 204 | using ui::DisplayPrimaries; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 205 | using ui::RenderIntent; |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 206 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 207 | using KernelIdleTimerController = scheduler::RefreshRateSelector::KernelIdleTimerController; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 208 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 209 | namespace hal = android::hardware::graphics::composer::hal; |
| 210 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 211 | namespace { |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 212 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 213 | static constexpr int FOUR_K_WIDTH = 3840; |
| 214 | static constexpr int FOUR_K_HEIGHT = 2160; |
| 215 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 216 | // TODO(b/141333600): Consolidate with DisplayMode::Builder::getDefaultDensity. |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 217 | constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 218 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 219 | float getDensityFromProperty(const char* property, bool required) { |
| 220 | char value[PROPERTY_VALUE_MAX]; |
| 221 | const float density = property_get(property, value, nullptr) > 0 ? std::atof(value) : 0.f; |
| 222 | if (!density && required) { |
| 223 | ALOGE("%s must be defined as a build property", property); |
| 224 | return FALLBACK_DENSITY; |
| 225 | } |
| 226 | return density; |
| 227 | } |
| 228 | |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 229 | // Currently we only support V0_SRGB and DISPLAY_P3 as composition preference. |
| 230 | bool validateCompositionDataspace(Dataspace dataspace) { |
| 231 | return dataspace == Dataspace::V0_SRGB || dataspace == Dataspace::DISPLAY_P3; |
| 232 | } |
| 233 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 234 | std::chrono::milliseconds getIdleTimerTimeout(DisplayId displayId) { |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 235 | const auto displayIdleTimerMsKey = [displayId] { |
| 236 | std::stringstream ss; |
| 237 | ss << "debug.sf.set_idle_timer_ms_" << displayId.value; |
| 238 | return ss.str(); |
| 239 | }(); |
| 240 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 241 | const int32_t displayIdleTimerMs = base::GetIntProperty(displayIdleTimerMsKey, 0); |
| 242 | if (displayIdleTimerMs > 0) { |
| 243 | return std::chrono::milliseconds(displayIdleTimerMs); |
| 244 | } |
| 245 | |
| 246 | const int32_t setIdleTimerMs = base::GetIntProperty("debug.sf.set_idle_timer_ms", 0); |
| 247 | const int32_t millis = setIdleTimerMs ? setIdleTimerMs : sysprop::set_idle_timer_ms(0); |
| 248 | return std::chrono::milliseconds(millis); |
| 249 | } |
| 250 | |
| 251 | bool getKernelIdleTimerSyspropConfig(DisplayId displayId) { |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 252 | const auto displaySupportKernelIdleTimerKey = [displayId] { |
| 253 | std::stringstream ss; |
| 254 | ss << "debug.sf.support_kernel_idle_timer_" << displayId.value; |
| 255 | return ss.str(); |
| 256 | }(); |
| 257 | |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 258 | const auto displaySupportKernelIdleTimer = |
| 259 | base::GetBoolProperty(displaySupportKernelIdleTimerKey, false); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 260 | return displaySupportKernelIdleTimer || sysprop::support_kernel_idle_timer(false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 263 | bool isAbove4k30(const ui::DisplayMode& outMode) { |
| 264 | using fps_approx_ops::operator>; |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 265 | Fps refreshRate = Fps::fromValue(outMode.peakRefreshRate); |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 266 | return outMode.resolution.getWidth() >= FOUR_K_WIDTH && |
| 267 | outMode.resolution.getHeight() >= FOUR_K_HEIGHT && refreshRate > 30_Hz; |
| 268 | } |
| 269 | |
| 270 | void excludeDolbyVisionIf4k30Present(const std::vector<ui::Hdr>& displayHdrTypes, |
| 271 | ui::DisplayMode& outMode) { |
| 272 | if (isAbove4k30(outMode) && |
| 273 | std::any_of(displayHdrTypes.begin(), displayHdrTypes.end(), |
| 274 | [](ui::Hdr type) { return type == ui::Hdr::DOLBY_VISION_4K30; })) { |
| 275 | for (ui::Hdr type : displayHdrTypes) { |
| 276 | if (type != ui::Hdr::DOLBY_VISION_4K30 && type != ui::Hdr::DOLBY_VISION) { |
| 277 | outMode.supportedHdrTypes.push_back(type); |
| 278 | } |
| 279 | } |
| 280 | } else { |
| 281 | for (ui::Hdr type : displayHdrTypes) { |
| 282 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 283 | outMode.supportedHdrTypes.push_back(type); |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | HdrCapabilities filterOut4k30(const HdrCapabilities& displayHdrCapabilities) { |
| 290 | std::vector<ui::Hdr> hdrTypes; |
| 291 | for (ui::Hdr type : displayHdrCapabilities.getSupportedHdrTypes()) { |
| 292 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 293 | hdrTypes.push_back(type); |
| 294 | } |
| 295 | } |
| 296 | return {hdrTypes, displayHdrCapabilities.getDesiredMaxLuminance(), |
| 297 | displayHdrCapabilities.getDesiredMaxAverageLuminance(), |
| 298 | displayHdrCapabilities.getDesiredMinLuminance()}; |
| 299 | } |
| 300 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 301 | uint32_t getLayerIdFromSurfaceControl(sp<SurfaceControl> surfaceControl) { |
| 302 | if (!surfaceControl) { |
| 303 | return UNASSIGNED_LAYER_ID; |
| 304 | } |
| 305 | return LayerHandle::getLayerId(surfaceControl->getHandle()); |
| 306 | } |
| 307 | |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 308 | /** |
| 309 | * Returns true if the file at path exists and is newer than duration. |
| 310 | */ |
| 311 | bool fileNewerThan(const std::string& path, std::chrono::minutes duration) { |
| 312 | using Clock = std::filesystem::file_time_type::clock; |
| 313 | std::error_code error; |
| 314 | std::filesystem::file_time_type updateTime = std::filesystem::last_write_time(path, error); |
| 315 | if (error) { |
| 316 | return false; |
| 317 | } |
| 318 | return duration > (Clock::now() - updateTime); |
| 319 | } |
| 320 | |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 321 | bool isFrameIntervalOnCadence(TimePoint expectedPresentTime, TimePoint lastExpectedPresentTimestamp, |
| 322 | Fps lastFrameInterval, Period timeout, Duration threshold) { |
| 323 | if (lastFrameInterval.getPeriodNsecs() == 0) { |
| 324 | return false; |
| 325 | } |
| 326 | |
| 327 | const auto expectedPresentTimeDeltaNs = |
| 328 | expectedPresentTime.ns() - lastExpectedPresentTimestamp.ns(); |
| 329 | |
| 330 | if (expectedPresentTimeDeltaNs > timeout.ns()) { |
| 331 | return false; |
| 332 | } |
| 333 | |
| 334 | const auto expectedPresentPeriods = static_cast<nsecs_t>( |
| 335 | std::round(static_cast<float>(expectedPresentTimeDeltaNs) / |
| 336 | static_cast<float>(lastFrameInterval.getPeriodNsecs()))); |
| 337 | const auto calculatedPeriodsOutNs = lastFrameInterval.getPeriodNsecs() * expectedPresentPeriods; |
| 338 | const auto calculatedExpectedPresentTimeNs = |
| 339 | lastExpectedPresentTimestamp.ns() + calculatedPeriodsOutNs; |
| 340 | const auto presentTimeDelta = |
| 341 | std::abs(expectedPresentTime.ns() - calculatedExpectedPresentTimeNs); |
| 342 | return presentTimeDelta < threshold.ns(); |
| 343 | } |
| 344 | |
| 345 | bool isExpectedPresentWithinTimeout(TimePoint expectedPresentTime, |
| 346 | TimePoint lastExpectedPresentTimestamp, |
| 347 | std::optional<Period> timeoutOpt, Duration threshold) { |
| 348 | if (!timeoutOpt) { |
| 349 | // Always within timeout if timeoutOpt is absent and don't send hint |
| 350 | // for the timeout |
| 351 | return true; |
| 352 | } |
| 353 | |
| 354 | if (timeoutOpt->ns() == 0) { |
| 355 | // Always outside timeout if timeoutOpt is 0 and always send |
| 356 | // the hint for the timeout. |
| 357 | return false; |
| 358 | } |
| 359 | |
| 360 | if (expectedPresentTime.ns() < lastExpectedPresentTimestamp.ns() + timeoutOpt->ns()) { |
| 361 | return true; |
| 362 | } |
| 363 | |
| 364 | // Check if within the threshold as it can be just outside the timeout |
| 365 | return std::abs(expectedPresentTime.ns() - |
| 366 | (lastExpectedPresentTimestamp.ns() + timeoutOpt->ns())) < threshold.ns(); |
| 367 | } |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 368 | } // namespace anonymous |
| 369 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | // --------------------------------------------------------------------------- |
| 371 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 372 | const String16 sHardwareTest("android.permission.HARDWARE_TEST"); |
| 373 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 374 | const String16 sRotateSurfaceFlinger("android.permission.ROTATE_SURFACE_FLINGER"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 375 | const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER"); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 376 | const String16 sControlDisplayBrightness("android.permission.CONTROL_DISPLAY_BRIGHTNESS"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 377 | const String16 sDump("android.permission.DUMP"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 378 | const String16 sCaptureBlackoutContent("android.permission.CAPTURE_BLACKOUT_CONTENT"); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 379 | const String16 sInternalSystemWindow("android.permission.INTERNAL_SYSTEM_WINDOW"); |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 380 | const String16 sWakeupSurfaceFlinger("android.permission.WAKEUP_SURFACE_FLINGER"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 381 | |
Amy Hsu | c8cdfef | 2020-05-07 13:06:25 +0800 | [diff] [blame] | 382 | const char* KERNEL_IDLE_TIMER_PROP = "graphics.display.kernel_idle_timer.enabled"; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 383 | |
| 384 | // --------------------------------------------------------------------------- |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 385 | int64_t SurfaceFlinger::dispSyncPresentTimeOffset; |
| 386 | bool SurfaceFlinger::useHwcForRgbToYuv; |
| 387 | bool SurfaceFlinger::hasSyncFramework; |
| 388 | int64_t SurfaceFlinger::maxFrameBufferAcquiredBuffers; |
| 389 | int64_t SurfaceFlinger::minAcquiredBuffers = 1; |
| 390 | uint32_t SurfaceFlinger::maxGraphicsWidth; |
| 391 | uint32_t SurfaceFlinger::maxGraphicsHeight; |
| 392 | bool SurfaceFlinger::useContextPriority; |
| 393 | Dataspace SurfaceFlinger::defaultCompositionDataspace = Dataspace::V0_SRGB; |
| 394 | ui::PixelFormat SurfaceFlinger::defaultCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
| 395 | Dataspace SurfaceFlinger::wideColorGamutCompositionDataspace = Dataspace::V0_SRGB; |
| 396 | ui::PixelFormat SurfaceFlinger::wideColorGamutCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 397 | LatchUnsignaledConfig SurfaceFlinger::enableLatchUnsignaledConfig; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 398 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 399 | std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) { |
| 400 | switch(displayColorSetting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 401 | case DisplayColorSetting::kManaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 402 | return std::string("Managed"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 403 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 404 | return std::string("Unmanaged"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 405 | case DisplayColorSetting::kEnhanced: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 406 | return std::string("Enhanced"); |
| 407 | default: |
| 408 | return std::string("Unknown ") + |
| 409 | std::to_string(static_cast<int>(displayColorSetting)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 410 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 411 | } |
| 412 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 413 | bool callingThreadHasPermission(const String16& permission) { |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 414 | IPCThreadState* ipc = IPCThreadState::self(); |
| 415 | const int pid = ipc->getCallingPid(); |
| 416 | const int uid = ipc->getCallingUid(); |
| 417 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 418 | PermissionCache::checkPermission(permission, pid, uid); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 421 | ui::Transform::RotationFlags SurfaceFlinger::sActiveDisplayRotationFlags = ui::Transform::ROT_0; |
| 422 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 423 | SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag) |
| 424 | : mFactory(factory), |
| 425 | mPid(getpid()), |
Yiwei Zhang | f0229a7 | 2019-09-09 19:28:02 -0700 | [diff] [blame] | 426 | mTimeStats(std::make_shared<impl::TimeStats>()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 427 | mFrameTracer(mFactory.createFrameTracer()), |
| 428 | mFrameTimeline(mFactory.createFrameTimeline(mTimeStats, mPid)), |
| 429 | mCompositionEngine(mFactory.createCompositionEngine()), |
| 430 | mHwcServiceName(base::GetProperty("debug.sf.hwc_service_name"s, "default"s)), |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 431 | mTunnelModeEnabledReporter(sp<TunnelModeEnabledReporter>::make()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 432 | mEmulatedDisplayDensity(getDensityFromProperty("qemu.sf.lcd_density", false)), |
| 433 | mInternalDisplayDensity( |
| 434 | getDensityFromProperty("ro.sf.lcd_density", !mEmulatedDisplayDensity)), |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 435 | mPowerAdvisor(std::make_unique<Hwc2::impl::PowerAdvisor>(*this)), |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 436 | mWindowInfosListenerInvoker(sp<WindowInfosListenerInvoker>::make()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 437 | ALOGI("Using HWComposer service: %s", mHwcServiceName.c_str()); |
| 438 | } |
Fabien Sanglard | 0cc1938 | 2017-03-06 11:54:40 -0800 | [diff] [blame] | 439 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 440 | SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { |
| 441 | ATRACE_CALL(); |
| 442 | ALOGI("SurfaceFlinger is starting"); |
| 443 | |
| 444 | hasSyncFramework = running_without_sync_framework(true); |
| 445 | |
| 446 | dispSyncPresentTimeOffset = present_time_offset_from_vsync_ns(0); |
| 447 | |
| 448 | useHwcForRgbToYuv = force_hwc_copy_for_virtual_displays(false); |
| 449 | |
| 450 | maxFrameBufferAcquiredBuffers = max_frame_buffer_acquired_buffers(2); |
| 451 | minAcquiredBuffers = |
| 452 | SurfaceFlingerProperties::min_acquired_buffers().value_or(minAcquiredBuffers); |
| 453 | |
| 454 | maxGraphicsWidth = std::max(max_graphics_width(0), 0); |
| 455 | maxGraphicsHeight = std::max(max_graphics_height(0), 0); |
| 456 | |
| 457 | mSupportsWideColor = has_wide_color_display(false); |
| 458 | mDefaultCompositionDataspace = |
| 459 | static_cast<ui::Dataspace>(default_composition_dataspace(Dataspace::V0_SRGB)); |
| 460 | mWideColorGamutCompositionDataspace = static_cast<ui::Dataspace>(wcg_composition_dataspace( |
| 461 | mSupportsWideColor ? Dataspace::DISPLAY_P3 : Dataspace::V0_SRGB)); |
| 462 | defaultCompositionDataspace = mDefaultCompositionDataspace; |
| 463 | wideColorGamutCompositionDataspace = mWideColorGamutCompositionDataspace; |
| 464 | defaultCompositionPixelFormat = static_cast<ui::PixelFormat>( |
| 465 | default_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 466 | wideColorGamutCompositionPixelFormat = |
| 467 | static_cast<ui::PixelFormat>(wcg_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 468 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 469 | mLayerCachingEnabled = [] { |
| 470 | const bool enable = |
| 471 | android::sysprop::SurfaceFlingerProperties::enable_layer_caching().value_or(false); |
| 472 | return base::GetBoolProperty(std::string("debug.sf.enable_layer_caching"), enable); |
| 473 | }(); |
| 474 | |
| 475 | useContextPriority = use_context_priority(true); |
| 476 | |
| 477 | mInternalDisplayPrimaries = sysprop::getDisplayNativePrimaries(); |
| 478 | |
| 479 | // debugging stuff... |
| 480 | char value[PROPERTY_VALUE_MAX]; |
| 481 | |
| 482 | property_get("ro.build.type", value, "user"); |
| 483 | mIsUserBuild = strcmp(value, "user") == 0; |
| 484 | |
| 485 | mDebugFlashDelay = base::GetUintProperty("debug.sf.showupdates"s, 0u); |
| 486 | |
| 487 | mBackpressureGpuComposition = base::GetBoolProperty("debug.sf.enable_gl_backpressure"s, true); |
| 488 | ALOGI_IF(mBackpressureGpuComposition, "Enabling backpressure for GPU composition"); |
| 489 | |
| 490 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 491 | bool supportsBlurs = atoi(value); |
| 492 | mSupportsBlur = supportsBlurs; |
| 493 | ALOGI_IF(!mSupportsBlur, "Disabling blur effects, they are not supported."); |
| 494 | |
| 495 | const size_t defaultListSize = MAX_LAYERS; |
| 496 | auto listSize = property_get_int32("debug.sf.max_igbp_list_size", int32_t(defaultListSize)); |
| 497 | mMaxGraphicBufferProducerListSize = (listSize > 0) ? size_t(listSize) : defaultListSize; |
| 498 | mGraphicBufferProducerListSizeLogThreshold = |
| 499 | std::max(static_cast<int>(0.95 * |
| 500 | static_cast<double>(mMaxGraphicBufferProducerListSize)), |
| 501 | 1); |
| 502 | |
| 503 | property_get("debug.sf.luma_sampling", value, "1"); |
| 504 | mLumaSampling = atoi(value); |
| 505 | |
| 506 | property_get("debug.sf.disable_client_composition_cache", value, "0"); |
| 507 | mDisableClientCompositionCache = atoi(value); |
| 508 | |
| 509 | property_get("debug.sf.predict_hwc_composition_strategy", value, "1"); |
| 510 | mPredictCompositionStrategy = atoi(value); |
| 511 | |
| 512 | property_get("debug.sf.treat_170m_as_sRGB", value, "0"); |
| 513 | mTreat170mAsSrgb = atoi(value); |
| 514 | |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 515 | property_get("debug.sf.dim_in_gamma_in_enhanced_screenshots", value, 0); |
| 516 | mDimInGammaSpaceForEnhancedScreenshots = atoi(value); |
| 517 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 518 | mIgnoreHwcPhysicalDisplayOrientation = |
| 519 | base::GetBoolProperty("debug.sf.ignore_hwc_physical_display_orientation"s, false); |
| 520 | |
| 521 | // We should be reading 'persist.sys.sf.color_saturation' here |
| 522 | // but since /data may be encrypted, we need to wait until after vold |
| 523 | // comes online to attempt to read the property. The property is |
| 524 | // instead read after the boot animation |
| 525 | |
| 526 | if (base::GetBoolProperty("debug.sf.treble_testing_override"s, false)) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 527 | // Without the override SurfaceFlinger cannot connect to HIDL |
| 528 | // services that are not listed in the manifests. Considered |
| 529 | // deriving the setting from the set service name, but it |
| 530 | // would be brittle if the name that's not 'default' is used |
| 531 | // for production purposes later on. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 532 | ALOGI("Enabling Treble testing override"); |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 533 | android::hardware::details::setTrebleTestingOverride(true); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 534 | } |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 535 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 536 | // TODO (b/270966065) Update the HWC based refresh rate overlay to support spinner |
| 537 | mRefreshRateOverlaySpinner = property_get_bool("debug.sf.show_refresh_rate_overlay_spinner", 0); |
| 538 | mRefreshRateOverlayRenderRate = |
| 539 | property_get_bool("debug.sf.show_refresh_rate_overlay_render_rate", 0); |
| 540 | mRefreshRateOverlayShowInMiddle = |
| 541 | property_get_bool("debug.sf.show_refresh_rate_overlay_in_middle", 0); |
| 542 | |
| 543 | if (!mIsUserBuild && base::GetBoolProperty("debug.sf.enable_transaction_tracing"s, true)) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 544 | mTransactionTracing.emplace(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 545 | mLayerTracing.setTransactionTracing(*mTransactionTracing); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 546 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 547 | |
| 548 | mIgnoreHdrCameraLayers = ignore_hdr_camera_layers(false); |
| 549 | |
| 550 | mLayerLifecycleManagerEnabled = |
Vishnu Nair | f42d9bd | 2023-08-23 21:35:33 +0000 | [diff] [blame] | 551 | base::GetBoolProperty("persist.debug.sf.enable_layer_lifecycle_manager"s, true); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 552 | mLegacyFrontEndEnabled = !mLayerLifecycleManagerEnabled || |
| 553 | base::GetBoolProperty("persist.debug.sf.enable_legacy_frontend"s, false); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | LatchUnsignaledConfig SurfaceFlinger::getLatchUnsignaledConfig() { |
Ady Abraham | d9e8d1b | 2022-02-25 00:36:10 +0000 | [diff] [blame] | 557 | if (base::GetBoolProperty("debug.sf.auto_latch_unsignaled"s, true)) { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 558 | return LatchUnsignaledConfig::AutoSingleLayer; |
| 559 | } |
| 560 | |
| 561 | return LatchUnsignaledConfig::Disabled; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | } |
| 563 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 564 | SurfaceFlinger::~SurfaceFlinger() = default; |
| 565 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 566 | void SurfaceFlinger::binderDied(const wp<IBinder>&) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 567 | // the window manager died on us. prepare its eulogy. |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 568 | mBootFinished = false; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 569 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 570 | static_cast<void>(mScheduler->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 571 | // Sever the link to inputflinger since it's gone as well. |
| 572 | mInputFlinger.clear(); |
Vishnu Nair | b9df470 | 2021-03-01 11:53:15 -0800 | [diff] [blame] | 573 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 574 | initializeDisplays(); |
| 575 | })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 576 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 577 | startBootAnim(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 578 | } |
| 579 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 580 | void SurfaceFlinger::run() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 581 | mScheduler->run(); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 582 | } |
| 583 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 584 | sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName, bool secure, |
| 585 | float requestedRefreshRate) { |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 586 | // onTransact already checks for some permissions, but adding an additional check here. |
| 587 | // This is to ensure that only system and graphics can request to create a secure |
| 588 | // display. Secure displays can show secure content so we add an additional restriction on it. |
| 589 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 590 | if (secure && uid != AID_GRAPHICS && uid != AID_SYSTEM) { |
| 591 | ALOGE("Only privileged processes can create a secure display"); |
| 592 | return nullptr; |
| 593 | } |
| 594 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 595 | class DisplayToken : public BBinder { |
| 596 | sp<SurfaceFlinger> flinger; |
| 597 | virtual ~DisplayToken() { |
| 598 | // no more references, this display must be terminated |
| 599 | Mutex::Autolock _l(flinger->mStateLock); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 600 | flinger->mCurrentState.displays.removeItem(wp<IBinder>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 601 | flinger->setTransactionFlags(eDisplayTransactionNeeded); |
| 602 | } |
| 603 | public: |
Chih-Hung Hsieh | c406791 | 2016-05-03 14:03:27 -0700 | [diff] [blame] | 604 | explicit DisplayToken(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 605 | : flinger(flinger) { |
| 606 | } |
| 607 | }; |
| 608 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 609 | sp<BBinder> token = sp<DisplayToken>::make(sp<SurfaceFlinger>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 610 | |
| 611 | Mutex::Autolock _l(mStateLock); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 612 | // Display ID is assigned when virtual display is allocated by HWC. |
| 613 | DisplayDeviceState state; |
| 614 | state.isSecure = secure; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 615 | // Set display as protected when marked as secure to ensure no behavior change |
| 616 | // TODO (b/314820005): separate as a different arg when creating the display. |
| 617 | state.isProtected = secure; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 618 | state.displayName = displayName; |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 619 | state.requestedRefreshRate = Fps::fromValue(requestedRefreshRate); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 620 | mCurrentState.displays.add(token, state); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 621 | return token; |
| 622 | } |
| 623 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 624 | void SurfaceFlinger::destroyDisplay(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 625 | Mutex::Autolock lock(mStateLock); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 626 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 627 | const ssize_t index = mCurrentState.displays.indexOfKey(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 628 | if (index < 0) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 629 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 630 | return; |
| 631 | } |
| 632 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 633 | const DisplayDeviceState& state = mCurrentState.displays.valueAt(index); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 634 | if (state.physical) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 635 | ALOGE("%s: Invalid operation on physical display", __func__); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 636 | return; |
| 637 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 638 | mCurrentState.displays.removeItemsAt(index); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 639 | setTransactionFlags(eDisplayTransactionNeeded); |
| 640 | } |
| 641 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 642 | void SurfaceFlinger::enableHalVirtualDisplays(bool enable) { |
| 643 | auto& generator = mVirtualDisplayIdGenerators.hal; |
| 644 | if (!generator && enable) { |
| 645 | ALOGI("Enabling HAL virtual displays"); |
| 646 | generator.emplace(getHwComposer().getMaxVirtualDisplayCount()); |
| 647 | } else if (generator && !enable) { |
| 648 | ALOGW_IF(generator->inUse(), "Disabling HAL virtual displays while in use"); |
| 649 | generator.reset(); |
| 650 | } |
| 651 | } |
| 652 | |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 653 | VirtualDisplayId SurfaceFlinger::acquireVirtualDisplay(ui::Size resolution, |
| 654 | ui::PixelFormat format) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 655 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 656 | if (const auto id = generator->generateId()) { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 657 | if (getHwComposer().allocateVirtualDisplay(*id, resolution, &format)) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 658 | return *id; |
| 659 | } |
| 660 | |
| 661 | generator->releaseId(*id); |
| 662 | } else { |
| 663 | ALOGW("%s: Exhausted HAL virtual displays", __func__); |
| 664 | } |
| 665 | |
| 666 | ALOGW("%s: Falling back to GPU virtual display", __func__); |
| 667 | } |
| 668 | |
| 669 | const auto id = mVirtualDisplayIdGenerators.gpu.generateId(); |
| 670 | LOG_ALWAYS_FATAL_IF(!id, "Failed to generate ID for GPU virtual display"); |
| 671 | return *id; |
| 672 | } |
| 673 | |
| 674 | void SurfaceFlinger::releaseVirtualDisplay(VirtualDisplayId displayId) { |
| 675 | if (const auto id = HalVirtualDisplayId::tryCast(displayId)) { |
| 676 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 677 | generator->releaseId(*id); |
| 678 | } |
| 679 | return; |
| 680 | } |
| 681 | |
| 682 | const auto id = GpuVirtualDisplayId::tryCast(displayId); |
| 683 | LOG_ALWAYS_FATAL_IF(!id); |
| 684 | mVirtualDisplayIdGenerators.gpu.releaseId(*id); |
| 685 | } |
| 686 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 687 | std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdsLocked() const { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 688 | std::vector<PhysicalDisplayId> displayIds; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 689 | displayIds.reserve(mPhysicalDisplays.size()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 690 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 691 | const auto defaultDisplayId = getDefaultDisplayDeviceLocked()->getPhysicalId(); |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 692 | displayIds.push_back(defaultDisplayId); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 693 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 694 | for (const auto& [id, display] : mPhysicalDisplays) { |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 695 | if (id != defaultDisplayId) { |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 696 | displayIds.push_back(id); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 697 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 698 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 699 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 700 | return displayIds; |
| 701 | } |
| 702 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 703 | std::optional<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdLocked( |
| 704 | const sp<display::DisplayToken>& displayToken) const { |
| 705 | return ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 706 | .transform(&ftl::to_key<PhysicalDisplays>); |
| 707 | } |
| 708 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 709 | sp<IBinder> SurfaceFlinger::getPhysicalDisplayToken(PhysicalDisplayId displayId) const { |
| 710 | Mutex::Autolock lock(mStateLock); |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 711 | return getPhysicalDisplayTokenLocked(displayId); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 714 | HWComposer& SurfaceFlinger::getHwComposer() const { |
| 715 | return mCompositionEngine->getHwComposer(); |
| 716 | } |
| 717 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 718 | renderengine::RenderEngine& SurfaceFlinger::getRenderEngine() const { |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 719 | return *mRenderEngine; |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 722 | compositionengine::CompositionEngine& SurfaceFlinger::getCompositionEngine() const { |
| 723 | return *mCompositionEngine.get(); |
| 724 | } |
| 725 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 726 | void SurfaceFlinger::bootFinished() { |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 727 | if (mBootFinished == true) { |
| 728 | ALOGE("Extra call to bootFinished"); |
| 729 | return; |
| 730 | } |
| 731 | mBootFinished = true; |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame] | 732 | FlagManager::getMutableInstance().markBootCompleted(); |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 733 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 734 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 735 | } |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 736 | |
| 737 | if (mRenderEnginePrimeCacheFuture.valid()) { |
| 738 | mRenderEnginePrimeCacheFuture.get(); |
| 739 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | const nsecs_t now = systemTime(); |
| 741 | const nsecs_t duration = now - mBootTime; |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 742 | ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 743 | |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 744 | mFrameTracer->initialize(); |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 745 | mFrameTimeline->onBootFinished(); |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 746 | getRenderEngine().setEnableTracing(FlagManager::getInstance().use_skia_tracing()); |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 747 | |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 748 | // wait patiently for the window manager death |
| 749 | const String16 name("window"); |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 750 | mWindowManager = defaultServiceManager()->waitForService(name); |
Steven Moreland | a904bb9 | 2019-07-02 17:37:23 -0700 | [diff] [blame] | 751 | if (mWindowManager != 0) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 752 | mWindowManager->linkToDeath(sp<IBinder::DeathRecipient>::fromExisting(this)); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | // stop boot animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 756 | // formerly we would just kill the process, but we now ask it to exit so it |
| 757 | // can choose where to stop the animation. |
| 758 | property_set("service.bootanim.exit", "1"); |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 759 | |
| 760 | const int LOGTAG_SF_STOP_BOOTANIM = 60110; |
| 761 | LOG_EVENT_LONG(LOGTAG_SF_STOP_BOOTANIM, |
| 762 | ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 763 | |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 764 | sp<IBinder> input(defaultServiceManager()->waitForService(String16("inputflinger"))); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 765 | |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 766 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 767 | if (input == nullptr) { |
| 768 | ALOGE("Failed to link to input service"); |
| 769 | } else { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 770 | mInputFlinger = interface_cast<os::IInputFlinger>(input); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 771 | } |
| 772 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 773 | readPersistentProperties(); |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 774 | const bool hintSessionEnabled = FlagManager::getInstance().use_adpf_cpu_hint(); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 775 | mPowerAdvisor->enablePowerHintSession(hintSessionEnabled); |
| 776 | const bool hintSessionUsed = mPowerAdvisor->usePowerHintSession(); |
Matt Buckley | 547cc0c | 2023-10-27 22:22:36 +0000 | [diff] [blame] | 777 | // Ordering is important here, as onBootFinished signals to PowerAdvisor that concurrency |
| 778 | // is safe because its variables are initialized. |
| 779 | mPowerAdvisor->onBootFinished(); |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 780 | ALOGD("Power hint is %s", |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 781 | hintSessionUsed ? "supported" : (hintSessionEnabled ? "unsupported" : "disabled")); |
| 782 | if (hintSessionUsed) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 783 | std::optional<pid_t> renderEngineTid = getRenderEngine().getRenderEngineTid(); |
| 784 | std::vector<int32_t> tidList; |
| 785 | tidList.emplace_back(gettid()); |
| 786 | if (renderEngineTid.has_value()) { |
| 787 | tidList.emplace_back(*renderEngineTid); |
| 788 | } |
Matt Buckley | 547cc0c | 2023-10-27 22:22:36 +0000 | [diff] [blame] | 789 | if (!mPowerAdvisor->startPowerHintSession(std::move(tidList))) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 790 | ALOGW("Cannot start power hint session"); |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 791 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 794 | mBootStage = BootStage::FINISHED; |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 795 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 796 | if (base::GetBoolProperty("sf.debug.show_refresh_rate_overlay"s, false)) { |
| 797 | ftl::FakeGuard guard(mStateLock); |
| 798 | enableRefreshRateOverlay(true); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 799 | } |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 800 | })); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | } |
| 802 | |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 803 | static std::optional<renderengine::RenderEngine::RenderEngineType> |
| 804 | chooseRenderEngineTypeViaSysProp() { |
| 805 | char prop[PROPERTY_VALUE_MAX]; |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 806 | property_get(PROPERTY_DEBUG_RENDERENGINE_BACKEND, prop, "skiaglthreaded"); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 807 | |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 808 | if (strcmp(prop, "skiagl") == 0) { |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 809 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL; |
| 810 | } else if (strcmp(prop, "skiaglthreaded") == 0) { |
| 811 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL_THREADED; |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 812 | } else if (strcmp(prop, "skiavk") == 0) { |
| 813 | return renderengine::RenderEngine::RenderEngineType::SKIA_VK; |
| 814 | } else if (strcmp(prop, "skiavkthreaded") == 0) { |
| 815 | return renderengine::RenderEngine::RenderEngineType::SKIA_VK_THREADED; |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 816 | } else { |
| 817 | ALOGE("Unrecognized RenderEngineType %s; ignoring!", prop); |
| 818 | return {}; |
| 819 | } |
| 820 | } |
| 821 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 822 | // Do not call property_set on main thread which will be blocked by init |
| 823 | // Use StartPropertySetThread instead. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 824 | void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) { |
Parth Sane | 343626c | 2023-04-06 16:17:04 +0000 | [diff] [blame] | 825 | ATRACE_CALL(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 826 | ALOGI( "SurfaceFlinger's main thread ready to run. " |
| 827 | "Initializing graphics H/W..."); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 828 | addTransactionReadyFilters(); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 829 | Mutex::Autolock lock(mStateLock); |
Kevin DuBois | 413287f | 2019-02-25 08:46:47 -0800 | [diff] [blame] | 830 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 831 | // Get a RenderEngine for the given display / config (can't fail) |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 832 | // 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] | 833 | // Sending maxFrameBufferAcquiredBuffers as the cache size is tightly tuned to single-display. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 834 | auto builder = renderengine::RenderEngineCreationArgs::Builder() |
| 835 | .setPixelFormat(static_cast<int32_t>(defaultCompositionPixelFormat)) |
| 836 | .setImageCacheSize(maxFrameBufferAcquiredBuffers) |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 837 | .setEnableProtectedContext(enable_protected_contents(false)) |
| 838 | .setPrecacheToneMapperShaderOnly(false) |
| 839 | .setSupportsBackgroundBlur(mSupportsBlur) |
| 840 | .setContextPriority( |
| 841 | useContextPriority |
| 842 | ? renderengine::RenderEngine::ContextPriority::REALTIME |
| 843 | : renderengine::RenderEngine::ContextPriority::MEDIUM); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 844 | if (auto type = chooseRenderEngineTypeViaSysProp()) { |
| 845 | builder.setRenderEngineType(type.value()); |
| 846 | } |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 847 | mRenderEngine = renderengine::RenderEngine::create(builder.build()); |
| 848 | mCompositionEngine->setRenderEngine(mRenderEngine.get()); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 849 | mMaxRenderTargetSize = |
| 850 | std::min(getRenderEngine().getMaxTextureSize(), getRenderEngine().getMaxViewportDims()); |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 851 | |
| 852 | // Set SF main policy after initializing RenderEngine which has its own policy. |
| 853 | if (!SetTaskProfiles(0, {"SFMainPolicy"})) { |
| 854 | ALOGW("Failed to set main task profile"); |
| 855 | } |
| 856 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 857 | mCompositionEngine->setTimeStats(mTimeStats); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 858 | mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName)); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 859 | mCompositionEngine->getHwComposer().setCallback(*this); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 860 | ClientCache::getInstance().setRenderEngine(&getRenderEngine()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 861 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 862 | enableLatchUnsignaledConfig = getLatchUnsignaledConfig(); |
| 863 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 864 | if (base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false)) { |
| 865 | enableHalVirtualDisplays(true); |
| 866 | } |
| 867 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 868 | // Process hotplug for displays connected at boot. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 869 | LOG_ALWAYS_FATAL_IF(!configureLocked(), |
| 870 | "Initial display configuration failed: HWC did not hotplug"); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 871 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 872 | // Commit primary display. |
| 873 | sp<const DisplayDevice> display; |
| 874 | if (const auto indexOpt = mCurrentState.getDisplayIndex(getPrimaryDisplayIdLocked())) { |
| 875 | const auto& displays = mCurrentState.displays; |
| 876 | |
| 877 | const auto& token = displays.keyAt(*indexOpt); |
| 878 | const auto& state = displays.valueAt(*indexOpt); |
| 879 | |
| 880 | processDisplayAdded(token, state); |
| 881 | mDrawingState.displays.add(token, state); |
| 882 | |
| 883 | display = getDefaultDisplayDeviceLocked(); |
| 884 | } |
| 885 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 886 | LOG_ALWAYS_FATAL_IF(!display, "Failed to configure the primary display"); |
| 887 | LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(display->getPhysicalId()), |
| 888 | "Primary display is disconnected"); |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 889 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 890 | // TODO(b/241285876): The Scheduler needlessly depends on creating the CompositionEngine part of |
| 891 | // the DisplayDevice, hence the above commit of the primary display. Remove that special case by |
| 892 | // initializing the Scheduler after configureLocked, once decoupled from DisplayDevice. |
| 893 | initScheduler(display); |
| 894 | dispatchDisplayHotplugEvent(display->getPhysicalId(), true); |
| 895 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 896 | mLayerTracing.setTakeLayersSnapshotProtoFunction([&](uint32_t traceFlags) { |
| 897 | auto snapshot = perfetto::protos::LayersSnapshotProto{}; |
| 898 | mScheduler |
| 899 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 900 | snapshot = takeLayersSnapshotProto(traceFlags, TimePoint::now(), |
| 901 | mLastCommittedVsyncId, true); |
| 902 | }) |
| 903 | .wait(); |
| 904 | return snapshot; |
| 905 | }); |
| 906 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 907 | // Commit secondary display(s). |
| 908 | processDisplayChangesLocked(); |
| 909 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 910 | // initialize our drawing state |
| 911 | mDrawingState = mCurrentState; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 912 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 913 | onActiveDisplayChangedLocked(nullptr, *display); |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 914 | |
| 915 | static_cast<void>(mScheduler->schedule( |
| 916 | [this]() FTL_FAKE_GUARD(kMainThreadContext) { initializeDisplays(); })); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 917 | |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 918 | mPowerAdvisor->init(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 919 | |
Bruno BELANYI | fd02878 | 2023-10-13 14:39:53 +0000 | [diff] [blame] | 920 | if (base::GetBoolProperty("service.sf.prime_shader_cache"s, true)) { |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 921 | if (setSchedFifo(false) != NO_ERROR) { |
| 922 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 923 | } |
| 924 | |
Bruno BELANYI | b9b5b70 | 2023-10-13 13:25:11 +0000 | [diff] [blame] | 925 | bool shouldPrimeUltraHDR = |
| 926 | base::GetBoolProperty("ro.surface_flinger.prime_shader_cache.ultrahdr"s, false); |
| 927 | mRenderEnginePrimeCacheFuture = getRenderEngine().primeCache(shouldPrimeUltraHDR); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 928 | |
| 929 | if (setSchedFifo(true) != NO_ERROR) { |
linkai | d696a4f | 2023-11-14 10:13:36 +0800 | [diff] [blame] | 930 | ALOGW("Can't set SCHED_FIFO after primeCache"); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 931 | } |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 932 | } |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 933 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 934 | // Inform native graphics APIs whether the present timestamp is supported: |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 935 | |
| 936 | const bool presentFenceReliable = |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 937 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE); |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 938 | mStartPropertySetThread = getFactory().createStartPropertySetThread(presentFenceReliable); |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 939 | |
| 940 | if (mStartPropertySetThread->Start() != NO_ERROR) { |
| 941 | ALOGE("Run StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 942 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 943 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 944 | initTransactionTraceWriter(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 945 | ALOGV("Done initializing"); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 946 | } |
| 947 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 948 | void SurfaceFlinger::initTransactionTraceWriter() { |
| 949 | if (!mTransactionTracing) { |
| 950 | return; |
| 951 | } |
| 952 | TransactionTraceWriter::getInstance().setWriterFunction( |
| 953 | [&](const std::string& filename, bool overwrite) { |
| 954 | auto writeFn = [&]() { |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 955 | if (!overwrite && fileNewerThan(filename, std::chrono::minutes{10})) { |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 956 | ALOGD("TransactionTraceWriter: file=%s already exists", filename.c_str()); |
| 957 | return; |
| 958 | } |
| 959 | mTransactionTracing->flush(); |
| 960 | mTransactionTracing->writeToFile(filename); |
| 961 | }; |
| 962 | if (std::this_thread::get_id() == mMainThreadId) { |
| 963 | writeFn(); |
| 964 | } else { |
| 965 | mScheduler->schedule(writeFn).get(); |
| 966 | } |
| 967 | }); |
| 968 | } |
| 969 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 970 | void SurfaceFlinger::readPersistentProperties() { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 971 | Mutex::Autolock _l(mStateLock); |
| 972 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 973 | char value[PROPERTY_VALUE_MAX]; |
| 974 | |
| 975 | property_get("persist.sys.sf.color_saturation", value, "1.0"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 976 | mGlobalSaturationFactor = atof(value); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 977 | updateColorMatrixLocked(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 978 | ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 979 | |
| 980 | property_get("persist.sys.sf.native_mode", value, "0"); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 981 | mDisplayColorSetting = static_cast<DisplayColorSetting>(atoi(value)); |
Peiyong Lin | a3ea559 | 2019-02-10 14:45:00 -0800 | [diff] [blame] | 982 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 983 | mForceColorMode = |
| 984 | 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] | 985 | } |
| 986 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 987 | void SurfaceFlinger::startBootAnim() { |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 988 | // Start boot animation service by setting a property mailbox |
| 989 | // 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] | 990 | mStartPropertySetThread->Start(); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 991 | // Wait until property was set |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 992 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 993 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 994 | } |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 995 | } |
| 996 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 997 | // ---------------------------------------------------------------------------- |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 998 | |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 999 | status_t SurfaceFlinger::getSupportedFrameTimestamps( |
| 1000 | std::vector<FrameEvent>* outSupported) const { |
| 1001 | *outSupported = { |
| 1002 | FrameEvent::REQUESTED_PRESENT, |
| 1003 | FrameEvent::ACQUIRE, |
| 1004 | FrameEvent::LATCH, |
| 1005 | FrameEvent::FIRST_REFRESH_START, |
| 1006 | FrameEvent::LAST_REFRESH_START, |
| 1007 | FrameEvent::GPU_COMPOSITION_DONE, |
| 1008 | FrameEvent::DEQUEUE_READY, |
| 1009 | FrameEvent::RELEASE, |
| 1010 | }; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1011 | |
| 1012 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 1013 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 1014 | if (!getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 1015 | outSupported->push_back(FrameEvent::DISPLAY_PRESENT); |
| 1016 | } |
| 1017 | return NO_ERROR; |
| 1018 | } |
| 1019 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1020 | status_t SurfaceFlinger::getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState* state) { |
| 1021 | if (!displayToken || !state) { |
| 1022 | return BAD_VALUE; |
| 1023 | } |
| 1024 | |
| 1025 | Mutex::Autolock lock(mStateLock); |
| 1026 | |
| 1027 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1028 | if (!display) { |
| 1029 | return NAME_NOT_FOUND; |
| 1030 | } |
| 1031 | |
| 1032 | state->layerStack = display->getLayerStack(); |
| 1033 | state->orientation = display->getOrientation(); |
| 1034 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 1035 | const Rect layerStackRect = display->getLayerStackSpaceRect(); |
| 1036 | state->layerStackSpaceRect = |
| 1037 | layerStackRect.isValid() ? layerStackRect.getSize() : display->getSize(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1038 | |
| 1039 | return NO_ERROR; |
| 1040 | } |
| 1041 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1042 | status_t SurfaceFlinger::getStaticDisplayInfo(int64_t displayId, ui::StaticDisplayInfo* info) { |
| 1043 | if (!info) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1044 | return BAD_VALUE; |
| 1045 | } |
| 1046 | |
| 1047 | Mutex::Autolock lock(mStateLock); |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1048 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 1049 | const auto displayOpt = mPhysicalDisplays.get(*id).and_then(getDisplayDeviceAndSnapshot()); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1050 | |
| 1051 | if (!displayOpt) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1052 | return NAME_NOT_FOUND; |
| 1053 | } |
| 1054 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1055 | const auto& [display, snapshotRef] = *displayOpt; |
| 1056 | const auto& snapshot = snapshotRef.get(); |
| 1057 | |
| 1058 | info->connectionType = snapshot.connectionType(); |
| 1059 | info->deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1060 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1061 | if (mEmulatedDisplayDensity) { |
| 1062 | info->density = mEmulatedDisplayDensity; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1063 | } else { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1064 | info->density = info->connectionType == ui::DisplayConnectionType::Internal |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1065 | ? mInternalDisplayDensity |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1066 | : FALLBACK_DENSITY; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1067 | } |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 1068 | info->density /= ACONFIGURATION_DENSITY_MEDIUM; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1069 | |
| 1070 | info->secure = display->isSecure(); |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1071 | info->installOrientation = display->getPhysicalOrientation(); |
Vishnu Nair | d0a8965 | 2022-01-13 12:05:54 -0800 | [diff] [blame] | 1072 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1073 | return NO_ERROR; |
| 1074 | } |
| 1075 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1076 | void SurfaceFlinger::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo*& info, |
| 1077 | const sp<DisplayDevice>& display, |
| 1078 | const display::DisplaySnapshot& snapshot) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1079 | const auto& displayModes = snapshot.displayModes(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1080 | info->supportedDisplayModes.clear(); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1081 | info->supportedDisplayModes.reserve(displayModes.size()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1082 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1083 | for (const auto& [id, mode] : displayModes) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1084 | ui::DisplayMode outMode; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1085 | outMode.id = static_cast<int32_t>(id.value()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1086 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1087 | auto [width, height] = mode->getResolution(); |
| 1088 | auto [xDpi, yDpi] = mode->getDpi(); |
Yiwei Zhang | 27de5df | 2018-08-23 17:04:51 -0700 | [diff] [blame] | 1089 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1090 | if (const auto physicalOrientation = display->getPhysicalOrientation(); |
| 1091 | physicalOrientation == ui::ROTATION_90 || physicalOrientation == ui::ROTATION_270) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1092 | std::swap(width, height); |
| 1093 | std::swap(xDpi, yDpi); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1096 | outMode.resolution = ui::Size(width, height); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1097 | |
Huan Song | f7eeb10 | 2022-03-28 11:02:38 -0700 | [diff] [blame] | 1098 | outMode.xDpi = xDpi; |
| 1099 | outMode.yDpi = yDpi; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1100 | |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1101 | const auto peakFps = mode->getPeakFps(); |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 1102 | outMode.peakRefreshRate = peakFps.getValue(); |
Alec Mouri | d122a1c | 2023-09-30 01:36:33 +0000 | [diff] [blame] | 1103 | outMode.vsyncRate = mode->getVsyncRate().getValue(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1104 | |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 1105 | const auto vsyncConfigSet = mVsyncConfiguration->getConfigsForRefreshRate( |
| 1106 | Fps::fromValue(outMode.peakRefreshRate)); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1107 | outMode.appVsyncOffset = vsyncConfigSet.late.appOffset; |
| 1108 | outMode.sfVsyncOffset = vsyncConfigSet.late.sfOffset; |
| 1109 | outMode.group = mode->getGroup(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1110 | |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1111 | // This is how far in advance a buffer must be queued for |
| 1112 | // presentation at a given time. If you want a buffer to appear |
| 1113 | // on the screen at time N, you must submit the buffer before |
| 1114 | // (N - presentationDeadline). |
| 1115 | // |
| 1116 | // Normally it's one full refresh period (to give SF a chance to |
| 1117 | // latch the buffer), but this can be reduced by configuring a |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 1118 | // VsyncController offset. Any additional delays introduced by the hardware |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1119 | // composer or panel must be accounted for here. |
| 1120 | // |
| 1121 | // We add an additional 1ms to allow for processing time and |
| 1122 | // differences between the ideal and actual refresh rate. |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1123 | outMode.presentationDeadline = peakFps.getPeriodNsecs() - outMode.sfVsyncOffset + 1000000; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1124 | excludeDolbyVisionIf4k30Present(display->getHdrCapabilities().getSupportedHdrTypes(), |
| 1125 | outMode); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1126 | info->supportedDisplayModes.push_back(outMode); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1129 | info->supportedColorModes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1130 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1131 | const PhysicalDisplayId displayId = snapshot.displayId(); |
| 1132 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1133 | const auto mode = display->refreshRateSelector().getActiveMode(); |
| 1134 | info->activeDisplayModeId = mode.modePtr->getId().value(); |
| 1135 | info->renderFrameRate = mode.fps.getValue(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1136 | info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1137 | info->hdrCapabilities = filterOut4k30(display->getHdrCapabilities()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1138 | |
Marin Shalamanov | b173f75 | 2021-02-16 19:38:36 +0100 | [diff] [blame] | 1139 | info->autoLowLatencyModeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1140 | getHwComposer().hasDisplayCapability(displayId, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1141 | DisplayCapability::AUTO_LOW_LATENCY_MODE); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1142 | info->gameContentTypeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1143 | getHwComposer().supportsContentType(displayId, hal::ContentType::GAME); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1144 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1145 | info->preferredBootDisplayMode = static_cast<ui::DisplayModeId>(-1); |
Kriti Dang | ac0a74d | 2022-03-16 11:52:35 +0100 | [diff] [blame] | 1146 | |
| 1147 | if (getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG)) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1148 | if (const auto hwcId = getHwComposer().getPreferredBootDisplayMode(displayId)) { |
| 1149 | if (const auto modeId = snapshot.translateModeId(*hwcId)) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1150 | info->preferredBootDisplayMode = modeId->value(); |
| 1151 | } |
| 1152 | } |
| 1153 | } |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1154 | } |
Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame] | 1155 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1156 | status_t SurfaceFlinger::getDynamicDisplayInfoFromId(int64_t physicalDisplayId, |
| 1157 | ui::DynamicDisplayInfo* info) { |
| 1158 | if (!info) { |
| 1159 | return BAD_VALUE; |
| 1160 | } |
| 1161 | |
| 1162 | Mutex::Autolock lock(mStateLock); |
| 1163 | |
| 1164 | const auto id_ = |
| 1165 | DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(physicalDisplayId)); |
| 1166 | const auto displayOpt = mPhysicalDisplays.get(*id_).and_then(getDisplayDeviceAndSnapshot()); |
| 1167 | |
| 1168 | if (!displayOpt) { |
| 1169 | return NAME_NOT_FOUND; |
| 1170 | } |
| 1171 | |
| 1172 | const auto& [display, snapshotRef] = *displayOpt; |
| 1173 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
| 1174 | return NO_ERROR; |
| 1175 | } |
| 1176 | |
| 1177 | status_t SurfaceFlinger::getDynamicDisplayInfoFromToken(const sp<IBinder>& displayToken, |
| 1178 | ui::DynamicDisplayInfo* info) { |
| 1179 | if (!displayToken || !info) { |
| 1180 | return BAD_VALUE; |
| 1181 | } |
| 1182 | |
| 1183 | Mutex::Autolock lock(mStateLock); |
| 1184 | |
| 1185 | const auto displayOpt = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1186 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1187 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1188 | |
| 1189 | if (!displayOpt) { |
| 1190 | return NAME_NOT_FOUND; |
| 1191 | } |
| 1192 | |
| 1193 | const auto& [display, snapshotRef] = *displayOpt; |
| 1194 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1195 | return NO_ERROR; |
| 1196 | } |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 1197 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1198 | status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>& displayToken, |
| 1199 | DisplayStatInfo* outStats) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1200 | if (!outStats) { |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1201 | return BAD_VALUE; |
| 1202 | } |
| 1203 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1204 | std::optional<PhysicalDisplayId> displayIdOpt; |
| 1205 | { |
| 1206 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1207 | if (displayToken) { |
| 1208 | displayIdOpt = getPhysicalDisplayIdLocked(displayToken); |
| 1209 | if (!displayIdOpt) { |
| 1210 | ALOGW("%s: Invalid physical display token %p", __func__, displayToken.get()); |
| 1211 | return NAME_NOT_FOUND; |
| 1212 | } |
| 1213 | } else { |
| 1214 | // TODO (b/277364366): Clients should be updated to pass in the display they |
| 1215 | // want, rather than us picking an arbitrary one (the active display, in this |
| 1216 | // case). |
| 1217 | displayIdOpt = mActiveDisplayId; |
| 1218 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1219 | } |
| 1220 | |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1221 | const auto schedule = mScheduler->getVsyncSchedule(displayIdOpt); |
| 1222 | if (!schedule) { |
| 1223 | ALOGE("%s: Missing VSYNC schedule for display %s!", __func__, |
| 1224 | to_string(*displayIdOpt).c_str()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1225 | return NAME_NOT_FOUND; |
| 1226 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1227 | outStats->vsyncTime = schedule->vsyncDeadlineAfter(TimePoint::now()).ns(); |
| 1228 | outStats->vsyncPeriod = schedule->period().ns(); |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1229 | return NO_ERROR; |
| 1230 | } |
| 1231 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1232 | void SurfaceFlinger::setDesiredMode(display::DisplayModeRequest&& request, bool force) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1233 | const auto displayId = request.mode.modePtr->getPhysicalDisplayId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1234 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
| 1235 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1236 | const auto display = getDisplayDeviceLocked(displayId); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1237 | if (!display) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1238 | ALOGW("%s: display is no longer valid", __func__); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1239 | return; |
| 1240 | } |
| 1241 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1242 | const auto mode = request.mode; |
| 1243 | const bool emitEvent = request.emitEvent; |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 1244 | |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1245 | switch (display->setDesiredMode(std::move(request), force)) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1246 | case DisplayDevice::DesiredModeAction::InitiateDisplayModeSwitch: |
| 1247 | // DisplayDevice::setDesiredMode updated the render rate, so inform Scheduler. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1248 | mScheduler->setRenderRate(displayId, |
| 1249 | display->refreshRateSelector().getActiveMode().fps); |
Ady Abraham | 95a37e2 | 2023-01-18 22:57:28 -0800 | [diff] [blame] | 1250 | |
| 1251 | // Schedule a new frame to initiate the display mode switch. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1252 | scheduleComposite(FrameHint::kNone); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1253 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1254 | // Start receiving vsync samples now, so that we can detect a period |
| 1255 | // switch. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1256 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 1257 | mode.modePtr.get()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1258 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1259 | // As we called to set period, we will call to onRefreshRateChangeCompleted once |
| 1260 | // VsyncController model is locked. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1261 | mScheduler->modulateVsync(displayId, &VsyncModulator::onRefreshRateChangeInitiated); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1262 | |
| 1263 | if (displayId == mActiveDisplayId) { |
| 1264 | updatePhaseConfiguration(mode.fps); |
| 1265 | } |
| 1266 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1267 | mScheduler->setModeChangePending(true); |
| 1268 | break; |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1269 | case DisplayDevice::DesiredModeAction::InitiateRenderRateSwitch: |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1270 | mScheduler->setRenderRate(displayId, mode.fps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1271 | |
| 1272 | if (displayId == mActiveDisplayId) { |
| 1273 | updatePhaseConfiguration(mode.fps); |
| 1274 | mRefreshRateStats->setRefreshRate(mode.fps); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1275 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1276 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1277 | if (emitEvent) { |
| 1278 | dispatchDisplayModeChangeEvent(displayId, mode); |
| 1279 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1280 | break; |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1281 | case DisplayDevice::DesiredModeAction::None: |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1282 | break; |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1283 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1284 | } |
| 1285 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1286 | status_t SurfaceFlinger::setActiveModeFromBackdoor(const sp<display::DisplayToken>& displayToken, |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1287 | DisplayModeId modeId, Fps minFps, Fps maxFps) { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1288 | ATRACE_CALL(); |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1289 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 1290 | if (!displayToken) { |
| 1291 | return BAD_VALUE; |
| 1292 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1293 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1294 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 1295 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1296 | const auto displayOpt = |
| 1297 | FTL_FAKE_GUARD(mStateLock, |
| 1298 | ftl::find_if(mPhysicalDisplays, |
| 1299 | PhysicalDisplay::hasToken(displayToken)) |
| 1300 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1301 | .and_then(getDisplayDeviceAndSnapshot())); |
| 1302 | if (!displayOpt) { |
| 1303 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1304 | return NAME_NOT_FOUND; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1305 | } |
| 1306 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1307 | const auto& [display, snapshotRef] = *displayOpt; |
| 1308 | const auto& snapshot = snapshotRef.get(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1309 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1310 | const auto fpsOpt = snapshot.displayModes().get(modeId).transform( |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1311 | [](const DisplayModePtr& mode) { return mode->getPeakFps(); }); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1312 | |
| 1313 | if (!fpsOpt) { |
| 1314 | ALOGE("%s: Invalid mode %d for display %s", whence, modeId.value(), |
| 1315 | to_string(snapshot.displayId()).c_str()); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1316 | return BAD_VALUE; |
| 1317 | } |
| 1318 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1319 | const Fps fps = *fpsOpt; |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1320 | const FpsRange physical = {fps, fps}; |
| 1321 | const FpsRange render = {minFps.isValid() ? minFps : fps, maxFps.isValid() ? maxFps : fps}; |
| 1322 | const FpsRanges ranges = {physical, render}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1323 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1324 | // Keep the old switching type. |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1325 | const bool allowGroupSwitching = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1326 | display->refreshRateSelector().getCurrentPolicy().allowGroupSwitching; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1327 | |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1328 | const scheduler::RefreshRateSelector::DisplayManagerPolicy policy{modeId, ranges, ranges, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 1329 | allowGroupSwitching}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1330 | |
| 1331 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1332 | }); |
| 1333 | |
| 1334 | return future.get(); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1335 | } |
| 1336 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1337 | void SurfaceFlinger::finalizeDisplayModeChange(DisplayDevice& display) { |
| 1338 | const auto displayId = display.getPhysicalId(); |
| 1339 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1340 | |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1341 | const auto pendingModeOpt = display.getPendingMode(); |
| 1342 | if (!pendingModeOpt) { |
Ady Abraham | faac6da | 2021-07-15 10:04:40 -0700 | [diff] [blame] | 1343 | // There is no pending mode change. This can happen if the active |
| 1344 | // display changed and the mode change happened on a different display. |
| 1345 | return; |
| 1346 | } |
| 1347 | |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1348 | const auto& activeMode = pendingModeOpt->mode; |
| 1349 | |
| 1350 | if (display.getActiveMode().modePtr->getResolution() != activeMode.modePtr->getResolution()) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1351 | auto& state = mCurrentState.displays.editValueFor(display.getDisplayToken()); |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1352 | // We need to generate new sequenceId in order to recreate the display (and this |
| 1353 | // way the framebuffer). |
| 1354 | state.sequenceId = DisplayDeviceState{}.sequenceId; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1355 | state.physical->activeMode = activeMode.modePtr.get(); |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1356 | processDisplayChangesLocked(); |
| 1357 | |
| 1358 | // processDisplayChangesLocked will update all necessary components so we're done here. |
| 1359 | return; |
| 1360 | } |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 1361 | |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1362 | display.finalizeModeChange(activeMode.modePtr->getId(), activeMode.modePtr->getVsyncRate(), |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1363 | activeMode.fps); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1364 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1365 | if (displayId == mActiveDisplayId) { |
| 1366 | mRefreshRateStats->setRefreshRate(activeMode.fps); |
| 1367 | updatePhaseConfiguration(activeMode.fps); |
| 1368 | } |
Dominik Laskowski | 22488f6 | 2019-03-28 09:53:04 -0700 | [diff] [blame] | 1369 | |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1370 | if (pendingModeOpt->emitEvent) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1371 | dispatchDisplayModeChangeEvent(displayId, activeMode); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 1372 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1373 | } |
| 1374 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1375 | void SurfaceFlinger::dropModeRequest(const sp<DisplayDevice>& display) { |
| 1376 | display->clearDesiredMode(); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 1377 | if (display->getPhysicalId() == mActiveDisplayId) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1378 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1379 | mScheduler->setModeChangePending(false); |
| 1380 | } |
Ady Abraham | 53852a5 | 2019-05-28 18:07:44 -0700 | [diff] [blame] | 1381 | } |
| 1382 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1383 | void SurfaceFlinger::applyActiveMode(const sp<DisplayDevice>& display) { |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1384 | const auto activeModeOpt = display->getDesiredMode(); |
| 1385 | auto activeModePtr = activeModeOpt->mode.modePtr; |
| 1386 | const auto displayId = activeModePtr->getPhysicalDisplayId(); |
| 1387 | const auto renderFps = activeModeOpt->mode.fps; |
| 1388 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1389 | dropModeRequest(display); |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1390 | |
| 1391 | constexpr bool kAllowToEnable = true; |
| 1392 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, std::move(activeModePtr).take()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1393 | mScheduler->setRenderRate(displayId, renderFps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1394 | |
| 1395 | if (displayId == mActiveDisplayId) { |
| 1396 | updatePhaseConfiguration(renderFps); |
| 1397 | } |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1398 | } |
| 1399 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1400 | void SurfaceFlinger::initiateDisplayModeChanges() { |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1401 | ATRACE_CALL(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1402 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1403 | std::optional<PhysicalDisplayId> displayToUpdateImmediately; |
| 1404 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1405 | for (const auto& [id, physical] : mPhysicalDisplays) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1406 | const auto display = getDisplayDeviceLocked(id); |
| 1407 | if (!display) continue; |
| 1408 | |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1409 | auto desiredModeOpt = display->getDesiredMode(); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1410 | if (!desiredModeOpt) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1411 | continue; |
| 1412 | } |
| 1413 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 1414 | if (!shouldApplyRefreshRateSelectorPolicy(*display)) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1415 | dropModeRequest(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1416 | continue; |
| 1417 | } |
| 1418 | |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1419 | const auto desiredModeId = desiredModeOpt->mode.modePtr->getId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1420 | const auto displayModePtrOpt = physical.snapshot().displayModes().get(desiredModeId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1421 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1422 | if (!displayModePtrOpt) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1423 | ALOGW("Desired display mode is no longer supported. Mode ID = %d", |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1424 | desiredModeId.value()); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1425 | dropModeRequest(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1426 | continue; |
| 1427 | } |
| 1428 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1429 | ALOGV("%s changing active mode to %d(%s) for display %s", __func__, desiredModeId.value(), |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1430 | to_string(displayModePtrOpt->get()->getVsyncRate()).c_str(), |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1431 | to_string(display->getId()).c_str()); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1432 | |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1433 | if (display->getActiveMode() == desiredModeOpt->mode) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1434 | applyActiveMode(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1435 | continue; |
| 1436 | } |
| 1437 | |
| 1438 | // Desired active mode was set, it is different than the mode currently in use, however |
| 1439 | // allowed modes might have changed by the time we process the refresh. |
| 1440 | // Make sure the desired mode is still allowed |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1441 | if (!display->refreshRateSelector().isModeAllowed(desiredModeOpt->mode)) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1442 | dropModeRequest(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1443 | continue; |
| 1444 | } |
| 1445 | |
| 1446 | // TODO(b/142753666) use constrains |
| 1447 | hal::VsyncPeriodChangeConstraints constraints; |
| 1448 | constraints.desiredTimeNanos = systemTime(); |
| 1449 | constraints.seamlessRequired = false; |
| 1450 | hal::VsyncPeriodChangeTimeline outTimeline; |
| 1451 | |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1452 | if (!display->initiateModeChange(std::move(*desiredModeOpt), constraints, outTimeline)) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1453 | continue; |
| 1454 | } |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1455 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1456 | display->refreshRateSelector().onModeChangeInitiated(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1457 | mScheduler->onNewVsyncPeriodChangeTimeline(outTimeline); |
| 1458 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1459 | if (outTimeline.refreshRequired) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 1460 | scheduleComposite(FrameHint::kNone); |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1461 | } else { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1462 | // TODO(b/255635711): Remove `displayToUpdateImmediately` to `finalizeDisplayModeChange` |
| 1463 | // for all displays. This was only needed when the loop iterated over `mDisplays` rather |
| 1464 | // than `mPhysicalDisplays`. |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1465 | displayToUpdateImmediately = display->getPhysicalId(); |
| 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | if (displayToUpdateImmediately) { |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1470 | const auto display = getDisplayDeviceLocked(*displayToUpdateImmediately); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1471 | finalizeDisplayModeChange(*display); |
| 1472 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1473 | const auto desiredModeOpt = display->getDesiredMode(); |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1474 | if (desiredModeOpt && display->getActiveMode() == desiredModeOpt->mode) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1475 | applyActiveMode(display); |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1476 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1477 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1478 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1479 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1480 | void SurfaceFlinger::disableExpensiveRendering() { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1481 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 1482 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1483 | ATRACE_NAME(whence); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1484 | if (mPowerAdvisor->isUsingExpensiveRendering()) { |
Dominik Laskowski | bc6c860 | 2022-01-11 08:53:24 -0800 | [diff] [blame] | 1485 | for (const auto& [_, display] : mDisplays) { |
| 1486 | constexpr bool kDisable = false; |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1487 | mPowerAdvisor->setExpensiveRenderingExpected(display->getId(), kDisable); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1488 | } |
| 1489 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1490 | }); |
| 1491 | |
| 1492 | future.wait(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1495 | status_t SurfaceFlinger::getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1496 | ui::DisplayPrimaries& primaries) { |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1497 | if (!displayToken) { |
| 1498 | return BAD_VALUE; |
| 1499 | } |
| 1500 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1501 | Mutex::Autolock lock(mStateLock); |
| 1502 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1503 | const auto display = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1504 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>); |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1505 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1506 | return NAME_NOT_FOUND; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1507 | } |
| 1508 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1509 | if (!display.transform(&PhysicalDisplay::isInternal).value()) { |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1510 | return INVALID_OPERATION; |
| 1511 | } |
| 1512 | |
| 1513 | // 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] | 1514 | primaries = mInternalDisplayPrimaries; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1515 | return NO_ERROR; |
| 1516 | } |
| 1517 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1518 | status_t SurfaceFlinger::setActiveColorMode(const sp<IBinder>& displayToken, ui::ColorMode mode) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1519 | if (!displayToken) { |
| 1520 | return BAD_VALUE; |
| 1521 | } |
| 1522 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1523 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 1524 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1525 | const auto displayOpt = |
| 1526 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1527 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1528 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1529 | |
| 1530 | if (!displayOpt) { |
| 1531 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1532 | return NAME_NOT_FOUND; |
| 1533 | } |
| 1534 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1535 | const auto& [display, snapshotRef] = *displayOpt; |
| 1536 | const auto& snapshot = snapshotRef.get(); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1537 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1538 | const auto modes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1539 | const bool exists = std::find(modes.begin(), modes.end(), mode) != modes.end(); |
| 1540 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1541 | if (mode < ui::ColorMode::NATIVE || !exists) { |
| 1542 | ALOGE("%s: Invalid color mode %s (%d) for display %s", whence, |
| 1543 | decodeColorMode(mode).c_str(), mode, to_string(snapshot.displayId()).c_str()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1544 | return BAD_VALUE; |
| 1545 | } |
| 1546 | |
| 1547 | display->getCompositionDisplay()->setColorProfile( |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 1548 | {mode, Dataspace::UNKNOWN, RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1549 | |
| 1550 | return NO_ERROR; |
| 1551 | }); |
| 1552 | |
Dominik Laskowski | 0a5f921 | 2021-08-05 17:00:04 -0700 | [diff] [blame] | 1553 | // TODO(b/195698395): Propagate error. |
| 1554 | future.wait(); |
| 1555 | return NO_ERROR; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1556 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1557 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1558 | status_t SurfaceFlinger::getBootDisplayModeSupport(bool* outSupport) const { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1559 | auto future = mScheduler->schedule( |
| 1560 | [this] { return getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG); }); |
| 1561 | |
| 1562 | *outSupport = future.get(); |
| 1563 | return NO_ERROR; |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1564 | } |
| 1565 | |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1566 | status_t SurfaceFlinger::getOverlaySupport(gui::OverlayProperties* outProperties) const { |
| 1567 | const auto& aidlProperties = getHwComposer().getOverlaySupport(); |
| 1568 | // convert aidl OverlayProperties to gui::OverlayProperties |
| 1569 | outProperties->combinations.reserve(aidlProperties.combinations.size()); |
| 1570 | for (const auto& combination : aidlProperties.combinations) { |
| 1571 | std::vector<int32_t> pixelFormats; |
| 1572 | pixelFormats.reserve(combination.pixelFormats.size()); |
| 1573 | std::transform(combination.pixelFormats.cbegin(), combination.pixelFormats.cend(), |
| 1574 | std::back_inserter(pixelFormats), |
| 1575 | [](const auto& val) { return static_cast<int32_t>(val); }); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1576 | std::vector<int32_t> standards; |
| 1577 | standards.reserve(combination.standards.size()); |
| 1578 | std::transform(combination.standards.cbegin(), combination.standards.cend(), |
| 1579 | std::back_inserter(standards), |
| 1580 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1581 | std::vector<int32_t> transfers; |
| 1582 | transfers.reserve(combination.transfers.size()); |
| 1583 | std::transform(combination.transfers.cbegin(), combination.transfers.cend(), |
| 1584 | std::back_inserter(transfers), |
| 1585 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1586 | std::vector<int32_t> ranges; |
| 1587 | ranges.reserve(combination.ranges.size()); |
| 1588 | std::transform(combination.ranges.cbegin(), combination.ranges.cend(), |
| 1589 | std::back_inserter(ranges), |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1590 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1591 | gui::OverlayProperties::SupportedBufferCombinations outCombination; |
| 1592 | outCombination.pixelFormats = std::move(pixelFormats); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1593 | outCombination.standards = std::move(standards); |
| 1594 | outCombination.transfers = std::move(transfers); |
| 1595 | outCombination.ranges = std::move(ranges); |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1596 | outProperties->combinations.emplace_back(outCombination); |
| 1597 | } |
Sally Qi | 8b4cb55 | 2022-12-14 16:24:31 -0800 | [diff] [blame] | 1598 | outProperties->supportMixedColorSpaces = aidlProperties.supportMixedColorSpaces; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 1599 | return NO_ERROR; |
| 1600 | } |
| 1601 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1602 | status_t SurfaceFlinger::setBootDisplayMode(const sp<display::DisplayToken>& displayToken, |
| 1603 | DisplayModeId modeId) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1604 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 1605 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1606 | const auto snapshotOpt = |
| 1607 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1608 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1609 | .transform(&PhysicalDisplay::snapshotRef); |
| 1610 | |
| 1611 | if (!snapshotOpt) { |
| 1612 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1613 | return NAME_NOT_FOUND; |
| 1614 | } |
Kriti Dang | f50d677 | 2022-02-18 15:09:12 +0100 | [diff] [blame] | 1615 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1616 | const auto& snapshot = snapshotOpt->get(); |
| 1617 | const auto hwcIdOpt = snapshot.displayModes().get(modeId).transform( |
| 1618 | [](const DisplayModePtr& mode) { return mode->getHwcId(); }); |
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 | if (!hwcIdOpt) { |
| 1621 | ALOGE("%s: Invalid mode %d for display %s", whence, modeId.value(), |
| 1622 | to_string(snapshot.displayId()).c_str()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1623 | return BAD_VALUE; |
| 1624 | } |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1625 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1626 | return getHwComposer().setBootDisplayMode(snapshot.displayId(), *hwcIdOpt); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1627 | }); |
| 1628 | return future.get(); |
| 1629 | } |
| 1630 | |
| 1631 | status_t SurfaceFlinger::clearBootDisplayMode(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1632 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 1633 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1634 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1635 | return getHwComposer().clearBootDisplayMode(*displayId); |
| 1636 | } else { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1637 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1638 | return BAD_VALUE; |
| 1639 | } |
| 1640 | }); |
| 1641 | return future.get(); |
| 1642 | } |
| 1643 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1644 | status_t SurfaceFlinger::getHdrConversionCapabilities( |
| 1645 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) const { |
| 1646 | bool hdrOutputConversionSupport; |
| 1647 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1648 | if (hdrOutputConversionSupport == false) { |
| 1649 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1650 | return INVALID_OPERATION; |
| 1651 | } |
| 1652 | const auto aidlConversionCapability = getHwComposer().getHdrConversionCapabilities(); |
| 1653 | for (auto capability : aidlConversionCapability) { |
| 1654 | gui::HdrConversionCapability tempCapability; |
Kriti Dang | 3c243dc | 2023-03-07 15:00:13 +0100 | [diff] [blame] | 1655 | tempCapability.sourceType = static_cast<int>(capability.sourceType); |
| 1656 | tempCapability.outputType = static_cast<int>(capability.outputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1657 | tempCapability.addsLatency = capability.addsLatency; |
| 1658 | hdrConversionCapabilities->push_back(tempCapability); |
| 1659 | } |
| 1660 | return NO_ERROR; |
| 1661 | } |
| 1662 | |
| 1663 | status_t SurfaceFlinger::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1664 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 1665 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1666 | bool hdrOutputConversionSupport; |
| 1667 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1668 | if (hdrOutputConversionSupport == false) { |
| 1669 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1670 | return INVALID_OPERATION; |
| 1671 | } |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 1672 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) mutable -> status_t { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1673 | using AidlHdrConversionStrategy = |
| 1674 | aidl::android::hardware::graphics::common::HdrConversionStrategy; |
| 1675 | using GuiHdrConversionStrategyTag = gui::HdrConversionStrategy::Tag; |
| 1676 | AidlHdrConversionStrategy aidlConversionStrategy; |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1677 | status_t status; |
| 1678 | aidl::android::hardware::graphics::common::Hdr aidlPreferredHdrOutputType; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1679 | switch (hdrConversionStrategy.getTag()) { |
| 1680 | case GuiHdrConversionStrategyTag::passthrough: { |
| 1681 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::passthrough>( |
| 1682 | hdrConversionStrategy.get<GuiHdrConversionStrategyTag::passthrough>()); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1683 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1684 | &aidlPreferredHdrOutputType); |
| 1685 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1686 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1687 | } |
| 1688 | case GuiHdrConversionStrategyTag::autoAllowedHdrTypes: { |
| 1689 | auto autoHdrTypes = |
| 1690 | hdrConversionStrategy |
| 1691 | .get<GuiHdrConversionStrategyTag::autoAllowedHdrTypes>(); |
| 1692 | std::vector<aidl::android::hardware::graphics::common::Hdr> aidlAutoHdrTypes; |
| 1693 | for (auto type : autoHdrTypes) { |
| 1694 | aidlAutoHdrTypes.push_back( |
| 1695 | static_cast<aidl::android::hardware::graphics::common::Hdr>(type)); |
| 1696 | } |
| 1697 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::autoAllowedHdrTypes>( |
| 1698 | aidlAutoHdrTypes); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1699 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1700 | &aidlPreferredHdrOutputType); |
| 1701 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1702 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1703 | } |
| 1704 | case GuiHdrConversionStrategyTag::forceHdrConversion: { |
| 1705 | auto forceHdrConversion = |
| 1706 | hdrConversionStrategy |
| 1707 | .get<GuiHdrConversionStrategyTag::forceHdrConversion>(); |
| 1708 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::forceHdrConversion>( |
| 1709 | static_cast<aidl::android::hardware::graphics::common::Hdr>( |
| 1710 | forceHdrConversion)); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1711 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1712 | &aidlPreferredHdrOutputType); |
| 1713 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1714 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1715 | } |
| 1716 | } |
| 1717 | }); |
| 1718 | return future.get(); |
| 1719 | } |
| 1720 | |
| 1721 | status_t SurfaceFlinger::getHdrOutputConversionSupport(bool* outSupport) const { |
| 1722 | auto future = mScheduler->schedule([this] { |
| 1723 | return getHwComposer().hasCapability(Capability::HDR_OUTPUT_CONVERSION_CONFIG); |
| 1724 | }); |
| 1725 | |
| 1726 | *outSupport = future.get(); |
| 1727 | return NO_ERROR; |
| 1728 | } |
| 1729 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1730 | void SurfaceFlinger::setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1731 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 1732 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1733 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1734 | getHwComposer().setAutoLowLatencyMode(*displayId, on); |
| 1735 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1736 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1737 | } |
| 1738 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1739 | } |
| 1740 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1741 | void SurfaceFlinger::setGameContentType(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1742 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 1743 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1744 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1745 | const auto type = on ? hal::ContentType::GAME : hal::ContentType::NONE; |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1746 | getHwComposer().setContentType(*displayId, type); |
| 1747 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1748 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1749 | } |
| 1750 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1751 | } |
| 1752 | |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1753 | status_t SurfaceFlinger::overrideHdrTypes(const sp<IBinder>& displayToken, |
| 1754 | const std::vector<ui::Hdr>& hdrTypes) { |
| 1755 | Mutex::Autolock lock(mStateLock); |
| 1756 | |
| 1757 | auto display = getDisplayDeviceLocked(displayToken); |
| 1758 | if (!display) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1759 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1760 | return NAME_NOT_FOUND; |
| 1761 | } |
| 1762 | |
| 1763 | display->overrideHdrTypes(hdrTypes); |
| 1764 | dispatchDisplayHotplugEvent(display->getPhysicalId(), true /* connected */); |
| 1765 | return NO_ERROR; |
| 1766 | } |
| 1767 | |
Huihong Luo | 30aa437 | 2022-10-03 14:54:12 -0700 | [diff] [blame] | 1768 | status_t SurfaceFlinger::onPullAtom(const int32_t atomId, std::vector<uint8_t>* pulledData, |
| 1769 | bool* success) { |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 1770 | *success = mTimeStats->onPullAtom(atomId, pulledData); |
| 1771 | return NO_ERROR; |
| 1772 | } |
| 1773 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1774 | status_t SurfaceFlinger::getDisplayedContentSamplingAttributes(const sp<IBinder>& displayToken, |
| 1775 | ui::PixelFormat* outFormat, |
| 1776 | ui::Dataspace* outDataspace, |
| 1777 | uint8_t* outComponentMask) const { |
| 1778 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 1779 | return BAD_VALUE; |
| 1780 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1781 | |
| 1782 | Mutex::Autolock lock(mStateLock); |
| 1783 | |
| 1784 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1785 | if (!displayId) { |
| 1786 | return NAME_NOT_FOUND; |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1787 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1788 | |
| 1789 | return getHwComposer().getDisplayedContentSamplingAttributes(*displayId, outFormat, |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1790 | outDataspace, outComponentMask); |
| 1791 | } |
| 1792 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1793 | status_t SurfaceFlinger::setDisplayContentSamplingEnabled(const sp<IBinder>& displayToken, |
| 1794 | bool enable, uint8_t componentMask, |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1795 | uint64_t maxFrames) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1796 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 1797 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1798 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1799 | return getHwComposer().setDisplayContentSamplingEnabled(*displayId, enable, |
| 1800 | componentMask, maxFrames); |
| 1801 | } else { |
| 1802 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
| 1803 | return NAME_NOT_FOUND; |
| 1804 | } |
| 1805 | }); |
| 1806 | |
| 1807 | return future.get(); |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1808 | } |
| 1809 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1810 | status_t SurfaceFlinger::getDisplayedContentSample(const sp<IBinder>& displayToken, |
| 1811 | uint64_t maxFrames, uint64_t timestamp, |
| 1812 | DisplayedFrameStats* outStats) const { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1813 | Mutex::Autolock lock(mStateLock); |
| 1814 | |
| 1815 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1816 | if (!displayId) { |
| 1817 | return NAME_NOT_FOUND; |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1820 | return getHwComposer().getDisplayedContentSample(*displayId, maxFrames, timestamp, outStats); |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
Peiyong Lin | 3c2791e | 2019-01-14 17:05:18 -0800 | [diff] [blame] | 1823 | status_t SurfaceFlinger::getProtectedContentSupport(bool* outSupported) const { |
| 1824 | if (!outSupported) { |
| 1825 | return BAD_VALUE; |
| 1826 | } |
| 1827 | *outSupported = getRenderEngine().supportsProtectedContent(); |
| 1828 | return NO_ERROR; |
| 1829 | } |
| 1830 | |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1831 | status_t SurfaceFlinger::isWideColorDisplay(const sp<IBinder>& displayToken, |
| 1832 | bool* outIsWideColorDisplay) const { |
| 1833 | if (!displayToken || !outIsWideColorDisplay) { |
| 1834 | return BAD_VALUE; |
| 1835 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1836 | |
| 1837 | Mutex::Autolock lock(mStateLock); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1838 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1839 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1840 | return NAME_NOT_FOUND; |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1841 | } |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 1842 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1843 | *outIsWideColorDisplay = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1844 | display->isPrimary() ? mSupportsWideColor : display->hasWideColorGamut(); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1845 | return NO_ERROR; |
| 1846 | } |
| 1847 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 1848 | status_t SurfaceFlinger::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1849 | outLayers->clear(); |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 1850 | auto future = mScheduler->schedule([=, this] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1851 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Vishnu Nair | 43bccf8 | 2020-06-05 10:53:37 -0700 | [diff] [blame] | 1852 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 1853 | outLayers->push_back(layer->getLayerDebugInfo(display.get())); |
| 1854 | }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1855 | }); |
| 1856 | |
| 1857 | future.wait(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1858 | return NO_ERROR; |
| 1859 | } |
| 1860 | |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1861 | status_t SurfaceFlinger::getCompositionPreference( |
| 1862 | Dataspace* outDataspace, ui::PixelFormat* outPixelFormat, |
| 1863 | Dataspace* outWideColorGamutDataspace, |
| 1864 | ui::PixelFormat* outWideColorGamutPixelFormat) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1865 | *outDataspace = mDefaultCompositionDataspace; |
| 1866 | *outPixelFormat = defaultCompositionPixelFormat; |
| 1867 | *outWideColorGamutDataspace = mWideColorGamutCompositionDataspace; |
| 1868 | *outWideColorGamutPixelFormat = wideColorGamutCompositionPixelFormat; |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 1869 | return NO_ERROR; |
| 1870 | } |
| 1871 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1872 | status_t SurfaceFlinger::addRegionSamplingListener(const Rect& samplingArea, |
| 1873 | const sp<IBinder>& stopLayerHandle, |
| 1874 | const sp<IRegionSamplingListener>& listener) { |
Leon Scroggins III | ae16b80 | 2022-01-12 11:42:05 -0500 | [diff] [blame] | 1875 | if (!listener || samplingArea == Rect::INVALID_RECT || samplingArea.isEmpty()) { |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1876 | return BAD_VALUE; |
| 1877 | } |
Alec Mouri | 9a02eda | 2020-04-21 17:39:34 -0700 | [diff] [blame] | 1878 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 1879 | // LayerHandle::getLayer promotes the layer object in a binder thread but we will not destroy |
| 1880 | // 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] | 1881 | const sp<Layer> stopLayer = LayerHandle::getLayer(stopLayerHandle); |
| 1882 | mRegionSamplingThread->addListener(samplingArea, |
| 1883 | stopLayer ? stopLayer->getSequence() : UNASSIGNED_LAYER_ID, |
| 1884 | listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1885 | return NO_ERROR; |
| 1886 | } |
| 1887 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1888 | status_t SurfaceFlinger::removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) { |
tangrobin | af45f01 | 2019-02-26 18:10:10 +0800 | [diff] [blame] | 1889 | if (!listener) { |
| 1890 | return BAD_VALUE; |
| 1891 | } |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1892 | mRegionSamplingThread->removeListener(listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1893 | return NO_ERROR; |
| 1894 | } |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1895 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1896 | status_t SurfaceFlinger::addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) { |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1897 | if (!listener) { |
| 1898 | return BAD_VALUE; |
| 1899 | } |
| 1900 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1901 | mFpsReporter->addListener(listener, taskId); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1902 | return NO_ERROR; |
| 1903 | } |
| 1904 | |
| 1905 | status_t SurfaceFlinger::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 1906 | if (!listener) { |
| 1907 | return BAD_VALUE; |
| 1908 | } |
| 1909 | mFpsReporter->removeListener(listener); |
| 1910 | return NO_ERROR; |
| 1911 | } |
| 1912 | |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 1913 | status_t SurfaceFlinger::addTunnelModeEnabledListener( |
| 1914 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1915 | if (!listener) { |
| 1916 | return BAD_VALUE; |
| 1917 | } |
| 1918 | |
| 1919 | mTunnelModeEnabledReporter->addListener(listener); |
| 1920 | return NO_ERROR; |
| 1921 | } |
| 1922 | |
| 1923 | status_t SurfaceFlinger::removeTunnelModeEnabledListener( |
| 1924 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1925 | if (!listener) { |
| 1926 | return BAD_VALUE; |
| 1927 | } |
| 1928 | |
| 1929 | mTunnelModeEnabledReporter->removeListener(listener); |
| 1930 | return NO_ERROR; |
| 1931 | } |
| 1932 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1933 | status_t SurfaceFlinger::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 1934 | bool* outSupport) const { |
| 1935 | if (!displayToken || !outSupport) { |
| 1936 | return BAD_VALUE; |
| 1937 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1938 | |
| 1939 | Mutex::Autolock lock(mStateLock); |
| 1940 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1941 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1942 | if (!displayId) { |
| 1943 | return NAME_NOT_FOUND; |
| 1944 | } |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1945 | *outSupport = getHwComposer().hasDisplayCapability(*displayId, DisplayCapability::BRIGHTNESS); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1946 | return NO_ERROR; |
| 1947 | } |
| 1948 | |
John Reck | 22be696 | 2021-03-10 12:59:54 -0500 | [diff] [blame] | 1949 | status_t SurfaceFlinger::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 1950 | const gui::DisplayBrightness& brightness) { |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1951 | if (!displayToken) { |
| 1952 | return BAD_VALUE; |
| 1953 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1954 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1955 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 1956 | return ftl::Future(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 1957 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1958 | const bool supportsDisplayBrightnessCommand = |
| 1959 | getHwComposer().getComposer()->isSupported( |
| 1960 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 1961 | // If we support applying display brightness as a command, then we also support |
| 1962 | // dimming SDR layers. |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1963 | if (supportsDisplayBrightnessCommand) { |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1964 | auto compositionDisplay = display->getCompositionDisplay(); |
| 1965 | float currentDimmingRatio = |
| 1966 | compositionDisplay->editState().sdrWhitePointNits / |
| 1967 | compositionDisplay->editState().displayBrightnessNits; |
Sally Qi | 0ea47b5 | 2023-06-22 13:27:20 -0700 | [diff] [blame] | 1968 | static constexpr float kDimmingThreshold = 0.02f; |
| 1969 | if (brightness.sdrWhitePointNits == 0.f || |
| 1970 | abs(brightness.sdrWhitePointNits - brightness.displayBrightnessNits) / |
| 1971 | brightness.sdrWhitePointNits >= |
| 1972 | kDimmingThreshold) { |
| 1973 | // to optimize, skip brightness setter if the brightness difference ratio |
| 1974 | // is lower than threshold |
| 1975 | compositionDisplay |
| 1976 | ->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 1977 | brightness.displayBrightnessNits); |
| 1978 | } else { |
| 1979 | compositionDisplay->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 1980 | brightness.sdrWhitePointNits); |
| 1981 | } |
| 1982 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1983 | FTL_FAKE_GUARD(kMainThreadContext, |
| 1984 | display->stageBrightness(brightness.displayBrightness)); |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 1985 | float currentHdrSdrRatio = |
| 1986 | compositionDisplay->editState().displayBrightnessNits / |
| 1987 | compositionDisplay->editState().sdrWhitePointNits; |
| 1988 | FTL_FAKE_GUARD(kMainThreadContext, |
| 1989 | display->updateHdrSdrRatioOverlayRatio(currentHdrSdrRatio)); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1990 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1991 | if (brightness.sdrWhitePointNits / brightness.displayBrightnessNits != |
| 1992 | currentDimmingRatio) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1993 | scheduleComposite(FrameHint::kNone); |
| 1994 | } else { |
| 1995 | scheduleCommit(FrameHint::kNone); |
| 1996 | } |
| 1997 | return ftl::yield<status_t>(OK); |
| 1998 | } else { |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1999 | return getHwComposer() |
| 2000 | .setDisplayBrightness(display->getPhysicalId(), |
| 2001 | brightness.displayBrightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 2002 | brightness.displayBrightnessNits, |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 2003 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 2004 | .applyImmediately = true}); |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 2005 | } |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2006 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2007 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2008 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 2009 | return ftl::yield<status_t>(NAME_NOT_FOUND); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2010 | } |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 2011 | })) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 2012 | .then([](ftl::Future<status_t> task) { return task; }) |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2013 | .get(); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2016 | status_t SurfaceFlinger::addHdrLayerInfoListener(const sp<IBinder>& displayToken, |
| 2017 | const sp<gui::IHdrLayerInfoListener>& listener) { |
| 2018 | if (!displayToken) { |
| 2019 | return BAD_VALUE; |
| 2020 | } |
| 2021 | |
| 2022 | Mutex::Autolock lock(mStateLock); |
| 2023 | |
| 2024 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2025 | if (!display) { |
| 2026 | return NAME_NOT_FOUND; |
| 2027 | } |
| 2028 | const auto displayId = display->getId(); |
| 2029 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2030 | if (!hdrInfoReporter) { |
| 2031 | hdrInfoReporter = sp<HdrLayerInfoReporter>::make(); |
| 2032 | } |
| 2033 | hdrInfoReporter->addListener(listener); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2034 | |
| 2035 | |
| 2036 | mAddingHDRLayerInfoListener = true; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2037 | return OK; |
| 2038 | } |
| 2039 | |
| 2040 | status_t SurfaceFlinger::removeHdrLayerInfoListener( |
| 2041 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 2042 | if (!displayToken) { |
| 2043 | return BAD_VALUE; |
| 2044 | } |
| 2045 | |
| 2046 | Mutex::Autolock lock(mStateLock); |
| 2047 | |
| 2048 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2049 | if (!display) { |
| 2050 | return NAME_NOT_FOUND; |
| 2051 | } |
| 2052 | const auto displayId = display->getId(); |
| 2053 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2054 | if (hdrInfoReporter) { |
| 2055 | hdrInfoReporter->removeListener(listener); |
| 2056 | } |
| 2057 | return OK; |
| 2058 | } |
| 2059 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2060 | status_t SurfaceFlinger::notifyPowerBoost(int32_t boostId) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 2061 | using aidl::android::hardware::power::Boost; |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2062 | Boost powerBoost = static_cast<Boost>(boostId); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2063 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2064 | if (powerBoost == Boost::INTERACTION) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2065 | mScheduler->onTouchHint(); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | return NO_ERROR; |
| 2069 | } |
| 2070 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2071 | status_t SurfaceFlinger::getDisplayDecorationSupport( |
| 2072 | const sp<IBinder>& displayToken, |
| 2073 | std::optional<DisplayDecorationSupport>* outSupport) const { |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2074 | if (!displayToken || !outSupport) { |
| 2075 | return BAD_VALUE; |
| 2076 | } |
| 2077 | |
| 2078 | Mutex::Autolock lock(mStateLock); |
| 2079 | |
| 2080 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 2081 | if (!displayId) { |
| 2082 | return NAME_NOT_FOUND; |
| 2083 | } |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2084 | getHwComposer().getDisplayDecorationSupport(*displayId, outSupport); |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2085 | return NO_ERROR; |
| 2086 | } |
| 2087 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 2088 | // ---------------------------------------------------------------------------- |
| 2089 | |
Jorim Jaggi | b1e2f8d | 2017-06-08 15:43:59 -0700 | [diff] [blame] | 2090 | sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection( |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 2091 | gui::ISurfaceComposer::VsyncSource vsyncSource, EventRegistrationFlags eventRegistration, |
| 2092 | const sp<IBinder>& layerHandle) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 2093 | const auto& handle = |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 2094 | vsyncSource == gui::ISurfaceComposer::VsyncSource::eVsyncSourceSurfaceFlinger |
| 2095 | ? mSfConnectionHandle |
| 2096 | : mAppConnectionHandle; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 2097 | |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 2098 | return mScheduler->createDisplayEventConnection(handle, eventRegistration, layerHandle); |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 2099 | } |
| 2100 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2101 | void SurfaceFlinger::scheduleCommit(FrameHint hint) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2102 | if (hint == FrameHint::kActive) { |
| 2103 | mScheduler->resetIdleTimer(); |
| 2104 | } |
Matt Buckley | 15ecd1c | 2022-11-01 21:57:16 +0000 | [diff] [blame] | 2105 | mPowerAdvisor->notifyDisplayUpdateImminentAndCpuReset(); |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 2106 | mScheduler->scheduleFrame(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2107 | } |
| 2108 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2109 | void SurfaceFlinger::scheduleComposite(FrameHint hint) { |
| 2110 | mMustComposite = true; |
| 2111 | scheduleCommit(hint); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | void SurfaceFlinger::scheduleRepaint() { |
| 2115 | mGeometryDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2116 | scheduleComposite(FrameHint::kActive); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2117 | } |
| 2118 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2119 | void SurfaceFlinger::scheduleSample() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2120 | static_cast<void>(mScheduler->schedule([this] { sample(); })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2121 | } |
| 2122 | |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 2123 | nsecs_t SurfaceFlinger::getVsyncPeriodFromHWC() const { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2124 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
| 2125 | return display->getVsyncPeriodFromHWC(); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2126 | } |
| 2127 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2128 | return 0; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2129 | } |
| 2130 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2131 | void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp, |
| 2132 | std::optional<hal::VsyncPeriodNanos> vsyncPeriod) { |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 2133 | if (FlagManager::getInstance().connected_display()) { |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2134 | // use ~0 instead of -1 as AidlComposerHal.cpp passes the param as unsigned int32 |
| 2135 | if (mIsHotplugErrViaNegVsync && timestamp < 0 && vsyncPeriod.has_value() && |
| 2136 | vsyncPeriod.value() == ~0) { |
| 2137 | int hotplugErrorCode = static_cast<int32_t>(-timestamp); |
| 2138 | ALOGD("SurfaceFlinger got hotplugErrorCode=%d", hotplugErrorCode); |
| 2139 | mScheduler->onHotplugConnectionError(mAppConnectionHandle, hotplugErrorCode); |
| 2140 | return; |
| 2141 | } |
| 2142 | } |
| 2143 | |
Dominik Laskowski | 3d48304 | 2023-02-22 17:58:56 -0500 | [diff] [blame] | 2144 | ATRACE_NAME(vsyncPeriod |
| 2145 | ? ftl::Concat(__func__, ' ', hwcDisplayId, ' ', *vsyncPeriod, "ns").c_str() |
| 2146 | : ftl::Concat(__func__, ' ', hwcDisplayId).c_str()); |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 2147 | |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2148 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2149 | if (const auto displayIdOpt = getHwComposer().onVsync(hwcDisplayId, timestamp)) { |
| 2150 | if (mScheduler->addResyncSample(*displayIdOpt, timestamp, vsyncPeriod)) { |
| 2151 | // period flushed |
| 2152 | mScheduler->modulateVsync(displayIdOpt, &VsyncModulator::onRefreshRateChangeCompleted); |
| 2153 | } |
Alec Mouri | 754c98a | 2019-03-18 18:53:42 -0700 | [diff] [blame] | 2154 | } |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 2155 | } |
| 2156 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2157 | void SurfaceFlinger::onComposerHalHotplugEvent(hal::HWDisplayId hwcDisplayId, |
| 2158 | DisplayHotplugEvent event) { |
| 2159 | if (event == DisplayHotplugEvent::CONNECTED || event == DisplayHotplugEvent::DISCONNECTED) { |
| 2160 | hal::Connection connection = (event == DisplayHotplugEvent::CONNECTED) |
| 2161 | ? hal::Connection::CONNECTED |
| 2162 | : hal::Connection::DISCONNECTED; |
| 2163 | { |
| 2164 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 2165 | mPendingHotplugEvents.push_back(HotplugEvent{hwcDisplayId, connection}); |
| 2166 | } |
| 2167 | |
| 2168 | if (mScheduler) { |
| 2169 | mScheduler->scheduleConfigure(); |
| 2170 | } |
| 2171 | |
| 2172 | return; |
Jiwen 'Steve' Cai | ccfd682 | 2018-02-21 16:15:58 -0800 | [diff] [blame] | 2173 | } |
| 2174 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2175 | if (FlagManager::getInstance().hotplug2()) { |
| 2176 | ALOGD("SurfaceFlinger got hotplug event=%d", static_cast<int32_t>(event)); |
| 2177 | // TODO(b/311403559): use enum type instead of int |
| 2178 | mScheduler->onHotplugConnectionError(mAppConnectionHandle, static_cast<int32_t>(event)); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2179 | } |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2182 | void SurfaceFlinger::onComposerHalVsyncPeriodTimingChanged( |
| 2183 | hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline& timeline) { |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2184 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2185 | mScheduler->onNewVsyncPeriodChangeTimeline(timeline); |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2186 | |
| 2187 | if (timeline.refreshRequired) { |
| 2188 | scheduleComposite(FrameHint::kNone); |
| 2189 | } |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2192 | void SurfaceFlinger::onComposerHalSeamlessPossible(hal::HWDisplayId) { |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 2193 | // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and |
Ady Abraham | b0433bc | 2020-01-08 17:31:06 -0800 | [diff] [blame] | 2194 | // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE. |
| 2195 | } |
| 2196 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2197 | void SurfaceFlinger::onComposerHalRefresh(hal::HWDisplayId) { |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2198 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2199 | scheduleComposite(FrameHint::kNone); |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2200 | } |
| 2201 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2202 | void SurfaceFlinger::onComposerHalVsyncIdle(hal::HWDisplayId) { |
Ady Abraham | e9befd7 | 2022-02-24 17:24:44 -0800 | [diff] [blame] | 2203 | ATRACE_CALL(); |
| 2204 | mScheduler->forceNextResync(); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2205 | } |
| 2206 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 2207 | void SurfaceFlinger::onRefreshRateChangedDebug(const RefreshRateChangedDebugData& data) { |
| 2208 | ATRACE_CALL(); |
| 2209 | if (const auto displayId = getHwComposer().toPhysicalDisplayId(data.display); displayId) { |
ramindani | 19919ff | 2023-12-07 11:27:06 -0800 | [diff] [blame] | 2210 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 2211 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
ramindani | 19919ff | 2023-12-07 11:27:06 -0800 | [diff] [blame] | 2212 | const Fps fps = Fps::fromPeriodNsecs(getHwComposer().getComposer()->isVrrSupported() |
| 2213 | ? data.refreshPeriodNanos |
| 2214 | : data.vsyncPeriodNanos); |
| 2215 | ATRACE_FORMAT("%s Fps %d", whence, fps.getIntValue()); |
| 2216 | const auto display = getDisplayDeviceLocked(*displayId); |
| 2217 | FTL_FAKE_GUARD(kMainThreadContext, |
| 2218 | display->updateRefreshRateOverlayRate(fps, display->getActiveMode().fps, |
| 2219 | /* setByHwc */ true)); |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 2220 | })); |
| 2221 | } |
ramindani | 12bfe6b | 2023-02-03 13:29:19 -0800 | [diff] [blame] | 2222 | } |
| 2223 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2224 | void SurfaceFlinger::configure() { |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2225 | Mutex::Autolock lock(mStateLock); |
| 2226 | if (configureLocked()) { |
| 2227 | setTransactionFlags(eDisplayTransactionNeeded); |
| 2228 | } |
| 2229 | } |
| 2230 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2231 | bool SurfaceFlinger::updateLayerSnapshotsLegacy(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2232 | bool flushTransactions, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2233 | bool& outTransactionsAreEmpty) { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2234 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2235 | frontend::Update update; |
| 2236 | if (flushTransactions) { |
| 2237 | update = flushLifecycleUpdates(); |
| 2238 | if (mTransactionTracing) { |
| 2239 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2240 | update, mFrontEndDisplayInfos, |
| 2241 | mFrontEndDisplayInfosChanged); |
| 2242 | } |
| 2243 | } |
| 2244 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2245 | bool needsTraversal = false; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2246 | if (flushTransactions) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2247 | needsTraversal |= commitMirrorDisplays(vsyncId); |
| 2248 | needsTraversal |= commitCreatedLayers(vsyncId, update.layerCreatedStates); |
| 2249 | needsTraversal |= applyTransactions(update.transactions, vsyncId); |
| 2250 | } |
| 2251 | outTransactionsAreEmpty = !needsTraversal; |
| 2252 | const bool shouldCommit = (getTransactionFlags() & ~eTransactionFlushNeeded) || needsTraversal; |
| 2253 | if (shouldCommit) { |
| 2254 | commitTransactions(); |
| 2255 | } |
| 2256 | |
| 2257 | bool mustComposite = latchBuffers() || shouldCommit; |
| 2258 | updateLayerGeometry(); |
| 2259 | return mustComposite; |
| 2260 | } |
| 2261 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2262 | void SurfaceFlinger::updateLayerHistory(nsecs_t now) { |
| 2263 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 2264 | using Changes = frontend::RequestedLayerState::Changes; |
| 2265 | if (snapshot->path.isClone()) { |
| 2266 | continue; |
| 2267 | } |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 2268 | |
Jerry Chang | 3667800 | 2023-11-29 16:56:17 +0000 | [diff] [blame] | 2269 | const bool updateSmallDirty = FlagManager::getInstance().enable_small_area_detection() && |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2270 | ((snapshot->clientChanges & layer_state_t::eSurfaceDamageRegionChanged) || |
| 2271 | snapshot->changes.any(Changes::Geometry)); |
| 2272 | |
| 2273 | const bool hasChanges = |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 2274 | snapshot->changes.any(Changes::FrameRate | Changes::Buffer | Changes::Animation | |
| 2275 | Changes::Geometry | Changes::Visibility) || |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2276 | (snapshot->clientChanges & layer_state_t::eDefaultFrameRateCompatibilityChanged) != |
| 2277 | 0; |
| 2278 | |
| 2279 | if (!updateSmallDirty && !hasChanges) { |
| 2280 | continue; |
| 2281 | } |
| 2282 | |
| 2283 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 2284 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 2285 | "Couldn't find layer object for %s", |
| 2286 | snapshot->getDebugString().c_str()); |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2287 | |
| 2288 | if (updateSmallDirty) { |
| 2289 | // Update small dirty flag while surface damage region or geometry changed |
| 2290 | it->second->setIsSmallDirty(snapshot.get()); |
| 2291 | } |
| 2292 | |
| 2293 | if (!hasChanges) { |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2294 | continue; |
| 2295 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2296 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2297 | const auto layerProps = scheduler::LayerProps{ |
| 2298 | .visible = snapshot->isVisible, |
| 2299 | .bounds = snapshot->geomLayerBounds, |
| 2300 | .transform = snapshot->geomLayerTransform, |
| 2301 | .setFrameRateVote = snapshot->frameRate, |
| 2302 | .frameRateSelectionPriority = snapshot->frameRateSelectionPriority, |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2303 | .isSmallDirty = snapshot->isSmallDirty, |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 2304 | .isFrontBuffered = snapshot->isFrontBuffered(), |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2305 | }; |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2306 | |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 2307 | if (snapshot->changes.any(Changes::Geometry | Changes::Visibility)) { |
| 2308 | mScheduler->setLayerProperties(snapshot->sequence, layerProps); |
| 2309 | } |
| 2310 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2311 | if (snapshot->clientChanges & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 2312 | mScheduler->setDefaultFrameRateCompatibility(snapshot->sequence, |
| 2313 | snapshot->defaultFrameRateCompatibility); |
| 2314 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2315 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2316 | if (snapshot->changes.test(Changes::Animation)) { |
| 2317 | it->second->recordLayerHistoryAnimationTx(layerProps, now); |
| 2318 | } |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 2319 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2320 | if (snapshot->changes.test(Changes::FrameRate)) { |
| 2321 | it->second->setFrameRateForLayerTree(snapshot->frameRate, layerProps, now); |
| 2322 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2323 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2324 | if (snapshot->changes.test(Changes::Buffer)) { |
| 2325 | it->second->recordLayerHistoryBufferUpdate(layerProps, now); |
| 2326 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2327 | } |
| 2328 | } |
| 2329 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2330 | bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2331 | bool flushTransactions, bool& outTransactionsAreEmpty) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2332 | using Changes = frontend::RequestedLayerState::Changes; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2333 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2334 | frontend::Update update; |
| 2335 | if (flushTransactions) { |
| 2336 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 2337 | // Locking: |
| 2338 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 2339 | // we must keep a copy of the transactions (specifically the composer |
| 2340 | // states) around outside the scope of the lock. |
| 2341 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 2342 | // transactions with layers still in the createdLayer queue, collect the transactions |
| 2343 | // before committing the created layers. |
| 2344 | // 3. Transactions can only be flushed after adding layers, since the layer can be a newly |
| 2345 | // created one |
| 2346 | mTransactionHandler.collectTransactions(); |
| 2347 | { |
| 2348 | // TODO(b/238781169) lockless queue this and keep order. |
| 2349 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 2350 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 2351 | mCreatedLayers.clear(); |
| 2352 | update.newLayers = std::move(mNewLayers); |
| 2353 | mNewLayers.clear(); |
| 2354 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 2355 | mNewLayerArgs.clear(); |
| 2356 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 2357 | mDestroyedHandles.clear(); |
| 2358 | } |
| 2359 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2360 | mLayerLifecycleManager.addLayers(std::move(update.newLayers)); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2361 | update.transactions = mTransactionHandler.flushTransactions(); |
| 2362 | if (mTransactionTracing) { |
| 2363 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2364 | update, mFrontEndDisplayInfos, |
| 2365 | mFrontEndDisplayInfosChanged); |
| 2366 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2367 | mLayerLifecycleManager.applyTransactions(update.transactions); |
| 2368 | mLayerLifecycleManager.onHandlesDestroyed(update.destroyedHandles); |
| 2369 | for (auto& legacyLayer : update.layerCreatedStates) { |
| 2370 | sp<Layer> layer = legacyLayer.layer.promote(); |
| 2371 | if (layer) { |
| 2372 | mLegacyLayers[layer->sequence] = layer; |
| 2373 | } |
| 2374 | } |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2375 | if (mLayerLifecycleManager.getGlobalChanges().test(Changes::Hierarchy)) { |
| 2376 | ATRACE_NAME("LayerHierarchyBuilder:update"); |
| 2377 | mLayerHierarchyBuilder.update(mLayerLifecycleManager.getLayers(), |
| 2378 | mLayerLifecycleManager.getDestroyedLayers()); |
| 2379 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2382 | bool mustComposite = false; |
| 2383 | mustComposite |= applyAndCommitDisplayTransactionStates(update.transactions); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2384 | |
| 2385 | { |
| 2386 | ATRACE_NAME("LayerSnapshotBuilder:update"); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2387 | frontend::LayerSnapshotBuilder::Args |
| 2388 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 2389 | .layerLifecycleManager = mLayerLifecycleManager, |
| 2390 | .displays = mFrontEndDisplayInfos, |
| 2391 | .displayChanges = mFrontEndDisplayInfosChanged, |
| 2392 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2393 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2394 | .forceFullDamage = mForceFullDamage, |
| 2395 | .supportedLayerGenericMetadata = |
| 2396 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 2397 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 2398 | .skipRoundCornersWhenProtected = |
| 2399 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2400 | mLayerSnapshotBuilder.update(args); |
| 2401 | } |
| 2402 | |
| 2403 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Geometry | Changes::Input | |
Vishnu Nair | 40d0228 | 2023-02-28 21:11:40 +0000 | [diff] [blame] | 2404 | Changes::Hierarchy | Changes::Visibility)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2405 | mUpdateInputInfo = true; |
| 2406 | } |
| 2407 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::VisibleRegion | Changes::Hierarchy | |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2408 | Changes::Visibility | Changes::Geometry)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2409 | mVisibleRegionsDirty = true; |
| 2410 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2411 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Hierarchy | Changes::FrameRate)) { |
| 2412 | // The frame rate of attached choreographers can only change as a result of a |
| 2413 | // FrameRate change (including when Hierarchy changes). |
| 2414 | mUpdateAttachedChoreographer = true; |
| 2415 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2416 | outTransactionsAreEmpty = mLayerLifecycleManager.getGlobalChanges().get() == 0; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2417 | mustComposite |= mLayerLifecycleManager.getGlobalChanges().get() != 0; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2418 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2419 | bool newDataLatched = false; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2420 | if (!mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2421 | ATRACE_NAME("DisplayCallbackAndStatsUpdates"); |
Vishnu Nair | d2a38f9 | 2023-08-23 18:43:01 -0700 | [diff] [blame] | 2422 | mustComposite |= applyTransactions(update.transactions, vsyncId); |
Vishnu Nair | c1d19d7 | 2023-08-10 12:35:11 -0700 | [diff] [blame] | 2423 | traverseLegacyLayers([&](Layer* layer) { layer->commitTransaction(); }); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2424 | const nsecs_t latchTime = systemTime(); |
| 2425 | bool unused = false; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2426 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2427 | for (auto& layer : mLayerLifecycleManager.getLayers()) { |
| 2428 | if (layer->changes.test(frontend::RequestedLayerState::Changes::Created) && |
| 2429 | layer->bgColorLayer) { |
| 2430 | sp<Layer> bgColorLayer = getFactory().createEffectLayer( |
| 2431 | LayerCreationArgs(this, nullptr, layer->name, |
| 2432 | ISurfaceComposerClient::eFXSurfaceEffect, LayerMetadata(), |
Vishnu Nair | e4af095 | 2023-05-01 09:11:33 -0700 | [diff] [blame] | 2433 | std::make_optional(layer->id), true)); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2434 | mLegacyLayers[bgColorLayer->sequence] = bgColorLayer; |
| 2435 | } |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2436 | const bool willReleaseBufferOnLatch = layer->willReleaseBufferOnLatch(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2437 | |
| 2438 | auto it = mLegacyLayers.find(layer->id); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 2439 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 2440 | "Couldnt find layer object for %s", |
| 2441 | layer->getDebugString().c_str()); |
Vishnu Nair | f32ff9b | 2023-08-23 14:32:30 -0700 | [diff] [blame] | 2442 | if (!layer->hasReadyFrame() && !willReleaseBufferOnLatch) { |
| 2443 | if (!it->second->hasBuffer()) { |
| 2444 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 2445 | // instead of a missed frame. This is used to identify scenarios where we |
| 2446 | // could not latch a buffer or apply a transaction due to backpressure. |
| 2447 | // We only update the latch time for buffer less layers here, the latch time |
| 2448 | // is updated for buffer layers when the buffer is latched. |
| 2449 | it->second->updateLastLatchTime(latchTime); |
| 2450 | } |
| 2451 | continue; |
| 2452 | } |
| 2453 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2454 | const bool bgColorOnly = |
| 2455 | !layer->externalTexture && (layer->bgColorLayerId != UNASSIGNED_LAYER_ID); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2456 | if (willReleaseBufferOnLatch) { |
| 2457 | mLayersWithBuffersRemoved.emplace(it->second); |
| 2458 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2459 | it->second->latchBufferImpl(unused, latchTime, bgColorOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2460 | newDataLatched = true; |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2461 | |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2462 | mLayersWithQueuedFrames.emplace(it->second); |
| 2463 | mLayersIdsWithQueuedFrames.emplace(it->second->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2466 | updateLayerHistory(latchTime); |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2467 | mLayerSnapshotBuilder.forEachVisibleSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2468 | if (mLayersIdsWithQueuedFrames.find(snapshot.path.id) == |
| 2469 | mLayersIdsWithQueuedFrames.end()) |
| 2470 | return; |
| 2471 | Region visibleReg; |
| 2472 | visibleReg.set(snapshot.transformedBoundsWithoutTransparentRegion); |
| 2473 | invalidateLayerStack(snapshot.outputFilter, visibleReg); |
| 2474 | }); |
| 2475 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2476 | for (auto& destroyedLayer : mLayerLifecycleManager.getDestroyedLayers()) { |
| 2477 | mLegacyLayers.erase(destroyedLayer->id); |
| 2478 | } |
| 2479 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2480 | { |
| 2481 | ATRACE_NAME("LLM:commitChanges"); |
| 2482 | mLayerLifecycleManager.commitChanges(); |
| 2483 | } |
| 2484 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2485 | // enter boot animation on first buffer latch |
| 2486 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 2487 | ALOGI("Enter boot animation"); |
| 2488 | mBootStage = BootStage::BOOTANIMATION; |
| 2489 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2490 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2491 | mustComposite |= (getTransactionFlags() & ~eTransactionFlushNeeded) || newDataLatched; |
Vishnu Nair | 8134c1a | 2023-10-17 22:55:49 -0700 | [diff] [blame] | 2492 | if (mustComposite && !mLegacyFrontEndEnabled) { |
| 2493 | commitTransactions(); |
| 2494 | } |
| 2495 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2496 | return mustComposite; |
| 2497 | } |
| 2498 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2499 | bool SurfaceFlinger::commit(PhysicalDisplayId pacesetterId, |
| 2500 | const scheduler::FrameTargets& frameTargets) { |
| 2501 | const scheduler::FrameTarget& pacesetterFrameTarget = *frameTargets.get(pacesetterId)->get(); |
| 2502 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2503 | const VsyncId vsyncId = pacesetterFrameTarget.vsyncId(); |
| 2504 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2505 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2506 | if (pacesetterFrameTarget.didMissFrame()) { |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2507 | mTimeStats->incrementMissedFrames(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2508 | } |
| 2509 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2510 | // If a mode set is pending and the fence hasn't fired yet, wait for the next commit. |
| 2511 | if (std::any_of(frameTargets.begin(), frameTargets.end(), |
| 2512 | [this](const auto& pair) FTL_FAKE_GUARD(mStateLock) |
| 2513 | FTL_FAKE_GUARD(kMainThreadContext) { |
| 2514 | if (!pair.second->isFramePending()) return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2515 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2516 | if (const auto display = getDisplayDeviceLocked(pair.first)) { |
| 2517 | return display->isModeSetPending(); |
| 2518 | } |
| 2519 | |
| 2520 | return false; |
| 2521 | })) { |
| 2522 | mScheduler->scheduleFrame(); |
| 2523 | return false; |
| 2524 | } |
| 2525 | |
| 2526 | { |
| 2527 | Mutex::Autolock lock(mStateLock); |
| 2528 | |
| 2529 | for (const auto [id, target] : frameTargets) { |
| 2530 | // TODO(b/241285876): This is `nullptr` when the DisplayDevice is about to be removed in |
| 2531 | // this commit, since the PhysicalDisplay has already been removed. Rather than checking |
| 2532 | // for `nullptr` below, change Scheduler::onFrameSignal to filter out the FrameTarget of |
| 2533 | // the removed display. |
| 2534 | const auto display = getDisplayDeviceLocked(id); |
| 2535 | |
| 2536 | if (display && display->isModeSetPending()) { |
| 2537 | finalizeDisplayModeChange(*display); |
| 2538 | } |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2539 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2540 | } |
| 2541 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2542 | if (pacesetterFrameTarget.isFramePending()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2543 | if (mBackpressureGpuComposition || pacesetterFrameTarget.didMissHwcFrame()) { |
Ady Abraham | e988303 | 2023-11-20 17:54:54 -0800 | [diff] [blame] | 2544 | if (FlagManager::getInstance().vrr_config()) { |
| 2545 | mScheduler->getVsyncSchedule()->getTracker().onFrameMissed( |
| 2546 | pacesetterFrameTarget.expectedPresentTime()); |
| 2547 | } |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2548 | scheduleCommit(FrameHint::kNone); |
| 2549 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2550 | } |
| 2551 | } |
| 2552 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2553 | const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); |
| 2554 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2555 | // Save this once per commit + composite to ensure consistency |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2556 | // TODO (b/240619471): consider removing active display check once AOD is fixed |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 2557 | const auto activeDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(mActiveDisplayId)); |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2558 | mPowerHintSessionEnabled = mPowerAdvisor->usePowerHintSession() && activeDisplay && |
| 2559 | activeDisplay->getPowerMode() == hal::PowerMode::ON; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2560 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2561 | mPowerAdvisor->setCommitStart(pacesetterFrameTarget.frameBeginTime()); |
| 2562 | mPowerAdvisor->setExpectedPresentTime(pacesetterFrameTarget.expectedPresentTime()); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2563 | |
| 2564 | // 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] | 2565 | const Duration idealSfWorkDuration = |
| 2566 | mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2567 | const Duration frameDelay = |
| 2568 | idealSfWorkDuration - pacesetterFrameTarget.expectedFrameDuration(); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2569 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2570 | mPowerAdvisor->setFrameDelay(frameDelay); |
| 2571 | mPowerAdvisor->setTotalFrameTargetWorkDuration(idealSfWorkDuration); |
Matt Buckley | 676e439 | 2023-05-25 22:09:26 +0000 | [diff] [blame] | 2572 | |
| 2573 | const auto& display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get(); |
| 2574 | const Period idealVsyncPeriod = display->getActiveMode().fps.getPeriod(); |
| 2575 | mPowerAdvisor->updateTargetWorkDuration(idealVsyncPeriod); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2576 | } |
| 2577 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2578 | if (mRefreshRateOverlaySpinner || mHdrSdrRatioOverlay) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 2579 | Mutex::Autolock lock(mStateLock); |
| 2580 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2581 | display->animateOverlay(); |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2582 | } |
| 2583 | } |
| 2584 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2585 | // Composite if transactions were committed, or if requested by HWC. |
| 2586 | bool mustComposite = mMustComposite.exchange(false); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2587 | { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2588 | mFrameTimeline->setSfWakeUp(ftl::to_underlying(vsyncId), |
| 2589 | pacesetterFrameTarget.frameBeginTime().ns(), |
Pascal Muetschard | ac7bcd9 | 2023-10-03 15:05:36 +0200 | [diff] [blame] | 2590 | Fps::fromPeriodNsecs(vsyncPeriod.ns()), |
| 2591 | mScheduler->getPacesetterRefreshRate()); |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 2592 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2593 | const bool flushTransactions = clearTransactionFlags(eTransactionFlushNeeded); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2594 | bool transactionsAreEmpty; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2595 | if (mLegacyFrontEndEnabled) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2596 | mustComposite |= |
| 2597 | updateLayerSnapshotsLegacy(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2598 | flushTransactions, transactionsAreEmpty); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2599 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2600 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2601 | mustComposite |= |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2602 | updateLayerSnapshots(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2603 | flushTransactions, transactionsAreEmpty); |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | if (transactionFlushNeeded()) { |
| 2607 | setTransactionFlags(eTransactionFlushNeeded); |
| 2608 | } |
| 2609 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2610 | // This has to be called after latchBuffers because we want to include the layers that have |
| 2611 | // been latched in the commit callback |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2612 | if (transactionsAreEmpty) { |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2613 | // Invoke empty transaction callbacks early. |
| 2614 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 2615 | } else { |
| 2616 | // Invoke OnCommit callbacks. |
| 2617 | mTransactionCallbackInvoker.sendCallbacks(true /* onCommitOnly */); |
| 2618 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2619 | } |
| 2620 | |
| 2621 | // Layers need to get updated (in the previous line) before we can use them for |
| 2622 | // choosing the refresh rate. |
| 2623 | // Hold mStateLock as chooseRefreshRateForContent promotes wp<Layer> to sp<Layer> |
| 2624 | // and may eventually call to ~Layer() if it holds the last reference |
| 2625 | { |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2626 | bool updateAttachedChoreographer = mUpdateAttachedChoreographer; |
| 2627 | mUpdateAttachedChoreographer = false; |
| 2628 | |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 2629 | Mutex::Autolock lock(mStateLock); |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2630 | mScheduler->chooseRefreshRateForContent(mLayerLifecycleManagerEnabled |
| 2631 | ? &mLayerHierarchyBuilder.getHierarchy() |
| 2632 | : nullptr, |
| 2633 | updateAttachedChoreographer); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2634 | initiateDisplayModeChanges(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2635 | } |
| 2636 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2637 | updateCursorAsync(); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2638 | if (!mustComposite) { |
| 2639 | updateInputFlinger(vsyncId, pacesetterFrameTarget.frameBeginTime()); |
| 2640 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2641 | doActiveLayersTracingIfNeeded(false, mVisibleRegionsDirty, |
| 2642 | pacesetterFrameTarget.frameBeginTime(), vsyncId); |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 2643 | |
Pablo Gamito | 6be8244 | 2022-06-13 11:04:34 +0000 | [diff] [blame] | 2644 | mLastCommittedVsyncId = vsyncId; |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2645 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2646 | persistDisplayBrightness(mustComposite); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2647 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2648 | return mustComposite && CC_LIKELY(mBootStage != BootStage::BOOTLOADER); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2649 | } |
| 2650 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2651 | CompositeResultsPerDisplay SurfaceFlinger::composite( |
| 2652 | PhysicalDisplayId pacesetterId, const scheduler::FrameTargeters& frameTargeters) { |
| 2653 | const scheduler::FrameTarget& pacesetterTarget = |
| 2654 | frameTargeters.get(pacesetterId)->get()->target(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2655 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2656 | const VsyncId vsyncId = pacesetterTarget.vsyncId(); |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2657 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2658 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2659 | compositionengine::CompositionRefreshArgs refreshArgs; |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 2660 | refreshArgs.powerCallback = this; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2661 | const auto& displays = FTL_FAKE_GUARD(mStateLock, mDisplays); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2662 | refreshArgs.outputs.reserve(displays.size()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2663 | |
| 2664 | // Add outputs for physical displays. |
| 2665 | for (const auto& [id, targeter] : frameTargeters) { |
| 2666 | ftl::FakeGuard guard(mStateLock); |
| 2667 | |
| 2668 | if (const auto display = getCompositionDisplayLocked(id)) { |
| 2669 | refreshArgs.outputs.push_back(display); |
| 2670 | } |
| 2671 | } |
| 2672 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2673 | std::vector<DisplayId> displayIds; |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2674 | for (const auto& [_, display] : displays) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2675 | displayIds.push_back(display->getId()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2676 | display->tracePowerMode(); |
| 2677 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2678 | // Add outputs for virtual displays. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2679 | if (display->isVirtual()) { |
| 2680 | const Fps refreshRate = display->getAdjustedRefreshRate(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2681 | |
| 2682 | if (!refreshRate.isValid() || |
| 2683 | mScheduler->isVsyncInPhase(pacesetterTarget.frameBeginTime(), refreshRate)) { |
| 2684 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2685 | } |
| 2686 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2687 | } |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2688 | mPowerAdvisor->setDisplays(displayIds); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2689 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 2690 | const bool updateTaskMetadata = mCompositionEngine->getFeatureFlags().test( |
| 2691 | compositionengine::Feature::kSnapshotLayerMetadata); |
| 2692 | if (updateTaskMetadata && (mVisibleRegionsDirty || mLayerMetadataSnapshotNeeded)) { |
| 2693 | updateLayerMetadataSnapshot(); |
| 2694 | mLayerMetadataSnapshotNeeded = false; |
| 2695 | } |
| 2696 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2697 | if (DOES_CONTAIN_BORDER) { |
| 2698 | refreshArgs.borderInfoList.clear(); |
| 2699 | mDrawingState.traverse([&refreshArgs](Layer* layer) { |
| 2700 | if (layer->isBorderEnabled()) { |
| 2701 | compositionengine::BorderRenderInfo info; |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 2702 | info.width = layer->getBorderWidth(); |
| 2703 | info.color = layer->getBorderColor(); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2704 | layer->traverse(LayerVector::StateSet::Drawing, [&info](Layer* ilayer) { |
| 2705 | info.layerIds.push_back(ilayer->getSequence()); |
| 2706 | }); |
| 2707 | refreshArgs.borderInfoList.emplace_back(std::move(info)); |
| 2708 | } |
| 2709 | }); |
| 2710 | } |
| 2711 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 2712 | refreshArgs.bufferIdsToUncache = std::move(mBufferIdsToUncache); |
| 2713 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2714 | refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); |
Alec Mouri | 5c9c960 | 2020-09-01 15:10:40 -0700 | [diff] [blame] | 2715 | for (auto layer : mLayersWithQueuedFrames) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 2716 | if (auto layerFE = layer->getCompositionEngineLayerFE()) |
| 2717 | refreshArgs.layersWithQueuedFrames.push_back(layerFE); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2718 | } |
| 2719 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 2720 | refreshArgs.outputColorSetting = mDisplayColorSetting; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 2721 | refreshArgs.forceOutputColorMode = mForceColorMode; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2722 | |
| 2723 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2724 | refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || mVisibleRegionsDirty; |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 2725 | refreshArgs.internalDisplayRotationFlags = getActiveDisplayRotationFlags(); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2726 | |
| 2727 | if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) { |
| 2728 | refreshArgs.colorTransformMatrix = mDrawingState.colorMatrix; |
| 2729 | mDrawingState.colorMatrixChanged = false; |
| 2730 | } |
| 2731 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2732 | refreshArgs.devOptForceClientComposition = mDebugDisableHWC; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2733 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2734 | if (mDebugFlashDelay != 0) { |
| 2735 | refreshArgs.devOptForceClientComposition = true; |
| 2736 | refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay); |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 2737 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2738 | |
Ady Abraham | 3db8a3c | 2023-11-20 17:53:47 -0800 | [diff] [blame] | 2739 | const Period minFramePeriod = mScheduler->getVsyncSchedule()->minFramePeriod(); |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2740 | |
Dominik Laskowski | 42ccc93 | 2023-04-20 10:08:04 -0400 | [diff] [blame] | 2741 | if (!getHwComposer().getComposer()->isSupported( |
| 2742 | Hwc2::Composer::OptionalFeature::ExpectedPresentTime) && |
Ady Abraham | 3db8a3c | 2023-11-20 17:53:47 -0800 | [diff] [blame] | 2743 | pacesetterTarget.wouldPresentEarly(minFramePeriod)) { |
Dominik Laskowski | 42ccc93 | 2023-04-20 10:08:04 -0400 | [diff] [blame] | 2744 | const auto hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration; |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2745 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2746 | // TODO(b/255601557): Calculate and pass per-display values for each FrameTarget. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2747 | refreshArgs.earliestPresentTime = |
Ady Abraham | 3db8a3c | 2023-11-20 17:53:47 -0800 | [diff] [blame] | 2748 | pacesetterTarget.previousFrameVsyncTime(minFramePeriod) - hwcMinWorkDuration; |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2749 | } |
| 2750 | |
ramindani | 0491e64 | 2023-11-16 17:42:14 -0800 | [diff] [blame] | 2751 | const TimePoint expectedPresentTime = pacesetterTarget.expectedPresentTime(); |
| 2752 | // TODO(b/255601557) Update frameInterval per display |
| 2753 | refreshArgs.frameInterval = mScheduler->getNextFrameInterval(pacesetterId, expectedPresentTime); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2754 | refreshArgs.scheduledFrameTime = mScheduler->getScheduledFrameTime(); |
ramindani | 0491e64 | 2023-11-16 17:42:14 -0800 | [diff] [blame] | 2755 | refreshArgs.expectedPresentTime = expectedPresentTime.ns(); |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 2756 | refreshArgs.hasTrustedPresentationListener = mNumTrustedPresentationListeners > 0; |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 2757 | { |
| 2758 | auto& notifyExpectedPresentData = mNotifyExpectedPresentMap[pacesetterId]; |
| 2759 | auto lastExpectedPresentTimestamp = TimePoint::fromNs( |
| 2760 | notifyExpectedPresentData.lastExpectedPresentTimestamp.load().ns()); |
| 2761 | if (expectedPresentTime > lastExpectedPresentTimestamp) { |
| 2762 | // If the values are not same, then hint is sent with newer value. |
| 2763 | // And because composition always follows the notifyExpectedPresentIfRequired, we can |
| 2764 | // skip updating the lastExpectedPresentTimestamp in this case. |
| 2765 | notifyExpectedPresentData.lastExpectedPresentTimestamp |
| 2766 | .compare_exchange_weak(lastExpectedPresentTimestamp, expectedPresentTime); |
| 2767 | } |
| 2768 | } |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2769 | // Store the present time just before calling to the composition engine so we could notify |
| 2770 | // the scheduler. |
| 2771 | const auto presentTime = systemTime(); |
| 2772 | |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2773 | constexpr bool kCursorOnly = false; |
| 2774 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
| 2775 | |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2776 | if (mLayerLifecycleManagerEnabled && !mVisibleRegionsDirty) { |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2777 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 2778 | auto compositionDisplay = display->getCompositionDisplay(); |
| 2779 | if (!compositionDisplay->getState().isEnabled) continue; |
| 2780 | for (auto outputLayer : compositionDisplay->getOutputLayersOrderedByZ()) { |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2781 | if (outputLayer->getLayerFE().getCompositionState() == nullptr) { |
| 2782 | // This is unexpected but instead of crashing, capture traces to disk |
| 2783 | // and recover gracefully by forcing CE to rebuild layer stack. |
| 2784 | ALOGE("Output layer %s for display %s %" PRIu64 " has a null " |
| 2785 | "snapshot. Forcing mVisibleRegionsDirty", |
| 2786 | outputLayer->getLayerFE().getDebugName(), |
| 2787 | compositionDisplay->getName().c_str(), compositionDisplay->getId().value); |
| 2788 | |
| 2789 | TransactionTraceWriter::getInstance().invoke(__func__, /* overwrite= */ false); |
| 2790 | mVisibleRegionsDirty = true; |
| 2791 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
| 2792 | refreshArgs.updatingGeometryThisFrame = mVisibleRegionsDirty; |
| 2793 | } |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2794 | } |
| 2795 | } |
| 2796 | } |
| 2797 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2798 | mCompositionEngine->present(refreshArgs); |
| 2799 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2800 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2801 | for (auto [layer, layerFE] : layers) { |
| 2802 | CompositionResult compositionResult{layerFE->stealCompositionResult()}; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2803 | layer->onPreComposition(compositionResult.refreshStartTime); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2804 | for (auto& [releaseFence, layerStack] : compositionResult.releaseFences) { |
Vishnu Nair | 332e6ba | 2023-01-25 17:16:19 -0800 | [diff] [blame] | 2805 | Layer* clonedFrom = layer->getClonedFrom().get(); |
| 2806 | auto owningLayer = clonedFrom ? clonedFrom : layer; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2807 | owningLayer->onLayerDisplayed(std::move(releaseFence), layerStack); |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2808 | } |
| 2809 | if (compositionResult.lastClientCompositionFence) { |
| 2810 | layer->setWasClientComposed(compositionResult.lastClientCompositionFence); |
| 2811 | } |
| 2812 | } |
| 2813 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2814 | mTimeStats->recordFrameDuration(pacesetterTarget.frameBeginTime().ns(), systemTime()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2815 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2816 | // Send a power hint after presentation is finished. |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2817 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2818 | // Now that the current frame has been presented above, PowerAdvisor needs the present time |
| 2819 | // of the previous frame (whose fence is signaled by now) to determine how long the HWC had |
| 2820 | // waited on that fence to retire before presenting. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2821 | const auto& previousPresentFence = pacesetterTarget.presentFenceForPreviousFrame(); |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2822 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2823 | mPowerAdvisor->setSfPresentTiming(TimePoint::fromNs(previousPresentFence->getSignalTime()), |
| 2824 | TimePoint::now()); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 2825 | mPowerAdvisor->reportActualWorkDuration(); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2826 | } |
| 2827 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2828 | if (mScheduler->onCompositionPresented(presentTime)) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2829 | scheduleComposite(FrameHint::kNone); |
| 2830 | } |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2831 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2832 | onCompositionPresented(pacesetterId, frameTargeters, presentTime); |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 2833 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2834 | const bool hadGpuComposited = |
| 2835 | multiDisplayUnion(mCompositionCoverage).test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2836 | mCompositionCoverage.clear(); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2837 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2838 | TimeStats::ClientCompositionRecord clientCompositionRecord; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2839 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2840 | for (const auto& [_, display] : displays) { |
| 2841 | const auto& state = display->getCompositionDisplay()->getState(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2842 | CompositionCoverageFlags& flags = |
| 2843 | mCompositionCoverage.try_emplace(display->getId()).first->second; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2844 | |
| 2845 | if (state.usesDeviceComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2846 | flags |= CompositionCoverage::Hwc; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | if (state.reusedClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2850 | flags |= CompositionCoverage::GpuReuse; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2851 | } else if (state.usesClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2852 | flags |= CompositionCoverage::Gpu; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2853 | } |
| 2854 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2855 | clientCompositionRecord.predicted |= |
| 2856 | (state.strategyPrediction != CompositionStrategyPredictionState::DISABLED); |
| 2857 | clientCompositionRecord.predictionSucceeded |= |
| 2858 | (state.strategyPrediction == CompositionStrategyPredictionState::SUCCESS); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2859 | } |
| 2860 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2861 | const auto coverage = multiDisplayUnion(mCompositionCoverage); |
| 2862 | const bool hasGpuComposited = coverage.test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2863 | |
| 2864 | clientCompositionRecord.hadClientComposition = hasGpuComposited; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2865 | clientCompositionRecord.reused = coverage.test(CompositionCoverage::GpuReuse); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2866 | clientCompositionRecord.changed = hadGpuComposited != hasGpuComposited; |
| 2867 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2868 | mTimeStats->pushCompositionStrategyState(clientCompositionRecord); |
| 2869 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2870 | using namespace ftl::flag_operators; |
| 2871 | |
| 2872 | // TODO(b/160583065): Enable skip validation when SF caches all client composition layers. |
| 2873 | const bool hasGpuUseOrReuse = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2874 | coverage.any(CompositionCoverage::Gpu | CompositionCoverage::GpuReuse); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2875 | mScheduler->modulateVsync({}, &VsyncModulator::onDisplayRefresh, hasGpuUseOrReuse); |
Dan Stoza | 14cd37c | 2015-07-09 12:43:33 -0700 | [diff] [blame] | 2876 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 2877 | mLayersWithQueuedFrames.clear(); |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2878 | mLayersIdsWithQueuedFrames.clear(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2879 | doActiveLayersTracingIfNeeded(true, mVisibleRegionsDirty, pacesetterTarget.frameBeginTime(), |
| 2880 | vsyncId); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2881 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2882 | updateInputFlinger(vsyncId, pacesetterTarget.frameBeginTime()); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2883 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2884 | if (mVisibleRegionsDirty) mHdrLayerInfoChanged = true; |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 2885 | mVisibleRegionsDirty = false; |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2886 | |
| 2887 | if (mCompositionEngine->needsAnotherUpdate()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2888 | scheduleCommit(FrameHint::kNone); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2889 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2890 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2891 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2892 | mPowerAdvisor->setCompositeEnd(TimePoint::now()); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2893 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2894 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2895 | CompositeResultsPerDisplay resultsPerDisplay; |
| 2896 | |
| 2897 | // Filter out virtual displays. |
| 2898 | for (const auto& [id, coverage] : mCompositionCoverage) { |
| 2899 | if (const auto idOpt = PhysicalDisplayId::tryCast(id)) { |
| 2900 | resultsPerDisplay.try_emplace(*idOpt, CompositeResult{coverage}); |
| 2901 | } |
| 2902 | } |
| 2903 | |
| 2904 | return resultsPerDisplay; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2905 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2906 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2907 | void SurfaceFlinger::updateLayerGeometry() { |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2908 | ATRACE_CALL(); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 2909 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2910 | if (mVisibleRegionsDirty) { |
| 2911 | computeLayerBounds(); |
| 2912 | } |
| 2913 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2914 | for (auto& layer : mLayersPendingRefresh) { |
| 2915 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2916 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2917 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2918 | } |
| 2919 | mLayersPendingRefresh.clear(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2922 | bool SurfaceFlinger::isHdrLayer(const frontend::LayerSnapshot& snapshot) const { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2923 | // Even though the camera layer may be using an HDR transfer function or otherwise be "HDR" |
| 2924 | // the device may need to avoid boosting the brightness as a result of these layers to |
| 2925 | // reduce power consumption during camera recording |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2926 | if (mIgnoreHdrCameraLayers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2927 | if (snapshot.externalTexture && |
| 2928 | (snapshot.externalTexture->getUsage() & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) { |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2929 | return false; |
| 2930 | } |
| 2931 | } |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 2932 | // RANGE_EXTENDED layer may identify themselves as being "HDR" |
| 2933 | // via a desired hdr/sdr ratio |
| 2934 | auto pixelFormat = snapshot.buffer |
| 2935 | ? std::make_optional(static_cast<ui::PixelFormat>(snapshot.buffer->getPixelFormat())) |
| 2936 | : std::nullopt; |
| 2937 | |
| 2938 | if (getHdrRenderType(snapshot.dataspace, pixelFormat, snapshot.desiredHdrSdrRatio) != |
| 2939 | HdrRenderType::SDR) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2940 | return true; |
| 2941 | } |
| 2942 | // If the layer is not allowed to be dimmed, treat it as HDR. WindowManager may disable |
| 2943 | // dimming in order to keep animations invoking SDR screenshots of HDR layers seamless. |
| 2944 | // Treat such tagged layers as HDR so that DisplayManagerService does not try to change |
| 2945 | // the screen brightness |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2946 | if (!snapshot.dimmingEnabled) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2947 | return true; |
| 2948 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2949 | return false; |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2950 | } |
| 2951 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2952 | ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId, |
| 2953 | bool isPrimary) const { |
| 2954 | const auto id = PhysicalDisplayId::tryCast(displayId); |
| 2955 | if (!id) { |
| 2956 | return ui::ROTATION_0; |
| 2957 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2958 | if (!mIgnoreHwcPhysicalDisplayOrientation && |
Neha Jain | 7b31cca | 2023-01-09 23:10:42 +0000 | [diff] [blame] | 2959 | getHwComposer().getComposer()->isSupported( |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2960 | Hwc2::Composer::OptionalFeature::PhysicalDisplayOrientation)) { |
| 2961 | switch (getHwComposer().getPhysicalDisplayOrientation(*id)) { |
| 2962 | case Hwc2::AidlTransform::ROT_90: |
| 2963 | return ui::ROTATION_90; |
| 2964 | case Hwc2::AidlTransform::ROT_180: |
| 2965 | return ui::ROTATION_180; |
| 2966 | case Hwc2::AidlTransform::ROT_270: |
| 2967 | return ui::ROTATION_270; |
| 2968 | default: |
| 2969 | return ui::ROTATION_0; |
| 2970 | } |
| 2971 | } |
| 2972 | |
| 2973 | if (isPrimary) { |
| 2974 | using Values = SurfaceFlingerProperties::primary_display_orientation_values; |
| 2975 | switch (primary_display_orientation(Values::ORIENTATION_0)) { |
| 2976 | case Values::ORIENTATION_90: |
| 2977 | return ui::ROTATION_90; |
| 2978 | case Values::ORIENTATION_180: |
| 2979 | return ui::ROTATION_180; |
| 2980 | case Values::ORIENTATION_270: |
| 2981 | return ui::ROTATION_270; |
| 2982 | default: |
| 2983 | break; |
| 2984 | } |
| 2985 | } |
| 2986 | return ui::ROTATION_0; |
| 2987 | } |
| 2988 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2989 | void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId, |
| 2990 | const scheduler::FrameTargeters& frameTargeters, |
| 2991 | nsecs_t presentStartTime) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2992 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2993 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2994 | ui::PhysicalDisplayMap<PhysicalDisplayId, std::shared_ptr<FenceTime>> presentFences; |
| 2995 | ui::PhysicalDisplayMap<PhysicalDisplayId, const sp<Fence>> gpuCompositionDoneFences; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2996 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2997 | for (const auto& [id, targeter] : frameTargeters) { |
| 2998 | auto presentFence = getHwComposer().getPresentFence(id); |
| 2999 | |
| 3000 | if (id == pacesetterId) { |
| 3001 | mTransactionCallbackInvoker.addPresentFence(presentFence); |
| 3002 | } |
| 3003 | |
| 3004 | if (auto fenceTime = targeter->setPresentFence(std::move(presentFence)); |
| 3005 | fenceTime->isValid()) { |
| 3006 | presentFences.try_emplace(id, std::move(fenceTime)); |
| 3007 | } |
| 3008 | |
| 3009 | ftl::FakeGuard guard(mStateLock); |
| 3010 | if (const auto display = getCompositionDisplayLocked(id); |
| 3011 | display && display->getState().usesClientComposition) { |
| 3012 | gpuCompositionDoneFences |
| 3013 | .try_emplace(id, display->getRenderSurface()->getClientTargetAcquireFence()); |
| 3014 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3015 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3016 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3017 | const auto pacesetterDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(pacesetterId)); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3018 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3019 | std::shared_ptr<FenceTime> pacesetterPresentFenceTime = |
| 3020 | presentFences.get(pacesetterId) |
| 3021 | .transform([](const FenceTimePtr& ptr) { return ptr; }) |
| 3022 | .value_or(FenceTime::NO_FENCE); |
| 3023 | |
| 3024 | std::shared_ptr<FenceTime> pacesetterGpuCompositionDoneFenceTime = |
| 3025 | gpuCompositionDoneFences.get(pacesetterId) |
| 3026 | .transform([](sp<Fence> fence) { |
| 3027 | return std::make_shared<FenceTime>(std::move(fence)); |
| 3028 | }) |
| 3029 | .value_or(FenceTime::NO_FENCE); |
| 3030 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 3031 | const TimePoint presentTime = TimePoint::now(); |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 3032 | |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 3033 | // Set presentation information before calling Layer::releasePendingBuffer, such that jank |
| 3034 | // information from previous' frame classification is already available when sending jank info |
| 3035 | // to clients, so they get jank classification as early as possible. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3036 | mFrameTimeline->setSfPresent(presentTime.ns(), pacesetterPresentFenceTime, |
| 3037 | pacesetterGpuCompositionDoneFenceTime); |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 3038 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 3039 | // We use the CompositionEngine::getLastFrameRefreshTimestamp() which might |
| 3040 | // 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] | 3041 | // but that should be okay since CompositorTiming has snapping logic. |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 3042 | const TimePoint compositeTime = |
| 3043 | TimePoint::fromNs(mCompositionEngine->getLastFrameRefreshTimestamp()); |
| 3044 | const Duration presentLatency = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3045 | getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE) |
| 3046 | ? Duration::zero() |
| 3047 | : mPresentLatencyTracker.trackPendingFrame(compositeTime, pacesetterPresentFenceTime); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3048 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3049 | const auto schedule = mScheduler->getVsyncSchedule(); |
| 3050 | const TimePoint vsyncDeadline = schedule->vsyncDeadlineAfter(presentTime); |
| 3051 | const Period vsyncPeriod = schedule->period(); |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 3052 | const nsecs_t vsyncPhase = mVsyncConfiguration->getCurrentConfigs().late.sfOffset; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3053 | |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 3054 | const CompositorTiming compositorTiming(vsyncDeadline.ns(), vsyncPeriod.ns(), vsyncPhase, |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 3055 | presentLatency.ns()); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 3056 | |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 3057 | ui::DisplayMap<ui::LayerStack, const DisplayDevice*> layerStackToDisplay; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3058 | { |
| 3059 | if (!mLayersWithBuffersRemoved.empty() || mNumTrustedPresentationListeners > 0) { |
| 3060 | Mutex::Autolock lock(mStateLock); |
| 3061 | for (const auto& [token, display] : mDisplays) { |
| 3062 | layerStackToDisplay.emplace_or_replace(display->getLayerStack(), display.get()); |
| 3063 | } |
| 3064 | } |
| 3065 | } |
| 3066 | |
| 3067 | for (auto layer : mLayersWithBuffersRemoved) { |
Vishnu Nair | f10a87b | 2023-05-01 14:02:51 -0700 | [diff] [blame] | 3068 | std::vector<ui::LayerStack> previouslyPresentedLayerStacks = |
| 3069 | std::move(layer->mPreviouslyPresentedLayerStacks); |
| 3070 | layer->mPreviouslyPresentedLayerStacks.clear(); |
| 3071 | for (auto layerStack : previouslyPresentedLayerStacks) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3072 | auto optDisplay = layerStackToDisplay.get(layerStack); |
| 3073 | if (optDisplay && !optDisplay->get()->isVirtual()) { |
| 3074 | auto fence = getHwComposer().getPresentFence(optDisplay->get()->getPhysicalId()); |
| 3075 | layer->onLayerDisplayed(ftl::yield<FenceResult>(fence).share(), |
| 3076 | ui::INVALID_LAYER_STACK); |
| 3077 | } |
| 3078 | } |
| 3079 | layer->releasePendingBuffer(presentTime.ns()); |
| 3080 | } |
| 3081 | mLayersWithBuffersRemoved.clear(); |
| 3082 | |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 3083 | for (const auto& layer: mLayersWithQueuedFrames) { |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 3084 | layer->onCompositionPresented(pacesetterDisplay.get(), |
| 3085 | pacesetterGpuCompositionDoneFenceTime, |
| 3086 | pacesetterPresentFenceTime, compositorTiming); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3087 | layer->releasePendingBuffer(presentTime.ns()); |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 3088 | } |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 3089 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3090 | std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>> |
| 3091 | hdrInfoListeners; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3092 | bool haveNewListeners = false; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3093 | { |
| 3094 | Mutex::Autolock lock(mStateLock); |
| 3095 | if (mFpsReporter) { |
| 3096 | mFpsReporter->dispatchLayerFps(); |
| 3097 | } |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 3098 | |
| 3099 | if (mTunnelModeEnabledReporter) { |
| 3100 | mTunnelModeEnabledReporter->updateTunnelModeStatus(); |
| 3101 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3102 | hdrInfoListeners.reserve(mHdrLayerInfoListeners.size()); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 3103 | for (const auto& [displayId, reporter] : mHdrLayerInfoListeners) { |
| 3104 | if (reporter && reporter->hasListeners()) { |
| 3105 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 3106 | hdrInfoListeners.emplace_back(display->getCompositionDisplay(), reporter); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3107 | } |
| 3108 | } |
| 3109 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3110 | haveNewListeners = mAddingHDRLayerInfoListener; // grab this with state lock |
| 3111 | mAddingHDRLayerInfoListener = false; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3112 | } |
| 3113 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3114 | if (haveNewListeners || mHdrLayerInfoChanged) { |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3115 | for (auto& [compositionDisplay, listener] : hdrInfoListeners) { |
| 3116 | HdrLayerInfoReporter::HdrLayerInfo info; |
| 3117 | int32_t maxArea = 0; |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3118 | auto updateInfoFn = |
| 3119 | [&](const std::shared_ptr<compositionengine::Display>& compositionDisplay, |
| 3120 | const frontend::LayerSnapshot& snapshot, const sp<LayerFE>& layerFe) { |
| 3121 | if (snapshot.isVisible && |
| 3122 | compositionDisplay->includesLayer(snapshot.outputFilter)) { |
| 3123 | if (isHdrLayer(snapshot)) { |
| 3124 | const auto* outputLayer = |
| 3125 | compositionDisplay->getOutputLayerForLayer(layerFe); |
| 3126 | if (outputLayer) { |
| 3127 | const float desiredHdrSdrRatio = |
| 3128 | snapshot.desiredHdrSdrRatio <= 1.f |
| 3129 | ? std::numeric_limits<float>::infinity() |
| 3130 | : snapshot.desiredHdrSdrRatio; |
| 3131 | info.mergeDesiredRatio(desiredHdrSdrRatio); |
| 3132 | info.numberOfHdrLayers++; |
| 3133 | const auto displayFrame = outputLayer->getState().displayFrame; |
| 3134 | const int32_t area = |
| 3135 | displayFrame.width() * displayFrame.height(); |
| 3136 | if (area > maxArea) { |
| 3137 | maxArea = area; |
| 3138 | info.maxW = displayFrame.width(); |
| 3139 | info.maxH = displayFrame.height(); |
| 3140 | } |
| 3141 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3142 | } |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 3143 | } |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3144 | }; |
| 3145 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3146 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3147 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 3148 | [&, compositionDisplay = compositionDisplay]( |
| 3149 | std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 3150 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 3151 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 3152 | "Couldnt find layer object for %s", |
| 3153 | snapshot->getDebugString().c_str()); |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3154 | auto& legacyLayer = it->second; |
| 3155 | sp<LayerFE> layerFe = |
| 3156 | legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
| 3157 | |
| 3158 | updateInfoFn(compositionDisplay, *snapshot, layerFe); |
| 3159 | }); |
| 3160 | } else { |
| 3161 | mDrawingState.traverse([&, compositionDisplay = compositionDisplay](Layer* layer) { |
| 3162 | const auto layerFe = layer->getCompositionEngineLayerFE(); |
| 3163 | const frontend::LayerSnapshot& snapshot = *layer->getLayerSnapshot(); |
| 3164 | updateInfoFn(compositionDisplay, snapshot, layerFe); |
| 3165 | }); |
| 3166 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3167 | listener->dispatchHdrLayerInfo(info); |
| 3168 | } |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3169 | } |
| 3170 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3171 | mHdrLayerInfoChanged = false; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3172 | |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 3173 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 3174 | mTransactionCallbackInvoker.clearCompletedTransactions(); |
| 3175 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3176 | mTimeStats->incrementTotalFrames(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3177 | mTimeStats->setPresentFenceGlobal(pacesetterPresentFenceTime); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3178 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3179 | for (auto&& [id, presentFence] : presentFences) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3180 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3181 | const bool isInternalDisplay = |
| 3182 | mPhysicalDisplays.get(id).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 3183 | |
| 3184 | if (isInternalDisplay) { |
| 3185 | mScheduler->addPresentFence(id, std::move(presentFence)); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3186 | } |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3187 | } |
| 3188 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3189 | const bool hasPacesetterDisplay = |
| 3190 | pacesetterDisplay && getHwComposer().isConnected(pacesetterId); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3191 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3192 | if (!hasSyncFramework) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3193 | if (hasPacesetterDisplay && pacesetterDisplay->isPoweredOn()) { |
| 3194 | mScheduler->enableHardwareVsync(pacesetterId); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3195 | } |
| 3196 | } |
| 3197 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3198 | if (hasPacesetterDisplay && !pacesetterDisplay->isPoweredOn()) { |
Lars Svensson | d9e5469 | 2021-12-21 07:41:57 +0100 | [diff] [blame] | 3199 | getRenderEngine().cleanupPostRender(); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 3200 | return; |
| 3201 | } |
| 3202 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 3203 | // Cleanup any outstanding resources due to rendering a prior frame. |
| 3204 | getRenderEngine().cleanupPostRender(); |
| 3205 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3206 | if (mNumTrustedPresentationListeners > 0) { |
| 3207 | // 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] | 3208 | traverseLegacyLayers([&](Layer* layer) { |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3209 | if (!layer->hasTrustedPresentationListener()) { |
| 3210 | return; |
| 3211 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3212 | const frontend::LayerSnapshot* snapshot = mLayerLifecycleManagerEnabled |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3213 | ? mLayerSnapshotBuilder.getSnapshot(layer->sequence) |
| 3214 | : layer->getLayerSnapshot(); |
| 3215 | std::optional<const DisplayDevice*> displayOpt = std::nullopt; |
| 3216 | if (snapshot) { |
| 3217 | displayOpt = layerStackToDisplay.get(snapshot->outputFilter.layerStack); |
| 3218 | } |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 3219 | const DisplayDevice* display = displayOpt.value_or(nullptr); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3220 | layer->updateTrustedPresentationState(display, snapshot, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 3221 | nanoseconds_to_milliseconds(presentStartTime), |
| 3222 | false); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3223 | }); |
| 3224 | } |
| 3225 | |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3226 | // Even though ATRACE_INT64 already checks if tracing is enabled, it doesn't prevent the |
| 3227 | // side-effect of getTotalSize(), so we check that again here |
| 3228 | if (ATRACE_ENABLED()) { |
Marissa Wall | 22b2de1 | 2019-12-02 18:11:43 -0800 | [diff] [blame] | 3229 | // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3230 | ATRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize()); |
| 3231 | } |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3232 | |
| 3233 | logFrameStats(presentTime); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 3234 | } |
| 3235 | |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3236 | FloatRect SurfaceFlinger::getMaxDisplayBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3237 | const ui::Size maxSize = [this] { |
| 3238 | ftl::FakeGuard guard(mStateLock); |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3239 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3240 | // The LayerTraceGenerator tool runs without displays. |
| 3241 | if (mDisplays.empty()) return ui::Size{5000, 5000}; |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3242 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3243 | return std::accumulate(mDisplays.begin(), mDisplays.end(), ui::kEmptySize, |
| 3244 | [](ui::Size size, const auto& pair) -> ui::Size { |
| 3245 | const auto& display = pair.second; |
| 3246 | return {std::max(size.getWidth(), display->getWidth()), |
| 3247 | std::max(size.getHeight(), display->getHeight())}; |
| 3248 | }); |
| 3249 | }(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3250 | |
| 3251 | // Ignore display bounds for now since they will be computed later. Use a large Rect bound |
| 3252 | // to ensure it's bigger than an actual display will be. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3253 | const float xMax = maxSize.getWidth() * 10.f; |
| 3254 | const float yMax = maxSize.getHeight() * 10.f; |
| 3255 | |
| 3256 | return {-xMax, -yMax, xMax, yMax}; |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | void SurfaceFlinger::computeLayerBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3260 | const FloatRect maxBounds = getMaxDisplayBounds(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3261 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 3262 | layer->computeBounds(maxBounds, ui::Transform(), 0.f /* shadowRadius */); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3263 | } |
| 3264 | } |
| 3265 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3266 | void SurfaceFlinger::commitTransactions() { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 3267 | ATRACE_CALL(); |
| 3268 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3269 | // Keep a copy of the drawing state (that is going to be overwritten |
| 3270 | // by commitTransactionsLocked) outside of mStateLock so that the side |
| 3271 | // effects of the State assignment don't happen with mStateLock held, |
| 3272 | // which can cause deadlocks. |
Mathias Agopian | 7cc6df5 | 2013-06-05 14:30:54 -0700 | [diff] [blame] | 3273 | State drawingState(mDrawingState); |
| 3274 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3275 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 3276 | mDebugInTransaction = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3277 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3278 | // Here we're guaranteed that some transaction flags are set |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3279 | // so we can call commitTransactionsLocked unconditionally. |
| 3280 | // We clear the flags with mStateLock held to guarantee that |
| 3281 | // mCurrentState won't change until the transaction is committed. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3282 | mScheduler->modulateVsync({}, &VsyncModulator::onTransactionCommit); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3283 | commitTransactionsLocked(clearTransactionFlags(eTransactionMask)); |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 3284 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3285 | mDebugInTransaction = 0; |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 3286 | } |
| 3287 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3288 | std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes( |
| 3289 | PhysicalDisplayId displayId) const { |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3290 | std::vector<HWComposer::HWCDisplayMode> hwcModes; |
| 3291 | std::optional<hal::HWDisplayId> activeModeHwcId; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3292 | |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3293 | int attempt = 0; |
| 3294 | constexpr int kMaxAttempts = 3; |
| 3295 | do { |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 3296 | hwcModes = getHwComposer().getModes(displayId, |
| 3297 | scheduler::RefreshRateSelector::kMinSupportedFrameRate |
| 3298 | .getPeriodNsecs()); |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3299 | activeModeHwcId = getHwComposer().getActiveMode(displayId); |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3300 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3301 | const auto isActiveMode = [activeModeHwcId](const HWComposer::HWCDisplayMode& mode) { |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3302 | return mode.hwcId == activeModeHwcId; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3303 | }; |
| 3304 | |
| 3305 | if (std::any_of(hwcModes.begin(), hwcModes.end(), isActiveMode)) { |
| 3306 | break; |
| 3307 | } |
| 3308 | } while (++attempt < kMaxAttempts); |
| 3309 | |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3310 | if (attempt == kMaxAttempts) { |
| 3311 | const std::string activeMode = |
| 3312 | activeModeHwcId ? std::to_string(*activeModeHwcId) : "unknown"s; |
| 3313 | ALOGE("HWC failed to report an active mode that is supported: activeModeHwcId=%s, " |
| 3314 | "hwcModes={%s}", |
| 3315 | activeMode.c_str(), base::Join(hwcModes, ", ").c_str()); |
| 3316 | return {}; |
| 3317 | } |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3318 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3319 | const DisplayModes oldModes = mPhysicalDisplays.get(displayId) |
| 3320 | .transform([](const PhysicalDisplay& display) { |
| 3321 | return display.snapshot().displayModes(); |
| 3322 | }) |
| 3323 | .value_or(DisplayModes{}); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3324 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3325 | ui::DisplayModeId nextModeId = 1 + |
| 3326 | std::accumulate(oldModes.begin(), oldModes.end(), static_cast<ui::DisplayModeId>(-1), |
| 3327 | [](ui::DisplayModeId max, const auto& pair) { |
| 3328 | return std::max(max, pair.first.value()); |
| 3329 | }); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3330 | |
| 3331 | DisplayModes newModes; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3332 | for (const auto& hwcMode : hwcModes) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3333 | const DisplayModeId id{nextModeId++}; |
| 3334 | newModes.try_emplace(id, |
| 3335 | DisplayMode::Builder(hwcMode.hwcId) |
| 3336 | .setId(id) |
| 3337 | .setPhysicalDisplayId(displayId) |
| 3338 | .setResolution({hwcMode.width, hwcMode.height}) |
| 3339 | .setVsyncPeriod(hwcMode.vsyncPeriod) |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 3340 | .setVrrConfig(hwcMode.vrrConfig) |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3341 | .setDpiX(hwcMode.dpiX) |
| 3342 | .setDpiY(hwcMode.dpiY) |
| 3343 | .setGroup(hwcMode.configGroup) |
| 3344 | .build()); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3345 | } |
| 3346 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3347 | const bool sameModes = |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3348 | std::equal(newModes.begin(), newModes.end(), oldModes.begin(), oldModes.end(), |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3349 | [](const auto& lhs, const auto& rhs) { |
| 3350 | return equalsExceptDisplayModeId(*lhs.second, *rhs.second); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3351 | }); |
| 3352 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3353 | // Keep IDs if modes have not changed. |
| 3354 | const auto& modes = sameModes ? oldModes : newModes; |
| 3355 | const DisplayModePtr activeMode = |
| 3356 | std::find_if(modes.begin(), modes.end(), [activeModeHwcId](const auto& pair) { |
| 3357 | return pair.second->getHwcId() == activeModeHwcId; |
| 3358 | })->second; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3359 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3360 | return {modes, activeMode}; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3361 | } |
| 3362 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3363 | bool SurfaceFlinger::configureLocked() { |
| 3364 | std::vector<HotplugEvent> events; |
| 3365 | { |
| 3366 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 3367 | events = std::move(mPendingHotplugEvents); |
| 3368 | } |
| 3369 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3370 | for (const auto [hwcDisplayId, connection] : events) { |
| 3371 | if (auto info = getHwComposer().onHotplug(hwcDisplayId, connection)) { |
| 3372 | const auto displayId = info->id; |
| 3373 | const bool connected = connection == hal::Connection::CONNECTED; |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3374 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3375 | if (const char* const log = |
| 3376 | processHotplug(displayId, hwcDisplayId, connected, std::move(*info))) { |
| 3377 | ALOGI("%s display %s (HAL ID %" PRIu64 ")", log, to_string(displayId).c_str(), |
| 3378 | hwcDisplayId); |
| 3379 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3380 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3381 | } |
| 3382 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3383 | return !events.empty(); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3384 | } |
| 3385 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3386 | const char* SurfaceFlinger::processHotplug(PhysicalDisplayId displayId, |
| 3387 | hal::HWDisplayId hwcDisplayId, bool connected, |
| 3388 | DisplayIdentificationInfo&& info) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3389 | const auto displayOpt = mPhysicalDisplays.get(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3390 | if (!connected) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3391 | LOG_ALWAYS_FATAL_IF(!displayOpt); |
| 3392 | const auto& display = displayOpt->get(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3393 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3394 | if (const ssize_t index = mCurrentState.displays.indexOfKey(display.token()); index >= 0) { |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3395 | mCurrentState.displays.removeItemsAt(index); |
| 3396 | } |
| 3397 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3398 | mPhysicalDisplays.erase(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3399 | return "Disconnecting"; |
| 3400 | } |
| 3401 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3402 | auto [displayModes, activeMode] = loadDisplayModes(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3403 | if (!activeMode) { |
| 3404 | // TODO(b/241286153): Report hotplug failure to the framework. |
| 3405 | ALOGE("Failed to hotplug display %s", to_string(displayId).c_str()); |
| 3406 | getHwComposer().disconnectDisplay(displayId); |
| 3407 | return nullptr; |
| 3408 | } |
| 3409 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3410 | ui::ColorModes colorModes = getHwComposer().getColorModes(displayId); |
| 3411 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3412 | if (displayOpt) { |
| 3413 | const auto& display = displayOpt->get(); |
| 3414 | const auto& snapshot = display.snapshot(); |
| 3415 | |
| 3416 | std::optional<DeviceProductInfo> deviceProductInfo; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3417 | if (getHwComposer().updatesDeviceProductInfoOnHotplugReconnect()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3418 | deviceProductInfo = std::move(info.deviceProductInfo); |
| 3419 | } else { |
| 3420 | deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3421 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3422 | |
| 3423 | const auto it = |
| 3424 | mPhysicalDisplays.try_replace(displayId, display.token(), displayId, |
| 3425 | snapshot.connectionType(), std::move(displayModes), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3426 | std::move(colorModes), std::move(deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3427 | |
| 3428 | auto& state = mCurrentState.displays.editValueFor(it->second.token()); |
| 3429 | state.sequenceId = DisplayDeviceState{}.sequenceId; // Generate new sequenceId. |
| 3430 | state.physical->activeMode = std::move(activeMode); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3431 | return "Reconnecting"; |
| 3432 | } |
| 3433 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3434 | const sp<IBinder> token = sp<BBinder>::make(); |
| 3435 | |
| 3436 | mPhysicalDisplays.try_emplace(displayId, token, displayId, |
| 3437 | getHwComposer().getDisplayConnectionType(displayId), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3438 | std::move(displayModes), std::move(colorModes), |
| 3439 | std::move(info.deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3440 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3441 | DisplayDeviceState state; |
| 3442 | state.physical = {.id = displayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3443 | .hwcDisplayId = hwcDisplayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3444 | .activeMode = std::move(activeMode)}; |
| 3445 | state.isSecure = true; // All physical displays are currently considered secure. |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3446 | state.isProtected = true; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3447 | state.displayName = std::move(info.name); |
| 3448 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3449 | mCurrentState.displays.add(token, state); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3450 | return "Connecting"; |
| 3451 | } |
| 3452 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 3453 | void SurfaceFlinger::dispatchDisplayHotplugEvent(PhysicalDisplayId displayId, bool connected) { |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 3454 | mScheduler->onHotplugReceived(mAppConnectionHandle, displayId, connected); |
| 3455 | mScheduler->onHotplugReceived(mSfConnectionHandle, displayId, connected); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 3456 | } |
| 3457 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3458 | void SurfaceFlinger::dispatchDisplayModeChangeEvent(PhysicalDisplayId displayId, |
| 3459 | const scheduler::FrameRateMode& mode) { |
| 3460 | // TODO(b/255635821): Merge code paths and move to Scheduler. |
| 3461 | const auto onDisplayModeChanged = displayId == mActiveDisplayId |
| 3462 | ? &scheduler::Scheduler::onPrimaryDisplayModeChanged |
| 3463 | : &scheduler::Scheduler::onNonPrimaryDisplayModeChanged; |
| 3464 | |
| 3465 | ((*mScheduler).*onDisplayModeChanged)(mAppConnectionHandle, mode); |
| 3466 | } |
| 3467 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3468 | sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3469 | const wp<IBinder>& displayToken, |
| 3470 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3471 | const DisplayDeviceState& state, |
| 3472 | const sp<compositionengine::DisplaySurface>& displaySurface, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3473 | const sp<IGraphicBufferProducer>& producer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3474 | DisplayDeviceCreationArgs creationArgs(sp<SurfaceFlinger>::fromExisting(this), getHwComposer(), |
| 3475 | displayToken, compositionDisplay); |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 3476 | creationArgs.sequenceId = state.sequenceId; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3477 | creationArgs.isSecure = state.isSecure; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3478 | creationArgs.isProtected = state.isProtected; |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3479 | creationArgs.displaySurface = displaySurface; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3480 | creationArgs.hasWideColorGamut = false; |
| 3481 | creationArgs.supportedPerFrameMetadata = 0; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 3482 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3483 | if (const auto& physical = state.physical) { |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3484 | creationArgs.activeModeId = physical->activeMode->getId(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3485 | const auto [kernelIdleTimerController, idleTimerTimeoutMs] = |
| 3486 | getKernelIdleTimerProperties(compositionDisplay->getId()); |
| 3487 | |
Ady Abraham | 0c8b723 | 2023-01-27 21:12:16 -0800 | [diff] [blame] | 3488 | using Config = scheduler::RefreshRateSelector::Config; |
| 3489 | const auto enableFrameRateOverride = sysprop::enable_frame_rate_override(true) |
| 3490 | ? Config::FrameRateOverride::Enabled |
| 3491 | : Config::FrameRateOverride::Disabled; |
Ady Abraham | 0d4b41c | 2023-02-14 23:28:40 +0000 | [diff] [blame] | 3492 | Config config = |
Ady Abraham | 8ca643a | 2022-10-18 18:26:47 -0700 | [diff] [blame] | 3493 | {.enableFrameRateOverride = enableFrameRateOverride, |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3494 | .frameRateMultipleThreshold = |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 3495 | base::GetIntProperty("debug.sf.frame_rate_multiple_threshold", 0), |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3496 | .idleTimerTimeout = idleTimerTimeoutMs, |
| 3497 | .kernelIdleTimerController = kernelIdleTimerController}; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3498 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3499 | creationArgs.refreshRateSelector = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3500 | mPhysicalDisplays.get(physical->id) |
| 3501 | .transform(&PhysicalDisplay::snapshotRef) |
| 3502 | .transform([&](const display::DisplaySnapshot& snapshot) { |
| 3503 | return std::make_shared< |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3504 | scheduler::RefreshRateSelector>(snapshot.displayModes(), |
| 3505 | creationArgs.activeModeId, |
| 3506 | config); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3507 | }) |
| 3508 | .value_or(nullptr); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3509 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3510 | creationArgs.isPrimary = physical->id == getPrimaryDisplayIdLocked(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3511 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 3512 | mPhysicalDisplays.get(physical->id) |
| 3513 | .transform(&PhysicalDisplay::snapshotRef) |
| 3514 | .transform(ftl::unit_fn([&](const display::DisplaySnapshot& snapshot) { |
| 3515 | for (const auto mode : snapshot.colorModes()) { |
| 3516 | creationArgs.hasWideColorGamut |= ui::isWideColorMode(mode); |
| 3517 | creationArgs.hwcColorModes |
| 3518 | .emplace(mode, |
| 3519 | getHwComposer().getRenderIntents(physical->id, mode)); |
| 3520 | } |
| 3521 | })); |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 3522 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3523 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3524 | if (const auto id = HalDisplayId::tryCast(compositionDisplay->getId())) { |
| 3525 | getHwComposer().getHdrCapabilities(*id, &creationArgs.hdrCapabilities); |
| 3526 | creationArgs.supportedPerFrameMetadata = getHwComposer().getSupportedPerFrameMetadata(*id); |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 3527 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3528 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 3529 | auto nativeWindowSurface = getFactory().createNativeWindowSurface(producer); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3530 | auto nativeWindow = nativeWindowSurface->getNativeWindow(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3531 | creationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3532 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3533 | // Make sure that composition can never be stalled by a virtual display |
| 3534 | // 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] | 3535 | // here, in case the display is composed entirely by HWC. |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 3536 | if (state.isVirtual()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3537 | nativeWindow->setSwapInterval(nativeWindow.get(), 0); |
| 3538 | } |
| 3539 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 3540 | creationArgs.physicalOrientation = |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3541 | getPhysicalDisplayOrientation(compositionDisplay->getId(), creationArgs.isPrimary); |
| 3542 | ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 3543 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3544 | // virtual displays are always considered enabled |
linpeter | 1c69cd3 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 3545 | creationArgs.initialPowerMode = |
| 3546 | state.isVirtual() ? std::make_optional(hal::PowerMode::ON) : std::nullopt; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3547 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3548 | creationArgs.requestedRefreshRate = state.requestedRefreshRate; |
| 3549 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3550 | sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3551 | |
Ady Abraham | 8565ad2 | 2021-06-22 17:45:44 -0700 | [diff] [blame] | 3552 | nativeWindowSurface->preallocateBuffers(); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3553 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3554 | ui::ColorMode defaultColorMode = ui::ColorMode::NATIVE; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 3555 | Dataspace defaultDataSpace = Dataspace::UNKNOWN; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3556 | if (display->hasWideColorGamut()) { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3557 | defaultColorMode = ui::ColorMode::SRGB; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 3558 | defaultDataSpace = Dataspace::V0_SRGB; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3559 | } |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 3560 | display->getCompositionDisplay()->setColorProfile( |
| 3561 | compositionengine::Output::ColorProfile{defaultColorMode, defaultDataSpace, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 3562 | RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3563 | |
| 3564 | if (const auto& physical = state.physical) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3565 | const auto& mode = *physical->activeMode; |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 3566 | display->setActiveMode(mode.getId(), mode.getVsyncRate(), mode.getVsyncRate()); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 3567 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3568 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3569 | display->setLayerFilter(makeLayerFilterForDisplay(display->getId(), state.layerStack)); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3570 | display->setProjection(state.orientation, state.layerStackSpaceRect, |
| 3571 | state.orientedDisplaySpaceRect); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3572 | display->setDisplayName(state.displayName); |
Vishnu Nair | a119aaa | 2021-09-24 07:19:35 -0700 | [diff] [blame] | 3573 | display->setFlags(state.flags); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3574 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3575 | return display; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3576 | } |
| 3577 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3578 | void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, |
| 3579 | const DisplayDeviceState& state) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3580 | ui::Size resolution(0, 0); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3581 | ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN); |
| 3582 | if (state.physical) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3583 | resolution = state.physical->activeMode->getResolution(); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3584 | pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888); |
| 3585 | } else if (state.surface != nullptr) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3586 | int status = state.surface->query(NATIVE_WINDOW_WIDTH, &resolution.width); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3587 | ALOGE_IF(status != NO_ERROR, "Unable to query width (%d)", status); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3588 | status = state.surface->query(NATIVE_WINDOW_HEIGHT, &resolution.height); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3589 | ALOGE_IF(status != NO_ERROR, "Unable to query height (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3590 | int format; |
| 3591 | status = state.surface->query(NATIVE_WINDOW_FORMAT, &format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3592 | ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3593 | pixelFormat = static_cast<ui::PixelFormat>(format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3594 | } else { |
| 3595 | // Virtual displays without a surface are dormant: |
| 3596 | // they have external state (layer stack, projection, |
| 3597 | // etc.) but no internal state (i.e. a DisplayDevice). |
| 3598 | return; |
| 3599 | } |
| 3600 | |
| 3601 | compositionengine::DisplayCreationArgsBuilder builder; |
| 3602 | if (const auto& physical = state.physical) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3603 | builder.setId(physical->id); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3604 | } else { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 3605 | builder.setId(acquireVirtualDisplay(resolution, pixelFormat)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3606 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3607 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3608 | builder.setPixels(resolution); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3609 | builder.setIsSecure(state.isSecure); |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3610 | builder.setIsProtected(state.isProtected); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 3611 | builder.setPowerAdvisor(mPowerAdvisor.get()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3612 | builder.setName(state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3613 | auto compositionDisplay = getCompositionEngine().createDisplay(builder.build()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3614 | compositionDisplay->setLayerCachingEnabled(mLayerCachingEnabled); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3615 | |
| 3616 | sp<compositionengine::DisplaySurface> displaySurface; |
| 3617 | sp<IGraphicBufferProducer> producer; |
| 3618 | sp<IGraphicBufferProducer> bqProducer; |
| 3619 | sp<IGraphicBufferConsumer> bqConsumer; |
| 3620 | getFactory().createBufferQueue(&bqProducer, &bqConsumer, /*consumerIsSurfaceFlinger =*/false); |
| 3621 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3622 | if (state.isVirtual()) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3623 | const auto displayId = VirtualDisplayId::tryCast(compositionDisplay->getId()); |
| 3624 | LOG_FATAL_IF(!displayId); |
| 3625 | auto surface = sp<VirtualDisplaySurface>::make(getHwComposer(), *displayId, state.surface, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3626 | bqProducer, bqConsumer, state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3627 | displaySurface = surface; |
| 3628 | producer = std::move(surface); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3629 | } else { |
| 3630 | ALOGE_IF(state.surface != nullptr, |
| 3631 | "adding a supported display, but rendering " |
| 3632 | "surface is provided (%p), ignoring it", |
| 3633 | state.surface.get()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3634 | const auto displayId = PhysicalDisplayId::tryCast(compositionDisplay->getId()); |
| 3635 | LOG_FATAL_IF(!displayId); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3636 | displaySurface = |
| 3637 | sp<FramebufferSurface>::make(getHwComposer(), *displayId, bqConsumer, |
| 3638 | state.physical->activeMode->getResolution(), |
| 3639 | ui::Size(maxGraphicsWidth, maxGraphicsHeight)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3640 | producer = bqProducer; |
| 3641 | } |
| 3642 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3643 | LOG_FATAL_IF(!displaySurface); |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3644 | auto display = setupNewDisplayDeviceInternal(displayToken, std::move(compositionDisplay), state, |
| 3645 | displaySurface, producer); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3646 | |
| 3647 | if (mScheduler && !display->isVirtual()) { |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3648 | const auto displayId = display->getPhysicalId(); |
| 3649 | { |
Dominik Laskowski | 59db956 | 2022-10-27 16:18:53 -0400 | [diff] [blame] | 3650 | // TODO(b/241285876): Annotate `processDisplayAdded` instead. |
| 3651 | ftl::FakeGuard guard(kMainThreadContext); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3652 | |
| 3653 | // For hotplug reconnect, renew the registration since display modes have been reloaded. |
| 3654 | mScheduler->registerDisplay(displayId, display->holdRefreshRateSelector()); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3655 | } |
Dominik Laskowski | b5a094b | 2022-10-27 12:00:12 -0400 | [diff] [blame] | 3656 | |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3657 | dispatchDisplayHotplugEvent(displayId, true); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3658 | } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3659 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3660 | if (display->isVirtual()) { |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 3661 | display->adjustRefreshRate(mScheduler->getPacesetterRefreshRate()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3662 | } |
| 3663 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3664 | mDisplays.try_emplace(displayToken, std::move(display)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3668 | auto display = getDisplayDeviceLocked(displayToken); |
| 3669 | if (display) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3670 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3671 | |
| 3672 | if (display->isVirtual()) { |
| 3673 | releaseVirtualDisplay(display->getVirtualId()); |
| 3674 | } else { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3675 | dispatchDisplayHotplugEvent(display->getPhysicalId(), false); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 3676 | mScheduler->unregisterDisplay(display->getPhysicalId()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3677 | } |
| 3678 | } |
| 3679 | |
| 3680 | mDisplays.erase(displayToken); |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3681 | |
| 3682 | if (display && display->isVirtual()) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 3683 | static_cast<void>(mScheduler->schedule([display = std::move(display)] { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3684 | // Destroy the display without holding the mStateLock. |
| 3685 | // This is a temporary solution until we can manage transaction queues without |
| 3686 | // holding the mStateLock. |
| 3687 | // With blast, the IGBP that is passed to the VirtualDisplaySurface is owned by the |
| 3688 | // client. When the IGBP is disconnected, its buffer cache in SF will be cleared |
| 3689 | // via SurfaceComposerClient::doUncacheBufferTransaction. This call from the client |
| 3690 | // ends up running on the main thread causing a deadlock since setTransactionstate |
| 3691 | // will try to acquire the mStateLock. Instead we extend the lifetime of |
| 3692 | // DisplayDevice and destroy it in the main thread without holding the mStateLock. |
| 3693 | // The display will be disconnected and removed from the mDisplays list so it will |
| 3694 | // not be accessible. |
| 3695 | })); |
| 3696 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3697 | } |
| 3698 | |
| 3699 | void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, |
| 3700 | const DisplayDeviceState& currentState, |
| 3701 | const DisplayDeviceState& drawingState) { |
| 3702 | const sp<IBinder> currentBinder = IInterface::asBinder(currentState.surface); |
| 3703 | const sp<IBinder> drawingBinder = IInterface::asBinder(drawingState.surface); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3704 | |
| 3705 | // Recreate the DisplayDevice if the surface or sequence ID changed. |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3706 | if (currentBinder != drawingBinder || currentState.sequenceId != drawingState.sequenceId) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3707 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3708 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3709 | if (display->isVirtual()) { |
| 3710 | releaseVirtualDisplay(display->getVirtualId()); |
| 3711 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3712 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3713 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3714 | mDisplays.erase(displayToken); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3715 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3716 | if (const auto& physical = currentState.physical) { |
| 3717 | getHwComposer().allocatePhysicalDisplay(physical->hwcDisplayId, physical->id); |
| 3718 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3719 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3720 | processDisplayAdded(displayToken, currentState); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3721 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3722 | if (currentState.physical) { |
Marin Shalamanov | 4c5e301 | 2020-06-04 21:41:42 +0200 | [diff] [blame] | 3723 | const auto display = getDisplayDeviceLocked(displayToken); |
| 3724 | setPowerModeInternal(display, hal::PowerMode::ON); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3725 | |
| 3726 | // TODO(b/175678251) Call a listener instead. |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 3727 | if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) { |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 3728 | resetPhaseConfiguration(display->getActiveMode().fps); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3729 | } |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3730 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3731 | return; |
| 3732 | } |
| 3733 | |
| 3734 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3735 | if (currentState.layerStack != drawingState.layerStack) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3736 | display->setLayerFilter( |
| 3737 | makeLayerFilterForDisplay(display->getId(), currentState.layerStack)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3738 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 3739 | if (currentState.flags != drawingState.flags) { |
| 3740 | display->setFlags(currentState.flags); |
| 3741 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3742 | if ((currentState.orientation != drawingState.orientation) || |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3743 | (currentState.layerStackSpaceRect != drawingState.layerStackSpaceRect) || |
| 3744 | (currentState.orientedDisplaySpaceRect != drawingState.orientedDisplaySpaceRect)) { |
| 3745 | display->setProjection(currentState.orientation, currentState.layerStackSpaceRect, |
| 3746 | currentState.orientedDisplaySpaceRect); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3747 | if (display->getId() == mActiveDisplayId) { |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 3748 | mActiveDisplayTransformHint = display->getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 3749 | sActiveDisplayRotationFlags = |
| 3750 | ui::Transform::toRotationFlags(display->getOrientation()); |
Arthur Hung | b6aa9a0 | 2021-06-09 14:23:01 +0800 | [diff] [blame] | 3751 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3752 | } |
| 3753 | if (currentState.width != drawingState.width || |
| 3754 | currentState.height != drawingState.height) { |
| 3755 | display->setDisplaySize(currentState.width, currentState.height); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 3756 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3757 | if (display->getId() == mActiveDisplayId) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 3758 | onActiveDisplaySizeChanged(*display); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3759 | } |
| 3760 | } |
| 3761 | } |
| 3762 | } |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 3763 | |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 3764 | void SurfaceFlinger::resetPhaseConfiguration(Fps refreshRate) { |
| 3765 | // Cancel the pending refresh rate change, if any, before updating the phase configuration. |
| 3766 | mScheduler->vsyncModulator().cancelRefreshRateChange(); |
| 3767 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3768 | mVsyncConfiguration->reset(); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3769 | updatePhaseConfiguration(refreshRate); |
| 3770 | mRefreshRateStats->setRefreshRate(refreshRate); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3771 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3772 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3773 | void SurfaceFlinger::processDisplayChangesLocked() { |
| 3774 | // here we take advantage of Vector's copy-on-write semantics to |
| 3775 | // improve performance by skipping the transaction entirely when |
| 3776 | // know that the lists are identical |
| 3777 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays); |
| 3778 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays); |
| 3779 | if (!curr.isIdenticalTo(draw)) { |
| 3780 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3781 | mUpdateInputInfo = true; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3782 | |
| 3783 | // find the displays that were removed |
| 3784 | // (ie: in drawing state but not in current state) |
| 3785 | // also handle displays that changed |
| 3786 | // (ie: displays that are in both lists) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3787 | for (size_t i = 0; i < draw.size(); i++) { |
| 3788 | const wp<IBinder>& displayToken = draw.keyAt(i); |
| 3789 | const ssize_t j = curr.indexOfKey(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3790 | if (j < 0) { |
| 3791 | // in drawing state but not in current state |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3792 | processDisplayRemoved(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3793 | } else { |
| 3794 | // this display is in both lists. see if something changed. |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3795 | const DisplayDeviceState& currentState = curr[j]; |
| 3796 | const DisplayDeviceState& drawingState = draw[i]; |
| 3797 | processDisplayChanged(displayToken, currentState, drawingState); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3798 | } |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | // find displays that were added |
| 3802 | // (ie: in current state but not in drawing state) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3803 | for (size_t i = 0; i < curr.size(); i++) { |
| 3804 | const wp<IBinder>& displayToken = curr.keyAt(i); |
| 3805 | if (draw.indexOfKey(displayToken) < 0) { |
| 3806 | processDisplayAdded(displayToken, curr[i]); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3807 | } |
| 3808 | } |
| 3809 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3810 | |
| 3811 | mDrawingState.displays = mCurrentState.displays; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3812 | } |
| 3813 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3814 | void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { |
| 3815 | // Commit display transactions. |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3816 | const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3817 | mFrontEndDisplayInfosChanged = displayTransactionNeeded; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3818 | if (displayTransactionNeeded && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3819 | processDisplayChangesLocked(); |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 3820 | mFrontEndDisplayInfos.clear(); |
| 3821 | for (const auto& [_, display] : mDisplays) { |
| 3822 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 3823 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3824 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 3825 | mForceTransactionDisplayChange = displayTransactionNeeded; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3826 | |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3827 | if (mSomeChildrenChanged) { |
| 3828 | mVisibleRegionsDirty = true; |
| 3829 | mSomeChildrenChanged = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3830 | mUpdateInputInfo = true; |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3833 | // Update transform hint. |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 3834 | if (transactionFlags & (eTransformHintUpdateNeeded | eDisplayTransactionNeeded)) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3835 | // 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] | 3836 | // |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 3837 | // 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] | 3838 | // the hint is set before we acquire a buffer from the surface texture. |
| 3839 | // |
| 3840 | // NOTE: layer transactions have taken place already, so we use their |
| 3841 | // drawing state. However, SurfaceFlinger's own transaction has not |
| 3842 | // happened yet, so we must use the current state layer list |
| 3843 | // (soon to become the drawing state list). |
| 3844 | // |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3845 | sp<const DisplayDevice> hintDisplay; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3846 | ui::LayerStack layerStack; |
| 3847 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3848 | mCurrentState.traverse([&](Layer* layer) REQUIRES(mStateLock) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3849 | // NOTE: we rely on the fact that layers are sorted by |
| 3850 | // layerStack first (so we don't have to traverse the list |
| 3851 | // of displays for every layer). |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3852 | if (const auto filter = layer->getOutputFilter(); layerStack != filter.layerStack) { |
| 3853 | layerStack = filter.layerStack; |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3854 | hintDisplay = nullptr; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3855 | |
| 3856 | // Find the display that includes the layer. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3857 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3858 | if (!display->getCompositionDisplay()->includesLayer(filter)) { |
| 3859 | continue; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3860 | } |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3861 | |
| 3862 | // Pick the primary display if another display mirrors the layer. |
| 3863 | if (hintDisplay) { |
| 3864 | hintDisplay = nullptr; |
| 3865 | break; |
| 3866 | } |
| 3867 | |
| 3868 | hintDisplay = display; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3869 | } |
| 3870 | } |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 3871 | |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3872 | if (!hintDisplay) { |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3873 | // NOTE: TEMPORARY FIX ONLY. Real fix should cause layers to |
| 3874 | // redraw after transform hint changes. See bug 8508397. |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3875 | // could be null when this layer is using a layerStack |
| 3876 | // that is not visible on any display. Also can occur at |
| 3877 | // screen off/on times. |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3878 | // U Update: Don't provide stale hints to the clients. For |
| 3879 | // special cases where we want the app to draw its |
| 3880 | // first frame before the display is available, we rely |
| 3881 | // on WMS and DMS to provide the right information |
| 3882 | // so the client can calculate the hint. |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3883 | layer->skipReportingTransformHint(); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3884 | } else { |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3885 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3886 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3887 | }); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3888 | } |
| 3889 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3890 | if (mLayersAdded) { |
| 3891 | mLayersAdded = false; |
| 3892 | // Layers have been added. |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3893 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3894 | mUpdateInputInfo = true; |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3895 | } |
| 3896 | |
| 3897 | // some layers might have been removed, so |
| 3898 | // we need to update the regions they're exposing. |
| 3899 | if (mLayersRemoved) { |
| 3900 | mLayersRemoved = false; |
| 3901 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3902 | mUpdateInputInfo = true; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3903 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3904 | if (mLayersPendingRemoval.indexOf(sp<Layer>::fromExisting(layer)) >= 0) { |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3905 | // this layer is not visible anymore |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3906 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3907 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3908 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 3909 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3910 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3911 | } |
| 3912 | |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 3913 | if (transactionFlags & eInputInfoUpdateNeeded) { |
| 3914 | mUpdateInputInfo = true; |
| 3915 | } |
| 3916 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3917 | doCommitTransactions(); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 3918 | } |
| 3919 | |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3920 | void SurfaceFlinger::updateInputFlinger(VsyncId vsyncId, TimePoint frameTime) { |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3921 | if (!mInputFlinger || (!mUpdateInputInfo && mInputWindowCommands.empty())) { |
Vishnu Nair | 42a27b5 | 2021-11-18 15:35:22 -0800 | [diff] [blame] | 3922 | return; |
| 3923 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3924 | ATRACE_CALL(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3925 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3926 | std::vector<WindowInfo> windowInfos; |
| 3927 | std::vector<DisplayInfo> displayInfos; |
| 3928 | bool updateWindowInfo = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3929 | if (mUpdateInputInfo) { |
| 3930 | mUpdateInputInfo = false; |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3931 | updateWindowInfo = true; |
| 3932 | buildWindowInfos(windowInfos, displayInfos); |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3933 | } |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3934 | |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3935 | std::unordered_set<int32_t> visibleWindowIds; |
| 3936 | for (WindowInfo& windowInfo : windowInfos) { |
| 3937 | if (!windowInfo.inputConfig.test(WindowInfo::InputConfig::NOT_VISIBLE)) { |
| 3938 | visibleWindowIds.insert(windowInfo.id); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3939 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3940 | } |
| 3941 | bool visibleWindowsChanged = false; |
| 3942 | if (visibleWindowIds != mVisibleWindowIds) { |
| 3943 | visibleWindowsChanged = true; |
| 3944 | mVisibleWindowIds = std::move(visibleWindowIds); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3945 | } |
| 3946 | |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 3947 | BackgroundExecutor::getInstance().sendCallbacks({[updateWindowInfo, |
| 3948 | windowInfos = std::move(windowInfos), |
| 3949 | displayInfos = std::move(displayInfos), |
| 3950 | inputWindowCommands = |
| 3951 | std::move(mInputWindowCommands), |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3952 | inputFlinger = mInputFlinger, this, |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3953 | visibleWindowsChanged, vsyncId, frameTime]() { |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3954 | ATRACE_NAME("BackgroundExecutor::updateInputFlinger"); |
| 3955 | if (updateWindowInfo) { |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 3956 | mWindowInfosListenerInvoker |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3957 | ->windowInfosChanged(gui::WindowInfosUpdate{std::move(windowInfos), |
| 3958 | std::move(displayInfos), |
| 3959 | ftl::to_underlying(vsyncId), |
| 3960 | frameTime.ns()}, |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3961 | std::move( |
| 3962 | inputWindowCommands.windowInfosReportedListeners), |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3963 | /* forceImmediateCall= */ visibleWindowsChanged || |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3964 | !inputWindowCommands.focusRequests.empty()); |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 3965 | } else { |
| 3966 | // If there are listeners but no changes to input windows, call the listeners |
| 3967 | // immediately. |
| 3968 | for (const auto& listener : inputWindowCommands.windowInfosReportedListeners) { |
| 3969 | if (IInterface::asBinder(listener)->isBinderAlive()) { |
| 3970 | listener->onWindowInfosReported(); |
| 3971 | } |
| 3972 | } |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3973 | } |
| 3974 | for (const auto& focusRequest : inputWindowCommands.focusRequests) { |
| 3975 | inputFlinger->setFocusedWindow(focusRequest); |
| 3976 | } |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 3977 | }}); |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 3978 | |
Arthur Hung | 6cbb975 | 2019-09-05 16:38:18 +0800 | [diff] [blame] | 3979 | mInputWindowCommands.clear(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3980 | } |
| 3981 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3982 | void SurfaceFlinger::persistDisplayBrightness(bool needsComposite) { |
| 3983 | const bool supportsDisplayBrightnessCommand = getHwComposer().getComposer()->isSupported( |
| 3984 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 3985 | if (!supportsDisplayBrightnessCommand) { |
| 3986 | return; |
| 3987 | } |
| 3988 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3989 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3990 | if (const auto brightness = display->getStagedBrightness(); brightness) { |
| 3991 | if (!needsComposite) { |
| 3992 | const status_t error = |
| 3993 | getHwComposer() |
| 3994 | .setDisplayBrightness(display->getPhysicalId(), *brightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 3995 | display->getCompositionDisplay() |
| 3996 | ->getState() |
| 3997 | .displayBrightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3998 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 3999 | .applyImmediately = true}) |
| 4000 | .get(); |
| 4001 | |
| 4002 | ALOGE_IF(error != NO_ERROR, |
| 4003 | "Error setting display brightness for display %s: %d (%s)", |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 4004 | to_string(display->getId()).c_str(), error, strerror(error)); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4005 | } |
| 4006 | display->persistBrightness(needsComposite); |
| 4007 | } |
| 4008 | } |
| 4009 | } |
| 4010 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4011 | void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, |
| 4012 | std::vector<DisplayInfo>& outDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4013 | static size_t sNumWindowInfos = 0; |
| 4014 | outWindowInfos.reserve(sNumWindowInfos); |
| 4015 | sNumWindowInfos = 0; |
| 4016 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4017 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4018 | mLayerSnapshotBuilder.forEachInputSnapshot( |
| 4019 | [&outWindowInfos](const frontend::LayerSnapshot& snapshot) { |
| 4020 | outWindowInfos.push_back(snapshot.inputInfo); |
| 4021 | }); |
| 4022 | } else { |
| 4023 | mDrawingState.traverseInReverseZOrder([&](Layer* layer) { |
| 4024 | if (!layer->needsInputInfo()) return; |
| 4025 | const auto opt = |
| 4026 | mFrontEndDisplayInfos.get(layer->getLayerStack()) |
| 4027 | .transform([](const frontend::DisplayInfo& info) { |
| 4028 | return Layer::InputDisplayArgs{&info.transform, info.isSecure}; |
| 4029 | }); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4030 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4031 | outWindowInfos.push_back(layer->fillInputInfo(opt.value_or(Layer::InputDisplayArgs{}))); |
| 4032 | }); |
| 4033 | } |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 4034 | |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4035 | sNumWindowInfos = outWindowInfos.size(); |
| 4036 | |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 4037 | outDisplayInfos.reserve(mFrontEndDisplayInfos.size()); |
| 4038 | for (const auto& [_, info] : mFrontEndDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4039 | outDisplayInfos.push_back(info.info); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 4040 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 4041 | } |
| 4042 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 4043 | void SurfaceFlinger::updateCursorAsync() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4044 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4045 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 4046 | if (HalDisplayId::tryCast(display->getId())) { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4047 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 4048 | } |
| 4049 | } |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 4050 | |
| 4051 | constexpr bool kCursorOnly = true; |
| 4052 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4053 | mCompositionEngine->updateCursorAsync(refreshArgs); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4054 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4055 | } |
| 4056 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 4057 | void SurfaceFlinger::requestHardwareVsync(PhysicalDisplayId displayId, bool enable) { |
| 4058 | getHwComposer().setVsyncEnabled(displayId, enable ? hal::Vsync::ENABLE : hal::Vsync::DISABLE); |
| 4059 | } |
| 4060 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4061 | void SurfaceFlinger::requestDisplayModes(std::vector<display::DisplayModeRequest> modeRequests) { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 4062 | if (mBootStage != BootStage::FINISHED) { |
| 4063 | ALOGV("Currently in the boot stage, skipping display mode changes"); |
| 4064 | return; |
| 4065 | } |
| 4066 | |
| 4067 | ATRACE_CALL(); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4068 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 4069 | // If this is called from the main thread mStateLock must be locked before |
| 4070 | // 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] | 4071 | // Scheduler::chooseRefreshRateForContent |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 4072 | |
| 4073 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
Marin Shalamanov | a63f9ae | 2021-11-03 15:05:16 +0100 | [diff] [blame] | 4074 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4075 | for (auto& request : modeRequests) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4076 | const auto& modePtr = request.mode.modePtr; |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 4077 | |
| 4078 | const auto displayId = modePtr->getPhysicalDisplayId(); |
| 4079 | const auto display = getDisplayDeviceLocked(displayId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4080 | |
| 4081 | if (!display) continue; |
| 4082 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 4083 | if (ftl::FakeGuard guard(kMainThreadContext); |
| 4084 | !shouldApplyRefreshRateSelectorPolicy(*display)) { |
| 4085 | ALOGV("%s(%s): Skipped applying policy", __func__, to_string(displayId).c_str()); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 4086 | continue; |
| 4087 | } |
| 4088 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4089 | if (display->refreshRateSelector().isModeAllowed(request.mode)) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 4090 | setDesiredMode(std::move(request)); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4091 | } else { |
| 4092 | ALOGV("%s: Mode %d is disallowed for display %s", __func__, modePtr->getId().value(), |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 4093 | to_string(displayId).c_str()); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4094 | } |
| 4095 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 4096 | } |
| 4097 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 4098 | void SurfaceFlinger::triggerOnFrameRateOverridesChanged() { |
| 4099 | PhysicalDisplayId displayId = [&]() { |
| 4100 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 4101 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 4102 | }(); |
| 4103 | |
| 4104 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
| 4105 | } |
| 4106 | |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 4107 | void SurfaceFlinger::notifyCpuLoadUp() { |
| 4108 | mPowerAdvisor->notifyCpuLoadUp(); |
| 4109 | } |
| 4110 | |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 4111 | void SurfaceFlinger::onChoreographerAttached() { |
| 4112 | ATRACE_CALL(); |
| 4113 | if (mLayerLifecycleManagerEnabled) { |
| 4114 | mUpdateAttachedChoreographer = true; |
| 4115 | scheduleCommit(FrameHint::kNone); |
| 4116 | } |
| 4117 | } |
| 4118 | |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4119 | void SurfaceFlinger::onVsyncGenerated(TimePoint expectedPresentTime, |
| 4120 | ftl::NonNull<DisplayModePtr> modePtr, Fps renderRate) { |
| 4121 | const auto vsyncPeriod = modePtr->getVsyncRate().getPeriod(); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4122 | const auto timeoutOpt = [&]() -> std::optional<Period> { |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4123 | const auto vrrConfig = modePtr->getVrrConfig(); |
| 4124 | if (!vrrConfig) return std::nullopt; |
| 4125 | |
| 4126 | const auto notifyExpectedPresentConfig = |
| 4127 | modePtr->getVrrConfig()->notifyExpectedPresentConfig; |
| 4128 | if (!notifyExpectedPresentConfig) return std::nullopt; |
| 4129 | return Period::fromNs(notifyExpectedPresentConfig->notifyExpectedPresentTimeoutNs); |
| 4130 | }(); |
| 4131 | |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4132 | notifyExpectedPresentIfRequired(modePtr->getPhysicalDisplayId(), vsyncPeriod, |
| 4133 | expectedPresentTime, renderRate, timeoutOpt); |
| 4134 | } |
| 4135 | |
| 4136 | void SurfaceFlinger::notifyExpectedPresentIfRequired(PhysicalDisplayId displayId, |
| 4137 | Period vsyncPeriod, |
| 4138 | TimePoint expectedPresentTime, |
| 4139 | Fps frameInterval, |
| 4140 | std::optional<Period> timeoutOpt) { |
| 4141 | { |
| 4142 | auto& data = mNotifyExpectedPresentMap[displayId]; |
| 4143 | const auto lastExpectedPresentTimestamp = data.lastExpectedPresentTimestamp.load(); |
| 4144 | const auto lastFrameInterval = data.lastFrameInterval; |
| 4145 | data.lastFrameInterval = frameInterval; |
| 4146 | const auto threshold = Duration::fromNs(vsyncPeriod.ns() / 2); |
| 4147 | |
| 4148 | const constexpr nsecs_t kOneSecondNs = |
| 4149 | std::chrono::duration_cast<std::chrono::nanoseconds>(1s).count(); |
| 4150 | const auto timeout = Period::fromNs(timeoutOpt && timeoutOpt->ns() > 0 ? timeoutOpt->ns() |
| 4151 | : kOneSecondNs); |
| 4152 | const bool frameIntervalIsOnCadence = |
| 4153 | isFrameIntervalOnCadence(expectedPresentTime, lastExpectedPresentTimestamp, |
| 4154 | lastFrameInterval, timeout, threshold); |
| 4155 | |
| 4156 | const bool expectedPresentWithinTimeout = |
| 4157 | isExpectedPresentWithinTimeout(expectedPresentTime, lastExpectedPresentTimestamp, |
| 4158 | timeoutOpt, threshold); |
| 4159 | |
| 4160 | using fps_approx_ops::operator!=; |
| 4161 | if (frameIntervalIsOnCadence && frameInterval != lastFrameInterval) { |
| 4162 | data.lastExpectedPresentTimestamp = expectedPresentTime; |
| 4163 | } |
| 4164 | |
| 4165 | if (expectedPresentWithinTimeout && frameIntervalIsOnCadence) { |
| 4166 | return; |
| 4167 | } |
| 4168 | data.lastExpectedPresentTimestamp = expectedPresentTime; |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4169 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4170 | |
| 4171 | const char* const whence = __func__; |
| 4172 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 4173 | const auto status = getHwComposer().notifyExpectedPresent(displayId, expectedPresentTime, |
| 4174 | frameInterval); |
| 4175 | if (status != NO_ERROR) { |
| 4176 | ALOGE("%s failed to notifyExpectedPresentHint for display %" PRId64, whence, |
| 4177 | displayId.value); |
| 4178 | } |
| 4179 | })); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4180 | } |
| 4181 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 4182 | void SurfaceFlinger::initScheduler(const sp<const DisplayDevice>& display) { |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4183 | using namespace scheduler; |
| 4184 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 4185 | LOG_ALWAYS_FATAL_IF(mScheduler); |
| 4186 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4187 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 4188 | const Fps activeRefreshRate = activeMode.fps; |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 4189 | mRefreshRateStats = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4190 | std::make_unique<RefreshRateStats>(*mTimeStats, activeRefreshRate, hal::PowerMode::OFF); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4191 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 4192 | mVsyncConfiguration = getFactory().createVsyncConfiguration(activeRefreshRate); |
Ady Abraham | 9e16a48 | 2019-12-03 17:19:41 -0800 | [diff] [blame] | 4193 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4194 | FeatureFlags features; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4195 | |
Ady Abraham | 3f84c50 | 2023-11-30 18:18:06 -0800 | [diff] [blame] | 4196 | const auto defaultContentDetectionValue = |
| 4197 | FlagManager::getInstance().enable_fro_dependent_features() && |
| 4198 | sysprop::enable_frame_rate_override(true); |
| 4199 | if (sysprop::use_content_detection_for_refresh_rate(defaultContentDetectionValue)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4200 | features |= Feature::kContentDetection; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 4201 | if (FlagManager::getInstance().enable_small_area_detection()) { |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 4202 | features |= Feature::kSmallDirtyContentDetection; |
| 4203 | } |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4204 | } |
| 4205 | if (base::GetBoolProperty("debug.sf.show_predicted_vsync"s, false)) { |
| 4206 | features |= Feature::kTracePredictedVsync; |
| 4207 | } |
| 4208 | if (!base::GetBoolProperty("debug.sf.vsync_reactor_ignore_present_fences"s, false) && |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 4209 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4210 | features |= Feature::kPresentFences; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4211 | } |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4212 | if (display->refreshRateSelector().kernelIdleTimerController()) { |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4213 | features |= Feature::kKernelIdleTimer; |
| 4214 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4215 | if (mBackpressureGpuComposition) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4216 | features |= Feature::kBackpressureGpuComposition; |
| 4217 | } |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4218 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4219 | auto modulatorPtr = sp<VsyncModulator>::make(mVsyncConfiguration->getCurrentConfigs()); |
| 4220 | |
| 4221 | mScheduler = std::make_unique<Scheduler>(static_cast<ICompositor&>(*this), |
| 4222 | static_cast<ISchedulerCallback&>(*this), features, |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4223 | std::move(modulatorPtr), |
| 4224 | static_cast<IVsyncTrackerCallback&>(*this)); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4225 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector()); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4226 | if (FlagManager::getInstance().vrr_config()) { |
| 4227 | mScheduler->setRenderRate(display->getPhysicalId(), activeMode.fps); |
| 4228 | } |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4229 | mScheduler->startTimers(); |
| 4230 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 4231 | const auto configs = mVsyncConfiguration->getCurrentConfigs(); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4232 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4233 | mAppConnectionHandle = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4234 | mScheduler->createEventThread(Scheduler::Cycle::Render, |
| 4235 | mFrameTimeline->getTokenManager(), |
| 4236 | /* workDuration */ configs.late.appWorkDuration, |
| 4237 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4238 | mSfConnectionHandle = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4239 | mScheduler->createEventThread(Scheduler::Cycle::LastComposite, |
| 4240 | mFrameTimeline->getTokenManager(), |
| 4241 | /* workDuration */ activeRefreshRate.getPeriod(), |
| 4242 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4243 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4244 | mScheduler->initVsync(mScheduler->getVsyncSchedule()->getDispatch(), |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 4245 | *mFrameTimeline->getTokenManager(), configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4246 | |
| 4247 | mRegionSamplingThread = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4248 | sp<RegionSamplingThread>::make(*this, |
| 4249 | RegionSamplingThread::EnvironmentTimingTunables()); |
| 4250 | mFpsReporter = sp<FpsReporter>::make(*mFrameTimeline, *this); |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 4251 | |
| 4252 | mIsHotplugErrViaNegVsync = |
| 4253 | base::GetBoolProperty("debug.sf.hwc_hotplug_error_via_neg_vsync"s, false); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4254 | } |
| 4255 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4256 | void SurfaceFlinger::updatePhaseConfiguration(Fps refreshRate) { |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 4257 | mVsyncConfiguration->setRefreshRateFps(refreshRate); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4258 | mScheduler->setVsyncConfigSet(mVsyncConfiguration->getCurrentConfigs(), |
| 4259 | refreshRate.getPeriod()); |
Dominik Laskowski | 08d05c2 | 2020-07-22 00:05:08 -0700 | [diff] [blame] | 4260 | } |
| 4261 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4262 | void SurfaceFlinger::doCommitTransactions() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 4263 | ATRACE_CALL(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4264 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4265 | if (!mLayersPendingRemoval.isEmpty()) { |
| 4266 | // Notify removed layers now that they can't be drawn from |
| 4267 | for (const auto& l : mLayersPendingRemoval) { |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4268 | // Ensure any buffers set to display on any children are released. |
| 4269 | if (l->isRemovedFromCurrentState()) { |
| 4270 | l->latchAndReleaseBuffer(); |
| 4271 | } |
| 4272 | |
chaviw | 6852bff | 2022-04-19 17:35:11 -0500 | [diff] [blame] | 4273 | // If a layer has a parent, we allow it to out-live it's handle |
| 4274 | // with the idea that the parent holds a reference and will eventually |
| 4275 | // be cleaned up. However no one cleans up the top-level so we do so |
| 4276 | // here. |
| 4277 | if (l->isAtRoot()) { |
| 4278 | l->setIsAtRoot(false); |
| 4279 | mCurrentState.layersSortedByZ.remove(l); |
| 4280 | } |
| 4281 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4282 | // If the layer has been removed and has no parent, then it will not be reachable |
| 4283 | // when traversing layers on screen. Add the layer to the offscreenLayers set to |
| 4284 | // ensure we can copy its current to drawing state. |
| 4285 | if (!l->getParent()) { |
| 4286 | mOffscreenLayers.emplace(l.get()); |
| 4287 | } |
| 4288 | } |
| 4289 | mLayersPendingRemoval.clear(); |
| 4290 | } |
| 4291 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4292 | mDrawingState = mCurrentState; |
| 4293 | // clear the "changed" flags in current state |
| 4294 | mCurrentState.colorMatrixChanged = false; |
| 4295 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4296 | if (mVisibleRegionsDirty) { |
| 4297 | for (const auto& rootLayer : mDrawingState.layersSortedByZ) { |
| 4298 | rootLayer->commitChildList(); |
| 4299 | } |
Andrei Stanciu | dadac5a | 2020-08-05 17:02:34 +0300 | [diff] [blame] | 4300 | } |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4301 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4302 | commitOffscreenLayers(); |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4303 | if (mLayerMirrorRoots.size() > 0) { |
| 4304 | std::deque<Layer*> pendingUpdates; |
| 4305 | pendingUpdates.insert(pendingUpdates.end(), mLayerMirrorRoots.begin(), |
| 4306 | mLayerMirrorRoots.end()); |
| 4307 | std::vector<Layer*> needsUpdating; |
| 4308 | for (Layer* cloneRoot : mLayerMirrorRoots) { |
| 4309 | pendingUpdates.pop_front(); |
| 4310 | if (cloneRoot->isRemovedFromCurrentState()) { |
| 4311 | continue; |
| 4312 | } |
| 4313 | if (cloneRoot->updateMirrorInfo(pendingUpdates)) { |
| 4314 | } else { |
| 4315 | needsUpdating.push_back(cloneRoot); |
| 4316 | } |
| 4317 | } |
| 4318 | for (Layer* cloneRoot : needsUpdating) { |
| 4319 | cloneRoot->updateMirrorInfo({}); |
| 4320 | } |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4321 | } |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4322 | } |
| 4323 | |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4324 | void SurfaceFlinger::commitOffscreenLayers() { |
| 4325 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4326 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, [](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4327 | if (layer->clearTransactionFlags(eTransactionNeeded)) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4328 | layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4329 | layer->commitChildList(); |
| 4330 | } |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4331 | }); |
| 4332 | } |
| 4333 | } |
| 4334 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4335 | void SurfaceFlinger::invalidateLayerStack(const ui::LayerFilter& layerFilter, const Region& dirty) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4336 | for (const auto& [token, displayDevice] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4337 | auto display = displayDevice->getCompositionDisplay(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4338 | if (display->includesLayer(layerFilter)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4339 | display->editState().dirtyRegion.orSelf(dirty); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 4340 | } |
| 4341 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 4342 | } |
| 4343 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4344 | bool SurfaceFlinger::latchBuffers() { |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 4345 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 4346 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4347 | const nsecs_t latchTime = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4348 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4349 | bool visibleRegions = false; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4350 | bool frameQueued = false; |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4351 | bool newDataLatched = false; |
Eric Penner | 51c59cd | 2014-07-28 19:51:58 -0700 | [diff] [blame] | 4352 | |
| 4353 | // Store the set of layers that need updates. This set must not change as |
| 4354 | // buffers are being latched, as this could result in a deadlock. |
| 4355 | // Example: Two producers share the same command stream and: |
| 4356 | // 1.) Layer 0 is latched |
| 4357 | // 2.) Layer 0 gets a new frame |
| 4358 | // 2.) Layer 1 gets a new frame |
| 4359 | // 3.) Layer 1 is latched. |
| 4360 | // Display is now waiting on Layer 1's frame, which is behind layer 0's |
| 4361 | // 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] | 4362 | mDrawingState.traverse([&](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4363 | if (layer->clearTransactionFlags(eTransactionNeeded) || mForceTransactionDisplayChange) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4364 | const uint32_t flags = layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4365 | if (flags & Layer::eVisibleRegion) { |
| 4366 | mVisibleRegionsDirty = true; |
| 4367 | } |
| 4368 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4369 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4370 | if (layer->hasReadyFrame() || layer->willReleaseBufferOnLatch()) { |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4371 | frameQueued = true; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4372 | mLayersWithQueuedFrames.emplace(sp<Layer>::fromExisting(layer)); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4373 | } else { |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 4374 | layer->useEmptyDamage(); |
Vishnu Nair | c09c023 | 2023-03-02 03:22:35 +0000 | [diff] [blame] | 4375 | if (!layer->hasBuffer()) { |
| 4376 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 4377 | // instead of a missed frame. This is used to identify scenarios where we |
| 4378 | // could not latch a buffer or apply a transaction due to backpressure. |
| 4379 | // We only update the latch time for buffer less layers here, the latch time |
| 4380 | // is updated for buffer layers when the buffer is latched. |
| 4381 | layer->updateLastLatchTime(latchTime); |
| 4382 | } |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4383 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4384 | }); |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4385 | mForceTransactionDisplayChange = false; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4386 | |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4387 | // The client can continue submitting buffers for offscreen layers, but they will not |
| 4388 | // be shown on screen. Therefore, we need to latch and release buffers of offscreen |
| 4389 | // layers to ensure dequeueBuffer doesn't block indefinitely. |
| 4390 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4391 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4392 | [&](Layer* l) { l->latchAndReleaseBuffer(); }); |
| 4393 | } |
| 4394 | |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4395 | if (!mLayersWithQueuedFrames.empty()) { |
| 4396 | // mStateLock is needed for latchBuffer as LayerRejecter::reject() |
| 4397 | // writes to Layer current state. See also b/119481871 |
| 4398 | Mutex::Autolock lock(mStateLock); |
| 4399 | |
Alec Mouri | 2f7d9ae | 2020-11-30 19:32:33 -0800 | [diff] [blame] | 4400 | for (const auto& layer : mLayersWithQueuedFrames) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4401 | if (layer->willReleaseBufferOnLatch()) { |
| 4402 | mLayersWithBuffersRemoved.emplace(layer); |
| 4403 | } |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 4404 | if (layer->latchBuffer(visibleRegions, latchTime)) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4405 | mLayersPendingRefresh.push_back(layer); |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4406 | newDataLatched = true; |
| 4407 | } |
Vishnu Nair | 1b70019 | 2022-02-04 10:09:47 -0800 | [diff] [blame] | 4408 | layer->useSurfaceDamage(); |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4409 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4410 | } |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 4411 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 4412 | mVisibleRegionsDirty |= visibleRegions; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4413 | |
| 4414 | // If we will need to wake up at some time in the future to deal with a |
| 4415 | // queued frame that shouldn't be displayed during this vsync period, wake |
| 4416 | // up during the next vsync period to check again. |
Chia-I Wu | a36bf92 | 2017-06-30 12:51:05 -0700 | [diff] [blame] | 4417 | if (frameQueued && (mLayersWithQueuedFrames.empty() || !newDataLatched)) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4418 | scheduleCommit(FrameHint::kNone); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4419 | } |
| 4420 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 4421 | // enter boot animation on first buffer latch |
| 4422 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 4423 | ALOGI("Enter boot animation"); |
| 4424 | mBootStage = BootStage::BOOTANIMATION; |
| 4425 | } |
| 4426 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4427 | if (mLayerMirrorRoots.size() > 0) { |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4428 | mDrawingState.traverse([&](Layer* layer) { layer->updateCloneBufferInfo(); }); |
| 4429 | } |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 4430 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4431 | // 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] | 4432 | return !mLayersWithQueuedFrames.empty() && newDataLatched; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4433 | } |
| 4434 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4435 | status_t SurfaceFlinger::addClientLayer(LayerCreationArgs& args, const sp<IBinder>& handle, |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4436 | const sp<Layer>& layer, const wp<Layer>& parent, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4437 | uint32_t* outTransformHint) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4438 | if (mNumLayers >= MAX_LAYERS) { |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4439 | ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(), |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4440 | MAX_LAYERS); |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 4441 | static_cast<void>(mScheduler->schedule([=, this] { |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4442 | ALOGE("Dumping layer keeping > 20 children alive:"); |
| 4443 | bool leakingParentLayerFound = false; |
| 4444 | mDrawingState.traverse([&](Layer* layer) { |
| 4445 | if (leakingParentLayerFound) { |
| 4446 | return; |
| 4447 | } |
| 4448 | if (layer->getChildrenCount() > 20) { |
| 4449 | leakingParentLayerFound = true; |
| 4450 | sp<Layer> parent = sp<Layer>::fromExisting(layer); |
| 4451 | while (parent) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4452 | ALOGE("Parent Layer: %s%s", parent->getName().c_str(), |
| 4453 | (parent->isHandleAlive() ? "handleAlive" : "")); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4454 | parent = parent->getParent(); |
| 4455 | } |
| 4456 | // Sample up to 100 layers |
| 4457 | ALOGE("Dumping random sampling of child layers total(%zu): ", |
| 4458 | layer->getChildrenCount()); |
| 4459 | int sampleSize = (layer->getChildrenCount() / 100) + 1; |
| 4460 | layer->traverseChildren([&](Layer* layer) { |
| 4461 | if (rand() % sampleSize == 0) { |
jiayongqiang | c476a34 | 2023-12-06 17:04:54 +0800 | [diff] [blame] | 4462 | ALOGE("Child Layer: %s%s", layer->getName().c_str(), |
| 4463 | (layer->isHandleAlive() ? "handleAlive" : "")); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4464 | } |
| 4465 | }); |
| 4466 | } |
| 4467 | }); |
| 4468 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4469 | int numLayers = 0; |
| 4470 | mDrawingState.traverse([&](Layer* layer) { numLayers++; }); |
| 4471 | |
| 4472 | ALOGE("Dumping random sampling of on-screen layers total(%u):", numLayers); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4473 | mDrawingState.traverse([&](Layer* layer) { |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4474 | // Aim to dump about 200 layers to avoid totally trashing |
| 4475 | // logcat. On the other hand, if there really are 4096 layers |
| 4476 | // something has gone totally wrong its probably the most |
| 4477 | // useful information in logcat. |
| 4478 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4479 | ALOGE("Layer: %s%s", layer->getName().c_str(), |
| 4480 | (layer->isHandleAlive() ? "handleAlive" : "")); |
| 4481 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4482 | } |
| 4483 | }); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4484 | ALOGE("Dumping random sampling of off-screen layers total(%zu): ", |
| 4485 | mOffscreenLayers.size()); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4486 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 4487 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4488 | ALOGE("Offscreen-layer: %s%s", offscreenLayer->getName().c_str(), |
| 4489 | (offscreenLayer->isHandleAlive() ? "handleAlive" : "")); |
| 4490 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4491 | } |
| 4492 | } |
| 4493 | })); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4494 | return NO_MEMORY; |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4495 | } |
| 4496 | |
Vishnu Nair | 86e1190 | 2022-09-06 16:03:27 +0000 | [diff] [blame] | 4497 | layer->updateTransformHint(mActiveDisplayTransformHint); |
| 4498 | if (outTransformHint) { |
| 4499 | *outTransformHint = mActiveDisplayTransformHint; |
| 4500 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4501 | args.parentId = LayerHandle::getLayerId(args.parentHandle.promote()); |
| 4502 | args.layerIdToMirror = LayerHandle::getLayerId(args.mirrorLayerHandle.promote()); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4503 | { |
| 4504 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4505 | mCreatedLayers.emplace_back(layer, parent, args.addToRoot); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4506 | mNewLayers.emplace_back(std::make_unique<frontend::RequestedLayerState>(args)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 4507 | args.mirrorLayerHandle.clear(); |
| 4508 | args.parentHandle.clear(); |
| 4509 | mNewLayerArgs.emplace_back(std::move(args)); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4510 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4511 | |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4512 | setTransactionFlags(eTransactionNeeded); |
| 4513 | return NO_ERROR; |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 4514 | } |
| 4515 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4516 | uint32_t SurfaceFlinger::getTransactionFlags() const { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 4517 | return mTransactionFlags; |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 4518 | } |
| 4519 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4520 | uint32_t SurfaceFlinger::clearTransactionFlags(uint32_t mask) { |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4521 | uint32_t transactionFlags = mTransactionFlags.fetch_and(~mask); |
| 4522 | ATRACE_INT("mTransactionFlags", transactionFlags); |
| 4523 | return transactionFlags & mask; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4524 | } |
| 4525 | |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4526 | void SurfaceFlinger::setTransactionFlags(uint32_t mask, TransactionSchedule schedule, |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4527 | const sp<IBinder>& applyToken, FrameHint frameHint) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4528 | mScheduler->modulateVsync({}, &VsyncModulator::setTransactionSchedule, schedule, applyToken); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4529 | uint32_t transactionFlags = mTransactionFlags.fetch_or(mask); |
| 4530 | ATRACE_INT("mTransactionFlags", transactionFlags); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4531 | |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4532 | if (const bool scheduled = transactionFlags & mask; !scheduled) { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4533 | scheduleCommit(frameHint); |
Ady Abraham | 27bcb55 | 2023-01-21 04:34:22 +0000 | [diff] [blame] | 4534 | } else if (frameHint == FrameHint::kActive) { |
| 4535 | // Even if the next frame is already scheduled, we should reset the idle timer |
| 4536 | // as a new activity just happened. |
| 4537 | mScheduler->resetIdleTimer(); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4538 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4539 | } |
| 4540 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4541 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyTimelineCheck( |
| 4542 | const TransactionHandler::TransactionFlushState& flushState) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 4543 | const auto& transaction = *flushState.transaction; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4544 | |
| 4545 | const TimePoint desiredPresentTime = TimePoint::fromNs(transaction.desiredPresentTime); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 4546 | const TimePoint expectedPresentTime = mScheduler->expectedPresentTimeForPacesetter(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4547 | |
| 4548 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4549 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4550 | // Do not present if the desiredPresentTime has not passed unless it is more than |
| 4551 | // one second in the future. We ignore timestamps more than 1 second in the future |
| 4552 | // for stability reasons. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4553 | if (!transaction.isAutoTimestamp && desiredPresentTime >= expectedPresentTime && |
| 4554 | desiredPresentTime < expectedPresentTime + 1s) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4555 | ATRACE_FORMAT("not current desiredPresentTime: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4556 | desiredPresentTime, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4557 | return TransactionReadiness::NotReady; |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4558 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4559 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4560 | if (!mScheduler->isVsyncValid(expectedPresentTime, transaction.originUid)) { |
| 4561 | ATRACE_FORMAT("!isVsyncValid expectedPresentTime: %" PRId64 " uid: %d", expectedPresentTime, |
| 4562 | transaction.originUid); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4563 | return TransactionReadiness::NotReady; |
| 4564 | } |
| 4565 | |
| 4566 | // If the client didn't specify desiredPresentTime, use the vsyncId to determine the |
| 4567 | // expected present time of this transaction. |
| 4568 | if (transaction.isAutoTimestamp && |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4569 | frameIsEarly(expectedPresentTime, VsyncId{transaction.frameTimelineInfo.vsyncId})) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4570 | ATRACE_FORMAT("frameIsEarly vsyncId: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4571 | transaction.frameTimelineInfo.vsyncId, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4572 | return TransactionReadiness::NotReady; |
| 4573 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4574 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4575 | return TransactionReadiness::Ready; |
| 4576 | } |
| 4577 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4578 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheckLegacy( |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4579 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4580 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4581 | auto ready = TransactionReadiness::Ready; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4582 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const ResolvedComposerState& |
| 4583 | resolvedState) -> bool { |
| 4584 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 4585 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4586 | const auto& transaction = *flushState.transaction; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4587 | const auto& s = resolvedState.state; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4588 | // check for barrier frames |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4589 | if (s.bufferData->hasBarrier) { |
| 4590 | // The current producerId is already a newer producer than the buffer that has a |
| 4591 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4592 | // 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] | 4593 | if (layer->getDrawingState().barrierProducerId > s.bufferData->producerId) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4594 | layer->callReleaseBufferCallback(s.bufferData->releaseBufferListener, |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4595 | resolvedState.externalTexture->getBuffer(), |
Chavi Weingarten | c8bcb68 | 2023-03-06 22:20:42 +0000 | [diff] [blame] | 4596 | s.bufferData->frameNumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4597 | s.bufferData->acquireFence); |
| 4598 | // Delete the entire state at this point and not just release the buffer because |
| 4599 | // 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] | 4600 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", |
| 4601 | layer->getDebugName(), layer->getDrawingState().barrierProducerId, |
| 4602 | s.bufferData->producerId); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4603 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4604 | } |
| 4605 | |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 4606 | if (layer->getDrawingState().barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4607 | const bool willApplyBarrierFrame = |
| 4608 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4609 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4610 | s.bufferData->barrierFrameNumber)); |
| 4611 | if (!willApplyBarrierFrame) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4612 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4613 | layer->getDebugName(), |
| 4614 | layer->getDrawingState().barrierFrameNumber, |
| 4615 | s.bufferData->barrierFrameNumber); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4616 | ready = TransactionReadiness::NotReadyBarrier; |
| 4617 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4618 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4619 | } |
| 4620 | } |
| 4621 | |
| 4622 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4623 | // the transaction in the queue. |
| 4624 | const bool hasPendingBuffer = |
| 4625 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4626 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4627 | ATRACE_FORMAT("hasPendingBuffer %s", layer->getDebugName()); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4628 | ready = TransactionReadiness::NotReady; |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4629 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4630 | } |
| 4631 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4632 | const bool acquireFenceAvailable = s.bufferData && |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4633 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4634 | s.bufferData->acquireFence; |
Ying Wei | 1fd9bfc | 2023-06-29 16:47:00 +0000 | [diff] [blame] | 4635 | const bool fenceSignaled = !acquireFenceAvailable || |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4636 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4637 | if (!fenceSignaled) { |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4638 | // check fence status |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4639 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(s, transaction.states.size(), |
| 4640 | flushState.firstTransaction) && |
| 4641 | layer->isSimpleBufferUpdate(s); |
| 4642 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4643 | if (allowLatchUnsignaled) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4644 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", |
| 4645 | layer->getDebugName()); |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4646 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4647 | } else { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4648 | ready = TransactionReadiness::NotReady; |
| 4649 | auto& listener = s.bufferData->releaseBufferListener; |
| 4650 | if (listener && |
| 4651 | (flushState.queueProcessTime - transaction.postTime) > |
| 4652 | std::chrono::nanoseconds(4s).count()) { |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 4653 | mTransactionHandler |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 4654 | .onTransactionQueueStalled(transaction.id, |
| 4655 | {.pid = layer->getOwnerPid(), |
| 4656 | .layerId = static_cast<uint32_t>( |
| 4657 | layer->getSequence()), |
| 4658 | .layerName = layer->getDebugName(), |
| 4659 | .bufferId = s.bufferData->getId(), |
| 4660 | .frameNumber = s.bufferData->frameNumber}); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4661 | } |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4662 | ATRACE_FORMAT("fence unsignaled %s", layer->getDebugName()); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4663 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4664 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4665 | } |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4666 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4667 | }); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4668 | return ready; |
| 4669 | } |
| 4670 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4671 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheck( |
| 4672 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4673 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4674 | auto ready = TransactionReadiness::Ready; |
| 4675 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const ResolvedComposerState& |
| 4676 | resolvedState) -> bool { |
| 4677 | const frontend::RequestedLayerState* layer = |
| 4678 | mLayerLifecycleManager.getLayerFromId(resolvedState.layerId); |
| 4679 | const auto& transaction = *flushState.transaction; |
| 4680 | const auto& s = resolvedState.state; |
| 4681 | // check for barrier frames |
| 4682 | if (s.bufferData->hasBarrier) { |
| 4683 | // The current producerId is already a newer producer than the buffer that has a |
| 4684 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4685 | // don't wait on the barrier since we know that's stale information. |
| 4686 | if (layer->barrierProducerId > s.bufferData->producerId) { |
| 4687 | if (s.bufferData->releaseBufferListener) { |
| 4688 | uint32_t currentMaxAcquiredBufferCount = |
| 4689 | getMaxAcquiredBufferCountForCurrentRefreshRate(layer->ownerUid.val()); |
| 4690 | ATRACE_FORMAT_INSTANT("callReleaseBufferCallback %s - %" PRIu64, |
| 4691 | layer->name.c_str(), s.bufferData->frameNumber); |
| 4692 | s.bufferData->releaseBufferListener |
| 4693 | ->onReleaseBuffer({resolvedState.externalTexture->getBuffer()->getId(), |
| 4694 | s.bufferData->frameNumber}, |
| 4695 | s.bufferData->acquireFence |
| 4696 | ? s.bufferData->acquireFence |
| 4697 | : Fence::NO_FENCE, |
| 4698 | currentMaxAcquiredBufferCount); |
| 4699 | } |
| 4700 | |
| 4701 | // Delete the entire state at this point and not just release the buffer because |
| 4702 | // everything associated with the Layer in this Transaction is now out of date. |
| 4703 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", layer->name.c_str(), |
| 4704 | layer->barrierProducerId, s.bufferData->producerId); |
| 4705 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4706 | } |
| 4707 | |
| 4708 | if (layer->barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
| 4709 | const bool willApplyBarrierFrame = |
| 4710 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4711 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4712 | s.bufferData->barrierFrameNumber)); |
| 4713 | if (!willApplyBarrierFrame) { |
| 4714 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4715 | layer->name.c_str(), layer->barrierFrameNumber, |
| 4716 | s.bufferData->barrierFrameNumber); |
| 4717 | ready = TransactionReadiness::NotReadyBarrier; |
| 4718 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4719 | } |
| 4720 | } |
| 4721 | } |
| 4722 | |
| 4723 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4724 | // the transaction in the queue. |
| 4725 | const bool hasPendingBuffer = |
| 4726 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4727 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
| 4728 | ATRACE_FORMAT("hasPendingBuffer %s", layer->name.c_str()); |
| 4729 | ready = TransactionReadiness::NotReady; |
| 4730 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4731 | } |
| 4732 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4733 | const bool acquireFenceAvailable = s.bufferData && |
| 4734 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4735 | s.bufferData->acquireFence; |
Ying Wei | 1fd9bfc | 2023-06-29 16:47:00 +0000 | [diff] [blame] | 4736 | const bool fenceSignaled = !acquireFenceAvailable || |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4737 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
| 4738 | if (!fenceSignaled) { |
| 4739 | // check fence status |
| 4740 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(s, transaction.states.size(), |
| 4741 | flushState.firstTransaction) && |
| 4742 | layer->isSimpleBufferUpdate(s); |
| 4743 | if (allowLatchUnsignaled) { |
| 4744 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", layer->name.c_str()); |
| 4745 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4746 | } else { |
| 4747 | ready = TransactionReadiness::NotReady; |
| 4748 | auto& listener = s.bufferData->releaseBufferListener; |
| 4749 | if (listener && |
| 4750 | (flushState.queueProcessTime - transaction.postTime) > |
| 4751 | std::chrono::nanoseconds(4s).count()) { |
| 4752 | mTransactionHandler |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 4753 | .onTransactionQueueStalled(transaction.id, |
| 4754 | {.pid = layer->ownerPid.val(), |
| 4755 | .layerId = layer->id, |
| 4756 | .layerName = layer->name, |
| 4757 | .bufferId = s.bufferData->getId(), |
| 4758 | .frameNumber = s.bufferData->frameNumber}); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4759 | } |
| 4760 | ATRACE_FORMAT("fence unsignaled %s", layer->name.c_str()); |
| 4761 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4762 | } |
| 4763 | } |
| 4764 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
| 4765 | }); |
| 4766 | return ready; |
| 4767 | } |
| 4768 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4769 | void SurfaceFlinger::addTransactionReadyFilters() { |
| 4770 | mTransactionHandler.addTransactionReadyFilter( |
| 4771 | std::bind(&SurfaceFlinger::transactionReadyTimelineCheck, this, std::placeholders::_1)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4772 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4773 | mTransactionHandler.addTransactionReadyFilter( |
| 4774 | std::bind(&SurfaceFlinger::transactionReadyBufferCheck, this, |
| 4775 | std::placeholders::_1)); |
| 4776 | } else { |
| 4777 | mTransactionHandler.addTransactionReadyFilter( |
| 4778 | std::bind(&SurfaceFlinger::transactionReadyBufferCheckLegacy, this, |
| 4779 | std::placeholders::_1)); |
| 4780 | } |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4781 | } |
| 4782 | |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4783 | // For tests only |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4784 | bool SurfaceFlinger::flushTransactionQueues(VsyncId vsyncId) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4785 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4786 | std::vector<TransactionState> transactions = mTransactionHandler.flushTransactions(); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4787 | return applyTransactions(transactions, vsyncId); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4788 | } |
| 4789 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4790 | bool SurfaceFlinger::applyTransactions(std::vector<TransactionState>& transactions, |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4791 | VsyncId vsyncId) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 4792 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4793 | return applyTransactionsLocked(transactions, vsyncId); |
| 4794 | } |
| 4795 | |
| 4796 | bool SurfaceFlinger::applyTransactionsLocked(std::vector<TransactionState>& transactions, |
| 4797 | VsyncId vsyncId) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4798 | bool needsTraversal = false; |
| 4799 | // Now apply all transactions. |
Robert Carr | ff7663b | 2022-02-08 12:46:49 -0800 | [diff] [blame] | 4800 | for (auto& transaction : transactions) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4801 | needsTraversal |= |
| 4802 | applyTransactionState(transaction.frameTimelineInfo, transaction.states, |
| 4803 | transaction.displays, transaction.flags, |
| 4804 | transaction.inputWindowCommands, |
| 4805 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4806 | std::move(transaction.uncacheBufferIds), transaction.postTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4807 | transaction.hasListenerCallbacks, |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4808 | transaction.listenerCallbacks, transaction.originPid, |
| 4809 | transaction.originUid, transaction.id); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4810 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4811 | return needsTraversal; |
Marissa Wall | e6e3c0d | 2019-03-29 10:28:30 -0700 | [diff] [blame] | 4812 | } |
| 4813 | |
| 4814 | bool SurfaceFlinger::transactionFlushNeeded() { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4815 | return mTransactionHandler.hasPendingTransactions(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4816 | } |
| 4817 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4818 | bool SurfaceFlinger::frameIsEarly(TimePoint expectedPresentTime, VsyncId vsyncId) const { |
| 4819 | const auto prediction = |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 4820 | mFrameTimeline->getTokenManager()->getPredictionsForToken(ftl::to_underlying(vsyncId)); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4821 | if (!prediction) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4822 | return false; |
| 4823 | } |
| 4824 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4825 | const auto predictedPresentTime = TimePoint::fromNs(prediction->presentTime); |
| 4826 | |
Rachel Lee | 0655a91 | 2023-04-20 19:54:18 -0700 | [diff] [blame] | 4827 | if (std::chrono::abs(predictedPresentTime - expectedPresentTime) >= |
| 4828 | scheduler::VsyncConfig::kEarlyLatchMaxThreshold) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4829 | return false; |
| 4830 | } |
| 4831 | |
Ady Abraham | 3db8a3c | 2023-11-20 17:53:47 -0800 | [diff] [blame] | 4832 | const Duration earlyLatchVsyncThreshold = mScheduler->getVsyncSchedule()->minFramePeriod() / 2; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4833 | |
| 4834 | return predictedPresentTime >= expectedPresentTime && |
| 4835 | predictedPresentTime - expectedPresentTime >= earlyLatchVsyncThreshold; |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4836 | } |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4837 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4838 | bool SurfaceFlinger::shouldLatchUnsignaled(const layer_state_t& state, size_t numStates, |
| 4839 | bool firstTransaction) const { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4840 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Disabled) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4841 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::Disabled)", __func__); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4842 | return false; |
| 4843 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4844 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4845 | // We only want to latch unsignaled when a single layer is updated in this |
| 4846 | // transaction (i.e. not a blast sync transaction). |
| 4847 | if (numStates != 1) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4848 | ATRACE_FORMAT_INSTANT("%s: false (numStates=%zu)", __func__, numStates); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4849 | return false; |
| 4850 | } |
| 4851 | |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4852 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::AutoSingleLayer) { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4853 | if (!firstTransaction) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4854 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; not first " |
| 4855 | "transaction)", |
| 4856 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4857 | return false; |
| 4858 | } |
| 4859 | |
| 4860 | // We don't want to latch unsignaled if are in early / client composition |
| 4861 | // as it leads to jank due to RenderEngine waiting for unsignaled buffer |
| 4862 | // or window animations being slow. |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 4863 | if (mScheduler->vsyncModulator().isVsyncConfigEarly()) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4864 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; " |
| 4865 | "isVsyncConfigEarly)", |
| 4866 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4867 | return false; |
| 4868 | } |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4869 | } |
| 4870 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4871 | return true; |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4872 | } |
| 4873 | |
chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 4874 | status_t SurfaceFlinger::setTransactionState( |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4875 | const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 4876 | const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4877 | InputWindowCommands inputWindowCommands, int64_t desiredPresentTime, bool isAutoTimestamp, |
| 4878 | const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 4879 | const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId, |
| 4880 | const std::vector<uint64_t>& mergedTransactionIds) { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 4881 | ATRACE_CALL(); |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 4882 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4883 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4884 | const int originPid = ipc->getCallingPid(); |
| 4885 | const int originUid = ipc->getCallingUid(); |
| 4886 | uint32_t permissions = LayerStatePermissions::getTransactionPermissions(originPid, originUid); |
| 4887 | for (auto composerState : states) { |
| 4888 | composerState.state.sanitize(permissions); |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4889 | } |
| 4890 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4891 | for (DisplayState display : displays) { |
| 4892 | display.sanitize(permissions); |
| 4893 | } |
| 4894 | |
| 4895 | if (!inputWindowCommands.empty() && |
| 4896 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) == 0) { |
| 4897 | ALOGE("Only privileged callers are allowed to send input commands."); |
| 4898 | inputWindowCommands.clear(); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 4899 | } |
| 4900 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 4901 | if (flags & (eEarlyWakeupStart | eEarlyWakeupEnd)) { |
| 4902 | const bool hasPermission = |
| 4903 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) || |
| 4904 | callingThreadHasPermission(sWakeupSurfaceFlinger); |
| 4905 | if (!hasPermission) { |
| 4906 | ALOGE("Caller needs permission android.permission.WAKEUP_SURFACE_FLINGER to use " |
| 4907 | "eEarlyWakeup[Start|End] flags"); |
| 4908 | flags &= ~(eEarlyWakeupStart | eEarlyWakeupEnd); |
| 4909 | } |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 4910 | } |
| 4911 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4912 | const int64_t postTime = systemTime(); |
| 4913 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4914 | std::vector<uint64_t> uncacheBufferIds; |
| 4915 | uncacheBufferIds.reserve(uncacheBuffers.size()); |
| 4916 | for (const auto& uncacheBuffer : uncacheBuffers) { |
| 4917 | sp<GraphicBuffer> buffer = ClientCache::getInstance().erase(uncacheBuffer); |
| 4918 | if (buffer != nullptr) { |
| 4919 | uncacheBufferIds.push_back(buffer->getId()); |
| 4920 | } |
| 4921 | } |
| 4922 | |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4923 | std::vector<ResolvedComposerState> resolvedStates; |
| 4924 | resolvedStates.reserve(states.size()); |
| 4925 | for (auto& state : states) { |
| 4926 | resolvedStates.emplace_back(std::move(state)); |
| 4927 | auto& resolvedState = resolvedStates.back(); |
| 4928 | if (resolvedState.state.hasBufferChanges() && resolvedState.state.hasValidBuffer() && |
| 4929 | resolvedState.state.surface) { |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 4930 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 4931 | std::string layerName = (layer) ? |
| 4932 | layer->getDebugName() : std::to_string(resolvedState.state.layerId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4933 | resolvedState.externalTexture = |
| 4934 | getExternalTextureFromBufferData(*resolvedState.state.bufferData, |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 4935 | layerName.c_str(), transactionId); |
Patrick Williams | 38d920e | 2023-08-31 17:31:18 -0500 | [diff] [blame] | 4936 | if (resolvedState.externalTexture) { |
| 4937 | resolvedState.state.bufferData->buffer = resolvedState.externalTexture->getBuffer(); |
| 4938 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4939 | mBufferCountTracker.increment(resolvedState.state.surface->localBinder()); |
| 4940 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4941 | resolvedState.layerId = LayerHandle::getLayerId(resolvedState.state.surface); |
| 4942 | if (resolvedState.state.what & layer_state_t::eReparent) { |
| 4943 | resolvedState.parentId = |
| 4944 | getLayerIdFromSurfaceControl(resolvedState.state.parentSurfaceControlForChild); |
| 4945 | } |
| 4946 | if (resolvedState.state.what & layer_state_t::eRelativeLayerChanged) { |
| 4947 | resolvedState.relativeParentId = |
| 4948 | getLayerIdFromSurfaceControl(resolvedState.state.relativeLayerSurfaceControl); |
| 4949 | } |
| 4950 | if (resolvedState.state.what & layer_state_t::eInputInfoChanged) { |
| 4951 | wp<IBinder>& touchableRegionCropHandle = |
| 4952 | resolvedState.state.windowInfoHandle->editInfo()->touchableRegionCropHandle; |
| 4953 | resolvedState.touchCropId = |
| 4954 | LayerHandle::getLayerId(touchableRegionCropHandle.promote()); |
| 4955 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4956 | } |
| 4957 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4958 | TransactionState state{frameTimelineInfo, |
| 4959 | resolvedStates, |
| 4960 | displays, |
| 4961 | flags, |
| 4962 | applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4963 | std::move(inputWindowCommands), |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4964 | desiredPresentTime, |
| 4965 | isAutoTimestamp, |
| 4966 | std::move(uncacheBufferIds), |
| 4967 | postTime, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4968 | hasListenerCallbacks, |
| 4969 | listenerCallbacks, |
| 4970 | originPid, |
| 4971 | originUid, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 4972 | transactionId, |
| 4973 | mergedTransactionIds}; |
Vishnu Nair | 83df034 | 2021-03-30 11:50:44 -0700 | [diff] [blame] | 4974 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 4975 | if (mTransactionTracing) { |
| 4976 | mTransactionTracing->addQueuedTransaction(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4977 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4978 | |
| 4979 | const auto schedule = [](uint32_t flags) { |
| 4980 | if (flags & eEarlyWakeupEnd) return TransactionSchedule::EarlyEnd; |
| 4981 | if (flags & eEarlyWakeupStart) return TransactionSchedule::EarlyStart; |
| 4982 | return TransactionSchedule::Late; |
| 4983 | }(state.flags); |
| 4984 | |
| 4985 | const auto frameHint = state.isFrameActive() ? FrameHint::kActive : FrameHint::kNone; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4986 | mTransactionHandler.queueTransaction(std::move(state)); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4987 | setTransactionFlags(eTransactionFlushNeeded, schedule, applyToken, frameHint); |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 4988 | return NO_ERROR; |
| 4989 | } |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4990 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4991 | bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4992 | std::vector<ResolvedComposerState>& states, |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 4993 | Vector<DisplayState>& displays, uint32_t flags, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4994 | const InputWindowCommands& inputWindowCommands, |
| 4995 | const int64_t desiredPresentTime, bool isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4996 | const std::vector<uint64_t>& uncacheBufferIds, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4997 | const int64_t postTime, bool hasListenerCallbacks, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4998 | const std::vector<ListenerCallbacks>& listenerCallbacks, |
| 4999 | int originPid, int originUid, uint64_t transactionId) { |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 5000 | uint32_t transactionFlags = 0; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5001 | if (!mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5002 | for (DisplayState& display : displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5003 | transactionFlags |= setDisplayStateLocked(display); |
| 5004 | } |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 5005 | } |
| 5006 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5007 | // start and end registration for listeners w/ no surface so they can get their callback. Note |
| 5008 | // that listeners with SurfaceControls will start registration during setClientStateLocked |
| 5009 | // below. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5010 | for (const auto& listener : listenerCallbacks) { |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5011 | mTransactionCallbackInvoker.addEmptyTransaction(listener); |
Marissa Wall | d600d57 | 2019-03-26 15:38:50 -0700 | [diff] [blame] | 5012 | } |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 5013 | nsecs_t now = systemTime(); |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5014 | uint32_t clientStateFlags = 0; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5015 | for (auto& resolvedState : states) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5016 | if (mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5017 | clientStateFlags |= |
| 5018 | setClientStateLocked(frameTimelineInfo, resolvedState, desiredPresentTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5019 | isAutoTimestamp, postTime, transactionId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5020 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5021 | } else /*mLayerLifecycleManagerEnabled*/ { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5022 | clientStateFlags |= updateLayerCallbacksAndStats(frameTimelineInfo, resolvedState, |
| 5023 | desiredPresentTime, isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5024 | postTime, transactionId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5025 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5026 | if ((flags & eAnimation) && resolvedState.state.surface) { |
| 5027 | if (const auto layer = LayerHandle::getLayer(resolvedState.state.surface)) { |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5028 | const auto layerProps = scheduler::LayerProps{ |
| 5029 | .visible = layer->isVisible(), |
| 5030 | .bounds = layer->getBounds(), |
| 5031 | .transform = layer->getTransform(), |
| 5032 | .setFrameRateVote = layer->getFrameRateForLayerTree(), |
| 5033 | .frameRateSelectionPriority = layer->getFrameRateSelectionPriority(), |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 5034 | .isFrontBuffered = layer->isFrontBuffered(), |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5035 | }; |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 5036 | layer->recordLayerHistoryAnimationTx(layerProps, now); |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 5037 | } |
| 5038 | } |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 5039 | } |
| 5040 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5041 | transactionFlags |= clientStateFlags; |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5042 | transactionFlags |= addInputWindowCommands(inputWindowCommands); |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5043 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5044 | for (uint64_t uncacheBufferId : uncacheBufferIds) { |
| 5045 | mBufferIdsToUncache.push_back(uncacheBufferId); |
Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 5046 | } |
| 5047 | |
Jorim Jaggi | bdcf09c | 2017-08-08 15:22:08 +0200 | [diff] [blame] | 5048 | // If a synchronous transaction is explicitly requested without any changes, force a transaction |
| 5049 | // anyway. This can be used as a flush mechanism for previous async transactions. |
| 5050 | // Empty animation transaction can be used to simulate back-pressure, so also force a |
| 5051 | // transaction for empty animation transactions. |
Vishnu Nair | 1523dad | 2022-09-29 16:05:18 -0700 | [diff] [blame] | 5052 | if (transactionFlags == 0 && (flags & eAnimation)) { |
Robert Carr | 2a7dbb4 | 2016-05-24 11:41:28 -0700 | [diff] [blame] | 5053 | transactionFlags = eTransactionNeeded; |
| 5054 | } |
| 5055 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5056 | bool needsTraversal = false; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 5057 | if (transactionFlags) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5058 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 5059 | // 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] | 5060 | if (transactionFlags & eTraversalNeeded) { |
| 5061 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5062 | needsTraversal = true; |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 5063 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5064 | if (transactionFlags) { |
| 5065 | setTransactionFlags(transactionFlags); |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 5066 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5067 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5068 | |
| 5069 | return needsTraversal; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5070 | } |
| 5071 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5072 | bool SurfaceFlinger::applyAndCommitDisplayTransactionStates( |
| 5073 | std::vector<TransactionState>& transactions) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5074 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5075 | bool needsTraversal = false; |
| 5076 | uint32_t transactionFlags = 0; |
| 5077 | for (auto& transaction : transactions) { |
| 5078 | for (DisplayState& display : transaction.displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5079 | transactionFlags |= setDisplayStateLocked(display); |
| 5080 | } |
| 5081 | } |
| 5082 | |
| 5083 | if (transactionFlags) { |
| 5084 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 5085 | // so we don't have to wake up again next frame to perform an unnecessary traversal. |
| 5086 | if (transactionFlags & eTraversalNeeded) { |
| 5087 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
| 5088 | needsTraversal = true; |
| 5089 | } |
| 5090 | if (transactionFlags) { |
| 5091 | setTransactionFlags(transactionFlags); |
| 5092 | } |
| 5093 | } |
| 5094 | |
| 5095 | mFrontEndDisplayInfosChanged = mTransactionFlags & eDisplayTransactionNeeded; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5096 | if (mFrontEndDisplayInfosChanged && !mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5097 | processDisplayChangesLocked(); |
| 5098 | mFrontEndDisplayInfos.clear(); |
| 5099 | for (const auto& [_, display] : mDisplays) { |
| 5100 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 5101 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5102 | needsTraversal = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5103 | } |
| 5104 | |
| 5105 | return needsTraversal; |
| 5106 | } |
| 5107 | |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5108 | uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s) { |
| 5109 | const ssize_t index = mCurrentState.displays.indexOfKey(s.token); |
| 5110 | if (index < 0) return 0; |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 5111 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5112 | uint32_t flags = 0; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5113 | DisplayDeviceState& state = mCurrentState.displays.editValueAt(index); |
| 5114 | |
| 5115 | const uint32_t what = s.what; |
| 5116 | if (what & DisplayState::eSurfaceChanged) { |
| 5117 | if (IInterface::asBinder(state.surface) != IInterface::asBinder(s.surface)) { |
| 5118 | state.surface = s.surface; |
| 5119 | flags |= eDisplayTransactionNeeded; |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 5120 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5121 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5122 | if (what & DisplayState::eLayerStackChanged) { |
| 5123 | if (state.layerStack != s.layerStack) { |
| 5124 | state.layerStack = s.layerStack; |
| 5125 | flags |= eDisplayTransactionNeeded; |
| 5126 | } |
| 5127 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 5128 | if (what & DisplayState::eFlagsChanged) { |
| 5129 | if (state.flags != s.flags) { |
| 5130 | state.flags = s.flags; |
| 5131 | flags |= eDisplayTransactionNeeded; |
| 5132 | } |
| 5133 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5134 | if (what & DisplayState::eDisplayProjectionChanged) { |
| 5135 | if (state.orientation != s.orientation) { |
| 5136 | state.orientation = s.orientation; |
| 5137 | flags |= eDisplayTransactionNeeded; |
| 5138 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5139 | if (state.orientedDisplaySpaceRect != s.orientedDisplaySpaceRect) { |
| 5140 | state.orientedDisplaySpaceRect = s.orientedDisplaySpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5141 | flags |= eDisplayTransactionNeeded; |
| 5142 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5143 | if (state.layerStackSpaceRect != s.layerStackSpaceRect) { |
| 5144 | state.layerStackSpaceRect = s.layerStackSpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5145 | flags |= eDisplayTransactionNeeded; |
| 5146 | } |
| 5147 | } |
| 5148 | if (what & DisplayState::eDisplaySizeChanged) { |
| 5149 | if (state.width != s.width) { |
| 5150 | state.width = s.width; |
| 5151 | flags |= eDisplayTransactionNeeded; |
| 5152 | } |
| 5153 | if (state.height != s.height) { |
| 5154 | state.height = s.height; |
| 5155 | flags |= eDisplayTransactionNeeded; |
| 5156 | } |
| 5157 | } |
| 5158 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5159 | return flags; |
| 5160 | } |
| 5161 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5162 | bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5163 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5164 | const int pid = ipc->getCallingPid(); |
| 5165 | const int uid = ipc->getCallingUid(); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5166 | if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) && |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5167 | (usePermissionCache ? !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid) |
| 5168 | : !checkPermission(sAccessSurfaceFlinger, pid, uid))) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5169 | return false; |
| 5170 | } |
| 5171 | return true; |
| 5172 | } |
| 5173 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5174 | uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5175 | ResolvedComposerState& composerState, |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5176 | int64_t desiredPresentTime, bool isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5177 | int64_t postTime, uint64_t transactionId) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5178 | layer_state_t& s = composerState.state; |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5179 | |
| 5180 | std::vector<ListenerCallbacks> filteredListeners; |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5181 | for (auto& listener : s.listeners) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5182 | // Starts a registration but separates the callback ids according to callback type. This |
| 5183 | // allows the callback invoker to send on latch callbacks earlier. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5184 | // note that startRegistration will not re-register if the listener has |
| 5185 | // already be registered for a prior surface control |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5186 | |
| 5187 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5188 | if (!onCommitCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5189 | filteredListeners.push_back(onCommitCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5190 | } |
| 5191 | |
| 5192 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5193 | if (!onCompleteCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5194 | filteredListeners.push_back(onCompleteCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5195 | } |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5196 | } |
| 5197 | |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 5198 | const uint64_t what = s.what; |
| 5199 | uint32_t flags = 0; |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 5200 | sp<Layer> layer = nullptr; |
| 5201 | if (s.surface) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5202 | layer = LayerHandle::getLayer(s.surface); |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 5203 | } else { |
| 5204 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5205 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5206 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5207 | if (layer == nullptr) { |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5208 | for (auto& [listener, callbackIds] : s.listeners) { |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 5209 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5210 | callbackIds, |
| 5211 | s.surface), |
| 5212 | std::vector<JankData>()); |
Marissa Wall | 88e2048 | 2019-06-24 10:49:42 -0700 | [diff] [blame] | 5213 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5214 | return 0; |
| 5215 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 5216 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5217 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 5218 | ui::LayerStack oldLayerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5219 | |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 5220 | // Only set by BLAST adapter layers |
| 5221 | if (what & layer_state_t::eProducerDisconnect) { |
| 5222 | layer->onDisconnect(); |
| 5223 | } |
| 5224 | |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5225 | if (what & layer_state_t::ePositionChanged) { |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 5226 | if (layer->setPosition(s.x, s.y)) { |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5227 | flags |= eTraversalNeeded; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5228 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5229 | } |
| 5230 | if (what & layer_state_t::eLayerChanged) { |
| 5231 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5232 | const auto& p = layer->getParent(); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5233 | if (p == nullptr) { |
chaviw | 64f7b42 | 2017-07-12 10:31:58 -0700 | [diff] [blame] | 5234 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5235 | if (layer->setLayer(s.z) && idx >= 0) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5236 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5237 | mCurrentState.layersSortedByZ.add(layer); |
| 5238 | // we need traversal (state changed) |
| 5239 | // AND transaction (list changed) |
| 5240 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5241 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5242 | } else { |
| 5243 | if (p->setChildLayer(layer, s.z)) { |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 5244 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5245 | } |
| 5246 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5247 | } |
| 5248 | if (what & layer_state_t::eRelativeLayerChanged) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5249 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5250 | const auto& p = layer->getParent(); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5251 | const auto& relativeHandle = s.relativeLayerSurfaceControl ? |
| 5252 | s.relativeLayerSurfaceControl->getHandle() : nullptr; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5253 | if (p == nullptr) { |
| 5254 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5255 | if (layer->setRelativeLayer(relativeHandle, s.z) && |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5256 | idx >= 0) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5257 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5258 | mCurrentState.layersSortedByZ.add(layer); |
| 5259 | // we need traversal (state changed) |
| 5260 | // AND transaction (list changed) |
| 5261 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5262 | } |
| 5263 | } else { |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5264 | if (p->setChildRelativeLayer(layer, relativeHandle, s.z)) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5265 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5266 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5267 | } |
| 5268 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5269 | if (what & layer_state_t::eAlphaChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5270 | if (layer->setAlpha(s.color.a)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5271 | } |
| 5272 | if (what & layer_state_t::eColorChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5273 | if (layer->setColor(s.color.rgb)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5274 | } |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 5275 | if (what & layer_state_t::eColorTransformChanged) { |
| 5276 | if (layer->setColorTransform(s.colorTransform)) { |
| 5277 | flags |= eTraversalNeeded; |
| 5278 | } |
| 5279 | } |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5280 | if (what & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5281 | if (layer->setBackgroundColor(s.bgColor.rgb, s.bgColor.a, s.bgColorDataspace)) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5282 | flags |= eTraversalNeeded; |
| 5283 | } |
| 5284 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5285 | if (what & layer_state_t::eMatrixChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5286 | if (layer->setMatrix(s.matrix)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5287 | } |
| 5288 | if (what & layer_state_t::eTransparentRegionChanged) { |
| 5289 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 5290 | flags |= eTraversalNeeded; |
| 5291 | } |
| 5292 | if (what & layer_state_t::eFlagsChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5293 | if (layer->setFlags(s.flags, s.mask)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5294 | } |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 5295 | if (what & layer_state_t::eCornerRadiusChanged) { |
| 5296 | if (layer->setCornerRadius(s.cornerRadius)) |
| 5297 | flags |= eTraversalNeeded; |
| 5298 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5299 | if (what & layer_state_t::eBackgroundBlurRadiusChanged && mSupportsBlur) { |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5300 | if (layer->setBackgroundBlurRadius(s.backgroundBlurRadius)) flags |= eTraversalNeeded; |
| 5301 | } |
Galia Peycheva | e11d575 | 2021-01-22 13:50:16 +0000 | [diff] [blame] | 5302 | if (what & layer_state_t::eBlurRegionsChanged) { |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5303 | if (layer->setBlurRegions(s.blurRegions)) flags |= eTraversalNeeded; |
| 5304 | } |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 5305 | if (what & layer_state_t::eRenderBorderChanged) { |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 5306 | if (layer->enableBorder(s.borderEnabled, s.borderWidth, s.borderColor)) { |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 5307 | flags |= eTraversalNeeded; |
| 5308 | } |
| 5309 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5310 | if (what & layer_state_t::eLayerStackChanged) { |
| 5311 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 5312 | // We only allow setting layer stacks for top level layers, |
| 5313 | // everything else inherits layer stack from its parent. |
| 5314 | if (layer->hasParent()) { |
| 5315 | 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] | 5316 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5317 | } else if (idx < 0) { |
| 5318 | ALOGE("Attempt to set layer stack on layer without parent (%s) that " |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5319 | "that also does not appear in the top level layer list. Something" |
| 5320 | " has gone wrong.", |
| 5321 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5322 | } else if (layer->setLayerStack(s.layerStack)) { |
| 5323 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5324 | mCurrentState.layersSortedByZ.add(layer); |
| 5325 | // we need traversal (state changed) |
| 5326 | // AND transaction (list changed) |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5327 | flags |= eTransactionNeeded | eTraversalNeeded | eTransformHintUpdateNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5328 | } |
| 5329 | } |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5330 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5331 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5332 | } |
| 5333 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5334 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5335 | flags |= eTraversalNeeded; |
| 5336 | } |
| 5337 | if (what & layer_state_t::eCropChanged) { |
| 5338 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5339 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5340 | if (what & layer_state_t::eDataspaceChanged) { |
| 5341 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5342 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5343 | if (what & layer_state_t::eSurfaceDamageRegionChanged) { |
| 5344 | if (layer->setSurfaceDamageRegion(s.surfaceDamageRegion)) flags |= eTraversalNeeded; |
| 5345 | } |
| 5346 | if (what & layer_state_t::eApiChanged) { |
| 5347 | if (layer->setApi(s.api)) flags |= eTraversalNeeded; |
| 5348 | } |
| 5349 | if (what & layer_state_t::eSidebandStreamChanged) { |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 5350 | if (layer->setSidebandStream(s.sidebandStream, frameTimelineInfo, postTime)) |
| 5351 | flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5352 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5353 | if (what & layer_state_t::eInputInfoChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5354 | layer->setInputInfo(*s.windowInfoHandle->getInfo()); |
| 5355 | flags |= eTraversalNeeded; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5356 | } |
Vishnu Nair | adf632b | 2021-01-07 14:05:08 -0800 | [diff] [blame] | 5357 | std::optional<nsecs_t> dequeueBufferTimestamp; |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5358 | if (what & layer_state_t::eMetadataChanged) { |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5359 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5360 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5361 | if (const int32_t gameMode = s.metadata.getInt32(gui::METADATA_GAME_MODE, -1); |
| 5362 | gameMode != -1) { |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5363 | // The transaction will be received on the Task layer and needs to be applied to all |
| 5364 | // child layers. Child layers that are added at a later point will obtain the game mode |
| 5365 | // info through addChild(). |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5366 | layer->setGameModeForTree(static_cast<GameMode>(gameMode)); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5367 | } |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5368 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 5369 | if (layer->setMetadata(s.metadata)) { |
| 5370 | flags |= eTraversalNeeded; |
| 5371 | mLayerMetadataSnapshotNeeded = true; |
| 5372 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5373 | } |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 5374 | if (what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 5375 | if (layer->setColorSpaceAgnostic(s.colorSpaceAgnostic)) { |
| 5376 | flags |= eTraversalNeeded; |
| 5377 | } |
| 5378 | } |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 5379 | if (what & layer_state_t::eShadowRadiusChanged) { |
| 5380 | if (layer->setShadowRadius(s.shadowRadius)) flags |= eTraversalNeeded; |
| 5381 | } |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 5382 | if (what & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 5383 | const auto compatibility = |
| 5384 | Layer::FrameRate::convertCompatibility(s.defaultFrameRateCompatibility); |
| 5385 | |
| 5386 | if (layer->setDefaultFrameRateCompatibility(compatibility)) { |
| 5387 | flags |= eTraversalNeeded; |
| 5388 | } |
| 5389 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5390 | if (what & layer_state_t::eFrameRateSelectionPriority) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5391 | if (layer->setFrameRateSelectionPriority(s.frameRateSelectionPriority)) { |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5392 | flags |= eTraversalNeeded; |
| 5393 | } |
| 5394 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5395 | if (what & layer_state_t::eFrameRateChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5396 | const auto compatibility = |
| 5397 | Layer::FrameRate::convertCompatibility(s.frameRateCompatibility); |
| 5398 | const auto strategy = |
| 5399 | Layer::FrameRate::convertChangeFrameRateStrategy(s.changeFrameRateStrategy); |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 5400 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 5401 | if (layer->setFrameRate(Layer::FrameRate::FrameRateVote(Fps::fromValue(s.frameRate), |
| 5402 | compatibility, strategy))) { |
| 5403 | flags |= eTraversalNeeded; |
| 5404 | } |
| 5405 | } |
| 5406 | if (what & layer_state_t::eFrameRateCategoryChanged) { |
| 5407 | const FrameRateCategory category = Layer::FrameRate::convertCategory(s.frameRateCategory); |
Rachel Lee | 67afbea | 2023-09-28 15:35:07 -0700 | [diff] [blame] | 5408 | if (layer->setFrameRateCategory(category, s.frameRateCategorySmoothSwitchOnly)) { |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 5409 | flags |= eTraversalNeeded; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 5410 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5411 | } |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 5412 | if (what & layer_state_t::eFrameRateSelectionStrategyChanged) { |
| 5413 | const scheduler::LayerInfo::FrameRateSelectionStrategy strategy = |
| 5414 | scheduler::LayerInfo::convertFrameRateSelectionStrategy( |
| 5415 | s.frameRateSelectionStrategy); |
| 5416 | if (layer->setFrameRateSelectionStrategy(strategy)) { |
| 5417 | flags |= eTraversalNeeded; |
| 5418 | } |
| 5419 | } |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5420 | if (what & layer_state_t::eFixedTransformHintChanged) { |
| 5421 | if (layer->setFixedTransformHint(s.fixedTransformHint)) { |
| 5422 | flags |= eTraversalNeeded | eTransformHintUpdateNeeded; |
| 5423 | } |
| 5424 | } |
Vishnu Nair | cf26a0a | 2020-11-13 12:56:20 -0800 | [diff] [blame] | 5425 | if (what & layer_state_t::eAutoRefreshChanged) { |
| 5426 | layer->setAutoRefresh(s.autoRefresh); |
| 5427 | } |
Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 5428 | if (what & layer_state_t::eDimmingEnabledChanged) { |
| 5429 | if (layer->setDimmingEnabled(s.dimmingEnabled)) flags |= eTraversalNeeded; |
| 5430 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5431 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 5432 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5433 | flags |= eTraversalNeeded; |
| 5434 | } |
| 5435 | } |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 5436 | if (what & layer_state_t::eCachingHintChanged) { |
| 5437 | if (layer->setCachingHint(s.cachingHint)) { |
| 5438 | flags |= eTraversalNeeded; |
| 5439 | } |
| 5440 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5441 | if (what & layer_state_t::eHdrMetadataChanged) { |
| 5442 | if (layer->setHdrMetadata(s.hdrMetadata)) flags |= eTraversalNeeded; |
| 5443 | } |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5444 | if (what & layer_state_t::eTrustedOverlayChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5445 | if (layer->setTrustedOverlay(s.isTrustedOverlay)) { |
| 5446 | flags |= eTraversalNeeded; |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5447 | } |
| 5448 | } |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 5449 | if (what & layer_state_t::eStretchChanged) { |
| 5450 | if (layer->setStretchEffect(s.stretchEffect)) { |
| 5451 | flags |= eTraversalNeeded; |
| 5452 | } |
| 5453 | } |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 5454 | if (what & layer_state_t::eBufferCropChanged) { |
| 5455 | if (layer->setBufferCrop(s.bufferCrop)) { |
| 5456 | flags |= eTraversalNeeded; |
| 5457 | } |
| 5458 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 5459 | if (what & layer_state_t::eDestinationFrameChanged) { |
| 5460 | if (layer->setDestinationFrame(s.destinationFrame)) { |
| 5461 | flags |= eTraversalNeeded; |
| 5462 | } |
| 5463 | } |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5464 | if (what & layer_state_t::eDropInputModeChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5465 | if (layer->setDropInputMode(s.dropInputMode)) { |
| 5466 | flags |= eTraversalNeeded; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 5467 | mUpdateInputInfo = true; |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5468 | } |
| 5469 | } |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5470 | // This has to happen after we reparent children because when we reparent to null we remove |
| 5471 | // child layers from current state and remove its relative z. If the children are reparented in |
| 5472 | // the same transaction, then we have to make sure we reparent the children first so we do not |
| 5473 | // lose its relative z order. |
| 5474 | if (what & layer_state_t::eReparent) { |
| 5475 | bool hadParent = layer->hasParent(); |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5476 | auto parentHandle = (s.parentSurfaceControlForChild) |
| 5477 | ? s.parentSurfaceControlForChild->getHandle() |
| 5478 | : nullptr; |
| 5479 | if (layer->reparent(parentHandle)) { |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5480 | if (!hadParent) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 5481 | layer->setIsAtRoot(false); |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5482 | mCurrentState.layersSortedByZ.remove(layer); |
| 5483 | } |
| 5484 | flags |= eTransactionNeeded | eTraversalNeeded; |
| 5485 | } |
| 5486 | } |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5487 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5488 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5489 | for (auto& [listener, callbackIds] : filteredListeners) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 5490 | callbackHandles.emplace_back( |
| 5491 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5492 | } |
| 5493 | } |
Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 5494 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5495 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5496 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5497 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 5498 | frameTimelineInfo)) { |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5499 | flags |= eTraversalNeeded; |
| 5500 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5501 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5502 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 5503 | } |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 5504 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5505 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5506 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5507 | } |
| 5508 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5509 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5510 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5511 | s.trustedPresentationListener)) { |
| 5512 | flags |= eTraversalNeeded; |
| 5513 | } |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5514 | } |
| 5515 | |
Pascal Muetschard | b39918f | 2023-01-27 11:36:11 +0100 | [diff] [blame] | 5516 | if (what & layer_state_t::eFlushJankData) { |
| 5517 | // Do nothing. Processing the transaction completed listeners currently cause the flush. |
| 5518 | } |
| 5519 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5520 | if (layer->setTransactionCompletedListeners(callbackHandles, |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5521 | layer->willPresentCurrentTransaction() || |
| 5522 | layer->willReleaseBufferOnLatch())) { |
Vishnu Nair | d691322 | 2023-02-01 22:56:21 +0000 | [diff] [blame] | 5523 | flags |= eTraversalNeeded; |
| 5524 | } |
| 5525 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5526 | // Do not put anything that updates layer state or modifies flags after |
| 5527 | // setTransactionCompletedListener |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5528 | |
| 5529 | // 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] | 5530 | if (((flags & eTransformHintUpdateNeeded) == 0) && |
| 5531 | oldLayerStack != layer->getLayerStack(LayerVector::StateSet::Current)) { |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5532 | flags |= eTransformHintUpdateNeeded; |
| 5533 | } |
| 5534 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5535 | return flags; |
| 5536 | } |
| 5537 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5538 | uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& frameTimelineInfo, |
| 5539 | ResolvedComposerState& composerState, |
| 5540 | int64_t desiredPresentTime, |
| 5541 | bool isAutoTimestamp, int64_t postTime, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5542 | uint64_t transactionId) { |
| 5543 | layer_state_t& s = composerState.state; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5544 | |
| 5545 | std::vector<ListenerCallbacks> filteredListeners; |
| 5546 | for (auto& listener : s.listeners) { |
| 5547 | // Starts a registration but separates the callback ids according to callback type. This |
| 5548 | // allows the callback invoker to send on latch callbacks earlier. |
| 5549 | // note that startRegistration will not re-register if the listener has |
| 5550 | // already be registered for a prior surface control |
| 5551 | |
| 5552 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5553 | if (!onCommitCallbacks.callbackIds.empty()) { |
| 5554 | filteredListeners.push_back(onCommitCallbacks); |
| 5555 | } |
| 5556 | |
| 5557 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5558 | if (!onCompleteCallbacks.callbackIds.empty()) { |
| 5559 | filteredListeners.push_back(onCompleteCallbacks); |
| 5560 | } |
| 5561 | } |
| 5562 | |
| 5563 | const uint64_t what = s.what; |
| 5564 | uint32_t flags = 0; |
| 5565 | sp<Layer> layer = nullptr; |
| 5566 | if (s.surface) { |
| 5567 | layer = LayerHandle::getLayer(s.surface); |
| 5568 | } else { |
| 5569 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5570 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5571 | } |
| 5572 | if (layer == nullptr) { |
| 5573 | for (auto& [listener, callbackIds] : s.listeners) { |
| 5574 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5575 | callbackIds, |
| 5576 | s.surface), |
| 5577 | std::vector<JankData>()); |
| 5578 | } |
| 5579 | return 0; |
| 5580 | } |
| 5581 | if (what & layer_state_t::eProducerDisconnect) { |
| 5582 | layer->onDisconnect(); |
| 5583 | } |
| 5584 | std::optional<nsecs_t> dequeueBufferTimestamp; |
| 5585 | if (what & layer_state_t::eMetadataChanged) { |
| 5586 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
| 5587 | } |
| 5588 | |
| 5589 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5590 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5591 | for (auto& [listener, callbackIds] : filteredListeners) { |
| 5592 | callbackHandles.emplace_back( |
| 5593 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
| 5594 | } |
| 5595 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5596 | // TODO(b/238781169) remove after screenshot refactor, currently screenshots |
| 5597 | // requires to read drawing state from binder thread. So we need to fix that |
| 5598 | // before removing this. |
Vishnu Nair | aeaf9d7 | 2023-09-12 15:47:41 -0700 | [diff] [blame] | 5599 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5600 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
| 5601 | } |
| 5602 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5603 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5604 | flags |= eTraversalNeeded; |
| 5605 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5606 | if (what & layer_state_t::eCropChanged) { |
| 5607 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5608 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5609 | if (what & layer_state_t::eSidebandStreamChanged) { |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 5610 | if (layer->setSidebandStream(s.sidebandStream, frameTimelineInfo, postTime)) |
| 5611 | flags |= eTraversalNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5612 | } |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 5613 | if (what & layer_state_t::eDataspaceChanged) { |
| 5614 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5615 | } |
Vishnu Nair | c5e3416 | 2023-08-22 13:21:20 -0700 | [diff] [blame] | 5616 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
| 5617 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
| 5618 | flags |= eTraversalNeeded; |
| 5619 | } |
| 5620 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5621 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 5622 | std::optional<ui::Transform::RotationFlags> transformHint = std::nullopt; |
| 5623 | frontend::LayerSnapshot* snapshot = mLayerSnapshotBuilder.getSnapshot(layer->sequence); |
| 5624 | if (snapshot) { |
| 5625 | transformHint = snapshot->transformHint; |
| 5626 | } |
| 5627 | layer->setTransformHint(transformHint); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5628 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5629 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
| 5630 | frameTimelineInfo)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5631 | flags |= eTraversalNeeded; |
| 5632 | } |
| 5633 | mLayersWithQueuedFrames.emplace(layer); |
| 5634 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5635 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
| 5636 | } |
| 5637 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5638 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5639 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5640 | } |
| 5641 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5642 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5643 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5644 | s.trustedPresentationListener)) { |
| 5645 | flags |= eTraversalNeeded; |
| 5646 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5647 | } |
| 5648 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5649 | const auto& requestedLayerState = mLayerLifecycleManager.getLayerFromId(layer->getSequence()); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5650 | bool willPresentCurrentTransaction = requestedLayerState && |
| 5651 | (requestedLayerState->hasReadyFrame() || |
| 5652 | requestedLayerState->willReleaseBufferOnLatch()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5653 | if (layer->setTransactionCompletedListeners(callbackHandles, willPresentCurrentTransaction)) |
| 5654 | flags |= eTraversalNeeded; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5655 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5656 | return flags; |
| 5657 | } |
| 5658 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5659 | uint32_t SurfaceFlinger::addInputWindowCommands(const InputWindowCommands& inputWindowCommands) { |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5660 | bool hasChanges = mInputWindowCommands.merge(inputWindowCommands); |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 5661 | return hasChanges ? eTraversalNeeded : 0; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5662 | } |
| 5663 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5664 | status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5665 | const sp<IBinder>& mirrorFromHandle, |
| 5666 | gui::CreateSurfaceResult& outResult) { |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5667 | if (!mirrorFromHandle) { |
| 5668 | return NAME_NOT_FOUND; |
| 5669 | } |
| 5670 | |
| 5671 | sp<Layer> mirrorLayer; |
| 5672 | sp<Layer> mirrorFrom; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5673 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5674 | { |
| 5675 | Mutex::Autolock _l(mStateLock); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5676 | mirrorFrom = LayerHandle::getLayer(mirrorFromHandle); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5677 | if (!mirrorFrom) { |
| 5678 | return NAME_NOT_FOUND; |
| 5679 | } |
Vishnu Nair | b21272e | 2022-07-01 22:47:33 +0000 | [diff] [blame] | 5680 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5681 | mirrorArgs.mirrorLayerHandle = mirrorFromHandle; |
| 5682 | mirrorArgs.addToRoot = false; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5683 | status_t result = createEffectLayer(mirrorArgs, &outResult.handle, &mirrorLayer); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5684 | if (result != NO_ERROR) { |
| 5685 | return result; |
| 5686 | } |
| 5687 | |
Vishnu Nair | de17725 | 2023-04-21 12:44:10 -0700 | [diff] [blame] | 5688 | mirrorLayer->setClonedChild(mirrorFrom->createClone(mirrorLayer->getSequence())); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5689 | } |
| 5690 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5691 | outResult.layerId = mirrorLayer->sequence; |
| 5692 | outResult.layerName = String16(mirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5693 | return addClientLayer(mirrorArgs, outResult.handle, mirrorLayer /* layer */, |
| 5694 | nullptr /* parent */, nullptr /* outTransformHint */); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5695 | } |
| 5696 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5697 | status_t SurfaceFlinger::mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5698 | gui::CreateSurfaceResult& outResult) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5699 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5700 | const int uid = ipc->getCallingUid(); |
| 5701 | if (uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM && uid != AID_SHELL) { |
| 5702 | ALOGE("Permission denied when trying to mirror display"); |
| 5703 | return PERMISSION_DENIED; |
| 5704 | } |
| 5705 | |
| 5706 | ui::LayerStack layerStack; |
| 5707 | sp<Layer> rootMirrorLayer; |
| 5708 | status_t result = 0; |
| 5709 | |
| 5710 | { |
| 5711 | Mutex::Autolock lock(mStateLock); |
| 5712 | |
| 5713 | const auto display = getDisplayDeviceLocked(displayId); |
| 5714 | if (!display) { |
| 5715 | return NAME_NOT_FOUND; |
| 5716 | } |
| 5717 | |
| 5718 | layerStack = display->getLayerStack(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5719 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5720 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5721 | mirrorArgs.addToRoot = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5722 | mirrorArgs.layerStackToMirror = layerStack; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5723 | result = createEffectLayer(mirrorArgs, &outResult.handle, &rootMirrorLayer); |
| 5724 | outResult.layerId = rootMirrorLayer->sequence; |
| 5725 | outResult.layerName = String16(rootMirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5726 | result |= addClientLayer(mirrorArgs, outResult.handle, rootMirrorLayer /* layer */, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5727 | nullptr /* parent */, nullptr /* outTransformHint */); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5728 | } |
| 5729 | |
| 5730 | if (result != NO_ERROR) { |
| 5731 | return result; |
| 5732 | } |
| 5733 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5734 | if (mLegacyFrontEndEnabled) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5735 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5736 | mMirrorDisplays.emplace_back(layerStack, outResult.handle, args.client); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5737 | } |
| 5738 | |
| 5739 | setTransactionFlags(eTransactionFlushNeeded); |
| 5740 | return NO_ERROR; |
| 5741 | } |
| 5742 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5743 | status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, gui::CreateSurfaceResult& outResult) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5744 | status_t result = NO_ERROR; |
| 5745 | |
| 5746 | sp<Layer> layer; |
| 5747 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5748 | switch (args.flags & ISurfaceComposerClient::eFXSurfaceMask) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5749 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 5750 | case ISurfaceComposerClient::eFXSurfaceContainer: |
| 5751 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 5752 | args.flags |= ISurfaceComposerClient::eNoColorFill; |
| 5753 | FMT_FALLTHROUGH; |
| 5754 | case ISurfaceComposerClient::eFXSurfaceEffect: { |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5755 | result = createBufferStateLayer(args, &outResult.handle, &layer); |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5756 | std::atomic<int32_t>* pendingBufferCounter = layer->getPendingBufferCounter(); |
| 5757 | if (pendingBufferCounter) { |
| 5758 | std::string counterName = layer->getPendingBufferCounterName(); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5759 | mBufferCountTracker.add(outResult.handle->localBinder(), counterName, |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5760 | pendingBufferCounter); |
| 5761 | } |
| 5762 | } break; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5763 | default: |
| 5764 | result = BAD_VALUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5765 | break; |
| 5766 | } |
| 5767 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5768 | if (result != NO_ERROR) { |
| 5769 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5770 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5771 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5772 | args.addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess(); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5773 | // We can safely promote the parent layer in binder thread because we have a strong reference |
| 5774 | // to the layer's handle inside this scope. |
| 5775 | sp<Layer> parent = LayerHandle::getLayer(args.parentHandle.promote()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5776 | if (args.parentHandle != nullptr && parent == nullptr) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5777 | ALOGE("Invalid parent handle %p", args.parentHandle.promote().get()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5778 | args.addToRoot = false; |
Garfield Tan | dbc93d7 | 2021-10-26 18:28:57 -0700 | [diff] [blame] | 5779 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5780 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5781 | uint32_t outTransformHint; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5782 | result = addClientLayer(args, outResult.handle, layer, parent, &outTransformHint); |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 5783 | if (result != NO_ERROR) { |
| 5784 | return result; |
| 5785 | } |
| 5786 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5787 | outResult.transformHint = static_cast<int32_t>(outTransformHint); |
| 5788 | outResult.layerId = layer->sequence; |
| 5789 | outResult.layerName = String16(layer->getDebugName()); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5790 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | } |
| 5792 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5793 | status_t SurfaceFlinger::createBufferStateLayer(LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5794 | sp<Layer>* outLayer) { |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5795 | *outLayer = getFactory().createBufferStateLayer(args); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5796 | *handle = (*outLayer)->getHandle(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5797 | return NO_ERROR; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 5798 | } |
| 5799 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5800 | status_t SurfaceFlinger::createEffectLayer(const LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5801 | sp<Layer>* outLayer) { |
| 5802 | *outLayer = getFactory().createEffectLayer(args); |
| 5803 | *handle = (*outLayer)->getHandle(); |
| 5804 | return NO_ERROR; |
| 5805 | } |
| 5806 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5807 | void SurfaceFlinger::markLayerPendingRemovalLocked(const sp<Layer>& layer) { |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5808 | mLayersPendingRemoval.add(layer); |
| 5809 | mLayersRemoved = true; |
| 5810 | setTransactionFlags(eTransactionNeeded); |
| 5811 | } |
| 5812 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5813 | void SurfaceFlinger::onHandleDestroyed(BBinder* handle, sp<Layer>& layer, uint32_t layerId) { |
| 5814 | { |
| 5815 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | 606d9d0 | 2023-08-19 14:20:18 -0700 | [diff] [blame] | 5816 | mDestroyedHandles.emplace_back(layerId, layer->getDebugName()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5817 | } |
| 5818 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 5819 | mTransactionHandler.onLayerDestroyed(layerId); |
| 5820 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5821 | Mutex::Autolock lock(mStateLock); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5822 | markLayerPendingRemovalLocked(layer); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 5823 | layer->onHandleDestroyed(); |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 5824 | mBufferCountTracker.remove(handle); |
Robert Carr | 695d528 | 2018-12-18 15:27:58 -0800 | [diff] [blame] | 5825 | layer.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5826 | |
| 5827 | setTransactionFlags(eTransactionFlushNeeded); |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 5828 | } |
| 5829 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 5830 | void SurfaceFlinger::initializeDisplays() { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5831 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 5832 | if (!display) return; |
| 5833 | |
| 5834 | const sp<IBinder> token = display->getDisplayToken().promote(); |
| 5835 | LOG_ALWAYS_FATAL_IF(token == nullptr); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 5836 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5837 | TransactionState state; |
| 5838 | state.inputWindowCommands = mInputWindowCommands; |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5839 | const nsecs_t now = systemTime(); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5840 | state.desiredPresentTime = now; |
| 5841 | state.postTime = now; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5842 | state.originPid = mPid; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5843 | state.originUid = static_cast<int>(getuid()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5844 | const uint64_t transactionId = (static_cast<uint64_t>(mPid) << 32) | mUniqueTransactionId++; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5845 | state.id = transactionId; |
| 5846 | |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 5847 | // reset screen orientation and use primary layer stack |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 5848 | DisplayState d; |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 5849 | d.what = DisplayState::eDisplayProjectionChanged | |
| 5850 | DisplayState::eLayerStackChanged; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 5851 | d.token = token; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 5852 | d.layerStack = ui::DEFAULT_LAYER_STACK; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 5853 | d.orientation = ui::ROTATION_0; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5854 | d.orientedDisplaySpaceRect.makeInvalid(); |
| 5855 | d.layerStackSpaceRect.makeInvalid(); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 5856 | d.width = 0; |
| 5857 | d.height = 0; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5858 | state.displays.add(d); |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5859 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5860 | std::vector<TransactionState> transactions; |
| 5861 | transactions.emplace_back(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5862 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5863 | if (mLegacyFrontEndEnabled) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5864 | applyTransactions(transactions, VsyncId{0}); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5865 | } else { |
| 5866 | applyAndCommitDisplayTransactionStates(transactions); |
| 5867 | } |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 5868 | |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5869 | { |
| 5870 | ftl::FakeGuard guard(mStateLock); |
| 5871 | setPowerModeInternal(display, hal::PowerMode::ON); |
| 5872 | } |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 5873 | } |
| 5874 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5875 | void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 5876 | if (display->isVirtual()) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 5877 | ALOGE("%s: Invalid operation on virtual display", __func__); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5878 | return; |
| 5879 | } |
| 5880 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5881 | const auto displayId = display->getPhysicalId(); |
| 5882 | 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] | 5883 | |
Dominik Laskowski | b4ff7d9 | 2022-11-22 13:59:53 -0500 | [diff] [blame] | 5884 | const auto currentModeOpt = display->getPowerMode(); |
| 5885 | if (currentModeOpt == mode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5886 | return; |
| 5887 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5888 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5889 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 5890 | .transform(&PhysicalDisplay::isInternal) |
| 5891 | .value_or(false); |
| 5892 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 5893 | const auto activeDisplay = getDisplayDeviceLocked(mActiveDisplayId); |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 5894 | |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5895 | ALOGW_IF(display != activeDisplay && isInternalDisplay && activeDisplay && |
| 5896 | activeDisplay->isPoweredOn(), |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 5897 | "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] | 5898 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5899 | display->setPowerMode(mode); |
| 5900 | |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 5901 | const auto activeMode = display->refreshRateSelector().getActiveMode().modePtr; |
Dominik Laskowski | b4ff7d9 | 2022-11-22 13:59:53 -0500 | [diff] [blame] | 5902 | if (!currentModeOpt || *currentModeOpt == hal::PowerMode::OFF) { |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 5903 | // Turn on the display |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5904 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 5905 | // Activate the display (which involves a modeset to the active mode) when the inner or |
| 5906 | // outer display of a foldable is powered on. This condition relies on the above |
| 5907 | // DisplayDevice::setPowerMode. If `display` and `activeDisplay` are the same display, |
| 5908 | // then the `activeDisplay->isPoweredOn()` below is true, such that the display is not |
| 5909 | // activated every time it is powered on. |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5910 | // |
| 5911 | // TODO(b/255635821): Remove the concept of active display. |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 5912 | if (isInternalDisplay && (!activeDisplay || !activeDisplay->isPoweredOn())) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 5913 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 5914 | } |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5915 | |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5916 | if (displayId == mActiveDisplayId) { |
| 5917 | // TODO(b/281692563): Merge the syscalls. For now, keep uclamp in a separate syscall and |
| 5918 | // set it before SCHED_FIFO due to b/190237315. |
| 5919 | if (setSchedAttr(true) != NO_ERROR) { |
| 5920 | ALOGW("Failed to set uclamp.min after powering on active display: %s", |
| 5921 | strerror(errno)); |
| 5922 | } |
| 5923 | if (setSchedFifo(true) != NO_ERROR) { |
| 5924 | ALOGW("Failed to set SCHED_FIFO after powering on active display: %s", |
| 5925 | strerror(errno)); |
| 5926 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 5927 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5928 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5929 | getHwComposer().setPowerMode(displayId, mode); |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 5930 | if (mode != hal::PowerMode::DOZE_SUSPEND && |
| 5931 | (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present())) { |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5932 | const bool enable = |
| 5933 | mScheduler->getVsyncSchedule(displayId)->getPendingHardwareVsyncState(); |
| 5934 | requestHardwareVsync(displayId, enable); |
| 5935 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 5936 | if (displayId == mActiveDisplayId) { |
| 5937 | mScheduler->enableSyntheticVsync(false); |
| 5938 | } |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5939 | |
| 5940 | constexpr bool kAllowToEnable = true; |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 5941 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, activeMode.get()); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5942 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5943 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5944 | mVisibleRegionsDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 5945 | scheduleComposite(FrameHint::kActive); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5946 | } else if (mode == hal::PowerMode::OFF) { |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 5947 | const bool currentModeNotDozeSuspend = (*currentModeOpt != hal::PowerMode::DOZE_SUSPEND); |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 5948 | // Turn off the display |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5949 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 5950 | if (const auto display = getActivatableDisplay()) { |
| 5951 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
| 5952 | } else { |
| 5953 | if (setSchedFifo(false) != NO_ERROR) { |
| 5954 | ALOGW("Failed to set SCHED_OTHER after powering off active display: %s", |
| 5955 | strerror(errno)); |
| 5956 | } |
| 5957 | if (setSchedAttr(false) != NO_ERROR) { |
| 5958 | ALOGW("Failed set uclamp.min after powering off active display: %s", |
| 5959 | strerror(errno)); |
| 5960 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5961 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 5962 | if (currentModeNotDozeSuspend) { |
| 5963 | if (!FlagManager::getInstance().multithreaded_present()) { |
| 5964 | mScheduler->disableHardwareVsync(displayId, true); |
| 5965 | } |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 5966 | mScheduler->enableSyntheticVsync(); |
| 5967 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5968 | } |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 5969 | } |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 5970 | if (currentModeNotDozeSuspend && FlagManager::getInstance().multithreaded_present()) { |
| 5971 | constexpr bool kDisallow = true; |
| 5972 | mScheduler->disableHardwareVsync(displayId, kDisallow); |
| 5973 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5974 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 5975 | // We must disable VSYNC *before* turning off the display. The call to |
| 5976 | // disableHardwareVsync, above, schedules a task to turn it off after |
| 5977 | // this method returns. But by that point, the display is OFF, so the |
| 5978 | // call just updates the pending state, without actually disabling |
| 5979 | // VSYNC. |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5980 | requestHardwareVsync(displayId, false); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5981 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5982 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5983 | mVisibleRegionsDirty = true; |
| 5984 | // from this point on, SF will stop drawing on this display |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5985 | } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5986 | // Update display while dozing |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5987 | getHwComposer().setPowerMode(displayId, mode); |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 5988 | if (*currentModeOpt == hal::PowerMode::DOZE_SUSPEND && |
| 5989 | (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present())) { |
| 5990 | if (displayId == mActiveDisplayId) { |
| 5991 | ALOGI("Force repainting for DOZE_SUSPEND -> DOZE or ON."); |
| 5992 | mVisibleRegionsDirty = true; |
| 5993 | scheduleRepaint(); |
| 5994 | mScheduler->enableSyntheticVsync(false); |
| 5995 | } |
| 5996 | constexpr bool kAllowToEnable = true; |
| 5997 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, activeMode.get()); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5998 | } |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5999 | } else if (mode == hal::PowerMode::DOZE_SUSPEND) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6000 | // Leave display going to doze |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6001 | if (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present()) { |
| 6002 | constexpr bool kDisallow = true; |
| 6003 | mScheduler->disableHardwareVsync(displayId, kDisallow); |
| 6004 | } |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6005 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6006 | mScheduler->enableSyntheticVsync(); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6007 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6008 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6009 | } else { |
Matthew Bouyack | 38d4961 | 2017-05-12 12:49:32 -0700 | [diff] [blame] | 6010 | ALOGE("Attempting to set unknown power mode: %d\n", mode); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6011 | getHwComposer().setPowerMode(displayId, mode); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6012 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6013 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6014 | if (displayId == mActiveDisplayId) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 6015 | mTimeStats->setPowerMode(mode); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 6016 | mRefreshRateStats->setPowerMode(mode); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 6017 | } |
| 6018 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6019 | mScheduler->setDisplayPowerMode(displayId, mode); |
| 6020 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6021 | 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] | 6022 | } |
| 6023 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6024 | void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) { |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 6025 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 6026 | kMainThreadContext) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 6027 | const auto display = getDisplayDeviceLocked(displayToken); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6028 | if (!display) { |
| 6029 | ALOGE("Attempt to set power mode %d for invalid display token %p", mode, |
| 6030 | displayToken.get()); |
| 6031 | } else if (display->isVirtual()) { |
| 6032 | ALOGW("Attempt to set power mode %d for virtual display", mode); |
| 6033 | } else { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6034 | setPowerModeInternal(display, static_cast<hal::PowerMode>(mode)); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6035 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6036 | }); |
| 6037 | |
| 6038 | future.wait(); |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 6039 | } |
| 6040 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 6041 | status_t SurfaceFlinger::doDump(int fd, const DumpArgs& args, bool asProto) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6042 | std::string result; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 6043 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 6044 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6045 | const int pid = ipc->getCallingPid(); |
| 6046 | const int uid = ipc->getCallingUid(); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 6047 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 6048 | if ((uid != AID_SHELL) && |
| 6049 | !PermissionCache::checkPermission(sDump, pid, uid)) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6050 | StringAppendF(&result, "Permission Denial: can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 6051 | pid, uid); |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6052 | write(fd, result.c_str(), result.size()); |
| 6053 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6054 | } |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 6055 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6056 | if (asProto && args.empty()) { |
| 6057 | perfetto::protos::LayersTraceFileProto traceFileProto = |
| 6058 | mLayerTracing.createTraceFileProto(); |
| 6059 | perfetto::protos::LayersSnapshotProto* layersTrace = traceFileProto.add_entry(); |
| 6060 | perfetto::protos::LayersProto layersProto = dumpProtoFromMainThread(); |
| 6061 | layersTrace->mutable_layers()->Swap(&layersProto); |
| 6062 | auto displayProtos = dumpDisplayProto(); |
| 6063 | layersTrace->mutable_displays()->Swap(&displayProtos); |
| 6064 | result.append(traceFileProto.SerializeAsString()); |
| 6065 | write(fd, result.c_str(), result.size()); |
| 6066 | return NO_ERROR; |
| 6067 | } |
| 6068 | |
| 6069 | static const std::unordered_map<std::string, Dumper> dumpers = { |
| 6070 | {"--comp-displays"s, dumper(&SurfaceFlinger::dumpCompositionDisplays)}, |
| 6071 | {"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)}, |
| 6072 | {"--displays"s, dumper(&SurfaceFlinger::dumpDisplays)}, |
| 6073 | {"--edid"s, argsDumper(&SurfaceFlinger::dumpRawDisplayIdentificationData)}, |
| 6074 | {"--events"s, dumper(&SurfaceFlinger::dumpEvents)}, |
| 6075 | {"--frametimeline"s, argsDumper(&SurfaceFlinger::dumpFrameTimeline)}, |
| 6076 | {"--frontend"s, mainThreadDumper(&SurfaceFlinger::dumpFrontEnd)}, |
| 6077 | {"--hdrinfo"s, dumper(&SurfaceFlinger::dumpHdrInfo)}, |
| 6078 | {"--hwclayers"s, mainThreadDumper(&SurfaceFlinger::dumpHwcLayersMinidump)}, |
| 6079 | {"--latency"s, argsDumper(&SurfaceFlinger::dumpStatsLocked)}, |
| 6080 | {"--latency-clear"s, argsDumper(&SurfaceFlinger::clearStatsLocked)}, |
| 6081 | {"--list"s, dumper(&SurfaceFlinger::listLayersLocked)}, |
| 6082 | {"--planner"s, argsDumper(&SurfaceFlinger::dumpPlannerInfo)}, |
| 6083 | {"--scheduler"s, dumper(&SurfaceFlinger::dumpScheduler)}, |
| 6084 | {"--timestats"s, protoDumper(&SurfaceFlinger::dumpTimeStats)}, |
| 6085 | {"--vsync"s, dumper(&SurfaceFlinger::dumpVsync)}, |
| 6086 | {"--wide-color"s, dumper(&SurfaceFlinger::dumpWideColorInfo)}, |
| 6087 | }; |
| 6088 | |
| 6089 | const auto flag = args.empty() ? ""s : std::string(String8(args[0])); |
| 6090 | if (const auto it = dumpers.find(flag); it != dumpers.end()) { |
| 6091 | (it->second)(args, asProto, result); |
| 6092 | write(fd, result.c_str(), result.size()); |
| 6093 | return NO_ERROR; |
| 6094 | } |
| 6095 | |
| 6096 | // Traversal of drawing state must happen on the main thread. |
| 6097 | // Otherwise, SortedVector may have shared ownership during concurrent |
| 6098 | // traversals, which can result in use-after-frees. |
| 6099 | std::string compositionLayers; |
| 6100 | mScheduler |
| 6101 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 6102 | dumpVisibleFrontEnd(compositionLayers); |
| 6103 | }) |
| 6104 | .get(); |
| 6105 | dumpAll(args, compositionLayers, result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6106 | write(fd, result.c_str(), result.size()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6107 | return NO_ERROR; |
| 6108 | } |
| 6109 | |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 6110 | status_t SurfaceFlinger::dumpCritical(int fd, const DumpArgs&, bool asProto) { |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 6111 | return doDump(fd, DumpArgs(), asProto); |
| 6112 | } |
| 6113 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6114 | void SurfaceFlinger::listLayersLocked(std::string& result) const { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6115 | mCurrentState.traverseInZOrder( |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 6116 | [&](Layer* layer) { StringAppendF(&result, "%s\n", layer->getDebugName()); }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6117 | } |
| 6118 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6119 | void SurfaceFlinger::dumpStatsLocked(const DumpArgs& args, std::string& result) const { |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 6120 | StringAppendF(&result, "%" PRId64 "\n", getVsyncPeriodFromHWC()); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6121 | if (args.size() < 2) return; |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 6122 | |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6123 | const auto name = String8(args[1]); |
| 6124 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 6125 | if (layer->getName() == name.c_str()) { |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6126 | layer->dumpFrameStats(result); |
| 6127 | } |
| 6128 | }); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6129 | } |
| 6130 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6131 | void SurfaceFlinger::clearStatsLocked(const DumpArgs& args, std::string&) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 6132 | const bool clearAll = args.size() < 2; |
| 6133 | const auto name = clearAll ? String8() : String8(args[1]); |
| 6134 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 6135 | mCurrentState.traverse([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 6136 | if (clearAll || layer->getName() == name.c_str()) { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 6137 | layer->clearFrameStats(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6138 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 6139 | }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6140 | } |
| 6141 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6142 | void SurfaceFlinger::dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const { |
| 6143 | mTimeStats->parseArgs(asProto, args, result); |
| 6144 | } |
| 6145 | |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 6146 | void SurfaceFlinger::dumpFrameTimeline(const DumpArgs& args, std::string& result) const { |
| 6147 | mFrameTimeline->parseArgs(args, result); |
| 6148 | } |
| 6149 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6150 | void SurfaceFlinger::logFrameStats(TimePoint now) { |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6151 | static TimePoint sTimestamp = now; |
| 6152 | if (now - sTimestamp < 30min) return; |
| 6153 | sTimestamp = now; |
| 6154 | |
| 6155 | ATRACE_CALL(); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6156 | mDrawingState.traverse([&](Layer* layer) { layer->logFrameStats(); }); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 6157 | } |
| 6158 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6159 | void SurfaceFlinger::appendSfConfigString(std::string& result) const { |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 6160 | result.append(" [sf"); |
Fabien Sanglard | c93afd5 | 2017-03-13 13:02:42 -0700 | [diff] [blame] | 6161 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6162 | StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); |
| 6163 | StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 6164 | StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%zu", |
| 6165 | getHwComposer().getMaxVirtualDisplayDimension()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6166 | StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6167 | StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6168 | maxFrameBufferAcquiredBuffers); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 6169 | result.append("]"); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6170 | } |
| 6171 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6172 | void SurfaceFlinger::dumpScheduler(std::string& result) const { |
| 6173 | utils::Dumper dumper{result}; |
| 6174 | |
| 6175 | mScheduler->dump(dumper); |
| 6176 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6177 | // TODO(b/241285876): Move to DisplayModeController. |
| 6178 | dumper.dump("debugDisplayModeSetByBackdoor"sv, mDebugDisplayModeSetByBackdoor); |
| 6179 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6180 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 6181 | mRefreshRateStats->dump(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6182 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6183 | |
Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 6184 | mVsyncConfiguration->dump(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6185 | StringAppendF(&result, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6186 | " present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64 |
| 6187 | " ns\n\n", |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6188 | dispSyncPresentTimeOffset, getVsyncPeriodFromHWC()); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6189 | } |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6190 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6191 | void SurfaceFlinger::dumpEvents(std::string& result) const { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 6192 | mScheduler->dump(mAppConnectionHandle, result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6193 | } |
| 6194 | |
| 6195 | void SurfaceFlinger::dumpVsync(std::string& result) const { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 6196 | mScheduler->dumpVsync(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6197 | } |
| 6198 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 6199 | void SurfaceFlinger::dumpPlannerInfo(const DumpArgs& args, std::string& result) const { |
| 6200 | for (const auto& [token, display] : mDisplays) { |
| 6201 | const auto compositionDisplay = display->getCompositionDisplay(); |
| 6202 | compositionDisplay->dumpPlannerInfo(args, result); |
| 6203 | } |
| 6204 | } |
| 6205 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6206 | void SurfaceFlinger::dumpCompositionDisplays(std::string& result) const { |
| 6207 | for (const auto& [token, display] : mDisplays) { |
| 6208 | display->getCompositionDisplay()->dump(result); |
| 6209 | result += '\n'; |
| 6210 | } |
| 6211 | } |
| 6212 | |
| 6213 | void SurfaceFlinger::dumpDisplays(std::string& result) const { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6214 | utils::Dumper dumper{result}; |
| 6215 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6216 | for (const auto& [id, display] : mPhysicalDisplays) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6217 | utils::Dumper::Section section(dumper, ftl::Concat("Display ", id.value).str()); |
| 6218 | |
| 6219 | display.snapshot().dump(dumper); |
| 6220 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6221 | if (const auto device = getDisplayDeviceLocked(id)) { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6222 | device->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6223 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6224 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6225 | |
| 6226 | for (const auto& [token, display] : mDisplays) { |
| 6227 | if (display->isVirtual()) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6228 | const auto displayId = display->getId(); |
| 6229 | utils::Dumper::Section section(dumper, |
| 6230 | ftl::Concat("Virtual Display ", displayId.value).str()); |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6231 | display->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6232 | } |
| 6233 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6234 | } |
| 6235 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6236 | void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 6237 | for (const auto& [token, display] : mDisplays) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6238 | const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6239 | if (!displayId) { |
| 6240 | continue; |
| 6241 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6242 | const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId); |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6243 | if (!hwcDisplayId) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6244 | continue; |
| 6245 | } |
| 6246 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6247 | StringAppendF(&result, |
| 6248 | "Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), |
| 6249 | *hwcDisplayId); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6250 | uint8_t port; |
| 6251 | DisplayIdentificationData data; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6252 | if (!getHwComposer().getDisplayIdentificationData(*hwcDisplayId, &port, &data)) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6253 | result.append("no identification data\n"); |
| 6254 | continue; |
| 6255 | } |
| 6256 | |
| 6257 | if (!isEdid(data)) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6258 | result.append("unknown identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6259 | continue; |
| 6260 | } |
| 6261 | |
| 6262 | const auto edid = parseEdid(data); |
| 6263 | if (!edid) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6264 | result.append("invalid EDID\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6265 | continue; |
| 6266 | } |
| 6267 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6268 | StringAppendF(&result, "port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6269 | result.append(edid->displayName.data(), edid->displayName.length()); |
| 6270 | result.append("\"\n"); |
| 6271 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6272 | } |
| 6273 | |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6274 | void SurfaceFlinger::dumpRawDisplayIdentificationData(const DumpArgs& args, |
| 6275 | std::string& result) const { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 6276 | hal::HWDisplayId hwcDisplayId; |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6277 | uint8_t port; |
| 6278 | DisplayIdentificationData data; |
| 6279 | |
| 6280 | if (args.size() > 1 && base::ParseUint(String8(args[1]), &hwcDisplayId) && |
| 6281 | getHwComposer().getDisplayIdentificationData(hwcDisplayId, &port, &data)) { |
| 6282 | result.append(reinterpret_cast<const char*>(data.data()), data.size()); |
| 6283 | } |
| 6284 | } |
| 6285 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6286 | void SurfaceFlinger::dumpWideColorInfo(std::string& result) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6287 | StringAppendF(&result, "Device supports wide color: %d\n", mSupportsWideColor); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6288 | StringAppendF(&result, "DisplayColorSetting: %s\n", |
| 6289 | decodeDisplayColorSetting(mDisplayColorSetting).c_str()); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6290 | |
| 6291 | // TODO: print out if wide-color mode is active or not |
| 6292 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6293 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6294 | StringAppendF(&result, "Display %s color modes:\n", to_string(id).c_str()); |
| 6295 | for (const auto mode : display.snapshot().colorModes()) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6296 | StringAppendF(&result, " %s (%d)\n", decodeColorMode(mode).c_str(), mode); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6297 | } |
| 6298 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6299 | if (const auto display = getDisplayDeviceLocked(id)) { |
| 6300 | ui::ColorMode currentMode = display->getCompositionDisplay()->getState().colorMode; |
| 6301 | StringAppendF(&result, " Current color mode: %s (%d)\n", |
| 6302 | decodeColorMode(currentMode).c_str(), currentMode); |
| 6303 | } |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6304 | } |
| 6305 | result.append("\n"); |
| 6306 | } |
| 6307 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6308 | void SurfaceFlinger::dumpHdrInfo(std::string& result) const { |
| 6309 | for (const auto& [displayId, listener] : mHdrLayerInfoListeners) { |
| 6310 | StringAppendF(&result, "HDR events for display %" PRIu64 "\n", displayId.value); |
| 6311 | listener->dump(result); |
| 6312 | result.append("\n"); |
| 6313 | } |
| 6314 | } |
| 6315 | |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6316 | void SurfaceFlinger::dumpFrontEnd(std::string& result) { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6317 | std::ostringstream out; |
| 6318 | out << "\nComposition list\n"; |
| 6319 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6320 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 6321 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 6322 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 6323 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6324 | } |
| 6325 | out << " " << *snapshot << "\n"; |
| 6326 | } |
| 6327 | |
| 6328 | out << "\nInput list\n"; |
| 6329 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6330 | mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6331 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 6332 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 6333 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6334 | } |
| 6335 | out << " " << snapshot << "\n"; |
| 6336 | }); |
| 6337 | |
| 6338 | out << "\nLayer Hierarchy\n" |
| 6339 | << mLayerHierarchyBuilder.getHierarchy().dump() << "\nOffscreen Hierarchy\n" |
| 6340 | << mLayerHierarchyBuilder.getOffscreenHierarchy().dump() << "\n\n"; |
| 6341 | result.append(out.str()); |
| 6342 | } |
| 6343 | |
| 6344 | void SurfaceFlinger::dumpVisibleFrontEnd(std::string& result) { |
| 6345 | if (!mLayerLifecycleManagerEnabled) { |
| 6346 | StringAppendF(&result, "Composition layers\n"); |
| 6347 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 6348 | auto* compositionState = layer->getCompositionState(); |
| 6349 | if (!compositionState || !compositionState->isVisible) return; |
| 6350 | android::base::StringAppendF(&result, "* Layer %p (%s)\n", layer, |
| 6351 | layer->getDebugName() ? layer->getDebugName() |
| 6352 | : "<unknown>"); |
| 6353 | compositionState->dump(result); |
| 6354 | }); |
| 6355 | |
| 6356 | StringAppendF(&result, "Offscreen Layers\n"); |
| 6357 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6358 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
| 6359 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
| 6360 | } |
| 6361 | } else { |
| 6362 | std::ostringstream out; |
| 6363 | out << "\nComposition list\n"; |
| 6364 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6365 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 6366 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 6367 | if (snapshot->hasSomethingToDraw()) { |
| 6368 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 6369 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 6370 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6371 | } |
| 6372 | out << " " << *snapshot << "\n"; |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6373 | } |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6374 | }); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6375 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6376 | out << "\nInput list\n"; |
| 6377 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6378 | mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6379 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 6380 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 6381 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6382 | } |
| 6383 | out << " " << snapshot << "\n"; |
| 6384 | }); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6385 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6386 | out << "\nLayer Hierarchy\n" |
| 6387 | << mLayerHierarchyBuilder.getHierarchy() << "\nOffscreen Hierarchy\n" |
| 6388 | << mLayerHierarchyBuilder.getOffscreenHierarchy() << "\n\n"; |
| 6389 | result = out.str(); |
| 6390 | dumpHwcLayersMinidump(result); |
| 6391 | } |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6392 | } |
| 6393 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6394 | perfetto::protos::LayersProto SurfaceFlinger::dumpDrawingStateProto(uint32_t traceFlags) const { |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 6395 | std::unordered_set<uint64_t> stackIdsToSkip; |
| 6396 | |
| 6397 | // Determine if virtual layers display should be skipped |
| 6398 | if ((traceFlags & LayerTracing::TRACE_VIRTUAL_DISPLAYS) == 0) { |
| 6399 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 6400 | if (display->isVirtual()) { |
| 6401 | stackIdsToSkip.insert(display->getLayerStack().id); |
| 6402 | } |
| 6403 | } |
| 6404 | } |
| 6405 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6406 | if (mLegacyFrontEndEnabled) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6407 | perfetto::protos::LayersProto layersProto; |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 6408 | for (const sp<Layer>& layer : mDrawingState.layersSortedByZ) { |
| 6409 | if (stackIdsToSkip.find(layer->getLayerStack().id) != stackIdsToSkip.end()) { |
| 6410 | continue; |
| 6411 | } |
| 6412 | layer->writeToProto(layersProto, traceFlags); |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 6413 | } |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 6414 | return layersProto; |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 6415 | } |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 6416 | |
Vishnu Nair | 22be349 | 2023-04-20 10:08:21 -0700 | [diff] [blame] | 6417 | return LayerProtoFromSnapshotGenerator(mLayerSnapshotBuilder, mFrontEndDisplayInfos, |
| 6418 | mLegacyLayers, traceFlags) |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 6419 | .generate(mLayerHierarchyBuilder.getHierarchy()); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6420 | } |
| 6421 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6422 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> |
| 6423 | SurfaceFlinger::dumpDisplayProto() const { |
| 6424 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> displays; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6425 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6426 | perfetto::protos::DisplayProto* displayProto = displays.Add(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6427 | displayProto->set_id(display->getId().value); |
| 6428 | displayProto->set_name(display->getDisplayName()); |
| 6429 | displayProto->set_layer_stack(display->getLayerStack().id); |
DoÄŸancan Emek | fc4b6ed | 2023-07-26 15:24:04 +0000 | [diff] [blame] | 6430 | |
| 6431 | if (!display->isVirtual()) { |
| 6432 | const auto dpi = display->refreshRateSelector().getActiveMode().modePtr->getDpi(); |
| 6433 | displayProto->set_dpi_x(dpi.x); |
| 6434 | displayProto->set_dpi_y(dpi.y); |
| 6435 | } |
| 6436 | |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6437 | LayerProtoHelper::writeSizeToProto(display->getWidth(), display->getHeight(), |
| 6438 | [&]() { return displayProto->mutable_size(); }); |
| 6439 | LayerProtoHelper::writeToProto(display->getLayerStackSpaceRect(), [&]() { |
| 6440 | return displayProto->mutable_layer_stack_space_rect(); |
| 6441 | }); |
| 6442 | LayerProtoHelper::writeTransformToProto(display->getTransform(), |
| 6443 | displayProto->mutable_transform()); |
Vishnu Nair | 791d48a | 2021-12-02 16:55:13 -0800 | [diff] [blame] | 6444 | displayProto->set_is_virtual(display->isVirtual()); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6445 | } |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 6446 | return displays; |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6447 | } |
| 6448 | |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 6449 | void SurfaceFlinger::dumpHwc(std::string& result) const { |
| 6450 | getHwComposer().dump(result); |
| 6451 | } |
| 6452 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6453 | void SurfaceFlinger::dumpOffscreenLayersProto(perfetto::protos::LayersProto& layersProto, |
| 6454 | uint32_t traceFlags) const { |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6455 | // Add a fake invisible root layer to the proto output and parent all the offscreen layers to |
| 6456 | // it. |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6457 | perfetto::protos::LayerProto* rootProto = layersProto.add_layers(); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6458 | const int32_t offscreenRootLayerId = INT32_MAX - 2; |
| 6459 | rootProto->set_id(offscreenRootLayerId); |
| 6460 | rootProto->set_name("Offscreen Root"); |
Vishnu Nair | d5aeb61 | 2019-09-20 14:39:39 -0700 | [diff] [blame] | 6461 | rootProto->set_parent(-1); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6462 | |
| 6463 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6464 | // Add layer as child of the fake root |
| 6465 | rootProto->add_children(offscreenLayer->sequence); |
| 6466 | |
| 6467 | // Add layer |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6468 | auto* layerProto = offscreenLayer->writeToProto(layersProto, traceFlags); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6469 | layerProto->set_parent(offscreenRootLayerId); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6470 | } |
| 6471 | } |
| 6472 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6473 | perfetto::protos::LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) { |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 6474 | return mScheduler->schedule([=, this] { return dumpDrawingStateProto(traceFlags); }).get(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 6475 | } |
| 6476 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6477 | void SurfaceFlinger::dumpOffscreenLayers(std::string& result) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6478 | auto future = mScheduler->schedule([this] { |
| 6479 | std::string result; |
| 6480 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6481 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
Vishnu Nair | 76554eb | 2022-12-09 03:38:36 +0000 | [diff] [blame] | 6482 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6483 | } |
| 6484 | return result; |
| 6485 | }); |
| 6486 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6487 | result.append("Offscreen Layers:\n"); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6488 | result.append(future.get()); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6489 | } |
| 6490 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6491 | void SurfaceFlinger::dumpHwcLayersMinidumpLockedLegacy(std::string& result) const { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6492 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6493 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6494 | if (!displayId) { |
| 6495 | continue; |
| 6496 | } |
| 6497 | |
| 6498 | 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] | 6499 | displayId == mActiveDisplayId ? "active" : "inactive"); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6500 | Layer::miniDumpHeader(result); |
| 6501 | |
| 6502 | const DisplayDevice& ref = *display; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6503 | mDrawingState.traverseInZOrder([&](Layer* layer) { layer->miniDumpLegacy(result, ref); }); |
| 6504 | result.append("\n"); |
| 6505 | } |
| 6506 | } |
| 6507 | |
| 6508 | void SurfaceFlinger::dumpHwcLayersMinidump(std::string& result) const { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6509 | if (!mLayerLifecycleManagerEnabled) { |
| 6510 | return dumpHwcLayersMinidumpLockedLegacy(result); |
| 6511 | } |
| 6512 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6513 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6514 | if (!displayId) { |
| 6515 | continue; |
| 6516 | } |
| 6517 | |
| 6518 | StringAppendF(&result, "Display %s (%s) HWC layers:\n", to_string(*displayId).c_str(), |
| 6519 | displayId == mActiveDisplayId ? "active" : "inactive"); |
| 6520 | Layer::miniDumpHeader(result); |
| 6521 | |
| 6522 | const DisplayDevice& ref = *display; |
| 6523 | mLayerSnapshotBuilder.forEachVisibleSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6524 | if (!snapshot.hasSomethingToDraw() || |
| 6525 | ref.getLayerStack() != snapshot.outputFilter.layerStack) { |
| 6526 | return; |
| 6527 | } |
| 6528 | auto it = mLegacyLayers.find(snapshot.sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 6529 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 6530 | "Couldnt find layer object for %s", |
| 6531 | snapshot.getDebugString().c_str()); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6532 | it->second->miniDump(result, snapshot, ref); |
| 6533 | }); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6534 | result.append("\n"); |
| 6535 | } |
| 6536 | } |
| 6537 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6538 | void SurfaceFlinger::dumpAll(const DumpArgs& args, const std::string& compositionLayers, |
| 6539 | std::string& result) const { |
| 6540 | TimedLock lock(mStateLock, s2ns(1), __func__); |
| 6541 | if (!lock.locked()) { |
| 6542 | StringAppendF(&result, "Dumping without lock after timeout: %s (%d)\n", |
| 6543 | strerror(-lock.status), lock.status); |
| 6544 | } |
| 6545 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6546 | const bool colorize = !args.empty() && args[0] == String16("--color"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6547 | Colorizer colorizer(colorize); |
| 6548 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6549 | // figure out if we're stuck somewhere |
| 6550 | const nsecs_t now = systemTime(); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6551 | const nsecs_t inTransaction(mDebugInTransaction); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6552 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 6553 | |
| 6554 | /* |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6555 | * Dump library configuration. |
| 6556 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6557 | |
| 6558 | colorizer.bold(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6559 | result.append("Build configuration:"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6560 | colorizer.reset(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6561 | appendSfConfigString(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6562 | result.append("\n"); |
| 6563 | |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6564 | result.append("\nDisplay identification data:\n"); |
| 6565 | dumpDisplayIdentificationData(result); |
| 6566 | |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6567 | result.append("\nWide-Color information:\n"); |
| 6568 | dumpWideColorInfo(result); |
| 6569 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6570 | dumpHdrInfo(result); |
| 6571 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6572 | colorizer.bold(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6573 | result.append("Sync configuration: "); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6574 | colorizer.reset(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6575 | result.append(SyncFeatures::getInstance().toString()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6576 | result.append("\n\n"); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6577 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6578 | colorizer.bold(result); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6579 | result.append("Scheduler:\n"); |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6580 | colorizer.reset(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6581 | dumpScheduler(result); |
| 6582 | dumpEvents(result); |
| 6583 | dumpVsync(result); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 6584 | result.append("\n"); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6585 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6586 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6587 | * Dump the visible layer list |
| 6588 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6589 | colorizer.bold(result); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6590 | StringAppendF(&result, "SurfaceFlinger New Frontend Enabled:%s\n", |
| 6591 | mLayerLifecycleManagerEnabled ? "true" : "false"); |
| 6592 | StringAppendF(&result, "Active Layers - layers with client handles (count = %zu)\n", |
| 6593 | mNumLayers.load()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6594 | colorizer.reset(result); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6595 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 6596 | result.append(compositionLayers); |
Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 6597 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6598 | colorizer.bold(result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6599 | StringAppendF(&result, "Displays (%zu entries)\n", mDisplays.size()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6600 | colorizer.reset(result); |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6601 | dumpDisplays(result); |
| 6602 | dumpCompositionDisplays(result); |
| 6603 | result.push_back('\n'); |
Lloyd Pique | c3cb729 | 2019-05-17 15:25:14 -0700 | [diff] [blame] | 6604 | |
| 6605 | mCompositionEngine->dump(result); |
| 6606 | |
| 6607 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6608 | * Dump SurfaceFlinger global state |
| 6609 | */ |
| 6610 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6611 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6612 | result.append("SurfaceFlinger global state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6613 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6614 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 6615 | getRenderEngine().dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6616 | |
Robert Carr | beba6f0 | 2021-02-10 21:06:27 -0800 | [diff] [blame] | 6617 | result.append("ClientCache state:\n"); |
| 6618 | ClientCache::getInstance().dump(result); |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 6619 | DebugEGLImageTracker::getInstance()->dump(result); |
| 6620 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6621 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 6622 | display->getCompositionDisplay()->getState().undefinedRegion.dump(result, |
| 6623 | "undefinedRegion"); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 6624 | StringAppendF(&result, " orientation=%s, isPoweredOn=%d\n", |
| 6625 | toCString(display->getOrientation()), display->isPoweredOn()); |
Lloyd Pique | 2ae2b3b | 2017-12-14 17:18:17 -0800 | [diff] [blame] | 6626 | } |
Carlos Martinez Romero | 779dc1f | 2022-10-27 23:23:30 +0000 | [diff] [blame] | 6627 | StringAppendF(&result, " transaction-flags : %08x\n", mTransactionFlags.load()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6628 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 6629 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6630 | std::string fps, xDpi, yDpi; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 6631 | if (const auto activeModePtr = |
| 6632 | display->refreshRateSelector().getActiveMode().modePtr.get()) { |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 6633 | fps = to_string(activeModePtr->getVsyncRate()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6634 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6635 | const auto dpi = activeModePtr->getDpi(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6636 | xDpi = base::StringPrintf("%.2f", dpi.x); |
| 6637 | yDpi = base::StringPrintf("%.2f", dpi.y); |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6638 | } else { |
| 6639 | fps = "unknown"; |
| 6640 | xDpi = "unknown"; |
| 6641 | yDpi = "unknown"; |
| 6642 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6643 | StringAppendF(&result, |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6644 | " refresh-rate : %s\n" |
| 6645 | " x-dpi : %s\n" |
| 6646 | " y-dpi : %s\n", |
| 6647 | fps.c_str(), xDpi.c_str(), yDpi.c_str()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6648 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6649 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6650 | StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6651 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6652 | result.append("\nTransaction tracing: "); |
| 6653 | if (mTransactionTracing) { |
| 6654 | result.append("enabled\n"); |
| 6655 | mTransactionTracing->dump(result); |
| 6656 | } else { |
| 6657 | result.append("disabled\n"); |
| 6658 | } |
| 6659 | result.push_back('\n'); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6660 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6661 | if (mLegacyFrontEndEnabled) { |
| 6662 | dumpHwcLayersMinidumpLockedLegacy(result); |
| 6663 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6664 | |
Ady Abraham | 2790e9f | 2021-04-28 13:14:20 -0700 | [diff] [blame] | 6665 | { |
| 6666 | DumpArgs plannerArgs; |
| 6667 | plannerArgs.add(); // first argument is ignored |
| 6668 | plannerArgs.add(String16("--layers")); |
| 6669 | dumpPlannerInfo(plannerArgs, result); |
| 6670 | } |
| 6671 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6672 | /* |
| 6673 | * Dump HWComposer state |
| 6674 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6675 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6676 | result.append("h/w composer state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6677 | colorizer.reset(result); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6678 | const bool hwcDisabled = mDebugDisableHWC || mDebugFlashDelay; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6679 | StringAppendF(&result, " h/w composer %s\n", hwcDisabled ? "disabled" : "enabled"); |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 6680 | dumpHwc(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6681 | |
| 6682 | /* |
| 6683 | * Dump gralloc state |
| 6684 | */ |
| 6685 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 6686 | alloc.dump(result); |
Karthik Ravi Shankar | 171155a | 2017-06-28 15:40:24 -0700 | [diff] [blame] | 6687 | |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6688 | /* |
| 6689 | * Dump flag/property manager state |
| 6690 | */ |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 6691 | FlagManager::getInstance().dump(result); |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6692 | |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 6693 | result.append(mTimeStats->miniDump()); |
| 6694 | result.append("\n"); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 6695 | |
| 6696 | result.append("Window Infos:\n"); |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 6697 | auto windowInfosDebug = mWindowInfosListenerInvoker->getDebugInfo(); |
| 6698 | StringAppendF(&result, " max send vsync id: %" PRId64 "\n", |
| 6699 | ftl::to_underlying(windowInfosDebug.maxSendDelayVsyncId)); |
| 6700 | StringAppendF(&result, " max send delay (ns): %" PRId64 " ns\n", |
| 6701 | windowInfosDebug.maxSendDelayDuration); |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 6702 | StringAppendF(&result, " unsent messages: %zu\n", windowInfosDebug.pendingMessageCount); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 6703 | result.append("\n"); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6704 | } |
| 6705 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6706 | mat4 SurfaceFlinger::calculateColorMatrix(float saturation) { |
| 6707 | if (saturation == 1) { |
| 6708 | return mat4(); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6709 | } |
| 6710 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6711 | float3 luminance{0.213f, 0.715f, 0.072f}; |
| 6712 | luminance *= 1.0f - saturation; |
| 6713 | mat4 saturationMatrix = mat4(vec4{luminance.r + saturation, luminance.r, luminance.r, 0.0f}, |
| 6714 | vec4{luminance.g, luminance.g + saturation, luminance.g, 0.0f}, |
| 6715 | vec4{luminance.b, luminance.b, luminance.b + saturation, 0.0f}, |
| 6716 | vec4{0.0f, 0.0f, 0.0f, 1.0f}); |
| 6717 | return saturationMatrix; |
| 6718 | } |
| 6719 | |
| 6720 | void SurfaceFlinger::updateColorMatrixLocked() { |
| 6721 | mat4 colorMatrix = |
| 6722 | mClientColorMatrix * calculateColorMatrix(mGlobalSaturationFactor) * mDaltonizer(); |
| 6723 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6724 | if (mCurrentState.colorMatrix != colorMatrix) { |
| 6725 | mCurrentState.colorMatrix = colorMatrix; |
| 6726 | mCurrentState.colorMatrixChanged = true; |
| 6727 | setTransactionFlags(eTransactionNeeded); |
| 6728 | } |
| 6729 | } |
| 6730 | |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6731 | status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6732 | #pragma clang diagnostic push |
| 6733 | #pragma clang diagnostic error "-Wswitch-enum" |
| 6734 | switch (static_cast<ISurfaceComposerTag>(code)) { |
| 6735 | // These methods should at minimum make sure that the client requested |
| 6736 | // access to SF. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6737 | case GET_HDR_CAPABILITIES: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6738 | case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6739 | case GET_GAME_CONTENT_TYPE_SUPPORT: |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6740 | case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6741 | // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary |
| 6742 | // permission dynamically. Don't use the permission cache for this check. |
| 6743 | bool usePermissionCache = code != OVERRIDE_HDR_TYPES; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6744 | if (!callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 6745 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6746 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", |
| 6747 | ipc->getCallingPid(), ipc->getCallingUid()); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6748 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6749 | } |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 6750 | return OK; |
| 6751 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6752 | // The following calls are currently used by clients that do not |
| 6753 | // request necessary permissions. However, they do not expose any secret |
| 6754 | // information, so it is OK to pass them. |
Peiyong Lin | d1fedb4 | 2019-03-11 17:48:41 -0700 | [diff] [blame] | 6755 | case GET_ACTIVE_COLOR_MODE: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6756 | case GET_ACTIVE_DISPLAY_MODE: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6757 | case GET_DISPLAY_COLOR_MODES: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6758 | case GET_DISPLAY_MODES: |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 6759 | case GET_SCHEDULING_POLICY: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6760 | // Calling setTransactionState is safe, because you need to have been |
| 6761 | // granted a reference to Client* and Handle* to do anything with it. |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6762 | case SET_TRANSACTION_STATE: { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 6763 | // This is not sensitive information, so should not require permission control. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6764 | return OK; |
| 6765 | } |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 6766 | case BOOT_FINISHED: |
| 6767 | // Used by apps to hook Choreographer to SurfaceFlinger. |
| 6768 | case CREATE_DISPLAY_EVENT_CONNECTION: |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6769 | case CREATE_CONNECTION: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6770 | case CREATE_DISPLAY: |
| 6771 | case DESTROY_DISPLAY: |
| 6772 | case GET_PRIMARY_PHYSICAL_DISPLAY_ID: |
| 6773 | case GET_PHYSICAL_DISPLAY_IDS: |
| 6774 | case GET_PHYSICAL_DISPLAY_TOKEN: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6775 | case AUTHENTICATE_SURFACE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6776 | case SET_POWER_MODE: |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 6777 | case GET_SUPPORTED_FRAME_TIMESTAMPS: |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6778 | case GET_DISPLAY_STATE: |
| 6779 | case GET_DISPLAY_STATS: |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 6780 | case GET_STATIC_DISPLAY_INFO: |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 6781 | case GET_DYNAMIC_DISPLAY_INFO: |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 6782 | case GET_DISPLAY_NATIVE_PRIMARIES: |
| 6783 | case SET_ACTIVE_COLOR_MODE: |
| 6784 | case SET_BOOT_DISPLAY_MODE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6785 | case CLEAR_BOOT_DISPLAY_MODE: |
| 6786 | case GET_BOOT_DISPLAY_MODE_SUPPORT: |
| 6787 | case SET_AUTO_LOW_LATENCY_MODE: |
| 6788 | case SET_GAME_CONTENT_TYPE: |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6789 | case CAPTURE_LAYERS: |
| 6790 | case CAPTURE_DISPLAY: |
| 6791 | case CAPTURE_DISPLAY_BY_ID: |
Huihong Luo | 4ed1c91 | 2022-02-22 14:30:01 -0800 | [diff] [blame] | 6792 | case CLEAR_ANIMATION_FRAME_STATS: |
| 6793 | case GET_ANIMATION_FRAME_STATS: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6794 | case OVERRIDE_HDR_TYPES: |
| 6795 | case ON_PULL_ATOM: |
| 6796 | case ENABLE_VSYNC_INJECTIONS: |
| 6797 | case INJECT_VSYNC: |
| 6798 | case GET_LAYER_DEBUG_INFO: |
| 6799 | case GET_COLOR_MANAGEMENT: |
| 6800 | case GET_COMPOSITION_PREFERENCE: |
| 6801 | case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: |
| 6802 | case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6803 | case GET_DISPLAYED_CONTENT_SAMPLE: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6804 | case GET_PROTECTED_CONTENT_SUPPORT: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6805 | case IS_WIDE_COLOR_DISPLAY: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6806 | case ADD_REGION_SAMPLING_LISTENER: |
| 6807 | case REMOVE_REGION_SAMPLING_LISTENER: |
| 6808 | case ADD_FPS_LISTENER: |
| 6809 | case REMOVE_FPS_LISTENER: |
| 6810 | case ADD_TUNNEL_MODE_ENABLED_LISTENER: |
| 6811 | case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: |
| 6812 | case ADD_WINDOW_INFOS_LISTENER: |
| 6813 | case REMOVE_WINDOW_INFOS_LISTENER: |
| 6814 | case SET_DESIRED_DISPLAY_MODE_SPECS: |
| 6815 | case GET_DESIRED_DISPLAY_MODE_SPECS: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6816 | case GET_DISPLAY_BRIGHTNESS_SUPPORT: |
| 6817 | case SET_DISPLAY_BRIGHTNESS: |
| 6818 | case ADD_HDR_LAYER_INFO_LISTENER: |
| 6819 | case REMOVE_HDR_LAYER_INFO_LISTENER: |
| 6820 | case NOTIFY_POWER_BOOST: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6821 | case SET_GLOBAL_SHADOW_SETTINGS: |
| 6822 | case GET_DISPLAY_DECORATION_SUPPORT: |
| 6823 | case SET_FRAME_RATE: |
| 6824 | case SET_OVERRIDE_FRAME_RATE: |
| 6825 | case SET_FRAME_TIMELINE_INFO: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6826 | case ADD_TRANSACTION_TRACE_LISTENER: |
| 6827 | case GET_GPU_CONTEXT_PRIORITY: |
| 6828 | case GET_MAX_ACQUIRED_BUFFER_COUNT: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6829 | LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6830 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6831 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6832 | |
| 6833 | // These codes are used for the IBinder protocol to either interrogate the recipient |
| 6834 | // side of the transaction for its canonical interface descriptor or to dump its state. |
| 6835 | // We let them pass by default. |
| 6836 | if (code == IBinder::INTERFACE_TRANSACTION || code == IBinder::DUMP_TRANSACTION || |
| 6837 | code == IBinder::PING_TRANSACTION || code == IBinder::SHELL_COMMAND_TRANSACTION || |
| 6838 | code == IBinder::SYSPROPS_TRANSACTION) { |
| 6839 | return OK; |
| 6840 | } |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 6841 | // Numbers from 1000 to 1045 are currently used for backdoors. The code |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6842 | // 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] | 6843 | if (code >= 1000 && code <= 1045) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6844 | ALOGV("Accessing SurfaceFlinger through backdoor code: %u", code); |
| 6845 | return OK; |
| 6846 | } |
| 6847 | ALOGE("Permission Denial: SurfaceFlinger did not recognize request code: %u", code); |
| 6848 | return PERMISSION_DENIED; |
| 6849 | #pragma clang diagnostic pop |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6850 | } |
| 6851 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6852 | status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 6853 | uint32_t flags) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6854 | if (const status_t error = CheckTransactCodeCredentials(code); error != OK) { |
| 6855 | return error; |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6856 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 6857 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6858 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 6859 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 6860 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Romain Guy | 8c6bbd6 | 2017-06-05 13:51:43 -0700 | [diff] [blame] | 6861 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6862 | const int uid = ipc->getCallingUid(); |
| 6863 | if (CC_UNLIKELY(uid != AID_SYSTEM |
| 6864 | && !PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6865 | const int pid = ipc->getCallingPid(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 6866 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6867 | "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] | 6868 | return PERMISSION_DENIED; |
| 6869 | } |
| 6870 | int n; |
| 6871 | switch (code) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6872 | case 1000: // Unused. |
| 6873 | case 1001: |
| 6874 | return NAME_NOT_FOUND; |
| 6875 | case 1002: // Toggle flashing on surface damage. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6876 | sfdo_setDebugFlash(data.readInt32()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6877 | return NO_ERROR; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6878 | case 1004: // Force composite ahead of next VSYNC. |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 6879 | case 1006: |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6880 | sfdo_scheduleComposite(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6881 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6882 | case 1005: { // Force commit ahead of next VSYNC. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6883 | sfdo_scheduleCommit(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 6884 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6885 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6886 | case 1007: // Unused. |
| 6887 | return NAME_NOT_FOUND; |
| 6888 | case 1008: // Toggle forced GPU composition. |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 6889 | sfdo_forceClientComposition(data.readInt32() != 0); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 6890 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6891 | case 1009: // Toggle use of transform hint. |
| 6892 | mDebugDisableTransformHint = data.readInt32() != 0; |
| 6893 | scheduleRepaint(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 6894 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6895 | case 1010: // Interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 6896 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6897 | reply->writeInt32(0); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6898 | reply->writeInt32(mDebugFlashDelay); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 6899 | reply->writeInt32(0); |
Dianne Hackborn | 12839be | 2012-02-06 21:21:05 -0800 | [diff] [blame] | 6900 | reply->writeInt32(mDebugDisableHWC); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6901 | return NO_ERROR; |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6902 | case 1013: // Unused. |
| 6903 | return NAME_NOT_FOUND; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6904 | case 1014: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6905 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6906 | // daltonize |
| 6907 | n = data.readInt32(); |
| 6908 | switch (n % 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6909 | case 1: |
| 6910 | mDaltonizer.setType(ColorBlindnessType::Protanomaly); |
| 6911 | break; |
| 6912 | case 2: |
| 6913 | mDaltonizer.setType(ColorBlindnessType::Deuteranomaly); |
| 6914 | break; |
| 6915 | case 3: |
| 6916 | mDaltonizer.setType(ColorBlindnessType::Tritanomaly); |
| 6917 | break; |
| 6918 | default: |
| 6919 | mDaltonizer.setType(ColorBlindnessType::None); |
| 6920 | break; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6921 | } |
| 6922 | if (n >= 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6923 | mDaltonizer.setMode(ColorBlindnessMode::Correction); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6924 | } else { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6925 | mDaltonizer.setMode(ColorBlindnessMode::Simulation); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6926 | } |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6927 | |
| 6928 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6929 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6930 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6931 | case 1015: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6932 | Mutex::Autolock _l(mStateLock); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6933 | // apply a color matrix |
| 6934 | n = data.readInt32(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6935 | if (n) { |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6936 | // color matrix is sent as a column-major mat4 matrix |
Alan Viverette | 794c5ba | 2013-10-03 16:40:52 -0700 | [diff] [blame] | 6937 | for (size_t i = 0 ; i < 4; i++) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6938 | for (size_t j = 0; j < 4; j++) { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6939 | mClientColorMatrix[i][j] = data.readFloat(); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6940 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6941 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6942 | } else { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6943 | mClientColorMatrix = mat4(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6944 | } |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 6945 | |
| 6946 | // Check that supplied matrix's last row is {0,0,0,1} so we can avoid |
| 6947 | // the division by w in the fragment shader |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6948 | float4 lastRow(transpose(mClientColorMatrix)[3]); |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 6949 | if (any(greaterThan(abs(lastRow - float4{0, 0, 0, 1}), float4{1e-4f}))) { |
| 6950 | ALOGE("The color transform's last row must be (0, 0, 0, 1)"); |
| 6951 | } |
| 6952 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6953 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6954 | return NO_ERROR; |
| 6955 | } |
Dominik Laskowski | 8d32ddc | 2019-08-07 11:25:35 -0700 | [diff] [blame] | 6956 | case 1016: { // Unused. |
| 6957 | return NAME_NOT_FOUND; |
Ruchi Kandoi | f52b3c8 | 2014-04-24 16:42:35 -0700 | [diff] [blame] | 6958 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 6959 | case 1017: { |
| 6960 | n = data.readInt32(); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 6961 | mForceFullDamage = n != 0; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 6962 | return NO_ERROR; |
| 6963 | } |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6964 | case 1018: { // Modify Choreographer's duration |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6965 | n = data.readInt32(); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6966 | mScheduler->setDuration(mAppConnectionHandle, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6967 | return NO_ERROR; |
| 6968 | } |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6969 | case 1019: { // Modify SurfaceFlinger's duration |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6970 | n = data.readInt32(); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6971 | mScheduler->setDuration(mSfConnectionHandle, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6972 | return NO_ERROR; |
| 6973 | } |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 6974 | case 1020: { // Unused |
| 6975 | return NAME_NOT_FOUND; |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 6976 | } |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 6977 | case 1021: { // Disable HWC virtual displays |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 6978 | const bool enable = data.readInt32() != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6979 | static_cast<void>( |
| 6980 | mScheduler->schedule([this, enable] { enableHalVirtualDisplays(enable); })); |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 6981 | return NO_ERROR; |
| 6982 | } |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6983 | case 1022: { // Set saturation boost |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6984 | Mutex::Autolock _l(mStateLock); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6985 | mGlobalSaturationFactor = std::max(0.0f, std::min(data.readFloat(), 2.0f)); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6986 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6987 | updateColorMatrixLocked(); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6988 | return NO_ERROR; |
| 6989 | } |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6990 | case 1023: { // Set color mode. |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6991 | mDisplayColorSetting = static_cast<DisplayColorSetting>(data.readInt32()); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6992 | |
| 6993 | if (int32_t colorMode; data.readInt32(&colorMode) == NO_ERROR) { |
| 6994 | mForceColorMode = static_cast<ui::ColorMode>(colorMode); |
Daniel Solomon | 7c7ede2 | 2019-07-11 16:35:40 -0700 | [diff] [blame] | 6995 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6996 | scheduleRepaint(); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 6997 | return NO_ERROR; |
| 6998 | } |
Peiyong Lin | 4bac91c | 2018-10-25 09:48:33 -0700 | [diff] [blame] | 6999 | // Deprecate, use 1030 to check whether the device is color managed. |
| 7000 | case 1024: { |
| 7001 | return NAME_NOT_FOUND; |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 7002 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7003 | // Deprecated, use perfetto to start/stop the layer tracing |
| 7004 | case 1025: { |
| 7005 | return NAME_NOT_FOUND; |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 7006 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7007 | // Deprecated, execute "adb shell perfetto --query" to see the ongoing tracing sessions |
| 7008 | case 1026: { |
| 7009 | return NAME_NOT_FOUND; |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 7010 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7011 | // Is a DisplayColorSetting supported? |
| 7012 | case 1027: { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7013 | const auto display = getDefaultDisplayDevice(); |
| 7014 | if (!display) { |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7015 | return NAME_NOT_FOUND; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7016 | } |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7017 | |
| 7018 | DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32()); |
| 7019 | switch (setting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7020 | case DisplayColorSetting::kManaged: |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7021 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7022 | reply->writeBool(true); |
| 7023 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7024 | case DisplayColorSetting::kEnhanced: |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7025 | reply->writeBool(display->hasRenderIntent(RenderIntent::ENHANCE)); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7026 | break; |
| 7027 | default: // vendor display color setting |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7028 | reply->writeBool( |
| 7029 | display->hasRenderIntent(static_cast<RenderIntent>(setting))); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7030 | break; |
| 7031 | } |
| 7032 | return NO_ERROR; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7033 | } |
Alec Mouri | 9c58bcd | 2020-09-09 18:57:07 -0700 | [diff] [blame] | 7034 | case 1028: { // Unused. |
| 7035 | return NAME_NOT_FOUND; |
Steven Thomas | 97f1f4c | 2018-06-01 12:04:16 -0700 | [diff] [blame] | 7036 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7037 | // Deprecated, use perfetto to set the active layer tracing buffer size |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 7038 | case 1029: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7039 | return NAME_NOT_FOUND; |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 7040 | } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 7041 | // Is device color managed? |
| 7042 | case 1030: { |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 7043 | // ColorDisplayManager stil calls this |
| 7044 | reply->writeBool(true); |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 7045 | return NO_ERROR; |
| 7046 | } |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7047 | // Override default composition data space |
| 7048 | // adb shell service call SurfaceFlinger 1031 i32 1 DATASPACE_NUMBER DATASPACE_NUMBER \ |
| 7049 | // && adb shell stop zygote && adb shell start zygote |
| 7050 | // to restore: adb shell service call SurfaceFlinger 1031 i32 0 && \ |
| 7051 | // adb shell stop zygote && adb shell start zygote |
| 7052 | case 1031: { |
| 7053 | Mutex::Autolock _l(mStateLock); |
| 7054 | n = data.readInt32(); |
| 7055 | if (n) { |
| 7056 | n = data.readInt32(); |
| 7057 | if (n) { |
| 7058 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 7059 | if (!validateCompositionDataspace(dataspace)) { |
| 7060 | return BAD_VALUE; |
| 7061 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7062 | mDefaultCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7063 | } |
| 7064 | n = data.readInt32(); |
| 7065 | if (n) { |
| 7066 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 7067 | if (!validateCompositionDataspace(dataspace)) { |
| 7068 | return BAD_VALUE; |
| 7069 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7070 | mWideColorGamutCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7071 | } |
| 7072 | } else { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7073 | // restore composition data space. |
| 7074 | mDefaultCompositionDataspace = defaultCompositionDataspace; |
| 7075 | mWideColorGamutCompositionDataspace = wideColorGamutCompositionDataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7076 | } |
| 7077 | return NO_ERROR; |
| 7078 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7079 | // Deprecated, use perfetto to set layer trace flags |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 7080 | case 1033: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7081 | return NAME_NOT_FOUND; |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 7082 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 7083 | case 1034: { |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7084 | n = data.readInt32(); |
| 7085 | if (n == 0 || n == 1) { |
| 7086 | sfdo_enableRefreshRateOverlay(static_cast<bool>(n)); |
| 7087 | } else { |
| 7088 | Mutex::Autolock lock(mStateLock); |
| 7089 | reply->writeBool(isRefreshRateOverlayEnabled()); |
| 7090 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 7091 | return NO_ERROR; |
| 7092 | } |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 7093 | case 1035: { |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7094 | // Parameters: |
| 7095 | // - (required) i32 mode id. |
| 7096 | // - (optional) i64 display id. Using default display if not provided. |
| 7097 | // - (optional) f min render rate. Using mode's fps is not provided. |
| 7098 | // - (optional) f max render rate. Using mode's fps is not provided. |
| 7099 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 7100 | const int modeId = data.readInt32(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 7101 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7102 | const auto display = [&]() -> sp<IBinder> { |
| 7103 | uint64_t value; |
| 7104 | if (data.readUint64(&value) != NO_ERROR) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7105 | return getDefaultDisplayDevice()->getDisplayToken().promote(); |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7106 | } |
| 7107 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7108 | if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(value)) { |
| 7109 | return getPhysicalDisplayToken(*id); |
| 7110 | } |
| 7111 | |
| 7112 | ALOGE("Invalid physical display ID"); |
| 7113 | return nullptr; |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7114 | }(); |
| 7115 | |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7116 | const auto getFps = [&] { |
| 7117 | float value; |
| 7118 | if (data.readFloat(&value) == NO_ERROR) { |
| 7119 | return Fps::fromValue(value); |
| 7120 | } |
| 7121 | |
| 7122 | return Fps(); |
| 7123 | }; |
| 7124 | |
| 7125 | const auto minFps = getFps(); |
| 7126 | const auto maxFps = getFps(); |
| 7127 | |
Shiyong Li | 2bcece9 | 2021-08-30 20:38:50 +0000 | [diff] [blame] | 7128 | mDebugDisplayModeSetByBackdoor = false; |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7129 | const status_t result = |
| 7130 | setActiveModeFromBackdoor(display, DisplayModeId{modeId}, minFps, maxFps); |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7131 | mDebugDisplayModeSetByBackdoor = result == NO_ERROR; |
| 7132 | return result; |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 7133 | } |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7134 | // Turn on/off frame rate flexibility mode. When turned on it overrides the display |
| 7135 | // manager frame rate policy a new policy which allows switching between all refresh |
| 7136 | // rates. |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7137 | case 1036: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7138 | if (data.readInt32() > 0) { // turn on |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7139 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7140 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7141 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7142 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7143 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7144 | // This is a little racy, but not in a way that hurts anything. As |
| 7145 | // we grab the defaultMode from the display manager policy, we could |
| 7146 | // be setting a new display manager policy, leaving us using a stale |
| 7147 | // defaultMode. The defaultMode doesn't matter for the override |
| 7148 | // policy though, since we set allowGroupSwitching to true, so it's |
| 7149 | // not a problem. |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7150 | scheduler::RefreshRateSelector::OverridePolicy overridePolicy; |
| 7151 | overridePolicy.defaultMode = display->refreshRateSelector() |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7152 | .getDisplayManagerPolicy() |
| 7153 | .defaultMode; |
| 7154 | overridePolicy.allowGroupSwitching = true; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7155 | return setDesiredDisplayModeSpecsInternal(display, overridePolicy); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7156 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7157 | .get(); |
| 7158 | } else { // turn off |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7159 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7160 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7161 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7162 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7163 | return setDesiredDisplayModeSpecsInternal( |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7164 | display, |
| 7165 | scheduler::RefreshRateSelector::NoOverridePolicy{}); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7166 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7167 | .get(); |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7168 | } |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7169 | } |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 7170 | // Inject a hotplug connected event for the primary display. This will deallocate and |
| 7171 | // reallocate the display state including framebuffers. |
| 7172 | case 1037: { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7173 | const hal::HWDisplayId hwcId = |
| 7174 | (Mutex::Autolock(mStateLock), getHwComposer().getPrimaryHwcDisplayId()); |
| 7175 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 7176 | onComposerHalHotplugEvent(hwcId, DisplayHotplugEvent::CONNECTED); |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 7177 | return NO_ERROR; |
| 7178 | } |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 7179 | // Modify the max number of display frames stored within FrameTimeline |
| 7180 | case 1038: { |
| 7181 | n = data.readInt32(); |
| 7182 | if (n < 0 || n > MAX_ALLOWED_DISPLAY_FRAMES) { |
| 7183 | ALOGW("Invalid max size. Maximum allowed is %d", MAX_ALLOWED_DISPLAY_FRAMES); |
| 7184 | return BAD_VALUE; |
| 7185 | } |
| 7186 | if (n == 0) { |
| 7187 | // restore to default |
| 7188 | mFrameTimeline->reset(); |
| 7189 | return NO_ERROR; |
| 7190 | } |
| 7191 | mFrameTimeline->setMaxDisplayFrames(n); |
| 7192 | return NO_ERROR; |
| 7193 | } |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 7194 | case 1039: { |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 7195 | PhysicalDisplayId displayId = [&]() { |
| 7196 | Mutex::Autolock lock(mStateLock); |
| 7197 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 7198 | }(); |
| 7199 | |
| 7200 | auto inUid = static_cast<uid_t>(data.readInt32()); |
| 7201 | const auto refreshRate = data.readFloat(); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 7202 | mScheduler->setPreferredRefreshRateForUid(FrameRateOverride{inUid, refreshRate}); |
| 7203 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 7204 | return NO_ERROR; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 7205 | } |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7206 | // Toggle caching feature |
| 7207 | // First argument is an int32 - nonzero enables caching and zero disables caching |
| 7208 | // Second argument is an optional uint64 - if present, then limits enabling/disabling |
| 7209 | // caching to a particular physical display |
| 7210 | case 1040: { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7211 | auto future = mScheduler->schedule([&] { |
| 7212 | n = data.readInt32(); |
| 7213 | std::optional<PhysicalDisplayId> inputId = std::nullopt; |
| 7214 | if (uint64_t inputDisplayId; data.readUint64(&inputDisplayId) == NO_ERROR) { |
| 7215 | inputId = DisplayId::fromValue<PhysicalDisplayId>(inputDisplayId); |
| 7216 | if (!inputId || getPhysicalDisplayToken(*inputId)) { |
| 7217 | ALOGE("No display with id: %" PRIu64, inputDisplayId); |
| 7218 | return NAME_NOT_FOUND; |
| 7219 | } |
| 7220 | } |
| 7221 | { |
| 7222 | Mutex::Autolock lock(mStateLock); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7223 | mLayerCachingEnabled = n != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7224 | for (const auto& [_, display] : mDisplays) { |
| 7225 | if (!inputId || *inputId == display->getPhysicalId()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7226 | display->enableLayerCaching(mLayerCachingEnabled); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7227 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7228 | } |
| 7229 | } |
| 7230 | return OK; |
| 7231 | }); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7232 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7233 | if (const status_t error = future.get(); error != OK) { |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7234 | return error; |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7235 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7236 | scheduleRepaint(); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7237 | return NO_ERROR; |
| 7238 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 7239 | case 1041: { // Transaction tracing |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7240 | if (mTransactionTracing) { |
Vishnu Nair | 640261c | 2023-09-21 21:22:51 -0700 | [diff] [blame] | 7241 | int arg = data.readInt32(); |
| 7242 | if (arg == -1) { |
Vishnu Nair | 50858e6 | 2023-10-13 23:28:24 +0000 | [diff] [blame] | 7243 | mScheduler->schedule([&]() { mTransactionTracing.reset(); }).get(); |
Vishnu Nair | 640261c | 2023-09-21 21:22:51 -0700 | [diff] [blame] | 7244 | } else if (arg > 0) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7245 | // Transaction tracing is always running but allow the user to temporarily |
| 7246 | // increase the buffer when actively debugging. |
| 7247 | mTransactionTracing->setBufferSize( |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 7248 | TransactionTracing::LEGACY_ACTIVE_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7249 | } else { |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 7250 | TransactionTraceWriter::getInstance().invoke("", /* overwrite= */ true); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7251 | mTransactionTracing->setBufferSize( |
| 7252 | TransactionTracing::CONTINUOUS_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7253 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 7254 | } |
| 7255 | reply->writeInt32(NO_ERROR); |
| 7256 | return NO_ERROR; |
| 7257 | } |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 7258 | case 1042: { // Write transaction trace to file |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7259 | if (mTransactionTracing) { |
| 7260 | mTransactionTracing->writeToFile(); |
| 7261 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7262 | reply->writeInt32(NO_ERROR); |
| 7263 | return NO_ERROR; |
| 7264 | } |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 7265 | // hdr sdr ratio overlay |
| 7266 | case 1043: { |
| 7267 | auto future = mScheduler->schedule( |
| 7268 | [&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 7269 | n = data.readInt32(); |
| 7270 | mHdrSdrRatioOverlay = n != 0; |
| 7271 | switch (n) { |
| 7272 | case 0: |
| 7273 | case 1: |
| 7274 | enableHdrSdrRatioOverlay(mHdrSdrRatioOverlay); |
| 7275 | break; |
| 7276 | default: |
| 7277 | reply->writeBool(isHdrSdrRatioOverlayEnabled()); |
| 7278 | } |
| 7279 | }); |
| 7280 | future.wait(); |
| 7281 | return NO_ERROR; |
| 7282 | } |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 7283 | |
| 7284 | case 1044: { // Enable/Disable mirroring from one display to another |
| 7285 | /* |
| 7286 | * Mirror one display onto another. |
| 7287 | * Ensure the source and destination displays are on. |
| 7288 | * Commands: |
| 7289 | * 0: Mirror one display to another |
| 7290 | * 1: Disable mirroring to a previously mirrored display |
| 7291 | * 2: Disable mirroring on previously mirrored displays |
| 7292 | * |
| 7293 | * Ex: |
| 7294 | * Get the display ids: |
| 7295 | * adb shell dumpsys SurfaceFlinger --display-id |
| 7296 | * Mirror first display to the second: |
| 7297 | * adb shell service call SurfaceFlinger 1044 i64 0 i64 4619827677550801152 i64 |
| 7298 | * 4619827677550801153 |
| 7299 | * Stop mirroring: |
| 7300 | * adb shell service call SurfaceFlinger 1044 i64 1 |
| 7301 | */ |
| 7302 | |
| 7303 | int64_t arg0 = data.readInt64(); |
| 7304 | |
| 7305 | switch (arg0) { |
| 7306 | case 0: { |
| 7307 | // Mirror arg1 to arg2 |
| 7308 | int64_t arg1 = data.readInt64(); |
| 7309 | int64_t arg2 = data.readInt64(); |
| 7310 | // Enable mirroring for one display |
| 7311 | const auto display1id = DisplayId::fromValue(arg1); |
| 7312 | auto mirrorRoot = SurfaceComposerClient::getDefault()->mirrorDisplay( |
| 7313 | display1id.value()); |
| 7314 | auto id2 = DisplayId::fromValue<PhysicalDisplayId>(arg2); |
| 7315 | const auto token2 = getPhysicalDisplayToken(*id2); |
| 7316 | ui::LayerStack layerStack; |
| 7317 | { |
| 7318 | Mutex::Autolock lock(mStateLock); |
| 7319 | sp<DisplayDevice> display = getDisplayDeviceLocked(token2); |
| 7320 | layerStack = display->getLayerStack(); |
| 7321 | } |
| 7322 | SurfaceComposerClient::Transaction t; |
| 7323 | t.setDisplayLayerStack(token2, layerStack); |
| 7324 | t.setLayer(mirrorRoot, INT_MAX); // Top-most layer |
| 7325 | t.setLayerStack(mirrorRoot, layerStack); |
| 7326 | t.apply(); |
| 7327 | |
| 7328 | mMirrorMapForDebug.emplace_or_replace(arg2, mirrorRoot); |
| 7329 | break; |
| 7330 | } |
| 7331 | |
| 7332 | case 1: { |
| 7333 | // Disable mirroring for arg1 |
| 7334 | int64_t arg1 = data.readInt64(); |
| 7335 | mMirrorMapForDebug.erase(arg1); |
| 7336 | break; |
| 7337 | } |
| 7338 | |
| 7339 | case 2: { |
| 7340 | // Disable mirroring for all displays |
| 7341 | mMirrorMapForDebug.clear(); |
| 7342 | break; |
| 7343 | } |
| 7344 | |
| 7345 | default: |
| 7346 | return BAD_VALUE; |
| 7347 | } |
| 7348 | return NO_ERROR; |
| 7349 | } |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7350 | // Inject jank |
| 7351 | // First argument is a float that describes the fraction of frame duration to jank by. |
| 7352 | // Second argument is a delay in ms for triggering the jank. This is useful for working |
| 7353 | // with tools that steal the adb connection. This argument is optional. |
| 7354 | case 1045: { |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 7355 | if (FlagManager::getInstance().vrr_config()) { |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7356 | float jankAmount = data.readFloat(); |
| 7357 | int32_t jankDelayMs = 0; |
| 7358 | if (data.readInt32(&jankDelayMs) != NO_ERROR) { |
| 7359 | jankDelayMs = 0; |
| 7360 | } |
| 7361 | |
| 7362 | const auto jankDelayDuration = Duration(std::chrono::milliseconds(jankDelayMs)); |
| 7363 | |
| 7364 | const bool jankAmountValid = jankAmount > 0.0 && jankAmount < 100.0; |
| 7365 | |
| 7366 | if (!jankAmountValid) { |
| 7367 | ALOGD("Ignoring invalid jank amount: %f", jankAmount); |
| 7368 | reply->writeInt32(BAD_VALUE); |
| 7369 | return BAD_VALUE; |
| 7370 | } |
| 7371 | |
| 7372 | (void)mScheduler->scheduleDelayed( |
| 7373 | [&, jankAmount]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 7374 | mScheduler->injectPacesetterDelay(jankAmount); |
| 7375 | scheduleComposite(FrameHint::kActive); |
| 7376 | }, |
| 7377 | jankDelayDuration.ns()); |
| 7378 | reply->writeInt32(NO_ERROR); |
| 7379 | return NO_ERROR; |
| 7380 | } |
| 7381 | return err; |
| 7382 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7383 | } |
| 7384 | } |
| 7385 | return err; |
| 7386 | } |
| 7387 | |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7388 | void SurfaceFlinger::kernelTimerChanged(bool expired) { |
| 7389 | static bool updateOverlay = |
| 7390 | property_get_bool("debug.sf.kernel_idle_timer_update_overlay", true); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7391 | if (!updateOverlay) return; |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7392 | |
| 7393 | // Update the overlay on the main thread to avoid race conditions with |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7394 | // RefreshRateSelector::getActiveMode |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 7395 | static_cast<void>(mScheduler->schedule([=, this] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7396 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7397 | if (!display) { |
| 7398 | ALOGW("%s: default display is null", __func__); |
| 7399 | return; |
| 7400 | } |
Adrian Salido | a942af8 | 2022-02-17 19:22:31 -0800 | [diff] [blame] | 7401 | if (!display->isRefreshRateOverlayEnabled()) return; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7402 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7403 | const auto desiredModeIdOpt = |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 7404 | display->getDesiredMode().transform([](const display::DisplayModeRequest& request) { |
| 7405 | return request.mode.modePtr->getId(); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7406 | }); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7407 | |
| 7408 | const bool timerExpired = mKernelIdleTimerEnabled && expired; |
| 7409 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7410 | if (display->onKernelTimerChanged(desiredModeIdOpt, timerExpired)) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 7411 | mScheduler->scheduleFrame(); |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7412 | } |
| 7413 | })); |
| 7414 | } |
| 7415 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7416 | std::pair<std::optional<KernelIdleTimerController>, std::chrono::milliseconds> |
| 7417 | SurfaceFlinger::getKernelIdleTimerProperties(DisplayId displayId) { |
| 7418 | const bool isKernelIdleTimerHwcSupported = getHwComposer().getComposer()->isSupported( |
| 7419 | android::Hwc2::Composer::OptionalFeature::KernelIdleTimer); |
| 7420 | const auto timeout = getIdleTimerTimeout(displayId); |
| 7421 | if (isKernelIdleTimerHwcSupported) { |
| 7422 | if (const auto id = PhysicalDisplayId::tryCast(displayId); |
| 7423 | getHwComposer().hasDisplayIdleTimerCapability(*id)) { |
| 7424 | // In order to decide if we can use the HWC api for idle timer |
| 7425 | // we query DisplayCapability::DISPLAY_IDLE_TIMER directly on the composer |
| 7426 | // without relying on hasDisplayCapability. |
| 7427 | // hasDisplayCapability relies on DisplayCapabilities |
| 7428 | // which are updated after we set the PowerMode::ON. |
| 7429 | // DISPLAY_IDLE_TIMER is a display driver property |
| 7430 | // and is available before the PowerMode::ON |
| 7431 | return {KernelIdleTimerController::HwcApi, timeout}; |
| 7432 | } |
| 7433 | return {std::nullopt, timeout}; |
| 7434 | } |
| 7435 | if (getKernelIdleTimerSyspropConfig(displayId)) { |
| 7436 | return {KernelIdleTimerController::Sysprop, timeout}; |
| 7437 | } |
| 7438 | |
| 7439 | return {std::nullopt, timeout}; |
| 7440 | } |
| 7441 | |
| 7442 | void SurfaceFlinger::updateKernelIdleTimer(std::chrono::milliseconds timeout, |
| 7443 | KernelIdleTimerController controller, |
| 7444 | PhysicalDisplayId displayId) { |
| 7445 | switch (controller) { |
| 7446 | case KernelIdleTimerController::HwcApi: { |
| 7447 | getHwComposer().setIdleTimerEnabled(displayId, timeout); |
| 7448 | break; |
| 7449 | } |
| 7450 | case KernelIdleTimerController::Sysprop: { |
| 7451 | base::SetProperty(KERNEL_IDLE_TIMER_PROP, timeout > 0ms ? "true" : "false"); |
| 7452 | break; |
| 7453 | } |
| 7454 | } |
| 7455 | } |
| 7456 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7457 | void SurfaceFlinger::toggleKernelIdleTimer() { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7458 | using KernelIdleTimerAction = scheduler::RefreshRateSelector::KernelIdleTimerAction; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7459 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7460 | const auto display = getDefaultDisplayDeviceLocked(); |
| 7461 | if (!display) { |
| 7462 | ALOGW("%s: default display is null", __func__); |
| 7463 | return; |
| 7464 | } |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7465 | |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7466 | // If the support for kernel idle timer is disabled for the active display, |
| 7467 | // don't do anything. |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7468 | const std::optional<KernelIdleTimerController> kernelIdleTimerController = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7469 | display->refreshRateSelector().kernelIdleTimerController(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7470 | if (!kernelIdleTimerController.has_value()) { |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7471 | return; |
| 7472 | } |
| 7473 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7474 | const KernelIdleTimerAction action = display->refreshRateSelector().getIdleTimerAction(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7475 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7476 | switch (action) { |
| 7477 | case KernelIdleTimerAction::TurnOff: |
| 7478 | if (mKernelIdleTimerEnabled) { |
| 7479 | ATRACE_INT("KernelIdleTimer", 0); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7480 | std::chrono::milliseconds constexpr kTimerDisabledTimeout = 0ms; |
| 7481 | updateKernelIdleTimer(kTimerDisabledTimeout, kernelIdleTimerController.value(), |
| 7482 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7483 | mKernelIdleTimerEnabled = false; |
| 7484 | } |
| 7485 | break; |
| 7486 | case KernelIdleTimerAction::TurnOn: |
| 7487 | if (!mKernelIdleTimerEnabled) { |
| 7488 | ATRACE_INT("KernelIdleTimer", 1); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7489 | const std::chrono::milliseconds timeout = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7490 | display->refreshRateSelector().getIdleTimerTimeout(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7491 | updateKernelIdleTimer(timeout, kernelIdleTimerController.value(), |
| 7492 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7493 | mKernelIdleTimerEnabled = true; |
| 7494 | } |
| 7495 | break; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7496 | } |
| 7497 | } |
| 7498 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7499 | // A simple RAII class to disconnect from an ANativeWindow* when it goes out of scope |
| 7500 | class WindowDisconnector { |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7501 | public: |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7502 | WindowDisconnector(ANativeWindow* window, int api) : mWindow(window), mApi(api) {} |
| 7503 | ~WindowDisconnector() { |
| 7504 | native_window_api_disconnect(mWindow, mApi); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7505 | } |
| 7506 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7507 | private: |
| 7508 | ANativeWindow* mWindow; |
| 7509 | const int mApi; |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7510 | }; |
| 7511 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7512 | static bool hasCaptureBlackoutContentPermission() { |
| 7513 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7514 | const int pid = ipc->getCallingPid(); |
| 7515 | const int uid = ipc->getCallingUid(); |
| 7516 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 7517 | PermissionCache::checkPermission(sCaptureBlackoutContent, pid, uid); |
| 7518 | } |
| 7519 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7520 | static status_t validateScreenshotPermissions(const CaptureArgs& captureArgs) { |
| 7521 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7522 | const int pid = ipc->getCallingPid(); |
| 7523 | const int uid = ipc->getCallingUid(); |
| 7524 | if (uid == AID_GRAPHICS || PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 7525 | return OK; |
| 7526 | } |
| 7527 | |
| 7528 | // If the caller doesn't have the correct permissions but is only attempting to screenshot |
| 7529 | // itself, we allow it to continue. |
| 7530 | if (captureArgs.uid == uid) { |
| 7531 | return OK; |
| 7532 | } |
| 7533 | |
| 7534 | ALOGE("Permission Denial: can't take screenshot pid=%d, uid=%d", pid, uid); |
| 7535 | return PERMISSION_DENIED; |
| 7536 | } |
| 7537 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7538 | status_t SurfaceFlinger::setSchedFifo(bool enabled) { |
| 7539 | static constexpr int kFifoPriority = 2; |
| 7540 | static constexpr int kOtherPriority = 0; |
| 7541 | |
| 7542 | struct sched_param param = {0}; |
| 7543 | int sched_policy; |
| 7544 | if (enabled) { |
| 7545 | sched_policy = SCHED_FIFO; |
| 7546 | param.sched_priority = kFifoPriority; |
| 7547 | } else { |
| 7548 | sched_policy = SCHED_OTHER; |
| 7549 | param.sched_priority = kOtherPriority; |
| 7550 | } |
| 7551 | |
| 7552 | if (sched_setscheduler(0, sched_policy, ¶m) != 0) { |
| 7553 | return -errno; |
| 7554 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7555 | |
| 7556 | return NO_ERROR; |
| 7557 | } |
| 7558 | |
| 7559 | status_t SurfaceFlinger::setSchedAttr(bool enabled) { |
| 7560 | static const unsigned int kUclampMin = |
| 7561 | base::GetUintProperty<unsigned int>("ro.surface_flinger.uclamp.min", 0U); |
| 7562 | |
| 7563 | if (!kUclampMin) { |
| 7564 | // uclamp.min set to 0 (default), skip setting |
| 7565 | return NO_ERROR; |
| 7566 | } |
| 7567 | |
| 7568 | // Currently, there is no wrapper in bionic: b/183240349. |
| 7569 | struct sched_attr { |
| 7570 | uint32_t size; |
| 7571 | uint32_t sched_policy; |
| 7572 | uint64_t sched_flags; |
| 7573 | int32_t sched_nice; |
| 7574 | uint32_t sched_priority; |
| 7575 | uint64_t sched_runtime; |
| 7576 | uint64_t sched_deadline; |
| 7577 | uint64_t sched_period; |
| 7578 | uint32_t sched_util_min; |
| 7579 | uint32_t sched_util_max; |
| 7580 | }; |
| 7581 | |
| 7582 | sched_attr attr = {}; |
| 7583 | attr.size = sizeof(attr); |
| 7584 | |
| 7585 | attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP); |
| 7586 | attr.sched_util_min = enabled ? kUclampMin : 0; |
| 7587 | attr.sched_util_max = 1024; |
| 7588 | |
| 7589 | if (syscall(__NR_sched_setattr, 0, &attr, 0)) { |
| 7590 | return -errno; |
| 7591 | } |
| 7592 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7593 | return NO_ERROR; |
| 7594 | } |
| 7595 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7596 | namespace { |
| 7597 | |
| 7598 | ui::Dataspace pickBestDataspace(ui::Dataspace requestedDataspace, const DisplayDevice* display, |
| 7599 | bool capturingHdrLayers, bool hintForSeamlessTransition) { |
| 7600 | if (requestedDataspace != ui::Dataspace::UNKNOWN || display == nullptr) { |
| 7601 | return requestedDataspace; |
| 7602 | } |
| 7603 | |
| 7604 | const auto& state = display->getCompositionDisplay()->getState(); |
| 7605 | |
| 7606 | const auto dataspaceForColorMode = ui::pickDataspaceFor(state.colorMode); |
| 7607 | |
Alec Mouri | 2964072 | 2023-05-16 23:22:41 +0000 | [diff] [blame] | 7608 | // TODO: Enable once HDR screenshots are ready. |
| 7609 | if constexpr (/* DISABLES CODE */ (false)) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7610 | // For now since we only support 8-bit screenshots, just use HLG and |
| 7611 | // assume that 1.0 >= display max luminance. This isn't quite as future |
| 7612 | // proof as PQ is, but is good enough. |
| 7613 | // Consider using PQ once we support 16-bit screenshots and we're able |
| 7614 | // to consistently supply metadata to image encoders. |
| 7615 | return ui::Dataspace::BT2020_HLG; |
| 7616 | } |
| 7617 | |
| 7618 | return dataspaceForColorMode; |
| 7619 | } |
| 7620 | |
| 7621 | } // namespace |
| 7622 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7623 | static void invokeScreenCaptureError(const status_t status, |
| 7624 | const sp<IScreenCaptureListener>& captureListener) { |
| 7625 | ScreenCaptureResults captureResults; |
| 7626 | captureResults.fenceResult = base::unexpected(status); |
| 7627 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7628 | } |
| 7629 | |
| 7630 | void SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, |
| 7631 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7632 | ATRACE_CALL(); |
| 7633 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7634 | status_t validate = validateScreenshotPermissions(args); |
| 7635 | if (validate != OK) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7636 | invokeScreenCaptureError(validate, captureListener); |
| 7637 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7638 | } |
| 7639 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7640 | if (!args.displayToken) { |
| 7641 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7642 | return; |
| 7643 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7644 | |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 7645 | if (args.captureSecureLayers && !hasCaptureBlackoutContentPermission()) { |
| 7646 | ALOGE("Attempting to capture secure layers without CAPTURE_BLACKOUT_CONTENT"); |
| 7647 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 7648 | return; |
| 7649 | } |
| 7650 | |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7651 | wp<const DisplayDevice> displayWeak; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7652 | ui::LayerStack layerStack; |
| 7653 | ui::Size reqSize(args.width, args.height); |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7654 | std::unordered_set<uint32_t> excludeLayerIds; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7655 | { |
| 7656 | Mutex::Autolock lock(mStateLock); |
| 7657 | sp<DisplayDevice> display = getDisplayDeviceLocked(args.displayToken); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7658 | if (!display) { |
| 7659 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7660 | return; |
| 7661 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7662 | displayWeak = display; |
| 7663 | layerStack = display->getLayerStack(); |
| 7664 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7665 | // 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] | 7666 | if (args.width == 0 || args.height == 0) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7667 | reqSize = display->getLayerStackSpaceRect().getSize(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7668 | } |
| 7669 | |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7670 | for (const auto& handle : args.excludeHandles) { |
| 7671 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7672 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7673 | excludeLayerIds.emplace(excludeLayer); |
| 7674 | } else { |
| 7675 | ALOGW("Invalid layer handle passed as excludeLayer to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7676 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7677 | return; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7678 | } |
| 7679 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7680 | } |
| 7681 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7682 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
Alec Mouri | c44a1ff | 2023-05-19 23:49:05 +0000 | [diff] [blame] | 7683 | return DisplayRenderArea::create(displayWeak, args.sourceCrop, reqSize, args.dataspace, |
Melody Hsu | 70a63e5 | 2023-11-17 19:49:12 +0000 | [diff] [blame] | 7684 | args.hintForSeamlessTransition, args.captureSecureLayers); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7685 | }); |
| 7686 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7687 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7688 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7689 | getLayerSnapshots = |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7690 | getLayerSnapshotsForScreenshots(layerStack, args.uid, std::move(excludeLayerIds)); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7691 | } else { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7692 | auto traverseLayers = [this, args, excludeLayerIds, |
| 7693 | layerStack](const LayerVector::Visitor& visitor) { |
| 7694 | traverseLayersInLayerStack(layerStack, args.uid, std::move(excludeLayerIds), visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7695 | }; |
| 7696 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7697 | } |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 7698 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7699 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, args.pixelFormat, |
| 7700 | args.allowProtected, args.grayscale, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7701 | } |
| 7702 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7703 | void SurfaceFlinger::captureDisplay(DisplayId displayId, const CaptureArgs& args, |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7704 | const sp<IScreenCaptureListener>& captureListener) { |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7705 | ui::LayerStack layerStack; |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7706 | wp<const DisplayDevice> displayWeak; |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7707 | ui::Size size; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7708 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7709 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7710 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7711 | const auto display = getDisplayDeviceLocked(displayId); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7712 | if (!display) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7713 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7714 | return; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7715 | } |
| 7716 | |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7717 | displayWeak = display; |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7718 | layerStack = display->getLayerStack(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7719 | size = display->getLayerStackSpaceRect().getSize(); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7720 | } |
| 7721 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7722 | size.width *= args.frameScaleX; |
| 7723 | size.height *= args.frameScaleY; |
| 7724 | |
| 7725 | // We could query a real value for this but it'll be a long, long time until we support |
| 7726 | // displays that need upwards of 1GB per buffer so... |
| 7727 | constexpr auto kMaxTextureSize = 16384; |
| 7728 | if (size.width <= 0 || size.height <= 0 || size.width >= kMaxTextureSize || |
| 7729 | size.height >= kMaxTextureSize) { |
| 7730 | ALOGE("capture display resolved to invalid size %d x %d", size.width, size.height); |
| 7731 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7732 | return; |
| 7733 | } |
| 7734 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7735 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7736 | return DisplayRenderArea::create(displayWeak, Rect(), size, args.dataspace, |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7737 | args.hintForSeamlessTransition, |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7738 | false /* captureSecureLayers */); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7739 | }); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7740 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7741 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7742 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7743 | getLayerSnapshots = getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID, |
| 7744 | /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7745 | } else { |
| 7746 | auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7747 | traverseLayersInLayerStack(layerStack, CaptureArgs::UNSET_UID, {}, visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7748 | }; |
| 7749 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7750 | } |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7751 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7752 | if (captureListener == nullptr) { |
| 7753 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7754 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7755 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7756 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7757 | |
| 7758 | constexpr bool kAllowProtected = false; |
| 7759 | constexpr bool kGrayscale = false; |
| 7760 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7761 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, size, args.pixelFormat, |
| 7762 | kAllowProtected, kGrayscale, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7763 | } |
| 7764 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7765 | void SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, |
| 7766 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7767 | ATRACE_CALL(); |
| 7768 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7769 | status_t validate = validateScreenshotPermissions(args); |
| 7770 | if (validate != OK) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7771 | invokeScreenCaptureError(validate, captureListener); |
| 7772 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7773 | } |
| 7774 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7775 | ui::Size reqSize; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7776 | sp<Layer> parent; |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7777 | Rect crop(args.sourceCrop); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7778 | std::unordered_set<uint32_t> excludeLayerIds; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7779 | ui::Dataspace dataspace = args.dataspace; |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7780 | |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 7781 | if (args.captureSecureLayers && !hasCaptureBlackoutContentPermission()) { |
| 7782 | ALOGE("Attempting to capture secure layers without CAPTURE_BLACKOUT_CONTENT"); |
| 7783 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 7784 | return; |
| 7785 | } |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7786 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7787 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7788 | Mutex::Autolock lock(mStateLock); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7789 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 7790 | parent = LayerHandle::getLayer(args.layerHandle); |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7791 | if (parent == nullptr) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7792 | ALOGE("captureLayers called with an invalid or removed parent"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7793 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7794 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7795 | } |
| 7796 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 7797 | Rect parentSourceBounds = parent->getCroppedBufferSize(parent->getDrawingState()); |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7798 | if (args.sourceCrop.width() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7799 | crop.left = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7800 | crop.right = parentSourceBounds.getWidth(); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7801 | } |
| 7802 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7803 | if (args.sourceCrop.height() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7804 | crop.top = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7805 | crop.bottom = parentSourceBounds.getHeight(); |
| 7806 | } |
| 7807 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7808 | if (crop.isEmpty() || args.frameScaleX <= 0.0f || args.frameScaleY <= 0.0f) { |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7809 | // Error out if the layer has no source bounds (i.e. they are boundless) and a source |
| 7810 | // crop was not specified, or an invalid frame scale was provided. |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7811 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7812 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7813 | } |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7814 | reqSize = ui::Size(crop.width() * args.frameScaleX, crop.height() * args.frameScaleY); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7815 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7816 | for (const auto& handle : args.excludeHandles) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7817 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7818 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7819 | excludeLayerIds.emplace(excludeLayer); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7820 | } else { |
| 7821 | ALOGW("Invalid layer handle passed as excludeLayer to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7822 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7823 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7824 | } |
| 7825 | } |
| 7826 | } // mStateLock |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7827 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7828 | // really small crop or frameScale |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7829 | if (reqSize.width <= 0 || reqSize.height <= 0) { |
| 7830 | ALOGW("Failed to captureLayes: crop or scale too small"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7831 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7832 | return; |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7833 | } |
| 7834 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7835 | bool childrenOnly = args.childrenOnly; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 7836 | RenderAreaFuture renderAreaFuture = ftl::defer([=, this]() -> std::unique_ptr<RenderArea> { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7837 | ui::Transform layerTransform; |
| 7838 | Rect layerBufferSize; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7839 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7840 | frontend::LayerSnapshot* snapshot = |
| 7841 | mLayerSnapshotBuilder.getSnapshot(parent->getSequence()); |
| 7842 | if (!snapshot) { |
| 7843 | ALOGW("Couldn't find layer snapshot for %d", parent->getSequence()); |
| 7844 | } else { |
| 7845 | layerTransform = snapshot->localTransform; |
| 7846 | layerBufferSize = snapshot->bufferSize; |
| 7847 | } |
| 7848 | } else { |
| 7849 | layerTransform = parent->getTransform(); |
| 7850 | layerBufferSize = parent->getBufferSize(parent->getDrawingState()); |
| 7851 | } |
| 7852 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7853 | return std::make_unique<LayerRenderArea>(*this, parent, crop, reqSize, dataspace, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7854 | childrenOnly, args.captureSecureLayers, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7855 | layerTransform, layerBufferSize, |
| 7856 | args.hintForSeamlessTransition); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7857 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7858 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7859 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7860 | std::optional<FloatRect> parentCrop = std::nullopt; |
| 7861 | if (args.childrenOnly) { |
| 7862 | parentCrop = crop.isEmpty() ? FloatRect(0, 0, reqSize.width, reqSize.height) |
| 7863 | : crop.toFloatRect(); |
| 7864 | } |
| 7865 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7866 | getLayerSnapshots = getLayerSnapshotsForScreenshots(parent->sequence, args.uid, |
| 7867 | std::move(excludeLayerIds), |
| 7868 | args.childrenOnly, parentCrop); |
| 7869 | } else { |
| 7870 | auto traverseLayers = [parent, args, excludeLayerIds](const LayerVector::Visitor& visitor) { |
| 7871 | parent->traverseChildrenInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
| 7872 | if (!layer->isVisible()) { |
| 7873 | return; |
| 7874 | } else if (args.childrenOnly && layer == parent.get()) { |
| 7875 | return; |
| 7876 | } else if (args.uid != CaptureArgs::UNSET_UID && args.uid != layer->getOwnerUid()) { |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 7877 | return; |
| 7878 | } |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 7879 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7880 | auto p = sp<Layer>::fromExisting(layer); |
| 7881 | while (p != nullptr) { |
| 7882 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 7883 | return; |
| 7884 | } |
| 7885 | p = p->getParent(); |
| 7886 | } |
| 7887 | |
| 7888 | visitor(layer); |
| 7889 | }); |
| 7890 | }; |
| 7891 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7892 | } |
Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 7893 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7894 | if (captureListener == nullptr) { |
| 7895 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7896 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7897 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7898 | } |
| 7899 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7900 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, args.pixelFormat, |
| 7901 | args.allowProtected, args.grayscale, captureListener); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7902 | } |
| 7903 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7904 | void SurfaceFlinger::captureScreenCommon(RenderAreaFuture renderAreaFuture, |
| 7905 | GetLayerSnapshotsFunction getLayerSnapshots, |
| 7906 | ui::Size bufferSize, ui::PixelFormat reqPixelFormat, |
| 7907 | bool allowProtected, bool grayscale, |
| 7908 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7909 | ATRACE_CALL(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 7910 | |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 7911 | if (exceedsMaxRenderTargetSize(bufferSize.getWidth(), bufferSize.getHeight())) { |
| 7912 | ALOGE("Attempted to capture screen with size (%" PRId32 ", %" PRId32 |
| 7913 | ") that exceeds render target size limit.", |
| 7914 | bufferSize.getWidth(), bufferSize.getHeight()); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7915 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7916 | return; |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 7917 | } |
| 7918 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7919 | // Loop over all visible layers to see whether there's any protected layer. A protected layer is |
| 7920 | // typically a layer with DRM contents, or have the GRALLOC_USAGE_PROTECTED set on the buffer. |
| 7921 | // A protected layer has no implication on whether it's secure, which is explicitly set by |
| 7922 | // application to avoid being screenshot or drawn via unsecure display. |
| 7923 | const bool supportsProtected = getRenderEngine().supportsProtectedContent(); |
| 7924 | bool hasProtectedLayer = false; |
| 7925 | if (allowProtected && supportsProtected) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7926 | hasProtectedLayer = mScheduler |
| 7927 | ->schedule([=]() { |
| 7928 | bool protectedLayerFound = false; |
| 7929 | auto layers = getLayerSnapshots(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7930 | for (auto& [_, layerFe] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7931 | protectedLayerFound |= |
| 7932 | (layerFe->mSnapshot->isVisible && |
| 7933 | layerFe->mSnapshot->hasProtectedContent); |
| 7934 | } |
| 7935 | return protectedLayerFound; |
| 7936 | }) |
| 7937 | .get(); |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7938 | } |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 7939 | const bool isProtected = hasProtectedLayer && allowProtected && supportsProtected; |
Richard Liu | cbcb895 | 2020-04-08 10:51:55 +0000 | [diff] [blame] | 7940 | const uint32_t usage = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER | |
| 7941 | GRALLOC_USAGE_HW_TEXTURE | |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 7942 | (isProtected ? GRALLOC_USAGE_PROTECTED |
| 7943 | : GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7944 | sp<GraphicBuffer> buffer = |
| 7945 | getFactory().createGraphicBuffer(bufferSize.getWidth(), bufferSize.getHeight(), |
| 7946 | static_cast<android_pixel_format>(reqPixelFormat), |
| 7947 | 1 /* layerCount */, usage, "screenshot"); |
Alec Mouri | 7013b6f | 2021-02-12 11:16:54 -0800 | [diff] [blame] | 7948 | |
| 7949 | const status_t bufferStatus = buffer->initCheck(); |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 7950 | if (bufferStatus != OK) { |
| 7951 | // Animations may end up being really janky, but don't crash here. |
| 7952 | // Otherwise an irreponsible process may cause an SF crash by allocating |
| 7953 | // too much. |
| 7954 | ALOGE("%s: Buffer failed to allocate: %d", __func__, bufferStatus); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7955 | invokeScreenCaptureError(bufferStatus, captureListener); |
| 7956 | return; |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 7957 | } |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 7958 | const std::shared_ptr<renderengine::ExternalTexture> texture = std::make_shared< |
| 7959 | renderengine::impl::ExternalTexture>(buffer, getRenderEngine(), |
| 7960 | renderengine::impl::ExternalTexture::Usage:: |
| 7961 | WRITEABLE); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7962 | auto fence = captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, texture, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 7963 | false /* regionSampling */, grayscale, isProtected, |
| 7964 | captureListener); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7965 | fence.get(); |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 7966 | } |
| 7967 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7968 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenCommon( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7969 | RenderAreaFuture renderAreaFuture, GetLayerSnapshotsFunction getLayerSnapshots, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 7970 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 7971 | bool grayscale, bool isProtected, const sp<IScreenCaptureListener>& captureListener) { |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 7972 | ATRACE_CALL(); |
| 7973 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7974 | auto future = mScheduler->schedule( |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 7975 | [=, this, renderAreaFuture = std::move(renderAreaFuture)]() FTL_FAKE_GUARD( |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7976 | kMainThreadContext) mutable -> ftl::SharedFuture<FenceResult> { |
| 7977 | ScreenCaptureResults captureResults; |
Patrick Williams | 3190813 | 2023-01-09 13:38:48 -0600 | [diff] [blame] | 7978 | std::shared_ptr<RenderArea> renderArea = renderAreaFuture.get(); |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7979 | if (!renderArea) { |
| 7980 | ALOGW("Skipping screen capture because of invalid render area."); |
Nolan Scobie | 1d2deb2 | 2022-11-18 12:57:47 -0500 | [diff] [blame] | 7981 | if (captureListener) { |
| 7982 | captureResults.fenceResult = base::unexpected(NO_MEMORY); |
| 7983 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7984 | } |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7985 | return ftl::yield<FenceResult>(base::unexpected(NO_ERROR)).share(); |
| 7986 | } |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7987 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7988 | ftl::SharedFuture<FenceResult> renderFuture; |
| 7989 | renderArea->render([&]() FTL_FAKE_GUARD(kMainThreadContext) { |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 7990 | renderFuture = |
| 7991 | renderScreenImpl(renderArea, getLayerSnapshots, buffer, regionSampling, |
| 7992 | grayscale, isProtected, captureResults); |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7993 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7994 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7995 | if (captureListener) { |
| 7996 | // Defer blocking on renderFuture back to the Binder thread. |
| 7997 | return ftl::Future(std::move(renderFuture)) |
| 7998 | .then([captureListener, captureResults = std::move(captureResults)]( |
| 7999 | FenceResult fenceResult) mutable -> FenceResult { |
| 8000 | captureResults.fenceResult = std::move(fenceResult); |
| 8001 | captureListener->onScreenCaptureCompleted(captureResults); |
| 8002 | return base::unexpected(NO_ERROR); |
| 8003 | }) |
| 8004 | .share(); |
| 8005 | } |
| 8006 | return renderFuture; |
| 8007 | }); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 8008 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8009 | // Flatten nested futures. |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 8010 | auto chain = ftl::Future(std::move(future)).then([](ftl::SharedFuture<FenceResult> future) { |
| 8011 | return future; |
| 8012 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8013 | |
| 8014 | return chain.share(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 8015 | } |
| 8016 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 8017 | ftl::SharedFuture<FenceResult> SurfaceFlinger::renderScreenImpl( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8018 | std::shared_ptr<const RenderArea> renderArea, GetLayerSnapshotsFunction getLayerSnapshots, |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 8019 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8020 | bool grayscale, bool isProtected, ScreenCaptureResults& captureResults) { |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 8021 | ATRACE_CALL(); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8022 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8023 | auto layers = getLayerSnapshots(); |
Alec Mouri | b4814de | 2023-09-11 22:09:03 +0000 | [diff] [blame] | 8024 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8025 | for (auto& [_, layerFE] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8026 | frontend::LayerSnapshot* snapshot = layerFE->mSnapshot.get(); |
| 8027 | captureResults.capturedSecureLayers |= (snapshot->isVisible && snapshot->isSecure); |
| 8028 | captureResults.capturedHdrLayers |= isHdrLayer(*snapshot); |
| 8029 | layerFE->mSnapshot->geomLayerTransform = |
| 8030 | renderArea->getTransform() * layerFE->mSnapshot->geomLayerTransform; |
Patrick Williams | c6e0cce | 2023-02-28 23:04:45 -0600 | [diff] [blame] | 8031 | layerFE->mSnapshot->geomInverseLayerTransform = |
| 8032 | layerFE->mSnapshot->geomLayerTransform.inverse(); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8033 | } |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8034 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8035 | auto capturedBuffer = buffer; |
| 8036 | |
| 8037 | auto requestedDataspace = renderArea->getReqDataSpace(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8038 | auto parent = renderArea->getParentLayer(); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 8039 | auto renderIntent = RenderIntent::TONE_MAP_COLORIMETRIC; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 8040 | auto sdrWhitePointNits = DisplayDevice::sDefaultMaxLumiance; |
| 8041 | auto displayBrightnessNits = DisplayDevice::sDefaultMaxLumiance; |
| 8042 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8043 | captureResults.capturedDataspace = requestedDataspace; |
| 8044 | |
| 8045 | { |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8046 | Mutex::Autolock lock(mStateLock); |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8047 | const DisplayDevice* display = nullptr; |
| 8048 | if (parent) { |
| 8049 | display = findDisplay([layerStack = parent->getLayerStack()](const auto& display) { |
| 8050 | return display.getLayerStack() == layerStack; |
| 8051 | }).get(); |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8052 | } |
| 8053 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8054 | if (display == nullptr) { |
| 8055 | display = renderArea->getDisplayDevice().get(); |
| 8056 | } |
| 8057 | |
| 8058 | if (display == nullptr) { |
| 8059 | display = getDefaultDisplayDeviceLocked().get(); |
| 8060 | } |
| 8061 | |
| 8062 | if (display != nullptr) { |
| 8063 | const auto& state = display->getCompositionDisplay()->getState(); |
| 8064 | captureResults.capturedDataspace = |
| 8065 | pickBestDataspace(requestedDataspace, display, captureResults.capturedHdrLayers, |
| 8066 | renderArea->getHintForSeamlessTransition()); |
| 8067 | sdrWhitePointNits = state.sdrWhitePointNits; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8068 | |
Alec Mouri | b4814de | 2023-09-11 22:09:03 +0000 | [diff] [blame] | 8069 | // TODO(b/298219334): Clean this up once we verify this doesn't break anything |
| 8070 | static constexpr bool kScreenshotsDontDim = true; |
| 8071 | |
| 8072 | if (kScreenshotsDontDim && !captureResults.capturedHdrLayers) { |
| 8073 | displayBrightnessNits = sdrWhitePointNits; |
| 8074 | } else { |
| 8075 | displayBrightnessNits = state.displayBrightnessNits; |
| 8076 | // Only clamp the display brightness if this is not a seamless transition. Otherwise |
| 8077 | // for seamless transitions it's important to match the current display state as the |
| 8078 | // buffer will be shown under these same conditions, and we want to avoid any |
| 8079 | // flickers |
| 8080 | if (sdrWhitePointNits > 1.0f && !renderArea->getHintForSeamlessTransition()) { |
| 8081 | // Restrict the amount of HDR "headroom" in the screenshot to avoid over-dimming |
| 8082 | // the SDR portion. 2.0 chosen by experimentation |
| 8083 | constexpr float kMaxScreenshotHeadroom = 2.0f; |
| 8084 | displayBrightnessNits = std::min(sdrWhitePointNits * kMaxScreenshotHeadroom, |
| 8085 | displayBrightnessNits); |
| 8086 | } |
Alec Mouri | 5e488f8 | 2023-09-15 01:27:49 +0000 | [diff] [blame] | 8087 | } |
Alec Mouri | ffb3221 | 2023-09-16 19:29:15 +0000 | [diff] [blame] | 8088 | |
| 8089 | // Screenshots leaving the device should be colorimetric |
| 8090 | if (requestedDataspace == ui::Dataspace::UNKNOWN && |
| 8091 | renderArea->getHintForSeamlessTransition()) { |
Alec Mouri | 5e488f8 | 2023-09-15 01:27:49 +0000 | [diff] [blame] | 8092 | renderIntent = state.renderIntent; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8093 | } |
| 8094 | } |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8095 | } |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8096 | |
| 8097 | captureResults.buffer = capturedBuffer->getBuffer(); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8098 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8099 | ui::LayerStack layerStack{ui::DEFAULT_LAYER_STACK}; |
| 8100 | if (!layers.empty()) { |
| 8101 | const sp<LayerFE>& layerFE = layers.back().second; |
| 8102 | layerStack = layerFE->getCompositionState()->outputFilter.layerStack; |
Yichi Chen | 40773d9 | 2020-04-01 10:10:18 +0800 | [diff] [blame] | 8103 | } |
Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 8104 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8105 | auto copyLayerFEs = [&layers]() { |
| 8106 | std::vector<sp<compositionengine::LayerFE>> layerFEs; |
| 8107 | layerFEs.reserve(layers.size()); |
| 8108 | for (const auto& [_, layerFE] : layers) { |
| 8109 | layerFEs.push_back(layerFE); |
| 8110 | } |
| 8111 | return layerFEs; |
| 8112 | }; |
| 8113 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8114 | auto present = [this, buffer = capturedBuffer, dataspace = captureResults.capturedDataspace, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8115 | sdrWhitePointNits, displayBrightnessNits, grayscale, isProtected, |
| 8116 | layerFEs = copyLayerFEs(), layerStack, regionSampling, |
| 8117 | renderArea = std::move(renderArea), renderIntent]() -> FenceResult { |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8118 | std::unique_ptr<compositionengine::CompositionEngine> compositionEngine = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8119 | mFactory.createCompositionEngine(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8120 | compositionEngine->setRenderEngine(mRenderEngine.get()); |
| 8121 | |
| 8122 | compositionengine::Output::ColorProfile colorProfile{.dataspace = dataspace, |
| 8123 | .renderIntent = renderIntent}; |
| 8124 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8125 | float targetBrightness = 1.0f; |
| 8126 | if (dataspace == ui::Dataspace::BT2020_HLG) { |
| 8127 | const float maxBrightnessNits = displayBrightnessNits / sdrWhitePointNits * 203; |
| 8128 | // With a low dimming ratio, don't fit the entire curve. Otherwise mixed content |
| 8129 | // will appear way too bright. |
| 8130 | if (maxBrightnessNits < 1000.f) { |
| 8131 | targetBrightness = 1000.f / maxBrightnessNits; |
| 8132 | } |
| 8133 | } |
| 8134 | |
Alec Mouri | ffb3221 | 2023-09-16 19:29:15 +0000 | [diff] [blame] | 8135 | // Screenshots leaving the device must not dim in gamma space. |
| 8136 | const bool dimInGammaSpaceForEnhancedScreenshots = mDimInGammaSpaceForEnhancedScreenshots && |
| 8137 | renderArea->getHintForSeamlessTransition(); |
| 8138 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8139 | std::shared_ptr<ScreenCaptureOutput> output = createScreenCaptureOutput( |
| 8140 | ScreenCaptureOutputArgs{.compositionEngine = *compositionEngine, |
| 8141 | .colorProfile = colorProfile, |
| 8142 | .renderArea = *renderArea, |
| 8143 | .layerStack = layerStack, |
| 8144 | .buffer = std::move(buffer), |
| 8145 | .sdrWhitePointNits = sdrWhitePointNits, |
| 8146 | .displayBrightnessNits = displayBrightnessNits, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8147 | .targetBrightness = targetBrightness, |
Alec Mouri | 7dae9c1 | 2023-07-13 19:40:53 +0000 | [diff] [blame] | 8148 | .regionSampling = regionSampling, |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 8149 | .treat170mAsSrgb = mTreat170mAsSrgb, |
| 8150 | .dimInGammaSpaceForEnhancedScreenshots = |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8151 | dimInGammaSpaceForEnhancedScreenshots, |
| 8152 | .isProtected = isProtected}); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8153 | |
| 8154 | const float colorSaturation = grayscale ? 0 : 1; |
| 8155 | compositionengine::CompositionRefreshArgs refreshArgs{ |
| 8156 | .outputs = {output}, |
| 8157 | .layers = std::move(layerFEs), |
| 8158 | .updatingOutputGeometryThisFrame = true, |
| 8159 | .updatingGeometryThisFrame = true, |
| 8160 | .colorTransformMatrix = calculateColorMatrix(colorSaturation), |
| 8161 | }; |
| 8162 | compositionEngine->present(refreshArgs); |
| 8163 | |
| 8164 | return output->getRenderSurface()->getClientTargetAcquireFence(); |
| 8165 | }; |
| 8166 | |
| 8167 | // If RenderEngine is threaded, we can safely call CompositionEngine::present off the main |
| 8168 | // thread as the RenderEngine::drawLayers call will run on RenderEngine's thread. Otherwise, |
| 8169 | // we need RenderEngine to run on the main thread so we call CompositionEngine::present |
| 8170 | // immediately. |
| 8171 | // |
| 8172 | // TODO(b/196334700) Once we use RenderEngineThreaded everywhere we can always defer the call |
| 8173 | // to CompositionEngine::present. |
| 8174 | const bool renderEngineIsThreaded = [&]() { |
| 8175 | using Type = renderengine::RenderEngine::RenderEngineType; |
| 8176 | const auto type = mRenderEngine->getRenderEngineType(); |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 8177 | return type == Type::SKIA_GL_THREADED; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8178 | }(); |
| 8179 | auto presentFuture = renderEngineIsThreaded ? ftl::defer(std::move(present)).share() |
| 8180 | : ftl::yield(present()).share(); |
| 8181 | |
| 8182 | for (auto& [layer, layerFE] : layers) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 8183 | layer->onLayerDisplayed(ftl::Future(presentFuture) |
| 8184 | .then([layerFE = std::move(layerFE)](FenceResult) { |
| 8185 | return layerFE->stealCompositionResult() |
| 8186 | .releaseFences.back() |
| 8187 | .first.get(); |
| 8188 | }) |
| 8189 | .share(), |
| 8190 | ui::INVALID_LAYER_STACK); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8191 | } |
| 8192 | |
| 8193 | return presentFuture; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 8194 | } |
| 8195 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8196 | void SurfaceFlinger::traverseLegacyLayers(const LayerVector::Visitor& visitor) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8197 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8198 | for (auto& layer : mLegacyLayers) { |
| 8199 | visitor(layer.second.get()); |
| 8200 | } |
| 8201 | } else { |
| 8202 | mDrawingState.traverse(visitor); |
| 8203 | } |
| 8204 | } |
| 8205 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 8206 | // --------------------------------------------------------------------------- |
| 8207 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 8208 | void SurfaceFlinger::State::traverse(const LayerVector::Visitor& visitor) const { |
| 8209 | layersSortedByZ.traverse(visitor); |
| 8210 | } |
| 8211 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 8212 | void SurfaceFlinger::State::traverseInZOrder(const LayerVector::Visitor& visitor) const { |
| 8213 | layersSortedByZ.traverseInZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 8214 | } |
| 8215 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 8216 | void SurfaceFlinger::State::traverseInReverseZOrder(const LayerVector::Visitor& visitor) const { |
| 8217 | layersSortedByZ.traverseInReverseZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 8218 | } |
| 8219 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8220 | void SurfaceFlinger::traverseLayersInLayerStack(ui::LayerStack layerStack, const int32_t uid, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8221 | std::unordered_set<uint32_t> excludeLayerIds, |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 8222 | const LayerVector::Visitor& visitor) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8223 | // We loop through the first level of layers without traversing, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 8224 | // as we need to determine which layers belong to the requested display. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8225 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 8226 | if (layer->getLayerStack() != layerStack) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8227 | continue; |
| 8228 | } |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 8229 | // relative layers are traversed in Layer::traverseInZOrder |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8230 | layer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 8231 | if (layer->isInternalDisplayOverlay()) { |
Adrian Roos | 8acf5a0 | 2018-01-17 21:28:19 +0100 | [diff] [blame] | 8232 | return; |
| 8233 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8234 | if (!layer->isVisible()) { |
| 8235 | return; |
| 8236 | } |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8237 | if (uid != CaptureArgs::UNSET_UID && layer->getOwnerUid() != uid) { |
| 8238 | return; |
| 8239 | } |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8240 | |
| 8241 | if (!excludeLayerIds.empty()) { |
| 8242 | auto p = sp<Layer>::fromExisting(layer); |
| 8243 | while (p != nullptr) { |
| 8244 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 8245 | return; |
| 8246 | } |
| 8247 | p = p->getParent(); |
| 8248 | } |
| 8249 | } |
| 8250 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8251 | visitor(layer); |
| 8252 | }); |
| 8253 | } |
| 8254 | } |
| 8255 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8256 | ftl::Optional<scheduler::FrameRateMode> SurfaceFlinger::getPreferredDisplayMode( |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8257 | PhysicalDisplayId displayId, DisplayModeId defaultModeId) const { |
| 8258 | if (const auto schedulerMode = mScheduler->getPreferredDisplayMode(); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8259 | schedulerMode.modePtr->getPhysicalDisplayId() == displayId) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8260 | return schedulerMode; |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8261 | } |
| 8262 | |
| 8263 | return mPhysicalDisplays.get(displayId) |
| 8264 | .transform(&PhysicalDisplay::snapshotRef) |
| 8265 | .and_then([&](const display::DisplaySnapshot& snapshot) { |
| 8266 | return snapshot.displayModes().get(defaultModeId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 8267 | }) |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8268 | .transform([](const DisplayModePtr& modePtr) { |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 8269 | return scheduler::FrameRateMode{modePtr->getPeakFps(), ftl::as_non_null(modePtr)}; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8270 | }); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8271 | } |
| 8272 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8273 | status_t SurfaceFlinger::setDesiredDisplayModeSpecsInternal( |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 8274 | const sp<DisplayDevice>& display, |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8275 | const scheduler::RefreshRateSelector::PolicyVariant& policy) { |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8276 | const auto displayId = display->getPhysicalId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8277 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8278 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 8279 | Mutex::Autolock lock(mStateLock); |
| 8280 | |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 8281 | if (mDebugDisplayModeSetByBackdoor) { |
| 8282 | // ignore this request as mode is overridden by backdoor |
| 8283 | return NO_ERROR; |
| 8284 | } |
| 8285 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8286 | auto& selector = display->refreshRateSelector(); |
| 8287 | using SetPolicyResult = scheduler::RefreshRateSelector::SetPolicyResult; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8288 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8289 | switch (selector.setPolicy(policy)) { |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8290 | case SetPolicyResult::Invalid: |
| 8291 | return BAD_VALUE; |
| 8292 | case SetPolicyResult::Unchanged: |
| 8293 | return NO_ERROR; |
| 8294 | case SetPolicyResult::Changed: |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8295 | break; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8296 | } |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8297 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 8298 | if (!shouldApplyRefreshRateSelectorPolicy(*display)) { |
| 8299 | ALOGV("%s(%s): Skipped applying policy", __func__, to_string(displayId).c_str()); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8300 | return NO_ERROR; |
| 8301 | } |
| 8302 | |
| 8303 | return applyRefreshRateSelectorPolicy(displayId, selector); |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8304 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8305 | |
Dominik Laskowski | ca96eff | 2023-09-21 14:30:34 -0400 | [diff] [blame] | 8306 | bool SurfaceFlinger::shouldApplyRefreshRateSelectorPolicy(const DisplayDevice& display) const { |
| 8307 | if (display.isPoweredOn() || mPhysicalDisplays.size() == 1) return true; |
| 8308 | |
| 8309 | LOG_ALWAYS_FATAL_IF(display.isVirtual()); |
| 8310 | const auto displayId = display.getPhysicalId(); |
| 8311 | |
| 8312 | // The display is powered off, and this is a multi-display device. If the display is the |
| 8313 | // inactive internal display of a dual-display foldable, then the policy will be applied |
| 8314 | // when it becomes active upon powering on. |
| 8315 | // |
| 8316 | // TODO(b/255635711): Remove this function (i.e. returning `false` as a special case) once |
| 8317 | // concurrent mode setting across multiple (potentially powered off) displays is supported. |
| 8318 | // |
| 8319 | return displayId == mActiveDisplayId || |
| 8320 | !mPhysicalDisplays.get(displayId) |
| 8321 | .transform(&PhysicalDisplay::isInternal) |
| 8322 | .value_or(false); |
| 8323 | } |
| 8324 | |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8325 | status_t SurfaceFlinger::applyRefreshRateSelectorPolicy( |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8326 | PhysicalDisplayId displayId, const scheduler::RefreshRateSelector& selector, bool force) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8327 | const scheduler::RefreshRateSelector::Policy currentPolicy = selector.getCurrentPolicy(); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8328 | ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str()); |
Adrian Salido | ab6ef6c | 2019-08-28 10:02:49 -0700 | [diff] [blame] | 8329 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 8330 | // TODO(b/140204874): Leave the event in until we do proper testing with all apps that might |
| 8331 | // be depending in this callback. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8332 | if (const auto activeMode = selector.getActiveMode(); displayId == mActiveDisplayId) { |
| 8333 | mScheduler->onPrimaryDisplayModeChanged(mAppConnectionHandle, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8334 | toggleKernelIdleTimer(); |
| 8335 | } else { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8336 | mScheduler->onNonPrimaryDisplayModeChanged(mAppConnectionHandle, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8337 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 8338 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8339 | auto preferredModeOpt = getPreferredDisplayMode(displayId, currentPolicy.defaultMode); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8340 | if (!preferredModeOpt) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8341 | ALOGE("%s: Preferred mode is unknown", __func__); |
| 8342 | return NAME_NOT_FOUND; |
| 8343 | } |
| 8344 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8345 | auto preferredMode = std::move(*preferredModeOpt); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8346 | const auto preferredModeId = preferredMode.modePtr->getId(); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 8347 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8348 | const Fps preferredFps = preferredMode.fps; |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8349 | ALOGV("Switching to Scheduler preferred mode %d (%s)", preferredModeId.value(), |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8350 | to_string(preferredFps).c_str()); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8351 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8352 | if (!selector.isModeAllowed(preferredMode)) { |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8353 | ALOGE("%s: Preferred mode %d is disallowed", __func__, preferredModeId.value()); |
| 8354 | return INVALID_OPERATION; |
Dominik Laskowski | 4f1dd8c | 2019-04-17 15:54:30 -0700 | [diff] [blame] | 8355 | } |
| 8356 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8357 | setDesiredMode({std::move(preferredMode), .emitEvent = true}, force); |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 8358 | |
| 8359 | // Update the frameRateOverride list as the display render rate might have changed |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8360 | if (mScheduler->updateFrameRateOverrides(scheduler::GlobalSignals{}, preferredFps)) { |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 8361 | triggerOnFrameRateOverridesChanged(); |
| 8362 | } |
| 8363 | |
Ady Abraham | d9b3ea6 | 2019-02-26 14:08:03 -0800 | [diff] [blame] | 8364 | return NO_ERROR; |
| 8365 | } |
| 8366 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8367 | namespace { |
| 8368 | FpsRange translate(const gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange& aidlRange) { |
| 8369 | return FpsRange{Fps::fromValue(aidlRange.min), Fps::fromValue(aidlRange.max)}; |
| 8370 | } |
| 8371 | |
| 8372 | FpsRanges translate(const gui::DisplayModeSpecs::RefreshRateRanges& aidlRanges) { |
| 8373 | return FpsRanges{translate(aidlRanges.physical), translate(aidlRanges.render)}; |
| 8374 | } |
| 8375 | |
| 8376 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange translate(const FpsRange& range) { |
| 8377 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange aidlRange; |
| 8378 | aidlRange.min = range.min.getValue(); |
| 8379 | aidlRange.max = range.max.getValue(); |
| 8380 | return aidlRange; |
| 8381 | } |
| 8382 | |
| 8383 | gui::DisplayModeSpecs::RefreshRateRanges translate(const FpsRanges& ranges) { |
| 8384 | gui::DisplayModeSpecs::RefreshRateRanges aidlRanges; |
| 8385 | aidlRanges.physical = translate(ranges.physical); |
| 8386 | aidlRanges.render = translate(ranges.render); |
| 8387 | return aidlRanges; |
| 8388 | } |
| 8389 | |
| 8390 | } // namespace |
| 8391 | |
| 8392 | status_t SurfaceFlinger::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 8393 | const gui::DisplayModeSpecs& specs) { |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8394 | ATRACE_CALL(); |
| 8395 | |
| 8396 | if (!displayToken) { |
| 8397 | return BAD_VALUE; |
| 8398 | } |
| 8399 | |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame^] | 8400 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8401 | const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayToken)); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8402 | if (!display) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8403 | ALOGE("Attempt to set desired display modes for invalid display token %p", |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8404 | displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8405 | return NAME_NOT_FOUND; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8406 | } else if (display->isVirtual()) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8407 | ALOGW("Attempt to set desired display modes for virtual display"); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8408 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8409 | } else { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8410 | using Policy = scheduler::RefreshRateSelector::DisplayManagerPolicy; |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8411 | const Policy policy{DisplayModeId(specs.defaultMode), translate(specs.primaryRanges), |
| 8412 | translate(specs.appRequestRanges), specs.allowGroupSwitching}; |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 8413 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8414 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8415 | } |
| 8416 | }); |
| 8417 | |
| 8418 | return future.get(); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8419 | } |
| 8420 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 8421 | status_t SurfaceFlinger::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8422 | gui::DisplayModeSpecs* outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8423 | ATRACE_CALL(); |
| 8424 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8425 | if (!displayToken || !outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8426 | return BAD_VALUE; |
| 8427 | } |
| 8428 | |
| 8429 | Mutex::Autolock lock(mStateLock); |
| 8430 | const auto display = getDisplayDeviceLocked(displayToken); |
| 8431 | if (!display) { |
| 8432 | return NAME_NOT_FOUND; |
| 8433 | } |
| 8434 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8435 | if (display->isVirtual()) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 8436 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8437 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8438 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8439 | scheduler::RefreshRateSelector::Policy policy = |
| 8440 | display->refreshRateSelector().getDisplayManagerPolicy(); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8441 | outSpecs->defaultMode = policy.defaultMode.value(); |
| 8442 | outSpecs->allowGroupSwitching = policy.allowGroupSwitching; |
| 8443 | outSpecs->primaryRanges = translate(policy.primaryRanges); |
| 8444 | outSpecs->appRequestRanges = translate(policy.appRequestRanges); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8445 | return NO_ERROR; |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8446 | } |
| 8447 | |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 8448 | void SurfaceFlinger::onLayerFirstRef(Layer* layer) { |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8449 | mNumLayers++; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8450 | if (!layer->isRemovedFromCurrentState()) { |
| 8451 | mScheduler->registerLayer(layer); |
| 8452 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8453 | } |
| 8454 | |
| 8455 | void SurfaceFlinger::onLayerDestroyed(Layer* layer) { |
| 8456 | mNumLayers--; |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8457 | removeHierarchyFromOffscreenLayers(layer); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8458 | if (!layer->isRemovedFromCurrentState()) { |
| 8459 | mScheduler->deregisterLayer(layer); |
| 8460 | } |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 8461 | if (mTransactionTracing) { |
| 8462 | mTransactionTracing->onLayerRemoved(layer->getSequence()); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 8463 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 8464 | mScheduler->onLayerDestroyed(layer); |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8465 | } |
| 8466 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8467 | void SurfaceFlinger::onLayerUpdate() { |
| 8468 | scheduleCommit(FrameHint::kActive); |
| 8469 | } |
| 8470 | |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8471 | // WARNING: ONLY CALL THIS FROM LAYER DTOR |
| 8472 | // Here we add children in the current state to offscreen layers and remove the |
| 8473 | // layer itself from the offscreen layer list. Since |
| 8474 | // this is the dtor, it is safe to access the current state. This keeps us |
| 8475 | // from dangling children layers such that they are not reachable from the |
| 8476 | // Drawing state nor the offscreen layer list |
| 8477 | // See b/141111965 |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8478 | void SurfaceFlinger::removeHierarchyFromOffscreenLayers(Layer* layer) { |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8479 | for (auto& child : layer->getCurrentChildren()) { |
| 8480 | mOffscreenLayers.emplace(child.get()); |
| 8481 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8482 | mOffscreenLayers.erase(layer); |
| 8483 | } |
| 8484 | |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8485 | void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) { |
| 8486 | mOffscreenLayers.erase(layer); |
| 8487 | } |
| 8488 | |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 8489 | status_t SurfaceFlinger::setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, |
| 8490 | float lightPosY, float lightPosZ, |
| 8491 | float lightRadius) { |
| 8492 | Mutex::Autolock _l(mStateLock); |
| 8493 | mCurrentState.globalShadowSettings.ambientColor = vec4(ambientColor); |
| 8494 | mCurrentState.globalShadowSettings.spotColor = vec4(spotColor); |
| 8495 | mCurrentState.globalShadowSettings.lightPos.y = lightPosY; |
| 8496 | mCurrentState.globalShadowSettings.lightPos.z = lightPosZ; |
| 8497 | mCurrentState.globalShadowSettings.lightRadius = lightRadius; |
| 8498 | |
| 8499 | // these values are overridden when calculating the shadow settings for a layer. |
| 8500 | mCurrentState.globalShadowSettings.lightPos.x = 0.f; |
| 8501 | mCurrentState.globalShadowSettings.length = 0.f; |
Vishnu Nair | b13bb95 | 2019-11-15 10:24:08 -0800 | [diff] [blame] | 8502 | return NO_ERROR; |
| 8503 | } |
| 8504 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8505 | const std::unordered_map<std::string, uint32_t>& SurfaceFlinger::getGenericLayerMetadataKeyMap() |
| 8506 | const { |
| 8507 | // TODO(b/149500060): Remove this fixed/static mapping. Please prefer taking |
| 8508 | // on the work to remove the table in that bug rather than adding more to |
| 8509 | // it. |
| 8510 | static const std::unordered_map<std::string, uint32_t> genericLayerMetadataKeyMap{ |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8511 | {"org.chromium.arc.V1_0.TaskId", gui::METADATA_TASK_ID}, |
| 8512 | {"org.chromium.arc.V1_0.CursorInfo", gui::METADATA_MOUSE_CURSOR}, |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8513 | }; |
| 8514 | return genericLayerMetadataKeyMap; |
| 8515 | } |
| 8516 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8517 | status_t SurfaceFlinger::setGameModeFrameRateOverride(uid_t uid, float frameRate) { |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 8518 | PhysicalDisplayId displayId = [&]() { |
| 8519 | Mutex::Autolock lock(mStateLock); |
| 8520 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 8521 | }(); |
| 8522 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8523 | mScheduler->setGameModeFrameRateForUid(FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 8524 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
| 8525 | return NO_ERROR; |
| 8526 | } |
| 8527 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8528 | status_t SurfaceFlinger::setGameDefaultFrameRateOverride(uid_t uid, float frameRate) { |
| 8529 | if (FlagManager::getInstance().game_default_frame_rate()) { |
| 8530 | mScheduler->setGameDefaultFrameRateForUid( |
| 8531 | FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
| 8532 | } |
| 8533 | return NO_ERROR; |
| 8534 | } |
| 8535 | |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8536 | status_t SurfaceFlinger::updateSmallAreaDetection( |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 8537 | std::vector<std::pair<int32_t, float>>& appIdThresholdMappings) { |
| 8538 | mScheduler->updateSmallAreaDetection(appIdThresholdMappings); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8539 | return NO_ERROR; |
| 8540 | } |
| 8541 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 8542 | status_t SurfaceFlinger::setSmallAreaDetectionThreshold(int32_t appId, float threshold) { |
| 8543 | mScheduler->setSmallAreaDetectionThreshold(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8544 | return NO_ERROR; |
| 8545 | } |
| 8546 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8547 | void SurfaceFlinger::enableRefreshRateOverlay(bool enable) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 8548 | bool setByHwc = getHwComposer().hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8549 | for (const auto& [id, display] : mPhysicalDisplays) { |
Sally Qi | de329f2 | 2023-09-26 16:21:39 -0700 | [diff] [blame] | 8550 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal || |
| 8551 | FlagManager::getInstance().refresh_rate_overlay_on_external_display()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8552 | if (const auto device = getDisplayDeviceLocked(id)) { |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 8553 | const auto enableOverlay = [&](const bool setByHwc) FTL_FAKE_GUARD( |
| 8554 | kMainThreadContext) { |
| 8555 | device->enableRefreshRateOverlay(enable, setByHwc, mRefreshRateOverlaySpinner, |
| 8556 | mRefreshRateOverlayRenderRate, |
| 8557 | mRefreshRateOverlayShowInMiddle); |
| 8558 | }; |
| 8559 | enableOverlay(setByHwc); |
| 8560 | if (setByHwc) { |
| 8561 | const auto status = |
| 8562 | getHwComposer().setRefreshRateChangedCallbackDebugEnabled(id, enable); |
| 8563 | if (status != NO_ERROR) { |
| 8564 | ALOGE("Error updating the refresh rate changed callback debug enabled"); |
| 8565 | enableOverlay(/*setByHwc*/ false); |
| 8566 | } |
| 8567 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8568 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8569 | } |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 8570 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8571 | } |
| 8572 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 8573 | void SurfaceFlinger::enableHdrSdrRatioOverlay(bool enable) { |
| 8574 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 8575 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal) { |
| 8576 | if (const auto device = getDisplayDeviceLocked(id)) { |
| 8577 | device->enableHdrSdrRatioOverlay(enable); |
| 8578 | } |
| 8579 | } |
| 8580 | } |
| 8581 | } |
| 8582 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8583 | int SurfaceFlinger::getGpuContextPriority() { |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 8584 | return getRenderEngine().getContextPriority(); |
Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 8585 | } |
| 8586 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8587 | int SurfaceFlinger::calculateMaxAcquiredBufferCount(Fps refreshRate, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8588 | std::chrono::nanoseconds presentLatency) { |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8589 | auto pipelineDepth = presentLatency.count() / refreshRate.getPeriodNsecs(); |
| 8590 | if (presentLatency.count() % refreshRate.getPeriodNsecs()) { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8591 | pipelineDepth++; |
| 8592 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8593 | return std::max(minAcquiredBuffers, static_cast<int64_t>(pipelineDepth - 1)); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8594 | } |
| 8595 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8596 | status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 8597 | Fps maxRefreshRate = 60_Hz; |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8598 | |
| 8599 | if (!getHwComposer().isHeadless()) { |
| 8600 | if (const auto display = getDefaultDisplayDevice()) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8601 | maxRefreshRate = display->refreshRateSelector().getSupportedRefreshRateRange().max; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8602 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8603 | } |
| 8604 | |
| 8605 | *buffers = getMaxAcquiredBufferCountForRefreshRate(maxRefreshRate); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8606 | return NO_ERROR; |
| 8607 | } |
| 8608 | |
rnlee | ed20fa4 | 2021-08-10 18:00:03 -0700 | [diff] [blame] | 8609 | uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 8610 | Fps refreshRate = 60_Hz; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8611 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8612 | if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) { |
| 8613 | refreshRate = *frameRateOverride; |
| 8614 | } else if (!getHwComposer().isHeadless()) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8615 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked())) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8616 | refreshRate = display->refreshRateSelector().getActiveMode().fps; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8617 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8618 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8619 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8620 | return getMaxAcquiredBufferCountForRefreshRate(refreshRate); |
| 8621 | } |
| 8622 | |
| 8623 | int SurfaceFlinger::getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const { |
| 8624 | const auto vsyncConfig = mVsyncConfiguration->getConfigsForRefreshRate(refreshRate).late; |
| 8625 | const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration; |
| 8626 | return calculateMaxAcquiredBufferCount(refreshRate, presentLatency); |
| 8627 | } |
| 8628 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 8629 | void SurfaceFlinger::handleLayerCreatedLocked(const LayerCreatedState& state, VsyncId vsyncId) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8630 | sp<Layer> layer = state.layer.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8631 | if (!layer) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8632 | ALOGD("Layer was destroyed soon after creation %p", state.layer.unsafe_get()); |
| 8633 | return; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8634 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 8635 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8636 | |
| 8637 | sp<Layer> parent; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8638 | bool addToRoot = state.addToRoot; |
| 8639 | if (state.initialParent != nullptr) { |
| 8640 | parent = state.initialParent.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8641 | if (parent == nullptr) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8642 | ALOGD("Parent was destroyed soon after creation %p", state.initialParent.unsafe_get()); |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 8643 | addToRoot = false; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8644 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8645 | } |
| 8646 | |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 8647 | if (parent == nullptr && addToRoot) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 8648 | layer->setIsAtRoot(true); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8649 | mCurrentState.layersSortedByZ.add(layer); |
| 8650 | } else if (parent == nullptr) { |
| 8651 | layer->onRemovedFromCurrentState(); |
| 8652 | } else if (parent->isRemovedFromCurrentState()) { |
| 8653 | parent->addChild(layer); |
| 8654 | layer->onRemovedFromCurrentState(); |
| 8655 | } else { |
| 8656 | parent->addChild(layer); |
| 8657 | } |
| 8658 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 8659 | ui::LayerStack layerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 8660 | sp<const DisplayDevice> hintDisplay; |
| 8661 | // Find the display that includes the layer. |
| 8662 | for (const auto& [token, display] : mDisplays) { |
| 8663 | if (display->getLayerStack() == layerStack) { |
| 8664 | hintDisplay = display; |
| 8665 | break; |
| 8666 | } |
| 8667 | } |
| 8668 | |
| 8669 | if (hintDisplay) { |
| 8670 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
| 8671 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8672 | } |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8673 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8674 | void SurfaceFlinger::sample() { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8675 | if (!mLumaSampling || !mRegionSamplingThread) { |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8676 | return; |
| 8677 | } |
| 8678 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 8679 | mRegionSamplingThread->onCompositionComplete(mScheduler->getScheduledFrameTime()); |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8680 | } |
| 8681 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8682 | void SurfaceFlinger::onActiveDisplaySizeChanged(const DisplayDevice& activeDisplay) { |
| 8683 | mScheduler->onActiveDisplayAreaChanged(activeDisplay.getWidth() * activeDisplay.getHeight()); |
| 8684 | getRenderEngine().onActiveDisplaySizeChanged(activeDisplay.getSize()); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8685 | } |
| 8686 | |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 8687 | sp<DisplayDevice> SurfaceFlinger::getActivatableDisplay() const { |
| 8688 | if (mPhysicalDisplays.size() == 1) return nullptr; |
| 8689 | |
| 8690 | // TODO(b/255635821): Choose the pacesetter display, considering both internal and external |
| 8691 | // displays. For now, pick the other internal display, assuming a dual-display foldable. |
| 8692 | return findDisplay([this](const DisplayDevice& display) REQUIRES(mStateLock) { |
| 8693 | const auto idOpt = PhysicalDisplayId::tryCast(display.getId()); |
| 8694 | return idOpt && *idOpt != mActiveDisplayId && display.isPoweredOn() && |
| 8695 | mPhysicalDisplays.get(*idOpt) |
| 8696 | .transform(&PhysicalDisplay::isInternal) |
| 8697 | .value_or(false); |
| 8698 | }); |
| 8699 | } |
| 8700 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8701 | void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveDisplayPtr, |
| 8702 | const DisplayDevice& activeDisplay) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8703 | ATRACE_CALL(); |
| 8704 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8705 | // 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] | 8706 | // because DM is about to send its policy via setDesiredDisplayModeSpecs. |
| 8707 | bool forceApplyPolicy = false; |
| 8708 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8709 | if (inactiveDisplayPtr) { |
| 8710 | inactiveDisplayPtr->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false); |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 8711 | forceApplyPolicy = true; |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 8712 | } |
| 8713 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8714 | mActiveDisplayId = activeDisplay.getPhysicalId(); |
| 8715 | activeDisplay.getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 8716 | |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 8717 | resetPhaseConfiguration(activeDisplay.getActiveMode().fps); |
| 8718 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8719 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8720 | mScheduler->setModeChangePending(false); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8721 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 8722 | mScheduler->setPacesetterDisplay(mActiveDisplayId); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 8723 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8724 | onActiveDisplaySizeChanged(activeDisplay); |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8725 | mActiveDisplayTransformHint = activeDisplay.getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 8726 | sActiveDisplayRotationFlags = ui::Transform::toRotationFlags(activeDisplay.getOrientation()); |
Ady Abraham | 85d692d | 2021-09-28 14:08:54 -0700 | [diff] [blame] | 8727 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 8728 | // 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] | 8729 | // that case, its preferred mode has not been propagated to HWC (via setDesiredMode). In either |
| 8730 | // case, the Scheduler's cachedModeChangedParams must be initialized to the newly active mode, |
| 8731 | // 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] | 8732 | applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay.refreshRateSelector(), |
| 8733 | forceApplyPolicy); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8734 | } |
| 8735 | |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 8736 | status_t SurfaceFlinger::addWindowInfosListener(const sp<IWindowInfosListener>& windowInfosListener, |
| 8737 | gui::WindowInfosListenerInfo* outInfo) { |
| 8738 | mWindowInfosListenerInvoker->addWindowInfosListener(windowInfosListener, outInfo); |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 8739 | setTransactionFlags(eInputInfoUpdateNeeded); |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 8740 | return NO_ERROR; |
| 8741 | } |
| 8742 | |
| 8743 | status_t SurfaceFlinger::removeWindowInfosListener( |
| 8744 | const sp<IWindowInfosListener>& windowInfosListener) const { |
| 8745 | mWindowInfosListenerInvoker->removeWindowInfosListener(windowInfosListener); |
| 8746 | return NO_ERROR; |
| 8747 | } |
| 8748 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 8749 | status_t SurfaceFlinger::getStalledTransactionInfo( |
| 8750 | int pid, std::optional<TransactionHandler::StalledTransactionInfo>& result) { |
| 8751 | result = mTransactionHandler.getStalledTransactionInfo(pid); |
| 8752 | return NO_ERROR; |
| 8753 | } |
| 8754 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8755 | std::shared_ptr<renderengine::ExternalTexture> SurfaceFlinger::getExternalTextureFromBufferData( |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8756 | BufferData& bufferData, const char* layerName, uint64_t transactionId) { |
| 8757 | if (bufferData.buffer && |
| 8758 | exceedsMaxRenderTargetSize(bufferData.buffer->getWidth(), bufferData.buffer->getHeight())) { |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 8759 | std::string errorMessage = |
| 8760 | base::StringPrintf("Attempted to create an ExternalTexture with size (%u, %u) for " |
| 8761 | "layer %s that exceeds render target size limit of %u.", |
| 8762 | bufferData.buffer->getWidth(), bufferData.buffer->getHeight(), |
| 8763 | layerName, static_cast<uint32_t>(mMaxRenderTargetSize)); |
| 8764 | ALOGD("%s", errorMessage.c_str()); |
| 8765 | if (bufferData.releaseBufferListener) { |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 8766 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
| 8767 | String8(errorMessage.c_str())); |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 8768 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8769 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8770 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8771 | |
| 8772 | bool cachedBufferChanged = |
| 8773 | bufferData.flags.test(BufferData::BufferDataChange::cachedBufferChanged); |
| 8774 | if (cachedBufferChanged && bufferData.buffer) { |
| 8775 | auto result = ClientCache::getInstance().add(bufferData.cachedBuffer, bufferData.buffer); |
| 8776 | if (result.ok()) { |
| 8777 | return result.value(); |
| 8778 | } |
| 8779 | |
| 8780 | if (result.error() == ClientCache::AddError::CacheFull) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 8781 | ALOGE("Attempted to create an ExternalTexture for layer %s but CacheFull", layerName); |
| 8782 | |
| 8783 | if (bufferData.releaseBufferListener) { |
| 8784 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 8785 | String8("Buffer processing hung due to full buffer cache")); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 8786 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8787 | } |
| 8788 | |
| 8789 | return nullptr; |
| 8790 | } |
| 8791 | |
| 8792 | if (cachedBufferChanged) { |
| 8793 | return ClientCache::getInstance().get(bufferData.cachedBuffer); |
| 8794 | } |
| 8795 | |
| 8796 | if (bufferData.buffer) { |
| 8797 | return std::make_shared< |
| 8798 | renderengine::impl::ExternalTexture>(bufferData.buffer, getRenderEngine(), |
| 8799 | renderengine::impl::ExternalTexture::Usage:: |
| 8800 | READABLE); |
| 8801 | } |
| 8802 | |
| 8803 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8804 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8805 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 8806 | bool SurfaceFlinger::commitMirrorDisplays(VsyncId vsyncId) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 8807 | std::vector<MirrorDisplayState> mirrorDisplays; |
| 8808 | { |
| 8809 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
| 8810 | mirrorDisplays = std::move(mMirrorDisplays); |
| 8811 | mMirrorDisplays.clear(); |
| 8812 | if (mirrorDisplays.size() == 0) { |
| 8813 | return false; |
| 8814 | } |
| 8815 | } |
| 8816 | |
| 8817 | sp<IBinder> unused; |
| 8818 | for (const auto& mirrorDisplay : mirrorDisplays) { |
| 8819 | // Set mirror layer's default layer stack to -1 so it doesn't end up rendered on a display |
| 8820 | // accidentally. |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 8821 | sp<Layer> rootMirrorLayer = LayerHandle::getLayer(mirrorDisplay.rootHandle); |
Qi Jing | b8e4c13 | 2023-08-25 23:01:47 +0000 | [diff] [blame] | 8822 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(rootMirrorLayer); |
| 8823 | bool ret = rootMirrorLayer->setLayerStack(ui::LayerStack::fromValue(-1)); |
| 8824 | if (idx >= 0 && ret) { |
| 8825 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 8826 | mCurrentState.layersSortedByZ.add(rootMirrorLayer); |
| 8827 | } |
| 8828 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 8829 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 8830 | if (layer->getLayerStack() != mirrorDisplay.layerStack || |
| 8831 | layer->isInternalDisplayOverlay()) { |
| 8832 | continue; |
| 8833 | } |
| 8834 | |
| 8835 | LayerCreationArgs mirrorArgs(this, mirrorDisplay.client, "MirrorLayerParent", |
| 8836 | ISurfaceComposerClient::eNoColorFill, |
| 8837 | gui::LayerMetadata()); |
| 8838 | sp<Layer> childMirror; |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 8839 | { |
| 8840 | Mutex::Autolock lock(mStateLock); |
| 8841 | createEffectLayer(mirrorArgs, &unused, &childMirror); |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 8842 | MUTEX_ALIAS(mStateLock, childMirror->mFlinger->mStateLock); |
Vishnu Nair | de17725 | 2023-04-21 12:44:10 -0700 | [diff] [blame] | 8843 | childMirror->setClonedChild(layer->createClone(childMirror->getSequence())); |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 8844 | childMirror->reparent(mirrorDisplay.rootHandle); |
| 8845 | } |
| 8846 | // lock on mStateLock needs to be released before binder handle gets destroyed |
| 8847 | unused.clear(); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 8848 | } |
| 8849 | } |
| 8850 | return true; |
| 8851 | } |
| 8852 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8853 | bool SurfaceFlinger::commitCreatedLayers(VsyncId vsyncId, |
| 8854 | std::vector<LayerCreatedState>& createdLayers) { |
| 8855 | if (createdLayers.size() == 0) { |
| 8856 | return false; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8857 | } |
| 8858 | |
| 8859 | Mutex::Autolock _l(mStateLock); |
| 8860 | for (const auto& createdLayer : createdLayers) { |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 8861 | handleLayerCreatedLocked(createdLayer, vsyncId); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8862 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8863 | mLayersAdded = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8864 | return mLayersAdded; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8865 | } |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8866 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 8867 | void SurfaceFlinger::updateLayerMetadataSnapshot() { |
| 8868 | LayerMetadata parentMetadata; |
| 8869 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 8870 | layer->updateMetadataSnapshot(parentMetadata); |
| 8871 | } |
| 8872 | |
| 8873 | std::unordered_set<Layer*> visited; |
| 8874 | mDrawingState.traverse([&visited](Layer* layer) { |
| 8875 | if (visited.find(layer) != visited.end()) { |
| 8876 | return; |
| 8877 | } |
| 8878 | |
| 8879 | // If the layer isRelativeOf, then either it's relative metadata will be set |
| 8880 | // recursively when updateRelativeMetadataSnapshot is called on its relative parent or |
| 8881 | // it's relative parent has been deleted. Clear the layer's relativeLayerMetadata to ensure |
| 8882 | // that layers with deleted relative parents don't hold stale relativeLayerMetadata. |
| 8883 | if (layer->getDrawingState().isRelativeOf) { |
| 8884 | layer->editLayerSnapshot()->relativeLayerMetadata = {}; |
| 8885 | return; |
| 8886 | } |
| 8887 | |
| 8888 | layer->updateRelativeMetadataSnapshot({}, visited); |
| 8889 | }); |
| 8890 | } |
| 8891 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8892 | void SurfaceFlinger::moveSnapshotsFromCompositionArgs( |
| 8893 | compositionengine::CompositionRefreshArgs& refreshArgs, |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 8894 | const std::vector<std::pair<Layer*, LayerFE*>>& layers) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8895 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8896 | std::vector<std::unique_ptr<frontend::LayerSnapshot>>& snapshots = |
| 8897 | mLayerSnapshotBuilder.getSnapshots(); |
| 8898 | for (auto [_, layerFE] : layers) { |
| 8899 | auto i = layerFE->mSnapshot->globalZ; |
| 8900 | snapshots[i] = std::move(layerFE->mSnapshot); |
| 8901 | } |
| 8902 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8903 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8904 | for (auto [layer, layerFE] : layers) { |
| 8905 | layer->updateLayerSnapshot(std::move(layerFE->mSnapshot)); |
| 8906 | } |
| 8907 | } |
| 8908 | } |
| 8909 | |
| 8910 | std::vector<std::pair<Layer*, LayerFE*>> SurfaceFlinger::moveSnapshotsToCompositionArgs( |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 8911 | compositionengine::CompositionRefreshArgs& refreshArgs, bool cursorOnly) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8912 | std::vector<std::pair<Layer*, LayerFE*>> layers; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8913 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 8914 | nsecs_t currentTime = systemTime(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8915 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 8916 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 8917 | if (cursorOnly && |
| 8918 | snapshot->compositionType != |
| 8919 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) { |
| 8920 | return; |
| 8921 | } |
| 8922 | |
| 8923 | if (!snapshot->hasSomethingToDraw()) { |
| 8924 | return; |
| 8925 | } |
| 8926 | |
| 8927 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 8928 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 8929 | "Couldnt find layer object for %s", |
| 8930 | snapshot->getDebugString().c_str()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8931 | auto& legacyLayer = it->second; |
| 8932 | sp<LayerFE> layerFE = legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 8933 | snapshot->fps = getLayerFramerate(currentTime, snapshot->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8934 | layerFE->mSnapshot = std::move(snapshot); |
| 8935 | refreshArgs.layers.push_back(layerFE); |
| 8936 | layers.emplace_back(legacyLayer.get(), layerFE.get()); |
| 8937 | }); |
| 8938 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8939 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 8940 | auto moveSnapshots = [&layers, &refreshArgs, cursorOnly](Layer* layer) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8941 | if (const auto& layerFE = layer->getCompositionEngineLayerFE()) { |
| 8942 | if (cursorOnly && |
| 8943 | layer->getLayerSnapshot()->compositionType != |
| 8944 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) |
| 8945 | return; |
| 8946 | layer->updateSnapshot(refreshArgs.updatingGeometryThisFrame); |
| 8947 | layerFE->mSnapshot = layer->stealLayerSnapshot(); |
| 8948 | refreshArgs.layers.push_back(layerFE); |
| 8949 | layers.emplace_back(layer, layerFE.get()); |
| 8950 | } |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 8951 | }; |
| 8952 | |
| 8953 | if (cursorOnly || !mVisibleRegionsDirty) { |
| 8954 | // for hot path avoid traversals by walking though the previous composition list |
| 8955 | for (sp<Layer> layer : mPreviouslyComposedLayers) { |
| 8956 | moveSnapshots(layer.get()); |
| 8957 | } |
| 8958 | } else { |
| 8959 | mPreviouslyComposedLayers.clear(); |
| 8960 | mDrawingState.traverseInZOrder( |
| 8961 | [&moveSnapshots](Layer* layer) { moveSnapshots(layer); }); |
| 8962 | mPreviouslyComposedLayers.reserve(layers.size()); |
| 8963 | for (auto [layer, _] : layers) { |
| 8964 | mPreviouslyComposedLayers.push_back(sp<Layer>::fromExisting(layer)); |
| 8965 | } |
| 8966 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8967 | } |
| 8968 | |
| 8969 | return layers; |
| 8970 | } |
| 8971 | |
| 8972 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8973 | SurfaceFlinger::getLayerSnapshotsForScreenshots( |
| 8974 | std::optional<ui::LayerStack> layerStack, uint32_t uid, |
| 8975 | std::function<bool(const frontend::LayerSnapshot&, bool& outStopTraversal)> |
| 8976 | snapshotFilterFn) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8977 | return [&, layerStack, uid]() { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8978 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers; |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8979 | bool stopTraversal = false; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8980 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 8981 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8982 | if (stopTraversal) { |
| 8983 | return; |
| 8984 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8985 | if (layerStack && snapshot->outputFilter.layerStack != *layerStack) { |
| 8986 | return; |
| 8987 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 8988 | if (uid != CaptureArgs::UNSET_UID && snapshot->uid != gui::Uid(uid)) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8989 | return; |
| 8990 | } |
| 8991 | if (!snapshot->hasSomethingToDraw()) { |
| 8992 | return; |
| 8993 | } |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8994 | if (snapshotFilterFn && !snapshotFilterFn(*snapshot, stopTraversal)) { |
| 8995 | return; |
| 8996 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8997 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8998 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 8999 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 9000 | "Couldnt find layer object for %s", |
| 9001 | snapshot->getDebugString().c_str()); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9002 | Layer* legacyLayer = (it == mLegacyLayers.end()) ? nullptr : it->second.get(); |
| 9003 | sp<LayerFE> layerFE = getFactory().createLayerFE(snapshot->name); |
| 9004 | layerFE->mSnapshot = std::make_unique<frontend::LayerSnapshot>(*snapshot); |
| 9005 | layers.emplace_back(legacyLayer, std::move(layerFE)); |
| 9006 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9007 | |
| 9008 | return layers; |
| 9009 | }; |
| 9010 | } |
| 9011 | |
| 9012 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9013 | SurfaceFlinger::getLayerSnapshotsForScreenshots(std::optional<ui::LayerStack> layerStack, |
| 9014 | uint32_t uid, |
| 9015 | std::unordered_set<uint32_t> excludeLayerIds) { |
| 9016 | return [&, layerStack, uid, excludeLayerIds = std::move(excludeLayerIds)]() { |
| 9017 | if (excludeLayerIds.empty()) { |
| 9018 | auto getLayerSnapshotsFn = |
| 9019 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 9020 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9021 | return layers; |
| 9022 | } |
| 9023 | |
| 9024 | frontend::LayerSnapshotBuilder::Args |
| 9025 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 9026 | .layerLifecycleManager = mLayerLifecycleManager, |
| 9027 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
| 9028 | .displays = mFrontEndDisplayInfos, |
| 9029 | .displayChanges = true, |
| 9030 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9031 | .supportsBlur = mSupportsBlur, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9032 | .forceFullDamage = mForceFullDamage, |
| 9033 | .excludeLayerIds = std::move(excludeLayerIds), |
| 9034 | .supportedLayerGenericMetadata = |
| 9035 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 9036 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 9037 | .skipRoundCornersWhenProtected = |
| 9038 | !getRenderEngine().supportsProtectedContent()}; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9039 | mLayerSnapshotBuilder.update(args); |
| 9040 | |
| 9041 | auto getLayerSnapshotsFn = |
| 9042 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 9043 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9044 | |
| 9045 | args.excludeLayerIds.clear(); |
| 9046 | mLayerSnapshotBuilder.update(args); |
| 9047 | |
| 9048 | return layers; |
| 9049 | }; |
| 9050 | } |
| 9051 | |
| 9052 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9053 | SurfaceFlinger::getLayerSnapshotsForScreenshots(uint32_t rootLayerId, uint32_t uid, |
| 9054 | std::unordered_set<uint32_t> excludeLayerIds, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 9055 | bool childrenOnly, |
| 9056 | const std::optional<FloatRect>& parentCrop) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9057 | return [&, rootLayerId, uid, excludeLayerIds = std::move(excludeLayerIds), childrenOnly, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9058 | parentCrop]() { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9059 | auto root = mLayerHierarchyBuilder.getPartialHierarchy(rootLayerId, childrenOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9060 | frontend::LayerSnapshotBuilder::Args |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9061 | args{.root = root, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9062 | .layerLifecycleManager = mLayerLifecycleManager, |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9063 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9064 | .displays = mFrontEndDisplayInfos, |
| 9065 | .displayChanges = true, |
| 9066 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9067 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9068 | .forceFullDamage = mForceFullDamage, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 9069 | .parentCrop = parentCrop, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9070 | .excludeLayerIds = std::move(excludeLayerIds), |
| 9071 | .supportedLayerGenericMetadata = |
| 9072 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 9073 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 9074 | .skipRoundCornersWhenProtected = |
| 9075 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | c54fdb0 | 2023-11-21 17:19:58 -0800 | [diff] [blame] | 9076 | // The layer may not exist if it was just created and a screenshot was requested immediately |
| 9077 | // after. In this case, the hierarchy will be empty so we will not render any layers. |
| 9078 | args.rootSnapshot.isSecure = mLayerLifecycleManager.getLayerFromId(rootLayerId) && |
| 9079 | mLayerLifecycleManager.isLayerSecure(rootLayerId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9080 | mLayerSnapshotBuilder.update(args); |
| 9081 | |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9082 | auto getLayerSnapshotsFn = |
| 9083 | getLayerSnapshotsForScreenshots({}, uid, /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9084 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9085 | args.root = mLayerHierarchyBuilder.getHierarchy(); |
| 9086 | args.parentCrop.reset(); |
| 9087 | args.excludeLayerIds.clear(); |
| 9088 | mLayerSnapshotBuilder.update(args); |
| 9089 | return layers; |
| 9090 | }; |
| 9091 | } |
| 9092 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9093 | frontend::Update SurfaceFlinger::flushLifecycleUpdates() { |
| 9094 | frontend::Update update; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9095 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 9096 | // Locking: |
| 9097 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 9098 | // we must keep a copy of the transactions (specifically the composer |
| 9099 | // states) around outside the scope of the lock. |
| 9100 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 9101 | // transactions with layers still in the createdLayer queue, flush the transactions |
| 9102 | // before committing the created layers. |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 9103 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9104 | update.transactions = mTransactionHandler.flushTransactions(); |
| 9105 | { |
| 9106 | // TODO(b/238781169) lockless queue this and keep order. |
| 9107 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 9108 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 9109 | mCreatedLayers.clear(); |
| 9110 | update.newLayers = std::move(mNewLayers); |
| 9111 | mNewLayers.clear(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9112 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 9113 | mNewLayerArgs.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9114 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 9115 | mDestroyedHandles.clear(); |
| 9116 | } |
| 9117 | return update; |
| 9118 | } |
| 9119 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9120 | void SurfaceFlinger::doActiveLayersTracingIfNeeded(bool isCompositionComputed, |
| 9121 | bool visibleRegionDirty, TimePoint time, |
| 9122 | VsyncId vsyncId) { |
| 9123 | if (!mLayerTracing.isActiveTracingStarted()) { |
| 9124 | return; |
| 9125 | } |
| 9126 | if (isCompositionComputed != |
| 9127 | mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_COMPOSITION)) { |
| 9128 | return; |
| 9129 | } |
| 9130 | if (!visibleRegionDirty && |
| 9131 | !mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_BUFFERS)) { |
| 9132 | return; |
| 9133 | } |
| 9134 | auto snapshot = takeLayersSnapshotProto(mLayerTracing.getActiveTracingFlags(), time, vsyncId, |
| 9135 | visibleRegionDirty); |
| 9136 | mLayerTracing.addProtoSnapshotToOstream(std::move(snapshot), LayerTracing::Mode::MODE_ACTIVE); |
| 9137 | } |
| 9138 | |
| 9139 | perfetto::protos::LayersSnapshotProto SurfaceFlinger::takeLayersSnapshotProto( |
| 9140 | uint32_t traceFlags, TimePoint time, VsyncId vsyncId, bool visibleRegionDirty) { |
| 9141 | ATRACE_CALL(); |
| 9142 | perfetto::protos::LayersSnapshotProto snapshot; |
| 9143 | snapshot.set_elapsed_realtime_nanos(time.ns()); |
| 9144 | snapshot.set_vsync_id(ftl::to_underlying(vsyncId)); |
| 9145 | snapshot.set_where(visibleRegionDirty ? "visibleRegionsDirty" : "bufferLatched"); |
| 9146 | snapshot.set_excludes_composition_state((traceFlags & LayerTracing::Flag::TRACE_COMPOSITION) == |
| 9147 | 0); |
| 9148 | |
| 9149 | auto layers = dumpDrawingStateProto(traceFlags); |
| 9150 | if (traceFlags & LayerTracing::Flag::TRACE_EXTRA) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9151 | dumpOffscreenLayersProto(layers); |
| 9152 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9153 | *snapshot.mutable_layers() = std::move(layers); |
| 9154 | |
| 9155 | if (traceFlags & LayerTracing::Flag::TRACE_HWC) { |
| 9156 | std::string hwcDump; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9157 | dumpHwc(hwcDump); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9158 | snapshot.set_hwc_blob(std::move(hwcDump)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9159 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9160 | |
| 9161 | *snapshot.mutable_displays() = dumpDisplayProto(); |
| 9162 | |
| 9163 | return snapshot; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9164 | } |
| 9165 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 9166 | // sfdo functions |
| 9167 | |
| 9168 | void SurfaceFlinger::sfdo_enableRefreshRateOverlay(bool active) { |
| 9169 | auto future = mScheduler->schedule( |
| 9170 | [&]() FTL_FAKE_GUARD(mStateLock) |
| 9171 | FTL_FAKE_GUARD(kMainThreadContext) { enableRefreshRateOverlay(active); }); |
| 9172 | future.wait(); |
| 9173 | } |
| 9174 | |
| 9175 | void SurfaceFlinger::sfdo_setDebugFlash(int delay) { |
| 9176 | if (delay > 0) { |
| 9177 | mDebugFlashDelay = delay; |
| 9178 | } else { |
| 9179 | mDebugFlashDelay = mDebugFlashDelay ? 0 : 1; |
| 9180 | } |
| 9181 | scheduleRepaint(); |
| 9182 | } |
| 9183 | |
| 9184 | void SurfaceFlinger::sfdo_scheduleComposite() { |
| 9185 | scheduleComposite(SurfaceFlinger::FrameHint::kActive); |
| 9186 | } |
| 9187 | |
| 9188 | void SurfaceFlinger::sfdo_scheduleCommit() { |
| 9189 | Mutex::Autolock lock(mStateLock); |
| 9190 | setTransactionFlags(eTransactionNeeded | eDisplayTransactionNeeded | eTraversalNeeded); |
| 9191 | } |
| 9192 | |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 9193 | void SurfaceFlinger::sfdo_forceClientComposition(bool enabled) { |
| 9194 | mDebugDisableHWC = enabled; |
| 9195 | scheduleRepaint(); |
| 9196 | } |
| 9197 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9198 | // gui::ISurfaceComposer |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9199 | |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9200 | binder::Status SurfaceComposerAIDL::bootFinished() { |
| 9201 | status_t status = checkAccessPermission(); |
| 9202 | if (status != OK) { |
| 9203 | return binderStatusFromStatusT(status); |
| 9204 | } |
| 9205 | mFlinger->bootFinished(); |
| 9206 | return binder::Status::ok(); |
| 9207 | } |
| 9208 | |
| 9209 | binder::Status SurfaceComposerAIDL::createDisplayEventConnection( |
| 9210 | VsyncSource vsyncSource, EventRegistration eventRegistration, |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 9211 | const sp<IBinder>& layerHandle, sp<IDisplayEventConnection>* outConnection) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9212 | sp<IDisplayEventConnection> conn = |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 9213 | mFlinger->createDisplayEventConnection(vsyncSource, eventRegistration, layerHandle); |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9214 | if (conn == nullptr) { |
| 9215 | *outConnection = nullptr; |
| 9216 | return binderStatusFromStatusT(BAD_VALUE); |
| 9217 | } else { |
| 9218 | *outConnection = conn; |
| 9219 | return binder::Status::ok(); |
| 9220 | } |
| 9221 | } |
| 9222 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9223 | binder::Status SurfaceComposerAIDL::createConnection(sp<gui::ISurfaceComposerClient>* outClient) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 9224 | const sp<Client> client = sp<Client>::make(mFlinger); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9225 | if (client->initCheck() == NO_ERROR) { |
| 9226 | *outClient = client; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 9227 | if (FlagManager::getInstance().misc1()) { |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 9228 | const int policy = SCHED_FIFO; |
| 9229 | client->setMinSchedulerPolicy(policy, sched_get_priority_min(policy)); |
| 9230 | } |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9231 | return binder::Status::ok(); |
| 9232 | } else { |
| 9233 | *outClient = nullptr; |
| 9234 | return binderStatusFromStatusT(BAD_VALUE); |
| 9235 | } |
| 9236 | } |
| 9237 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9238 | binder::Status SurfaceComposerAIDL::createDisplay(const std::string& displayName, bool secure, |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 9239 | float requestedRefreshRate, |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9240 | sp<IBinder>* outDisplay) { |
| 9241 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9242 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9243 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9244 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9245 | String8 displayName8 = String8::format("%s", displayName.c_str()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 9246 | *outDisplay = mFlinger->createDisplay(displayName8, secure, requestedRefreshRate); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9247 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9248 | } |
| 9249 | |
| 9250 | binder::Status SurfaceComposerAIDL::destroyDisplay(const sp<IBinder>& display) { |
| 9251 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9252 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9253 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9254 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9255 | mFlinger->destroyDisplay(display); |
| 9256 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9257 | } |
| 9258 | |
| 9259 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) { |
| 9260 | std::vector<PhysicalDisplayId> physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); |
| 9261 | std::vector<int64_t> displayIds; |
| 9262 | displayIds.reserve(physicalDisplayIds.size()); |
| 9263 | for (auto item : physicalDisplayIds) { |
| 9264 | displayIds.push_back(static_cast<int64_t>(item.value)); |
| 9265 | } |
| 9266 | *outDisplayIds = displayIds; |
| 9267 | return binder::Status::ok(); |
| 9268 | } |
| 9269 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9270 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, |
| 9271 | sp<IBinder>* outDisplay) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9272 | status_t status = checkAccessPermission(); |
| 9273 | if (status != OK) { |
| 9274 | return binderStatusFromStatusT(status); |
| 9275 | } |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9276 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 9277 | *outDisplay = mFlinger->getPhysicalDisplayToken(*id); |
| 9278 | return binder::Status::ok(); |
| 9279 | } |
| 9280 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9281 | binder::Status SurfaceComposerAIDL::setPowerMode(const sp<IBinder>& display, int mode) { |
| 9282 | status_t status = checkAccessPermission(); |
| 9283 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9284 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9285 | } |
| 9286 | mFlinger->setPowerMode(display, mode); |
| 9287 | return binder::Status::ok(); |
| 9288 | } |
| 9289 | |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 9290 | binder::Status SurfaceComposerAIDL::getSupportedFrameTimestamps( |
| 9291 | std::vector<FrameEvent>* outSupported) { |
| 9292 | status_t status; |
| 9293 | if (!outSupported) { |
| 9294 | status = UNEXPECTED_NULL; |
| 9295 | } else { |
| 9296 | outSupported->clear(); |
| 9297 | status = mFlinger->getSupportedFrameTimestamps(outSupported); |
| 9298 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9299 | return binderStatusFromStatusT(status); |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 9300 | } |
| 9301 | |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9302 | binder::Status SurfaceComposerAIDL::getDisplayStats(const sp<IBinder>& display, |
| 9303 | gui::DisplayStatInfo* outStatInfo) { |
| 9304 | DisplayStatInfo statInfo; |
| 9305 | status_t status = mFlinger->getDisplayStats(display, &statInfo); |
| 9306 | if (status == NO_ERROR) { |
| 9307 | outStatInfo->vsyncTime = static_cast<long>(statInfo.vsyncTime); |
| 9308 | outStatInfo->vsyncPeriod = static_cast<long>(statInfo.vsyncPeriod); |
| 9309 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9310 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9311 | } |
| 9312 | |
| 9313 | binder::Status SurfaceComposerAIDL::getDisplayState(const sp<IBinder>& display, |
| 9314 | gui::DisplayState* outState) { |
| 9315 | ui::DisplayState state; |
| 9316 | status_t status = mFlinger->getDisplayState(display, &state); |
| 9317 | if (status == NO_ERROR) { |
| 9318 | outState->layerStack = state.layerStack.id; |
| 9319 | outState->orientation = static_cast<gui::Rotation>(state.orientation); |
| 9320 | outState->layerStackSpaceRect.width = state.layerStackSpaceRect.width; |
| 9321 | outState->layerStackSpaceRect.height = state.layerStackSpaceRect.height; |
| 9322 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9323 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9324 | } |
| 9325 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9326 | binder::Status SurfaceComposerAIDL::getStaticDisplayInfo(int64_t displayId, |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9327 | gui::StaticDisplayInfo* outInfo) { |
| 9328 | using Tag = gui::DeviceProductInfo::ManufactureOrModelDate::Tag; |
| 9329 | ui::StaticDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9330 | |
| 9331 | status_t status = mFlinger->getStaticDisplayInfo(displayId, &info); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9332 | if (status == NO_ERROR) { |
| 9333 | // convert ui::StaticDisplayInfo to gui::StaticDisplayInfo |
| 9334 | outInfo->connectionType = static_cast<gui::DisplayConnectionType>(info.connectionType); |
| 9335 | outInfo->density = info.density; |
| 9336 | outInfo->secure = info.secure; |
| 9337 | outInfo->installOrientation = static_cast<gui::Rotation>(info.installOrientation); |
| 9338 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9339 | if (const std::optional<DeviceProductInfo> dpi = info.deviceProductInfo) { |
| 9340 | gui::DeviceProductInfo dinfo; |
| 9341 | dinfo.name = std::move(dpi->name); |
| 9342 | dinfo.manufacturerPnpId = std::vector<uint8_t>(dpi->manufacturerPnpId.begin(), |
| 9343 | dpi->manufacturerPnpId.end()); |
| 9344 | dinfo.productId = dpi->productId; |
| 9345 | dinfo.relativeAddress = |
| 9346 | std::vector<uint8_t>(dpi->relativeAddress.begin(), dpi->relativeAddress.end()); |
| 9347 | if (const auto* model = |
| 9348 | std::get_if<DeviceProductInfo::ModelYear>(&dpi->manufactureOrModelDate)) { |
| 9349 | gui::DeviceProductInfo::ModelYear modelYear; |
| 9350 | modelYear.year = model->year; |
| 9351 | dinfo.manufactureOrModelDate.set<Tag::modelYear>(modelYear); |
| 9352 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureYear>( |
| 9353 | &dpi->manufactureOrModelDate)) { |
| 9354 | gui::DeviceProductInfo::ManufactureYear date; |
| 9355 | date.modelYear.year = manufacture->year; |
| 9356 | dinfo.manufactureOrModelDate.set<Tag::manufactureYear>(date); |
| 9357 | } else if (const auto* manufacture = |
| 9358 | std::get_if<DeviceProductInfo::ManufactureWeekAndYear>( |
| 9359 | &dpi->manufactureOrModelDate)) { |
| 9360 | gui::DeviceProductInfo::ManufactureWeekAndYear date; |
| 9361 | date.manufactureYear.modelYear.year = manufacture->year; |
| 9362 | date.week = manufacture->week; |
| 9363 | dinfo.manufactureOrModelDate.set<Tag::manufactureWeekAndYear>(date); |
| 9364 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9365 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9366 | outInfo->deviceProductInfo = dinfo; |
| 9367 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9368 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9369 | return binderStatusFromStatusT(status); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9370 | } |
| 9371 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9372 | void SurfaceComposerAIDL::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo& info, |
| 9373 | gui::DynamicDisplayInfo*& outInfo) { |
| 9374 | // convert ui::DynamicDisplayInfo to gui::DynamicDisplayInfo |
| 9375 | outInfo->supportedDisplayModes.clear(); |
| 9376 | outInfo->supportedDisplayModes.reserve(info.supportedDisplayModes.size()); |
| 9377 | for (const auto& mode : info.supportedDisplayModes) { |
| 9378 | gui::DisplayMode outMode; |
| 9379 | outMode.id = mode.id; |
| 9380 | outMode.resolution.width = mode.resolution.width; |
| 9381 | outMode.resolution.height = mode.resolution.height; |
| 9382 | outMode.xDpi = mode.xDpi; |
| 9383 | outMode.yDpi = mode.yDpi; |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 9384 | outMode.peakRefreshRate = mode.peakRefreshRate; |
Alec Mouri | d122a1c | 2023-09-30 01:36:33 +0000 | [diff] [blame] | 9385 | outMode.vsyncRate = mode.vsyncRate; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9386 | outMode.appVsyncOffset = mode.appVsyncOffset; |
| 9387 | outMode.sfVsyncOffset = mode.sfVsyncOffset; |
| 9388 | outMode.presentationDeadline = mode.presentationDeadline; |
| 9389 | outMode.group = mode.group; |
| 9390 | std::transform(mode.supportedHdrTypes.begin(), mode.supportedHdrTypes.end(), |
| 9391 | std::back_inserter(outMode.supportedHdrTypes), |
| 9392 | [](const ui::Hdr& value) { return static_cast<int32_t>(value); }); |
| 9393 | outInfo->supportedDisplayModes.push_back(outMode); |
| 9394 | } |
| 9395 | |
| 9396 | outInfo->activeDisplayModeId = info.activeDisplayModeId; |
| 9397 | outInfo->renderFrameRate = info.renderFrameRate; |
| 9398 | |
| 9399 | outInfo->supportedColorModes.clear(); |
| 9400 | outInfo->supportedColorModes.reserve(info.supportedColorModes.size()); |
| 9401 | for (const auto& cmode : info.supportedColorModes) { |
| 9402 | outInfo->supportedColorModes.push_back(static_cast<int32_t>(cmode)); |
| 9403 | } |
| 9404 | |
| 9405 | outInfo->activeColorMode = static_cast<int32_t>(info.activeColorMode); |
| 9406 | |
| 9407 | gui::HdrCapabilities& hdrCapabilities = outInfo->hdrCapabilities; |
| 9408 | hdrCapabilities.supportedHdrTypes.clear(); |
| 9409 | hdrCapabilities.supportedHdrTypes.reserve(info.hdrCapabilities.getSupportedHdrTypes().size()); |
| 9410 | for (const auto& hdr : info.hdrCapabilities.getSupportedHdrTypes()) { |
| 9411 | hdrCapabilities.supportedHdrTypes.push_back(static_cast<int32_t>(hdr)); |
| 9412 | } |
| 9413 | hdrCapabilities.maxLuminance = info.hdrCapabilities.getDesiredMaxLuminance(); |
| 9414 | hdrCapabilities.maxAverageLuminance = info.hdrCapabilities.getDesiredMaxAverageLuminance(); |
| 9415 | hdrCapabilities.minLuminance = info.hdrCapabilities.getDesiredMinLuminance(); |
| 9416 | |
| 9417 | outInfo->autoLowLatencyModeSupported = info.autoLowLatencyModeSupported; |
| 9418 | outInfo->gameContentTypeSupported = info.gameContentTypeSupported; |
| 9419 | outInfo->preferredBootDisplayMode = info.preferredBootDisplayMode; |
| 9420 | } |
| 9421 | |
| 9422 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromToken( |
| 9423 | const sp<IBinder>& display, gui::DynamicDisplayInfo* outInfo) { |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9424 | ui::DynamicDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9425 | status_t status = mFlinger->getDynamicDisplayInfoFromToken(display, &info); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9426 | if (status == NO_ERROR) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9427 | getDynamicDisplayInfoInternal(info, outInfo); |
| 9428 | } |
| 9429 | return binderStatusFromStatusT(status); |
| 9430 | } |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 9431 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9432 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromId(int64_t displayId, |
| 9433 | gui::DynamicDisplayInfo* outInfo) { |
| 9434 | ui::DynamicDisplayInfo info; |
| 9435 | status_t status = mFlinger->getDynamicDisplayInfoFromId(displayId, &info); |
| 9436 | if (status == NO_ERROR) { |
| 9437 | getDynamicDisplayInfoInternal(info, outInfo); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9438 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9439 | return binderStatusFromStatusT(status); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9440 | } |
| 9441 | |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9442 | binder::Status SurfaceComposerAIDL::getDisplayNativePrimaries(const sp<IBinder>& display, |
| 9443 | gui::DisplayPrimaries* outPrimaries) { |
| 9444 | ui::DisplayPrimaries primaries; |
| 9445 | status_t status = mFlinger->getDisplayNativePrimaries(display, primaries); |
| 9446 | if (status == NO_ERROR) { |
| 9447 | outPrimaries->red.X = primaries.red.X; |
| 9448 | outPrimaries->red.Y = primaries.red.Y; |
| 9449 | outPrimaries->red.Z = primaries.red.Z; |
| 9450 | |
| 9451 | outPrimaries->green.X = primaries.green.X; |
| 9452 | outPrimaries->green.Y = primaries.green.Y; |
| 9453 | outPrimaries->green.Z = primaries.green.Z; |
| 9454 | |
| 9455 | outPrimaries->blue.X = primaries.blue.X; |
| 9456 | outPrimaries->blue.Y = primaries.blue.Y; |
| 9457 | outPrimaries->blue.Z = primaries.blue.Z; |
| 9458 | |
| 9459 | outPrimaries->white.X = primaries.white.X; |
| 9460 | outPrimaries->white.Y = primaries.white.Y; |
| 9461 | outPrimaries->white.Z = primaries.white.Z; |
| 9462 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9463 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9464 | } |
| 9465 | |
| 9466 | binder::Status SurfaceComposerAIDL::setActiveColorMode(const sp<IBinder>& display, int colorMode) { |
| 9467 | status_t status = checkAccessPermission(); |
| 9468 | if (status == OK) { |
| 9469 | status = mFlinger->setActiveColorMode(display, static_cast<ui::ColorMode>(colorMode)); |
| 9470 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9471 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9472 | } |
| 9473 | |
| 9474 | binder::Status SurfaceComposerAIDL::setBootDisplayMode(const sp<IBinder>& display, |
| 9475 | int displayModeId) { |
| 9476 | status_t status = checkAccessPermission(); |
| 9477 | if (status == OK) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 9478 | status = mFlinger->setBootDisplayMode(display, DisplayModeId{displayModeId}); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9479 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9480 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9481 | } |
| 9482 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9483 | binder::Status SurfaceComposerAIDL::clearBootDisplayMode(const sp<IBinder>& display) { |
| 9484 | status_t status = checkAccessPermission(); |
| 9485 | if (status == OK) { |
| 9486 | status = mFlinger->clearBootDisplayMode(display); |
| 9487 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9488 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9489 | } |
| 9490 | |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 9491 | binder::Status SurfaceComposerAIDL::getOverlaySupport(gui::OverlayProperties* outProperties) { |
| 9492 | status_t status = checkAccessPermission(); |
| 9493 | if (status == OK) { |
| 9494 | status = mFlinger->getOverlaySupport(outProperties); |
| 9495 | } |
| 9496 | return binderStatusFromStatusT(status); |
| 9497 | } |
| 9498 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9499 | binder::Status SurfaceComposerAIDL::getBootDisplayModeSupport(bool* outMode) { |
| 9500 | status_t status = checkAccessPermission(); |
| 9501 | if (status == OK) { |
| 9502 | status = mFlinger->getBootDisplayModeSupport(outMode); |
| 9503 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9504 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9505 | } |
| 9506 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9507 | binder::Status SurfaceComposerAIDL::getHdrConversionCapabilities( |
| 9508 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) { |
| 9509 | status_t status = checkAccessPermission(); |
| 9510 | if (status == OK) { |
| 9511 | status = mFlinger->getHdrConversionCapabilities(hdrConversionCapabilities); |
| 9512 | } |
| 9513 | return binderStatusFromStatusT(status); |
| 9514 | } |
| 9515 | |
| 9516 | binder::Status SurfaceComposerAIDL::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 9517 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 9518 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9519 | status_t status = checkAccessPermission(); |
| 9520 | if (status == OK) { |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 9521 | status = mFlinger->setHdrConversionStrategy(hdrConversionStrategy, |
| 9522 | outPreferredHdrOutputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9523 | } |
| 9524 | return binderStatusFromStatusT(status); |
| 9525 | } |
| 9526 | |
| 9527 | binder::Status SurfaceComposerAIDL::getHdrOutputConversionSupport(bool* outMode) { |
| 9528 | status_t status = checkAccessPermission(); |
| 9529 | if (status == OK) { |
| 9530 | status = mFlinger->getHdrOutputConversionSupport(outMode); |
| 9531 | } |
| 9532 | return binderStatusFromStatusT(status); |
| 9533 | } |
| 9534 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9535 | binder::Status SurfaceComposerAIDL::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) { |
| 9536 | status_t status = checkAccessPermission(); |
| 9537 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9538 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9539 | } |
| 9540 | mFlinger->setAutoLowLatencyMode(display, on); |
| 9541 | return binder::Status::ok(); |
| 9542 | } |
| 9543 | |
| 9544 | binder::Status SurfaceComposerAIDL::setGameContentType(const sp<IBinder>& display, bool on) { |
| 9545 | status_t status = checkAccessPermission(); |
| 9546 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9547 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9548 | } |
| 9549 | mFlinger->setGameContentType(display, on); |
| 9550 | return binder::Status::ok(); |
| 9551 | } |
| 9552 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9553 | binder::Status SurfaceComposerAIDL::captureDisplay( |
| 9554 | const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9555 | mFlinger->captureDisplay(args, captureListener); |
| 9556 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9557 | } |
| 9558 | |
| 9559 | binder::Status SurfaceComposerAIDL::captureDisplayById( |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 9560 | int64_t displayId, const CaptureArgs& args, |
| 9561 | const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9562 | // status_t status; |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9563 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9564 | const int uid = ipc->getCallingUid(); |
| 9565 | if (uid == AID_ROOT || uid == AID_GRAPHICS || uid == AID_SYSTEM || uid == AID_SHELL) { |
| 9566 | std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId)); |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 9567 | mFlinger->captureDisplay(*id, args, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9568 | } else { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9569 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9570 | } |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9571 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9572 | } |
| 9573 | |
| 9574 | binder::Status SurfaceComposerAIDL::captureLayers( |
| 9575 | const LayerCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9576 | mFlinger->captureLayers(args, captureListener); |
| 9577 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9578 | } |
| 9579 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9580 | binder::Status SurfaceComposerAIDL::overrideHdrTypes(const sp<IBinder>& display, |
| 9581 | const std::vector<int32_t>& hdrTypes) { |
| 9582 | // overrideHdrTypes is used by CTS tests, which acquire the necessary |
| 9583 | // permission dynamically. Don't use the permission cache for this check. |
| 9584 | status_t status = checkAccessPermission(false); |
| 9585 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9586 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9587 | } |
| 9588 | |
| 9589 | std::vector<ui::Hdr> hdrTypesVector; |
| 9590 | for (int32_t i : hdrTypes) { |
| 9591 | hdrTypesVector.push_back(static_cast<ui::Hdr>(i)); |
| 9592 | } |
| 9593 | status = mFlinger->overrideHdrTypes(display, hdrTypesVector); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9594 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9595 | } |
| 9596 | |
| 9597 | binder::Status SurfaceComposerAIDL::onPullAtom(int32_t atomId, gui::PullAtomData* outPullData) { |
| 9598 | status_t status; |
| 9599 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 9600 | if (uid != AID_SYSTEM) { |
| 9601 | status = PERMISSION_DENIED; |
| 9602 | } else { |
| 9603 | status = mFlinger->onPullAtom(atomId, &outPullData->data, &outPullData->success); |
| 9604 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9605 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9606 | } |
| 9607 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9608 | binder::Status SurfaceComposerAIDL::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
| 9609 | if (!outLayers) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9610 | return binderStatusFromStatusT(UNEXPECTED_NULL); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9611 | } |
| 9612 | |
| 9613 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9614 | const int pid = ipc->getCallingPid(); |
| 9615 | const int uid = ipc->getCallingUid(); |
| 9616 | if ((uid != AID_SHELL) && !PermissionCache::checkPermission(sDump, pid, uid)) { |
| 9617 | 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] | 9618 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9619 | } |
| 9620 | status_t status = mFlinger->getLayerDebugInfo(outLayers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9621 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9622 | } |
| 9623 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9624 | binder::Status SurfaceComposerAIDL::getCompositionPreference(gui::CompositionPreference* outPref) { |
| 9625 | ui::Dataspace dataspace; |
| 9626 | ui::PixelFormat pixelFormat; |
| 9627 | ui::Dataspace wideColorGamutDataspace; |
| 9628 | ui::PixelFormat wideColorGamutPixelFormat; |
| 9629 | status_t status = |
| 9630 | mFlinger->getCompositionPreference(&dataspace, &pixelFormat, &wideColorGamutDataspace, |
| 9631 | &wideColorGamutPixelFormat); |
| 9632 | if (status == NO_ERROR) { |
| 9633 | outPref->defaultDataspace = static_cast<int32_t>(dataspace); |
| 9634 | outPref->defaultPixelFormat = static_cast<int32_t>(pixelFormat); |
| 9635 | outPref->wideColorGamutDataspace = static_cast<int32_t>(wideColorGamutDataspace); |
| 9636 | outPref->wideColorGamutPixelFormat = static_cast<int32_t>(wideColorGamutPixelFormat); |
| 9637 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9638 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9639 | } |
| 9640 | |
| 9641 | binder::Status SurfaceComposerAIDL::getDisplayedContentSamplingAttributes( |
| 9642 | const sp<IBinder>& display, gui::ContentSamplingAttributes* outAttrs) { |
| 9643 | status_t status = checkAccessPermission(); |
| 9644 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9645 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9646 | } |
| 9647 | |
| 9648 | ui::PixelFormat format; |
| 9649 | ui::Dataspace dataspace; |
| 9650 | uint8_t componentMask; |
| 9651 | status = mFlinger->getDisplayedContentSamplingAttributes(display, &format, &dataspace, |
| 9652 | &componentMask); |
| 9653 | if (status == NO_ERROR) { |
| 9654 | outAttrs->format = static_cast<int32_t>(format); |
| 9655 | outAttrs->dataspace = static_cast<int32_t>(dataspace); |
| 9656 | outAttrs->componentMask = static_cast<int8_t>(componentMask); |
| 9657 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9658 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9659 | } |
| 9660 | |
| 9661 | binder::Status SurfaceComposerAIDL::setDisplayContentSamplingEnabled(const sp<IBinder>& display, |
| 9662 | bool enable, |
| 9663 | int8_t componentMask, |
| 9664 | int64_t maxFrames) { |
| 9665 | status_t status = checkAccessPermission(); |
| 9666 | if (status == OK) { |
| 9667 | status = mFlinger->setDisplayContentSamplingEnabled(display, enable, |
| 9668 | static_cast<uint8_t>(componentMask), |
| 9669 | static_cast<uint64_t>(maxFrames)); |
| 9670 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9671 | return binderStatusFromStatusT(status); |
| 9672 | } |
| 9673 | |
| 9674 | binder::Status SurfaceComposerAIDL::getDisplayedContentSample(const sp<IBinder>& display, |
| 9675 | int64_t maxFrames, int64_t timestamp, |
| 9676 | gui::DisplayedFrameStats* outStats) { |
| 9677 | if (!outStats) { |
| 9678 | return binderStatusFromStatusT(BAD_VALUE); |
| 9679 | } |
| 9680 | |
| 9681 | status_t status = checkAccessPermission(); |
| 9682 | if (status != OK) { |
| 9683 | return binderStatusFromStatusT(status); |
| 9684 | } |
| 9685 | |
| 9686 | DisplayedFrameStats stats; |
| 9687 | status = mFlinger->getDisplayedContentSample(display, static_cast<uint64_t>(maxFrames), |
| 9688 | static_cast<uint64_t>(timestamp), &stats); |
| 9689 | if (status == NO_ERROR) { |
| 9690 | // convert from ui::DisplayedFrameStats to gui::DisplayedFrameStats |
| 9691 | outStats->numFrames = static_cast<int64_t>(stats.numFrames); |
| 9692 | outStats->component_0_sample.reserve(stats.component_0_sample.size()); |
| 9693 | for (const auto& s : stats.component_0_sample) { |
| 9694 | outStats->component_0_sample.push_back(static_cast<int64_t>(s)); |
| 9695 | } |
| 9696 | outStats->component_1_sample.reserve(stats.component_1_sample.size()); |
| 9697 | for (const auto& s : stats.component_1_sample) { |
| 9698 | outStats->component_1_sample.push_back(static_cast<int64_t>(s)); |
| 9699 | } |
| 9700 | outStats->component_2_sample.reserve(stats.component_2_sample.size()); |
| 9701 | for (const auto& s : stats.component_2_sample) { |
| 9702 | outStats->component_2_sample.push_back(static_cast<int64_t>(s)); |
| 9703 | } |
| 9704 | outStats->component_3_sample.reserve(stats.component_3_sample.size()); |
| 9705 | for (const auto& s : stats.component_3_sample) { |
| 9706 | outStats->component_3_sample.push_back(static_cast<int64_t>(s)); |
| 9707 | } |
| 9708 | } |
| 9709 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9710 | } |
| 9711 | |
| 9712 | binder::Status SurfaceComposerAIDL::getProtectedContentSupport(bool* outSupported) { |
| 9713 | status_t status = mFlinger->getProtectedContentSupport(outSupported); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9714 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9715 | } |
| 9716 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9717 | binder::Status SurfaceComposerAIDL::isWideColorDisplay(const sp<IBinder>& token, |
| 9718 | bool* outIsWideColorDisplay) { |
| 9719 | status_t status = mFlinger->isWideColorDisplay(token, outIsWideColorDisplay); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9720 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9721 | } |
| 9722 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9723 | binder::Status SurfaceComposerAIDL::addRegionSamplingListener( |
| 9724 | const gui::ARect& samplingArea, const sp<IBinder>& stopLayerHandle, |
| 9725 | const sp<gui::IRegionSamplingListener>& listener) { |
| 9726 | status_t status = checkReadFrameBufferPermission(); |
| 9727 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9728 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9729 | } |
| 9730 | android::Rect rect; |
| 9731 | rect.left = samplingArea.left; |
| 9732 | rect.top = samplingArea.top; |
| 9733 | rect.right = samplingArea.right; |
| 9734 | rect.bottom = samplingArea.bottom; |
| 9735 | status = mFlinger->addRegionSamplingListener(rect, stopLayerHandle, listener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9736 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9737 | } |
| 9738 | |
| 9739 | binder::Status SurfaceComposerAIDL::removeRegionSamplingListener( |
| 9740 | const sp<gui::IRegionSamplingListener>& listener) { |
| 9741 | status_t status = checkReadFrameBufferPermission(); |
| 9742 | if (status == OK) { |
| 9743 | status = mFlinger->removeRegionSamplingListener(listener); |
| 9744 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9745 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9746 | } |
| 9747 | |
| 9748 | binder::Status SurfaceComposerAIDL::addFpsListener(int32_t taskId, |
| 9749 | const sp<gui::IFpsListener>& listener) { |
| 9750 | status_t status = checkReadFrameBufferPermission(); |
| 9751 | if (status == OK) { |
| 9752 | status = mFlinger->addFpsListener(taskId, listener); |
| 9753 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9754 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9755 | } |
| 9756 | |
| 9757 | binder::Status SurfaceComposerAIDL::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 9758 | status_t status = checkReadFrameBufferPermission(); |
| 9759 | if (status == OK) { |
| 9760 | status = mFlinger->removeFpsListener(listener); |
| 9761 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9762 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9763 | } |
| 9764 | |
| 9765 | binder::Status SurfaceComposerAIDL::addTunnelModeEnabledListener( |
| 9766 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 9767 | status_t status = checkAccessPermission(); |
| 9768 | if (status == OK) { |
| 9769 | status = mFlinger->addTunnelModeEnabledListener(listener); |
| 9770 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9771 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9772 | } |
| 9773 | |
| 9774 | binder::Status SurfaceComposerAIDL::removeTunnelModeEnabledListener( |
| 9775 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 9776 | status_t status = checkAccessPermission(); |
| 9777 | if (status == OK) { |
| 9778 | status = mFlinger->removeTunnelModeEnabledListener(listener); |
| 9779 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9780 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9781 | } |
| 9782 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 9783 | binder::Status SurfaceComposerAIDL::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 9784 | const gui::DisplayModeSpecs& specs) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9785 | status_t status = checkAccessPermission(); |
| 9786 | if (status == OK) { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 9787 | status = mFlinger->setDesiredDisplayModeSpecs(displayToken, specs); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9788 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9789 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9790 | } |
| 9791 | |
| 9792 | binder::Status SurfaceComposerAIDL::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 9793 | gui::DisplayModeSpecs* outSpecs) { |
| 9794 | if (!outSpecs) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9795 | return binderStatusFromStatusT(BAD_VALUE); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9796 | } |
| 9797 | |
| 9798 | status_t status = checkAccessPermission(); |
| 9799 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9800 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9801 | } |
| 9802 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 9803 | status = mFlinger->getDesiredDisplayModeSpecs(displayToken, outSpecs); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9804 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9805 | } |
| 9806 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9807 | binder::Status SurfaceComposerAIDL::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 9808 | bool* outSupport) { |
| 9809 | status_t status = mFlinger->getDisplayBrightnessSupport(displayToken, outSupport); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9810 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9811 | } |
| 9812 | |
| 9813 | binder::Status SurfaceComposerAIDL::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 9814 | const gui::DisplayBrightness& brightness) { |
| 9815 | status_t status = checkControlDisplayBrightnessPermission(); |
| 9816 | if (status == OK) { |
| 9817 | status = mFlinger->setDisplayBrightness(displayToken, brightness); |
| 9818 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9819 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9820 | } |
| 9821 | |
| 9822 | binder::Status SurfaceComposerAIDL::addHdrLayerInfoListener( |
| 9823 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 9824 | status_t status = checkControlDisplayBrightnessPermission(); |
| 9825 | if (status == OK) { |
| 9826 | status = mFlinger->addHdrLayerInfoListener(displayToken, listener); |
| 9827 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9828 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9829 | } |
| 9830 | |
| 9831 | binder::Status SurfaceComposerAIDL::removeHdrLayerInfoListener( |
| 9832 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 9833 | status_t status = checkControlDisplayBrightnessPermission(); |
| 9834 | if (status == OK) { |
| 9835 | status = mFlinger->removeHdrLayerInfoListener(displayToken, listener); |
| 9836 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9837 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9838 | } |
| 9839 | |
| 9840 | binder::Status SurfaceComposerAIDL::notifyPowerBoost(int boostId) { |
| 9841 | status_t status = checkAccessPermission(); |
| 9842 | if (status == OK) { |
| 9843 | status = mFlinger->notifyPowerBoost(boostId); |
| 9844 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9845 | return binderStatusFromStatusT(status); |
| 9846 | } |
| 9847 | |
| 9848 | binder::Status SurfaceComposerAIDL::setGlobalShadowSettings(const gui::Color& ambientColor, |
| 9849 | const gui::Color& spotColor, |
| 9850 | float lightPosY, float lightPosZ, |
| 9851 | float lightRadius) { |
| 9852 | status_t status = checkAccessPermission(); |
| 9853 | if (status != OK) { |
| 9854 | return binderStatusFromStatusT(status); |
| 9855 | } |
| 9856 | |
| 9857 | half4 ambientColorHalf = {ambientColor.r, ambientColor.g, ambientColor.b, ambientColor.a}; |
| 9858 | half4 spotColorHalf = {spotColor.r, spotColor.g, spotColor.b, spotColor.a}; |
| 9859 | status = mFlinger->setGlobalShadowSettings(ambientColorHalf, spotColorHalf, lightPosY, |
| 9860 | lightPosZ, lightRadius); |
| 9861 | return binderStatusFromStatusT(status); |
| 9862 | } |
| 9863 | |
| 9864 | binder::Status SurfaceComposerAIDL::getDisplayDecorationSupport( |
| 9865 | const sp<IBinder>& displayToken, std::optional<gui::DisplayDecorationSupport>* outSupport) { |
| 9866 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport> support; |
| 9867 | status_t status = mFlinger->getDisplayDecorationSupport(displayToken, &support); |
| 9868 | if (status != NO_ERROR) { |
| 9869 | ALOGE("getDisplayDecorationSupport failed with error %d", status); |
| 9870 | return binderStatusFromStatusT(status); |
| 9871 | } |
| 9872 | |
| 9873 | if (!support || !support.has_value()) { |
| 9874 | outSupport->reset(); |
| 9875 | } else { |
| 9876 | outSupport->emplace(); |
| 9877 | outSupport->value().format = static_cast<int32_t>(support->format); |
| 9878 | outSupport->value().alphaInterpretation = |
| 9879 | static_cast<int32_t>(support->alphaInterpretation); |
| 9880 | } |
| 9881 | |
| 9882 | return binder::Status::ok(); |
| 9883 | } |
| 9884 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 9885 | binder::Status SurfaceComposerAIDL::setGameModeFrameRateOverride(int32_t uid, float frameRate) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9886 | status_t status; |
| 9887 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 9888 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 9889 | status = mFlinger->setGameModeFrameRateOverride(uid, frameRate); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9890 | } else { |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 9891 | ALOGE("setGameModeFrameRateOverride() permission denied for uid: %d", c_uid); |
| 9892 | status = PERMISSION_DENIED; |
| 9893 | } |
| 9894 | return binderStatusFromStatusT(status); |
| 9895 | } |
| 9896 | |
| 9897 | binder::Status SurfaceComposerAIDL::setGameDefaultFrameRateOverride(int32_t uid, float frameRate) { |
| 9898 | status_t status; |
| 9899 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 9900 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 9901 | status = mFlinger->setGameDefaultFrameRateOverride(uid, frameRate); |
| 9902 | } else { |
| 9903 | ALOGE("setGameDefaultFrameRateOverride() permission denied for uid: %d", c_uid); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9904 | status = PERMISSION_DENIED; |
| 9905 | } |
| 9906 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9907 | } |
| 9908 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 9909 | binder::Status SurfaceComposerAIDL::enableRefreshRateOverlay(bool active) { |
| 9910 | mFlinger->sfdo_enableRefreshRateOverlay(active); |
| 9911 | return binder::Status::ok(); |
| 9912 | } |
| 9913 | |
| 9914 | binder::Status SurfaceComposerAIDL::setDebugFlash(int delay) { |
| 9915 | mFlinger->sfdo_setDebugFlash(delay); |
| 9916 | return binder::Status::ok(); |
| 9917 | } |
| 9918 | |
| 9919 | binder::Status SurfaceComposerAIDL::scheduleComposite() { |
| 9920 | mFlinger->sfdo_scheduleComposite(); |
| 9921 | return binder::Status::ok(); |
| 9922 | } |
| 9923 | |
| 9924 | binder::Status SurfaceComposerAIDL::scheduleCommit() { |
| 9925 | mFlinger->sfdo_scheduleCommit(); |
| 9926 | return binder::Status::ok(); |
| 9927 | } |
| 9928 | |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 9929 | binder::Status SurfaceComposerAIDL::forceClientComposition(bool enabled) { |
| 9930 | mFlinger->sfdo_forceClientComposition(enabled); |
| 9931 | return binder::Status::ok(); |
| 9932 | } |
| 9933 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 9934 | binder::Status SurfaceComposerAIDL::updateSmallAreaDetection(const std::vector<int32_t>& appIds, |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9935 | const std::vector<float>& thresholds) { |
| 9936 | status_t status; |
| 9937 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 9938 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 9939 | if (appIds.size() != thresholds.size()) return binderStatusFromStatusT(BAD_VALUE); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9940 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 9941 | std::vector<std::pair<int32_t, float>> mappings; |
| 9942 | const size_t size = appIds.size(); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9943 | mappings.reserve(size); |
| 9944 | for (int i = 0; i < size; i++) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 9945 | auto row = std::make_pair(appIds[i], thresholds[i]); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9946 | mappings.push_back(row); |
| 9947 | } |
| 9948 | status = mFlinger->updateSmallAreaDetection(mappings); |
| 9949 | } else { |
| 9950 | ALOGE("updateSmallAreaDetection() permission denied for uid: %d", c_uid); |
| 9951 | status = PERMISSION_DENIED; |
| 9952 | } |
| 9953 | return binderStatusFromStatusT(status); |
| 9954 | } |
| 9955 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 9956 | binder::Status SurfaceComposerAIDL::setSmallAreaDetectionThreshold(int32_t appId, float threshold) { |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9957 | status_t status; |
| 9958 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 9959 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 9960 | status = mFlinger->setSmallAreaDetectionThreshold(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9961 | } else { |
| 9962 | ALOGE("setSmallAreaDetectionThreshold() permission denied for uid: %d", c_uid); |
| 9963 | status = PERMISSION_DENIED; |
| 9964 | } |
| 9965 | return binderStatusFromStatusT(status); |
| 9966 | } |
| 9967 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9968 | binder::Status SurfaceComposerAIDL::getGpuContextPriority(int32_t* outPriority) { |
| 9969 | *outPriority = mFlinger->getGpuContextPriority(); |
| 9970 | return binder::Status::ok(); |
| 9971 | } |
| 9972 | |
| 9973 | binder::Status SurfaceComposerAIDL::getMaxAcquiredBufferCount(int32_t* buffers) { |
| 9974 | status_t status = mFlinger->getMaxAcquiredBufferCount(buffers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9975 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9976 | } |
| 9977 | |
| 9978 | binder::Status SurfaceComposerAIDL::addWindowInfosListener( |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 9979 | const sp<gui::IWindowInfosListener>& windowInfosListener, |
| 9980 | gui::WindowInfosListenerInfo* outInfo) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9981 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9982 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9983 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9984 | // TODO(b/270566761) update permissions check so that only system_server and shell can add |
| 9985 | // WindowInfosListeners |
| 9986 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 9987 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 9988 | status = mFlinger->addWindowInfosListener(windowInfosListener, outInfo); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9989 | } else { |
| 9990 | status = PERMISSION_DENIED; |
| 9991 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9992 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9993 | } |
| 9994 | |
| 9995 | binder::Status SurfaceComposerAIDL::removeWindowInfosListener( |
| 9996 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 9997 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9998 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9999 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10000 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 10001 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10002 | status = mFlinger->removeWindowInfosListener(windowInfosListener); |
| 10003 | } else { |
| 10004 | status = PERMISSION_DENIED; |
| 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 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 10009 | binder::Status SurfaceComposerAIDL::getStalledTransactionInfo( |
| 10010 | int pid, std::optional<gui::StalledTransactionInfo>* outInfo) { |
| 10011 | const int callingPid = IPCThreadState::self()->getCallingPid(); |
| 10012 | const int callingUid = IPCThreadState::self()->getCallingUid(); |
| 10013 | if (!checkPermission(sAccessSurfaceFlinger, callingPid, callingUid)) { |
| 10014 | return binderStatusFromStatusT(PERMISSION_DENIED); |
| 10015 | } |
| 10016 | |
| 10017 | std::optional<TransactionHandler::StalledTransactionInfo> stalledTransactionInfo; |
| 10018 | status_t status = mFlinger->getStalledTransactionInfo(pid, stalledTransactionInfo); |
| 10019 | if (stalledTransactionInfo) { |
| 10020 | gui::StalledTransactionInfo result; |
| 10021 | result.layerName = String16{stalledTransactionInfo->layerName.c_str()}, |
| 10022 | result.bufferId = stalledTransactionInfo->bufferId, |
| 10023 | result.frameNumber = stalledTransactionInfo->frameNumber, |
| 10024 | outInfo->emplace(std::move(result)); |
| 10025 | } else { |
| 10026 | outInfo->reset(); |
| 10027 | } |
| 10028 | return binderStatusFromStatusT(status); |
| 10029 | } |
| 10030 | |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 10031 | binder::Status SurfaceComposerAIDL::getSchedulingPolicy(gui::SchedulingPolicy* outPolicy) { |
| 10032 | return gui::getSchedulingPolicy(outPolicy); |
| 10033 | } |
| 10034 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 10035 | status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { |
| 10036 | if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
| 10037 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10038 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", ipc->getCallingPid(), |
| 10039 | ipc->getCallingUid()); |
| 10040 | return PERMISSION_DENIED; |
| 10041 | } |
| 10042 | return OK; |
| 10043 | } |
| 10044 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10045 | status_t SurfaceComposerAIDL::checkControlDisplayBrightnessPermission() { |
| 10046 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10047 | const int pid = ipc->getCallingPid(); |
| 10048 | const int uid = ipc->getCallingUid(); |
Rheygine Medel | 9e9281e | 2022-09-22 10:13:56 -0700 | [diff] [blame] | 10049 | if ((uid != AID_GRAPHICS) && (uid != AID_SYSTEM) && |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10050 | !PermissionCache::checkPermission(sControlDisplayBrightness, pid, uid)) { |
| 10051 | ALOGE("Permission Denial: can't control brightness pid=%d, uid=%d", pid, uid); |
| 10052 | return PERMISSION_DENIED; |
| 10053 | } |
| 10054 | return OK; |
| 10055 | } |
| 10056 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10057 | status_t SurfaceComposerAIDL::checkReadFrameBufferPermission() { |
| 10058 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10059 | const int pid = ipc->getCallingPid(); |
| 10060 | const int uid = ipc->getCallingUid(); |
| 10061 | if ((uid != AID_GRAPHICS) && !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 10062 | ALOGE("Permission Denial: can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 10063 | return PERMISSION_DENIED; |
| 10064 | } |
| 10065 | return OK; |
| 10066 | } |
| 10067 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 10068 | void SurfaceFlinger::forceFutureUpdate(int delayInMs) { |
| 10069 | static_cast<void>(mScheduler->scheduleDelayed([&]() { scheduleRepaint(); }, ms2ns(delayInMs))); |
| 10070 | } |
| 10071 | |
Vishnu Nair | 2f65e97 | 2023-04-04 16:36:28 +0000 | [diff] [blame] | 10072 | const DisplayDevice* SurfaceFlinger::getDisplayFromLayerStack(ui::LayerStack layerStack) { |
| 10073 | for (const auto& [_, display] : mDisplays) { |
| 10074 | if (display->getLayerStack() == layerStack) { |
| 10075 | return display.get(); |
| 10076 | } |
| 10077 | } |
| 10078 | return nullptr; |
| 10079 | } |
| 10080 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 10081 | } // namespace android |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 10082 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 10083 | #if defined(__gl_h_) |
| 10084 | #error "don't include gl/gl.h in this file" |
| 10085 | #endif |
| 10086 | |
| 10087 | #if defined(__gl2_h_) |
| 10088 | #error "don't include gl2/gl2.h in this file" |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 10089 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 10090 | |
| 10091 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 10092 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |