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> |
Nolan Scobie | 488101b | 2024-05-20 13:32:13 -0400 | [diff] [blame] | 43 | #include <com_android_graphics_surfaceflinger_flags.h> |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 44 | #include <common/FlagManager.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 45 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 46 | #include <compositionengine/CompositionRefreshArgs.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 47 | #include <compositionengine/Display.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 48 | #include <compositionengine/DisplayColorProfile.h> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 49 | #include <compositionengine/DisplayColorProfileCreationArgs.h> |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 50 | #include <compositionengine/DisplayCreationArgs.h> |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 51 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 52 | #include <compositionengine/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 53 | #include <compositionengine/RenderSurface.h> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 54 | #include <compositionengine/impl/DisplayColorProfile.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 55 | #include <compositionengine/impl/OutputCompositionState.h> |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 56 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 57 | #include <configstore/Utils.h> |
| 58 | #include <cutils/compiler.h> |
| 59 | #include <cutils/properties.h> |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 60 | #include <fmt/format.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 61 | #include <ftl/algorithm.h> |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 62 | #include <ftl/concat.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 63 | #include <ftl/fake_guard.h> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 64 | #include <ftl/future.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 65 | #include <ftl/unit.h> |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 66 | #include <gui/AidlStatusUtil.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 67 | #include <gui/BufferQueue.h> |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 68 | #include <gui/DebugEGLImageTracker.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 69 | #include <gui/IProducerListener.h> |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 70 | #include <gui/LayerMetadata.h> |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 71 | #include <gui/LayerState.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 72 | #include <gui/Surface.h> |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 73 | #include <gui/SurfaceComposerClient.h> |
rnlee | 60f46b5 | 2021-05-21 15:14:07 -0700 | [diff] [blame] | 74 | #include <gui/TraceUtils.h> |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 75 | #include <hidl/ServiceManagement.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 76 | #include <layerproto/LayerProtoParser.h> |
Elliott Hughes | e3ffd13 | 2023-06-28 19:45:15 +0000 | [diff] [blame] | 77 | #include <linux/sched/types.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 78 | #include <log/log.h> |
| 79 | #include <private/android_filesystem_config.h> |
| 80 | #include <private/gui/SyncFeatures.h> |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 81 | #include <processgroup/processgroup.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 82 | #include <renderengine/RenderEngine.h> |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 83 | #include <renderengine/impl/ExternalTexture.h> |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 84 | #include <scheduler/FrameTargeter.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 85 | #include <sys/types.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 86 | #include <ui/ColorSpace.h> |
| 87 | #include <ui/DebugUtils.h> |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 88 | #include <ui/DisplayId.h> |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 89 | #include <ui/DisplayMode.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 90 | #include <ui/DisplayStatInfo.h> |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 91 | #include <ui/DisplayState.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 92 | #include <ui/DynamicDisplayInfo.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 93 | #include <ui/GraphicBufferAllocator.h> |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 94 | #include <ui/HdrRenderTypeUtils.h> |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 95 | #include <ui/LayerStack.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 96 | #include <ui/PixelFormat.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 97 | #include <ui/StaticDisplayInfo.h> |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 98 | #include <unistd.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | #include <utils/StopWatch.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 100 | #include <utils/String16.h> |
| 101 | #include <utils/String8.h> |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 102 | #include <utils/Timers.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 103 | #include <utils/misc.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 104 | #include <algorithm> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 105 | #include <cerrno> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 106 | #include <cinttypes> |
| 107 | #include <cmath> |
| 108 | #include <cstdint> |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 109 | #include <filesystem> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 110 | #include <functional> |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 111 | #include <memory> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 112 | #include <mutex> |
| 113 | #include <optional> |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 114 | #include <string> |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 115 | #include <type_traits> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 116 | #include <unordered_map> |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 117 | #include <vector> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | |
Alec Mouri | 9b133ca | 2023-11-14 19:00:01 +0000 | [diff] [blame] | 119 | #include <common/FlagManager.h> |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 120 | #include <gui/LayerStatePermissions.h> |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 121 | #include <gui/SchedulingPolicy.h> |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 122 | #include <gui/SyncScreenCaptureListener.h> |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 123 | #include <ui/DisplayIdentification.h> |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 124 | #include "BackgroundExecutor.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 125 | #include "Client.h" |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 126 | #include "ClientCache.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 127 | #include "Colorizer.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 128 | #include "DisplayDevice.h" |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 129 | #include "DisplayHardware/ComposerHal.h" |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 130 | #include "DisplayHardware/FramebufferSurface.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 131 | #include "DisplayHardware/HWComposer.h" |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 132 | #include "DisplayHardware/Hal.h" |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 133 | #include "DisplayHardware/PowerAdvisor.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 134 | #include "DisplayHardware/VirtualDisplaySurface.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 135 | #include "DisplayRenderArea.h" |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 136 | #include "Effects/Daltonizer.h" |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 137 | #include "FpsReporter.h" |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 138 | #include "FrameTimeline/FrameTimeline.h" |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 139 | #include "FrameTracer/FrameTracer.h" |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 140 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 141 | #include "FrontEnd/LayerHandle.h" |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 142 | #include "FrontEnd/LayerLifecycleManager.h" |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 143 | #include "FrontEnd/LayerLog.h" |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 144 | #include "FrontEnd/LayerSnapshot.h" |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 145 | #include "HdrLayerInfoReporter.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 146 | #include "Layer.h" |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 147 | #include "LayerProtoHelper.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 148 | #include "LayerRenderArea.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 149 | #include "LayerVector.h" |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 150 | #include "MutexUtils.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 151 | #include "NativeWindowSurface.h" |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 152 | #include "RegionSamplingThread.h" |
Melody Hsu | 41ade20 | 2024-05-03 01:25:50 +0000 | [diff] [blame] | 153 | #include "RenderAreaBuilder.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 154 | #include "Scheduler/EventThread.h" |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 155 | #include "Scheduler/LayerHistory.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 156 | #include "Scheduler/Scheduler.h" |
Ady Abraham | c581d3c | 2020-08-06 17:34:27 -0700 | [diff] [blame] | 157 | #include "Scheduler/VsyncConfiguration.h" |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 158 | #include "Scheduler/VsyncModulator.h" |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 159 | #include "ScreenCaptureOutput.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 160 | #include "SurfaceFlingerProperties.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 161 | #include "TimeStats/TimeStats.h" |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 162 | #include "TunnelModeEnabledReporter.h" |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 163 | #include "Utils/Dumper.h" |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 164 | #include "WindowInfosListenerInvoker.h" |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 165 | |
dianlujitao | b38ee07 | 2020-05-25 18:23:49 +0800 | [diff] [blame^] | 166 | #ifdef QCOM_UM_FAMILY |
Ramakant Singh | f7e8191 | 2020-04-11 16:02:43 +0530 | [diff] [blame] | 167 | #if __has_include("QtiGralloc.h") |
| 168 | #include "QtiGralloc.h" |
| 169 | #else |
| 170 | #include "gralloc_priv.h" |
| 171 | #endif |
dianlujitao | b38ee07 | 2020-05-25 18:23:49 +0800 | [diff] [blame^] | 172 | #endif |
Ramakant Singh | f7e8191 | 2020-04-11 16:02:43 +0530 | [diff] [blame] | 173 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 174 | #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 175 | #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 176 | #include <aidl/android/hardware/graphics/composer3/RenderIntent.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 177 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 178 | #undef NO_THREAD_SAFETY_ANALYSIS |
| 179 | #define NO_THREAD_SAFETY_ANALYSIS \ |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 180 | _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] | 181 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | namespace android { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 183 | using namespace std::chrono_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 184 | using namespace std::string_literals; |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 185 | using namespace std::string_view_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 186 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 187 | using namespace hardware::configstore; |
| 188 | using namespace hardware::configstore::V1_0; |
| 189 | using namespace sysprop; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 190 | using ftl::Flags; |
| 191 | using namespace ftl::flag_operators; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 192 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 193 | using aidl::android::hardware::graphics::common::DisplayDecorationSupport; |
| 194 | using aidl::android::hardware::graphics::composer3::Capability; |
| 195 | using aidl::android::hardware::graphics::composer3::DisplayCapability; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 196 | using CompositionStrategyPredictionState = android::compositionengine::impl:: |
| 197 | OutputCompositionState::CompositionStrategyPredictionState; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 198 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 199 | using base::StringAppendF; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 200 | using display::PhysicalDisplay; |
| 201 | using display::PhysicalDisplays; |
Vishnu Nair | af6d297 | 2022-11-18 06:26:38 +0000 | [diff] [blame] | 202 | using frontend::TransactionHandler; |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 203 | using gui::DisplayInfo; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 204 | using gui::GameMode; |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 205 | using gui::IDisplayEventConnection; |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 206 | using gui::IWindowInfosListener; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 207 | using gui::LayerMetadata; |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 208 | using gui::WindowInfo; |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 209 | using gui::aidl_utils::binderStatusFromStatusT; |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 210 | using scheduler::VsyncModulator; |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 211 | using ui::Dataspace; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 212 | using ui::DisplayPrimaries; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 213 | using ui::RenderIntent; |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 214 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 215 | using KernelIdleTimerController = scheduler::RefreshRateSelector::KernelIdleTimerController; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 216 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 217 | namespace hal = android::hardware::graphics::composer::hal; |
| 218 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 219 | namespace { |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 220 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 221 | static constexpr int FOUR_K_WIDTH = 3840; |
| 222 | static constexpr int FOUR_K_HEIGHT = 2160; |
| 223 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 224 | // TODO(b/141333600): Consolidate with DisplayMode::Builder::getDefaultDensity. |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 225 | constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 226 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 227 | float getDensityFromProperty(const char* property, bool required) { |
| 228 | char value[PROPERTY_VALUE_MAX]; |
| 229 | const float density = property_get(property, value, nullptr) > 0 ? std::atof(value) : 0.f; |
| 230 | if (!density && required) { |
| 231 | ALOGE("%s must be defined as a build property", property); |
| 232 | return FALLBACK_DENSITY; |
| 233 | } |
| 234 | return density; |
| 235 | } |
| 236 | |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 237 | // Currently we only support V0_SRGB and DISPLAY_P3 as composition preference. |
| 238 | bool validateCompositionDataspace(Dataspace dataspace) { |
| 239 | return dataspace == Dataspace::V0_SRGB || dataspace == Dataspace::DISPLAY_P3; |
| 240 | } |
| 241 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 242 | std::chrono::milliseconds getIdleTimerTimeout(PhysicalDisplayId displayId) { |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 243 | if (const int32_t displayIdleTimerMs = |
| 244 | base::GetIntProperty("debug.sf.set_idle_timer_ms_"s + |
| 245 | std::to_string(displayId.value), |
| 246 | 0); |
| 247 | displayIdleTimerMs > 0) { |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 248 | return std::chrono::milliseconds(displayIdleTimerMs); |
| 249 | } |
| 250 | |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 251 | const int32_t setIdleTimerMs = base::GetIntProperty("debug.sf.set_idle_timer_ms"s, 0); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 252 | const int32_t millis = setIdleTimerMs ? setIdleTimerMs : sysprop::set_idle_timer_ms(0); |
| 253 | return std::chrono::milliseconds(millis); |
| 254 | } |
| 255 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 256 | bool getKernelIdleTimerSyspropConfig(PhysicalDisplayId displayId) { |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 257 | const bool displaySupportKernelIdleTimer = |
| 258 | base::GetBoolProperty("debug.sf.support_kernel_idle_timer_"s + |
| 259 | std::to_string(displayId.value), |
| 260 | false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 261 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 262 | return displaySupportKernelIdleTimer || sysprop::support_kernel_idle_timer(false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 265 | bool isAbove4k30(const ui::DisplayMode& outMode) { |
| 266 | using fps_approx_ops::operator>; |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 267 | Fps refreshRate = Fps::fromValue(outMode.peakRefreshRate); |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 268 | return outMode.resolution.getWidth() >= FOUR_K_WIDTH && |
| 269 | outMode.resolution.getHeight() >= FOUR_K_HEIGHT && refreshRate > 30_Hz; |
| 270 | } |
| 271 | |
| 272 | void excludeDolbyVisionIf4k30Present(const std::vector<ui::Hdr>& displayHdrTypes, |
| 273 | ui::DisplayMode& outMode) { |
| 274 | if (isAbove4k30(outMode) && |
| 275 | std::any_of(displayHdrTypes.begin(), displayHdrTypes.end(), |
| 276 | [](ui::Hdr type) { return type == ui::Hdr::DOLBY_VISION_4K30; })) { |
| 277 | for (ui::Hdr type : displayHdrTypes) { |
| 278 | if (type != ui::Hdr::DOLBY_VISION_4K30 && type != ui::Hdr::DOLBY_VISION) { |
| 279 | outMode.supportedHdrTypes.push_back(type); |
| 280 | } |
| 281 | } |
| 282 | } else { |
| 283 | for (ui::Hdr type : displayHdrTypes) { |
| 284 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 285 | outMode.supportedHdrTypes.push_back(type); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | HdrCapabilities filterOut4k30(const HdrCapabilities& displayHdrCapabilities) { |
| 292 | std::vector<ui::Hdr> hdrTypes; |
| 293 | for (ui::Hdr type : displayHdrCapabilities.getSupportedHdrTypes()) { |
| 294 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 295 | hdrTypes.push_back(type); |
| 296 | } |
| 297 | } |
| 298 | return {hdrTypes, displayHdrCapabilities.getDesiredMaxLuminance(), |
| 299 | displayHdrCapabilities.getDesiredMaxAverageLuminance(), |
| 300 | displayHdrCapabilities.getDesiredMinLuminance()}; |
| 301 | } |
| 302 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 303 | uint32_t getLayerIdFromSurfaceControl(sp<SurfaceControl> surfaceControl) { |
| 304 | if (!surfaceControl) { |
| 305 | return UNASSIGNED_LAYER_ID; |
| 306 | } |
| 307 | return LayerHandle::getLayerId(surfaceControl->getHandle()); |
| 308 | } |
| 309 | |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 310 | /** |
| 311 | * Returns true if the file at path exists and is newer than duration. |
| 312 | */ |
| 313 | bool fileNewerThan(const std::string& path, std::chrono::minutes duration) { |
| 314 | using Clock = std::filesystem::file_time_type::clock; |
| 315 | std::error_code error; |
| 316 | std::filesystem::file_time_type updateTime = std::filesystem::last_write_time(path, error); |
| 317 | if (error) { |
| 318 | return false; |
| 319 | } |
| 320 | return duration > (Clock::now() - updateTime); |
| 321 | } |
| 322 | |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 323 | bool isFrameIntervalOnCadence(TimePoint expectedPresentTime, TimePoint lastExpectedPresentTimestamp, |
| 324 | Fps lastFrameInterval, Period timeout, Duration threshold) { |
| 325 | if (lastFrameInterval.getPeriodNsecs() == 0) { |
| 326 | return false; |
| 327 | } |
| 328 | |
| 329 | const auto expectedPresentTimeDeltaNs = |
| 330 | expectedPresentTime.ns() - lastExpectedPresentTimestamp.ns(); |
| 331 | |
| 332 | if (expectedPresentTimeDeltaNs > timeout.ns()) { |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | const auto expectedPresentPeriods = static_cast<nsecs_t>( |
| 337 | std::round(static_cast<float>(expectedPresentTimeDeltaNs) / |
| 338 | static_cast<float>(lastFrameInterval.getPeriodNsecs()))); |
| 339 | const auto calculatedPeriodsOutNs = lastFrameInterval.getPeriodNsecs() * expectedPresentPeriods; |
| 340 | const auto calculatedExpectedPresentTimeNs = |
| 341 | lastExpectedPresentTimestamp.ns() + calculatedPeriodsOutNs; |
| 342 | const auto presentTimeDelta = |
| 343 | std::abs(expectedPresentTime.ns() - calculatedExpectedPresentTimeNs); |
| 344 | return presentTimeDelta < threshold.ns(); |
| 345 | } |
| 346 | |
| 347 | bool isExpectedPresentWithinTimeout(TimePoint expectedPresentTime, |
| 348 | TimePoint lastExpectedPresentTimestamp, |
| 349 | std::optional<Period> timeoutOpt, Duration threshold) { |
| 350 | if (!timeoutOpt) { |
| 351 | // Always within timeout if timeoutOpt is absent and don't send hint |
| 352 | // for the timeout |
| 353 | return true; |
| 354 | } |
| 355 | |
| 356 | if (timeoutOpt->ns() == 0) { |
| 357 | // Always outside timeout if timeoutOpt is 0 and always send |
| 358 | // the hint for the timeout. |
| 359 | return false; |
| 360 | } |
| 361 | |
| 362 | if (expectedPresentTime.ns() < lastExpectedPresentTimestamp.ns() + timeoutOpt->ns()) { |
| 363 | return true; |
| 364 | } |
| 365 | |
| 366 | // Check if within the threshold as it can be just outside the timeout |
| 367 | return std::abs(expectedPresentTime.ns() - |
| 368 | (lastExpectedPresentTimestamp.ns() + timeoutOpt->ns())) < threshold.ns(); |
| 369 | } |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 370 | } // namespace anonymous |
| 371 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | // --------------------------------------------------------------------------- |
| 373 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 374 | const String16 sHardwareTest("android.permission.HARDWARE_TEST"); |
| 375 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 376 | const String16 sRotateSurfaceFlinger("android.permission.ROTATE_SURFACE_FLINGER"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 377 | const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER"); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 378 | const String16 sControlDisplayBrightness("android.permission.CONTROL_DISPLAY_BRIGHTNESS"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 379 | const String16 sDump("android.permission.DUMP"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 380 | const String16 sCaptureBlackoutContent("android.permission.CAPTURE_BLACKOUT_CONTENT"); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 381 | const String16 sInternalSystemWindow("android.permission.INTERNAL_SYSTEM_WINDOW"); |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 382 | const String16 sWakeupSurfaceFlinger("android.permission.WAKEUP_SURFACE_FLINGER"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 383 | |
Amy Hsu | c8cdfef | 2020-05-07 13:06:25 +0800 | [diff] [blame] | 384 | const char* KERNEL_IDLE_TIMER_PROP = "graphics.display.kernel_idle_timer.enabled"; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 385 | |
| 386 | // --------------------------------------------------------------------------- |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 387 | int64_t SurfaceFlinger::dispSyncPresentTimeOffset; |
| 388 | bool SurfaceFlinger::useHwcForRgbToYuv; |
| 389 | bool SurfaceFlinger::hasSyncFramework; |
| 390 | int64_t SurfaceFlinger::maxFrameBufferAcquiredBuffers; |
| 391 | int64_t SurfaceFlinger::minAcquiredBuffers = 1; |
| 392 | uint32_t SurfaceFlinger::maxGraphicsWidth; |
| 393 | uint32_t SurfaceFlinger::maxGraphicsHeight; |
| 394 | bool SurfaceFlinger::useContextPriority; |
| 395 | Dataspace SurfaceFlinger::defaultCompositionDataspace = Dataspace::V0_SRGB; |
| 396 | ui::PixelFormat SurfaceFlinger::defaultCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
| 397 | Dataspace SurfaceFlinger::wideColorGamutCompositionDataspace = Dataspace::V0_SRGB; |
| 398 | ui::PixelFormat SurfaceFlinger::wideColorGamutCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 399 | LatchUnsignaledConfig SurfaceFlinger::enableLatchUnsignaledConfig; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 400 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 401 | std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) { |
| 402 | switch(displayColorSetting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 403 | case DisplayColorSetting::kManaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 404 | return std::string("Managed"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 405 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 406 | return std::string("Unmanaged"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 407 | case DisplayColorSetting::kEnhanced: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 408 | return std::string("Enhanced"); |
| 409 | default: |
| 410 | return std::string("Unknown ") + |
| 411 | std::to_string(static_cast<int>(displayColorSetting)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 412 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 413 | } |
| 414 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 415 | bool callingThreadHasPermission(const String16& permission) { |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 416 | IPCThreadState* ipc = IPCThreadState::self(); |
| 417 | const int pid = ipc->getCallingPid(); |
| 418 | const int uid = ipc->getCallingUid(); |
| 419 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 420 | PermissionCache::checkPermission(permission, pid, uid); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 423 | ui::Transform::RotationFlags SurfaceFlinger::sActiveDisplayRotationFlags = ui::Transform::ROT_0; |
| 424 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 425 | SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag) |
| 426 | : mFactory(factory), |
| 427 | mPid(getpid()), |
Yiwei Zhang | f0229a7 | 2019-09-09 19:28:02 -0700 | [diff] [blame] | 428 | mTimeStats(std::make_shared<impl::TimeStats>()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 429 | mFrameTracer(mFactory.createFrameTracer()), |
| 430 | mFrameTimeline(mFactory.createFrameTimeline(mTimeStats, mPid)), |
| 431 | mCompositionEngine(mFactory.createCompositionEngine()), |
| 432 | mHwcServiceName(base::GetProperty("debug.sf.hwc_service_name"s, "default"s)), |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 433 | mTunnelModeEnabledReporter(sp<TunnelModeEnabledReporter>::make()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 434 | mEmulatedDisplayDensity(getDensityFromProperty("qemu.sf.lcd_density", false)), |
| 435 | mInternalDisplayDensity( |
| 436 | getDensityFromProperty("ro.sf.lcd_density", !mEmulatedDisplayDensity)), |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 437 | mPowerAdvisor(std::make_unique<Hwc2::impl::PowerAdvisor>(*this)), |
Robert Horvath | dce110a | 2022-09-16 11:08:47 +0200 | [diff] [blame] | 438 | mWindowInfosListenerInvoker(sp<WindowInfosListenerInvoker>::make()), |
| 439 | mSkipPowerOnForQuiescent(base::GetBoolProperty("ro.boot.quiescent"s, false)) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 440 | ALOGI("Using HWComposer service: %s", mHwcServiceName.c_str()); |
| 441 | } |
Fabien Sanglard | 0cc1938 | 2017-03-06 11:54:40 -0800 | [diff] [blame] | 442 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 443 | SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { |
| 444 | ATRACE_CALL(); |
| 445 | ALOGI("SurfaceFlinger is starting"); |
| 446 | |
| 447 | hasSyncFramework = running_without_sync_framework(true); |
| 448 | |
| 449 | dispSyncPresentTimeOffset = present_time_offset_from_vsync_ns(0); |
| 450 | |
| 451 | useHwcForRgbToYuv = force_hwc_copy_for_virtual_displays(false); |
| 452 | |
| 453 | maxFrameBufferAcquiredBuffers = max_frame_buffer_acquired_buffers(2); |
| 454 | minAcquiredBuffers = |
| 455 | SurfaceFlingerProperties::min_acquired_buffers().value_or(minAcquiredBuffers); |
| 456 | |
| 457 | maxGraphicsWidth = std::max(max_graphics_width(0), 0); |
| 458 | maxGraphicsHeight = std::max(max_graphics_height(0), 0); |
| 459 | |
| 460 | mSupportsWideColor = has_wide_color_display(false); |
| 461 | mDefaultCompositionDataspace = |
| 462 | static_cast<ui::Dataspace>(default_composition_dataspace(Dataspace::V0_SRGB)); |
| 463 | mWideColorGamutCompositionDataspace = static_cast<ui::Dataspace>(wcg_composition_dataspace( |
| 464 | mSupportsWideColor ? Dataspace::DISPLAY_P3 : Dataspace::V0_SRGB)); |
| 465 | defaultCompositionDataspace = mDefaultCompositionDataspace; |
| 466 | wideColorGamutCompositionDataspace = mWideColorGamutCompositionDataspace; |
| 467 | defaultCompositionPixelFormat = static_cast<ui::PixelFormat>( |
| 468 | default_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 469 | wideColorGamutCompositionPixelFormat = |
| 470 | static_cast<ui::PixelFormat>(wcg_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 471 | |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 472 | mLayerCachingEnabled = |
| 473 | base::GetBoolProperty("debug.sf.enable_layer_caching"s, |
| 474 | sysprop::SurfaceFlingerProperties::enable_layer_caching() |
| 475 | .value_or(false)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 476 | |
| 477 | useContextPriority = use_context_priority(true); |
| 478 | |
| 479 | mInternalDisplayPrimaries = sysprop::getDisplayNativePrimaries(); |
| 480 | |
| 481 | // debugging stuff... |
| 482 | char value[PROPERTY_VALUE_MAX]; |
| 483 | |
| 484 | property_get("ro.build.type", value, "user"); |
| 485 | mIsUserBuild = strcmp(value, "user") == 0; |
| 486 | |
| 487 | mDebugFlashDelay = base::GetUintProperty("debug.sf.showupdates"s, 0u); |
| 488 | |
| 489 | mBackpressureGpuComposition = base::GetBoolProperty("debug.sf.enable_gl_backpressure"s, true); |
| 490 | ALOGI_IF(mBackpressureGpuComposition, "Enabling backpressure for GPU composition"); |
| 491 | |
| 492 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 493 | bool supportsBlurs = atoi(value); |
| 494 | mSupportsBlur = supportsBlurs; |
| 495 | ALOGI_IF(!mSupportsBlur, "Disabling blur effects, they are not supported."); |
| 496 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 497 | property_get("debug.sf.luma_sampling", value, "1"); |
| 498 | mLumaSampling = atoi(value); |
| 499 | |
| 500 | property_get("debug.sf.disable_client_composition_cache", value, "0"); |
| 501 | mDisableClientCompositionCache = atoi(value); |
| 502 | |
| 503 | property_get("debug.sf.predict_hwc_composition_strategy", value, "1"); |
| 504 | mPredictCompositionStrategy = atoi(value); |
| 505 | |
| 506 | property_get("debug.sf.treat_170m_as_sRGB", value, "0"); |
| 507 | mTreat170mAsSrgb = atoi(value); |
| 508 | |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 509 | property_get("debug.sf.dim_in_gamma_in_enhanced_screenshots", value, 0); |
| 510 | mDimInGammaSpaceForEnhancedScreenshots = atoi(value); |
| 511 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 512 | mIgnoreHwcPhysicalDisplayOrientation = |
| 513 | base::GetBoolProperty("debug.sf.ignore_hwc_physical_display_orientation"s, false); |
| 514 | |
| 515 | // We should be reading 'persist.sys.sf.color_saturation' here |
| 516 | // but since /data may be encrypted, we need to wait until after vold |
| 517 | // comes online to attempt to read the property. The property is |
| 518 | // instead read after the boot animation |
| 519 | |
| 520 | if (base::GetBoolProperty("debug.sf.treble_testing_override"s, false)) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 521 | // Without the override SurfaceFlinger cannot connect to HIDL |
| 522 | // services that are not listed in the manifests. Considered |
| 523 | // deriving the setting from the set service name, but it |
| 524 | // would be brittle if the name that's not 'default' is used |
| 525 | // for production purposes later on. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 526 | ALOGI("Enabling Treble testing override"); |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 527 | android::hardware::details::setTrebleTestingOverride(true); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 528 | } |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 529 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 530 | // TODO (b/270966065) Update the HWC based refresh rate overlay to support spinner |
| 531 | mRefreshRateOverlaySpinner = property_get_bool("debug.sf.show_refresh_rate_overlay_spinner", 0); |
| 532 | mRefreshRateOverlayRenderRate = |
| 533 | property_get_bool("debug.sf.show_refresh_rate_overlay_render_rate", 0); |
| 534 | mRefreshRateOverlayShowInMiddle = |
| 535 | property_get_bool("debug.sf.show_refresh_rate_overlay_in_middle", 0); |
| 536 | |
| 537 | if (!mIsUserBuild && base::GetBoolProperty("debug.sf.enable_transaction_tracing"s, true)) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 538 | mTransactionTracing.emplace(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 539 | mLayerTracing.setTransactionTracing(*mTransactionTracing); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 540 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 541 | |
| 542 | mIgnoreHdrCameraLayers = ignore_hdr_camera_layers(false); |
| 543 | |
| 544 | mLayerLifecycleManagerEnabled = |
Vishnu Nair | f42d9bd | 2023-08-23 21:35:33 +0000 | [diff] [blame] | 545 | base::GetBoolProperty("persist.debug.sf.enable_layer_lifecycle_manager"s, true); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 546 | |
| 547 | // These are set by the HWC implementation to indicate that they will use the workarounds. |
| 548 | mIsHotplugErrViaNegVsync = |
| 549 | base::GetBoolProperty("debug.sf.hwc_hotplug_error_via_neg_vsync"s, false); |
| 550 | |
| 551 | mIsHdcpViaNegVsync = base::GetBoolProperty("debug.sf.hwc_hdcp_via_neg_vsync"s, false); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | LatchUnsignaledConfig SurfaceFlinger::getLatchUnsignaledConfig() { |
Ady Abraham | d9e8d1b | 2022-02-25 00:36:10 +0000 | [diff] [blame] | 555 | if (base::GetBoolProperty("debug.sf.auto_latch_unsignaled"s, true)) { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 556 | return LatchUnsignaledConfig::AutoSingleLayer; |
| 557 | } |
| 558 | |
| 559 | return LatchUnsignaledConfig::Disabled; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | } |
| 561 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 562 | SurfaceFlinger::~SurfaceFlinger() = default; |
| 563 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 564 | void SurfaceFlinger::binderDied(const wp<IBinder>&) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 565 | // the window manager died on us. prepare its eulogy. |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 566 | mBootFinished = false; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 567 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 568 | static_cast<void>(mScheduler->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 569 | // Sever the link to inputflinger since it's gone as well. |
| 570 | mInputFlinger.clear(); |
Vishnu Nair | b9df470 | 2021-03-01 11:53:15 -0800 | [diff] [blame] | 571 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 572 | initializeDisplays(); |
| 573 | })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 574 | |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 575 | mInitBootPropsFuture.callOnce([this] { |
| 576 | return std::async(std::launch::async, &SurfaceFlinger::initBootProperties, this); |
| 577 | }); |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 578 | |
| 579 | mInitBootPropsFuture.wait(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 580 | } |
| 581 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 582 | void SurfaceFlinger::run() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 583 | mScheduler->run(); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 584 | } |
| 585 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 586 | sp<IBinder> SurfaceFlinger::createVirtualDisplay(const std::string& displayName, bool isSecure, |
| 587 | const std::string& uniqueId, |
| 588 | float requestedRefreshRate) { |
Patrick Williams | e58a92b | 2024-02-29 14:52:25 -0600 | [diff] [blame] | 589 | // SurfaceComposerAIDL checks for some permissions, but adding an additional check here. |
| 590 | // This is to ensure that only root, system, and graphics can request to create a secure |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 591 | // display. Secure displays can show secure content so we add an additional restriction on it. |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 592 | const uid_t uid = IPCThreadState::self()->getCallingUid(); |
| 593 | if (isSecure && uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM) { |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 594 | ALOGE("Only privileged processes can create a secure display"); |
| 595 | return nullptr; |
| 596 | } |
| 597 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 598 | class DisplayToken : public BBinder { |
| 599 | sp<SurfaceFlinger> flinger; |
| 600 | virtual ~DisplayToken() { |
| 601 | // no more references, this display must be terminated |
| 602 | Mutex::Autolock _l(flinger->mStateLock); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 603 | flinger->mCurrentState.displays.removeItem(wp<IBinder>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 604 | flinger->setTransactionFlags(eDisplayTransactionNeeded); |
| 605 | } |
| 606 | public: |
Chih-Hung Hsieh | c406791 | 2016-05-03 14:03:27 -0700 | [diff] [blame] | 607 | explicit DisplayToken(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 608 | : flinger(flinger) { |
| 609 | } |
| 610 | }; |
| 611 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 612 | sp<BBinder> token = sp<DisplayToken>::make(sp<SurfaceFlinger>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 613 | |
| 614 | Mutex::Autolock _l(mStateLock); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 615 | // Display ID is assigned when virtual display is allocated by HWC. |
| 616 | DisplayDeviceState state; |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 617 | state.isSecure = isSecure; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 618 | // Set display as protected when marked as secure to ensure no behavior change |
| 619 | // TODO (b/314820005): separate as a different arg when creating the display. |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 620 | state.isProtected = isSecure; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 621 | state.displayName = displayName; |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 622 | state.uniqueId = uniqueId; |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 623 | state.requestedRefreshRate = Fps::fromValue(requestedRefreshRate); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 624 | mCurrentState.displays.add(token, state); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 625 | return token; |
| 626 | } |
| 627 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 628 | status_t SurfaceFlinger::destroyVirtualDisplay(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 629 | Mutex::Autolock lock(mStateLock); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 630 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 631 | const ssize_t index = mCurrentState.displays.indexOfKey(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 632 | if (index < 0) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 633 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 634 | return NAME_NOT_FOUND; |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 637 | const DisplayDeviceState& state = mCurrentState.displays.valueAt(index); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 638 | if (state.physical) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 639 | ALOGE("%s: Invalid operation on physical display", __func__); |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 640 | return INVALID_OPERATION; |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 641 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 642 | mCurrentState.displays.removeItemsAt(index); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 643 | setTransactionFlags(eDisplayTransactionNeeded); |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 644 | return NO_ERROR; |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 647 | void SurfaceFlinger::enableHalVirtualDisplays(bool enable) { |
| 648 | auto& generator = mVirtualDisplayIdGenerators.hal; |
| 649 | if (!generator && enable) { |
| 650 | ALOGI("Enabling HAL virtual displays"); |
| 651 | generator.emplace(getHwComposer().getMaxVirtualDisplayCount()); |
| 652 | } else if (generator && !enable) { |
| 653 | ALOGW_IF(generator->inUse(), "Disabling HAL virtual displays while in use"); |
| 654 | generator.reset(); |
| 655 | } |
| 656 | } |
| 657 | |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 658 | VirtualDisplayId SurfaceFlinger::acquireVirtualDisplay(ui::Size resolution, |
Rajat Yadav | bc0c03d | 2021-07-05 19:32:01 +0530 | [diff] [blame] | 659 | ui::PixelFormat format, |
| 660 | bool canAllocateHwcForVDS) { |
| 661 | auto& generator = mVirtualDisplayIdGenerators.hal; |
| 662 | if (canAllocateHwcForVDS && generator) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 663 | if (const auto id = generator->generateId()) { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 664 | if (getHwComposer().allocateVirtualDisplay(*id, resolution, &format)) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 665 | return *id; |
| 666 | } |
| 667 | |
| 668 | generator->releaseId(*id); |
| 669 | } else { |
| 670 | ALOGW("%s: Exhausted HAL virtual displays", __func__); |
| 671 | } |
| 672 | |
| 673 | ALOGW("%s: Falling back to GPU virtual display", __func__); |
| 674 | } |
| 675 | |
| 676 | const auto id = mVirtualDisplayIdGenerators.gpu.generateId(); |
| 677 | LOG_ALWAYS_FATAL_IF(!id, "Failed to generate ID for GPU virtual display"); |
| 678 | return *id; |
| 679 | } |
| 680 | |
| 681 | void SurfaceFlinger::releaseVirtualDisplay(VirtualDisplayId displayId) { |
| 682 | if (const auto id = HalVirtualDisplayId::tryCast(displayId)) { |
| 683 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 684 | generator->releaseId(*id); |
| 685 | } |
| 686 | return; |
| 687 | } |
| 688 | |
| 689 | const auto id = GpuVirtualDisplayId::tryCast(displayId); |
| 690 | LOG_ALWAYS_FATAL_IF(!id); |
| 691 | mVirtualDisplayIdGenerators.gpu.releaseId(*id); |
| 692 | } |
| 693 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 694 | std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdsLocked() const { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 695 | std::vector<PhysicalDisplayId> displayIds; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 696 | displayIds.reserve(mPhysicalDisplays.size()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 697 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 698 | const auto defaultDisplayId = getDefaultDisplayDeviceLocked()->getPhysicalId(); |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 699 | displayIds.push_back(defaultDisplayId); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 700 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 701 | for (const auto& [id, display] : mPhysicalDisplays) { |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 702 | if (id != defaultDisplayId) { |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 703 | displayIds.push_back(id); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 704 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 705 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 706 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 707 | return displayIds; |
| 708 | } |
| 709 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 710 | std::optional<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdLocked( |
| 711 | const sp<display::DisplayToken>& displayToken) const { |
| 712 | return ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 713 | .transform(&ftl::to_key<PhysicalDisplays>); |
| 714 | } |
| 715 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 716 | sp<IBinder> SurfaceFlinger::getPhysicalDisplayToken(PhysicalDisplayId displayId) const { |
| 717 | Mutex::Autolock lock(mStateLock); |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 718 | return getPhysicalDisplayTokenLocked(displayId); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 721 | HWComposer& SurfaceFlinger::getHwComposer() const { |
| 722 | return mCompositionEngine->getHwComposer(); |
| 723 | } |
| 724 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 725 | renderengine::RenderEngine& SurfaceFlinger::getRenderEngine() const { |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 726 | return *mRenderEngine; |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 729 | compositionengine::CompositionEngine& SurfaceFlinger::getCompositionEngine() const { |
| 730 | return *mCompositionEngine.get(); |
| 731 | } |
| 732 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 733 | void SurfaceFlinger::bootFinished() { |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 734 | if (mBootFinished == true) { |
| 735 | ALOGE("Extra call to bootFinished"); |
| 736 | return; |
| 737 | } |
| 738 | mBootFinished = true; |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame] | 739 | FlagManager::getMutableInstance().markBootCompleted(); |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 740 | |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 741 | mInitBootPropsFuture.wait(); |
| 742 | mRenderEnginePrimeCacheFuture.wait(); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 743 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | const nsecs_t now = systemTime(); |
| 745 | const nsecs_t duration = now - mBootTime; |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 746 | ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 747 | |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 748 | mFrameTracer->initialize(); |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 749 | mFrameTimeline->onBootFinished(); |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 750 | getRenderEngine().setEnableTracing(FlagManager::getInstance().use_skia_tracing()); |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 751 | |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 752 | // wait patiently for the window manager death |
| 753 | const String16 name("window"); |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 754 | mWindowManager = defaultServiceManager()->waitForService(name); |
Steven Moreland | a904bb9 | 2019-07-02 17:37:23 -0700 | [diff] [blame] | 755 | if (mWindowManager != 0) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 756 | mWindowManager->linkToDeath(sp<IBinder::DeathRecipient>::fromExisting(this)); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | // stop boot animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 760 | // formerly we would just kill the process, but we now ask it to exit so it |
| 761 | // can choose where to stop the animation. |
| 762 | property_set("service.bootanim.exit", "1"); |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 763 | |
| 764 | const int LOGTAG_SF_STOP_BOOTANIM = 60110; |
| 765 | LOG_EVENT_LONG(LOGTAG_SF_STOP_BOOTANIM, |
| 766 | ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 767 | |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 768 | sp<IBinder> input(defaultServiceManager()->waitForService(String16("inputflinger"))); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 769 | |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 770 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 771 | if (input == nullptr) { |
| 772 | ALOGE("Failed to link to input service"); |
| 773 | } else { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 774 | mInputFlinger = interface_cast<os::IInputFlinger>(input); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 775 | } |
| 776 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 777 | readPersistentProperties(); |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 778 | const bool hintSessionEnabled = FlagManager::getInstance().use_adpf_cpu_hint(); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 779 | mPowerAdvisor->enablePowerHintSession(hintSessionEnabled); |
| 780 | const bool hintSessionUsed = mPowerAdvisor->usePowerHintSession(); |
Matt Buckley | 547cc0c | 2023-10-27 22:22:36 +0000 | [diff] [blame] | 781 | // Ordering is important here, as onBootFinished signals to PowerAdvisor that concurrency |
| 782 | // is safe because its variables are initialized. |
| 783 | mPowerAdvisor->onBootFinished(); |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 784 | ALOGD("Power hint is %s", |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 785 | hintSessionUsed ? "supported" : (hintSessionEnabled ? "unsupported" : "disabled")); |
| 786 | if (hintSessionUsed) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 787 | std::optional<pid_t> renderEngineTid = getRenderEngine().getRenderEngineTid(); |
| 788 | std::vector<int32_t> tidList; |
| 789 | tidList.emplace_back(gettid()); |
| 790 | if (renderEngineTid.has_value()) { |
| 791 | tidList.emplace_back(*renderEngineTid); |
| 792 | } |
Matt Buckley | 547cc0c | 2023-10-27 22:22:36 +0000 | [diff] [blame] | 793 | if (!mPowerAdvisor->startPowerHintSession(std::move(tidList))) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 794 | ALOGW("Cannot start power hint session"); |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 795 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 796 | } |
| 797 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 798 | mBootStage = BootStage::FINISHED; |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 799 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 800 | if (base::GetBoolProperty("sf.debug.show_refresh_rate_overlay"s, false)) { |
| 801 | ftl::FakeGuard guard(mStateLock); |
| 802 | enableRefreshRateOverlay(true); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 803 | } |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 804 | })); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 805 | } |
| 806 | |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 807 | void chooseRenderEngineType(renderengine::RenderEngineCreationArgs::Builder& builder) { |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 808 | char prop[PROPERTY_VALUE_MAX]; |
Leon Scroggins III | f840ae5 | 2024-01-25 15:10:12 -0500 | [diff] [blame] | 809 | property_get(PROPERTY_DEBUG_RENDERENGINE_BACKEND, prop, ""); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 810 | |
Nolan Scobie | 576e77f | 2024-03-26 10:59:59 -0400 | [diff] [blame] | 811 | // TODO: b/293371537 - Once GraphiteVk is deemed relatively stable, log a warning that |
| 812 | // PROPERTY_DEBUG_RENDERENGINE_BACKEND is deprecated |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 813 | if (strcmp(prop, "skiagl") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 814 | builder.setThreaded(renderengine::RenderEngine::Threaded::NO) |
| 815 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::GL); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 816 | } else if (strcmp(prop, "skiaglthreaded") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 817 | builder.setThreaded(renderengine::RenderEngine::Threaded::YES) |
| 818 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::GL); |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 819 | } else if (strcmp(prop, "skiavk") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 820 | builder.setThreaded(renderengine::RenderEngine::Threaded::NO) |
| 821 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::VK); |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 822 | } else if (strcmp(prop, "skiavkthreaded") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 823 | builder.setThreaded(renderengine::RenderEngine::Threaded::YES) |
| 824 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::VK); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 825 | } else { |
Leon Scroggins III | f3369ed | 2024-02-16 17:52:42 -0500 | [diff] [blame] | 826 | const auto kVulkan = renderengine::RenderEngine::GraphicsApi::VK; |
Nolan Scobie | 488101b | 2024-05-20 13:32:13 -0400 | [diff] [blame] | 827 | // TODO: b/341728634 - Clean up conditional compilation. |
| 828 | // Note: this guard in particular must check e.g. |
| 829 | // COM_ANDROID_GRAPHICS_SURFACEFLINGER_FLAGS_GRAPHITE_RENDERENGINE directly (instead of calling e.g. |
| 830 | // COM_ANDROID_GRAPHICS_SURFACEFLINGER_FLAGS(GRAPHITE_RENDERENGINE)) because that macro is undefined |
| 831 | // in the libsurfaceflingerflags_test variant of com_android_graphics_surfaceflinger_flags.h, which |
| 832 | // is used by layertracegenerator (which also needs SurfaceFlinger.cpp). :) |
| 833 | #if COM_ANDROID_GRAPHICS_SURFACEFLINGER_FLAGS_GRAPHITE_RENDERENGINE || \ |
| 834 | COM_ANDROID_GRAPHICS_SURFACEFLINGER_FLAGS_FORCE_COMPILE_GRAPHITE_RENDERENGINE |
Nolan Scobie | 2526b2f | 2024-04-16 15:12:22 -0400 | [diff] [blame] | 835 | const bool useGraphite = FlagManager::getInstance().graphite_renderengine() && |
| 836 | renderengine::RenderEngine::canSupport(kVulkan); |
Nolan Scobie | 488101b | 2024-05-20 13:32:13 -0400 | [diff] [blame] | 837 | #else |
| 838 | const bool useGraphite = false; |
| 839 | if (FlagManager::getInstance().graphite_renderengine()) { |
| 840 | ALOGE("RenderEngine's Graphite Skia backend was requested with the " |
| 841 | "debug.renderengine.graphite system property, but it is not compiled in this " |
| 842 | "build! Falling back to Ganesh backend selection logic."); |
| 843 | } |
| 844 | #endif |
Nolan Scobie | 576e77f | 2024-03-26 10:59:59 -0400 | [diff] [blame] | 845 | const bool useVulkan = useGraphite || |
Nolan Scobie | 2526b2f | 2024-04-16 15:12:22 -0400 | [diff] [blame] | 846 | (FlagManager::getInstance().vulkan_renderengine() && |
| 847 | renderengine::RenderEngine::canSupport(kVulkan)); |
Nolan Scobie | 576e77f | 2024-03-26 10:59:59 -0400 | [diff] [blame] | 848 | |
| 849 | builder.setSkiaBackend(useGraphite ? renderengine::RenderEngine::SkiaBackend::GRAPHITE |
| 850 | : renderengine::RenderEngine::SkiaBackend::GANESH); |
Leon Scroggins III | f3369ed | 2024-02-16 17:52:42 -0500 | [diff] [blame] | 851 | builder.setGraphicsApi(useVulkan ? kVulkan : renderengine::RenderEngine::GraphicsApi::GL); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 852 | } |
| 853 | } |
| 854 | |
Robin Lee | 7338bd9 | 2024-04-04 14:05:07 +0000 | [diff] [blame] | 855 | /** |
| 856 | * Choose a suggested blurring algorithm if supportsBlur is true. By default Kawase will be |
| 857 | * suggested as it's faster than a full Gaussian blur and looks close enough. |
| 858 | */ |
| 859 | renderengine::RenderEngine::BlurAlgorithm chooseBlurAlgorithm(bool supportsBlur) { |
| 860 | if (!supportsBlur) { |
| 861 | return renderengine::RenderEngine::BlurAlgorithm::NONE; |
| 862 | } |
| 863 | |
| 864 | auto const algorithm = base::GetProperty(PROPERTY_DEBUG_RENDERENGINE_BLUR_ALGORITHM, ""); |
| 865 | if (algorithm == "gaussian") { |
| 866 | return renderengine::RenderEngine::BlurAlgorithm::GAUSSIAN; |
| 867 | } else { |
| 868 | return renderengine::RenderEngine::BlurAlgorithm::KAWASE; |
| 869 | } |
| 870 | } |
| 871 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 872 | void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) { |
Parth Sane | 343626c | 2023-04-06 16:17:04 +0000 | [diff] [blame] | 873 | ATRACE_CALL(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 874 | ALOGI( "SurfaceFlinger's main thread ready to run. " |
| 875 | "Initializing graphics H/W..."); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 876 | addTransactionReadyFilters(); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 877 | Mutex::Autolock lock(mStateLock); |
Kevin DuBois | 413287f | 2019-02-25 08:46:47 -0800 | [diff] [blame] | 878 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 879 | // Get a RenderEngine for the given display / config (can't fail) |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 880 | // 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] | 881 | // Sending maxFrameBufferAcquiredBuffers as the cache size is tightly tuned to single-display. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 882 | auto builder = renderengine::RenderEngineCreationArgs::Builder() |
| 883 | .setPixelFormat(static_cast<int32_t>(defaultCompositionPixelFormat)) |
| 884 | .setImageCacheSize(maxFrameBufferAcquiredBuffers) |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 885 | .setEnableProtectedContext(enable_protected_contents(false)) |
| 886 | .setPrecacheToneMapperShaderOnly(false) |
Robin Lee | 7338bd9 | 2024-04-04 14:05:07 +0000 | [diff] [blame] | 887 | .setBlurAlgorithm(chooseBlurAlgorithm(mSupportsBlur)) |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 888 | .setContextPriority( |
| 889 | useContextPriority |
| 890 | ? renderengine::RenderEngine::ContextPriority::REALTIME |
| 891 | : renderengine::RenderEngine::ContextPriority::MEDIUM); |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 892 | chooseRenderEngineType(builder); |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 893 | mRenderEngine = renderengine::RenderEngine::create(builder.build()); |
| 894 | mCompositionEngine->setRenderEngine(mRenderEngine.get()); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 895 | mMaxRenderTargetSize = |
| 896 | std::min(getRenderEngine().getMaxTextureSize(), getRenderEngine().getMaxViewportDims()); |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 897 | |
| 898 | // Set SF main policy after initializing RenderEngine which has its own policy. |
| 899 | if (!SetTaskProfiles(0, {"SFMainPolicy"})) { |
| 900 | ALOGW("Failed to set main task profile"); |
| 901 | } |
| 902 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 903 | mCompositionEngine->setTimeStats(mTimeStats); |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 904 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 905 | mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName)); |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 906 | auto& composer = mCompositionEngine->getHwComposer(); |
| 907 | composer.setCallback(*this); |
| 908 | mDisplayModeController.setHwComposer(&composer); |
| 909 | |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 910 | ClientCache::getInstance().setRenderEngine(&getRenderEngine()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 911 | |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 912 | mHasReliablePresentFences = |
| 913 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE); |
| 914 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 915 | enableLatchUnsignaledConfig = getLatchUnsignaledConfig(); |
| 916 | |
Rheygine Medel | 9be9d5f | 2022-05-25 19:20:55 -0700 | [diff] [blame] | 917 | mAllowHwcForWFD = base::GetBoolProperty("vendor.display.vds_allow_hwc"s, false); |
| 918 | mAllowHwcForVDS = mAllowHwcForWFD && base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false); |
Rheygine Medel | 88606ff | 2022-06-30 11:21:55 -0700 | [diff] [blame] | 919 | mFirstApiLevel = android::base::GetIntProperty("ro.product.first_api_level", 0); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 920 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 921 | // Process hotplug for displays connected at boot. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 922 | LOG_ALWAYS_FATAL_IF(!configureLocked(), |
| 923 | "Initial display configuration failed: HWC did not hotplug"); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 924 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 925 | // Commit primary display. |
| 926 | sp<const DisplayDevice> display; |
| 927 | if (const auto indexOpt = mCurrentState.getDisplayIndex(getPrimaryDisplayIdLocked())) { |
| 928 | const auto& displays = mCurrentState.displays; |
| 929 | |
| 930 | const auto& token = displays.keyAt(*indexOpt); |
| 931 | const auto& state = displays.valueAt(*indexOpt); |
| 932 | |
| 933 | processDisplayAdded(token, state); |
| 934 | mDrawingState.displays.add(token, state); |
| 935 | |
| 936 | display = getDefaultDisplayDeviceLocked(); |
| 937 | } |
| 938 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 939 | LOG_ALWAYS_FATAL_IF(!display, "Failed to configure the primary display"); |
| 940 | LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(display->getPhysicalId()), |
| 941 | "Primary display is disconnected"); |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 942 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 943 | // TODO(b/241285876): The Scheduler needlessly depends on creating the CompositionEngine part of |
| 944 | // the DisplayDevice, hence the above commit of the primary display. Remove that special case by |
| 945 | // initializing the Scheduler after configureLocked, once decoupled from DisplayDevice. |
| 946 | initScheduler(display); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 947 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 948 | // Start listening after creating the Scheduler, since the listener calls into it. |
| 949 | mDisplayModeController.setActiveModeListener( |
| 950 | display::DisplayModeController::ActiveModeListener::make( |
| 951 | [this](PhysicalDisplayId displayId, Fps vsyncRate, Fps renderRate) { |
| 952 | // This callback cannot lock mStateLock, as some callers already lock it. |
| 953 | // Instead, switch context to the main thread. |
| 954 | static_cast<void>(mScheduler->schedule([=, |
| 955 | this]() FTL_FAKE_GUARD(mStateLock) { |
| 956 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 957 | display->updateRefreshRateOverlayRate(vsyncRate, renderRate); |
| 958 | } |
| 959 | })); |
| 960 | })); |
| 961 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 962 | mLayerTracing.setTakeLayersSnapshotProtoFunction([&](uint32_t traceFlags) { |
| 963 | auto snapshot = perfetto::protos::LayersSnapshotProto{}; |
| 964 | mScheduler |
| 965 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 966 | snapshot = takeLayersSnapshotProto(traceFlags, TimePoint::now(), |
| 967 | mLastCommittedVsyncId, true); |
| 968 | }) |
| 969 | .wait(); |
| 970 | return snapshot; |
| 971 | }); |
| 972 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 973 | // Commit secondary display(s). |
| 974 | processDisplayChangesLocked(); |
| 975 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 976 | // initialize our drawing state |
| 977 | mDrawingState = mCurrentState; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 978 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 979 | onActiveDisplayChangedLocked(nullptr, *display); |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 980 | |
| 981 | static_cast<void>(mScheduler->schedule( |
| 982 | [this]() FTL_FAKE_GUARD(kMainThreadContext) { initializeDisplays(); })); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 983 | |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 984 | mPowerAdvisor->init(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 985 | |
Bruno BELANYI | fd02878 | 2023-10-13 14:39:53 +0000 | [diff] [blame] | 986 | if (base::GetBoolProperty("service.sf.prime_shader_cache"s, true)) { |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 987 | if (setSchedFifo(false) != NO_ERROR) { |
| 988 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 989 | } |
| 990 | |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 991 | mRenderEnginePrimeCacheFuture.callOnce([this] { |
Russell Myers | 3348c74 | 2024-04-29 20:22:42 +0000 | [diff] [blame] | 992 | renderengine::PrimeCacheConfig config; |
| 993 | config.cacheHolePunchLayer = |
| 994 | base::GetBoolProperty("debug.sf.prime_shader_cache.hole_punch"s, true); |
| 995 | config.cacheSolidLayers = |
| 996 | base::GetBoolProperty("debug.sf.prime_shader_cache.solid_layers"s, true); |
| 997 | config.cacheSolidDimmedLayers = |
| 998 | base::GetBoolProperty("debug.sf.prime_shader_cache.solid_dimmed_layers"s, true); |
| 999 | config.cacheImageLayers = |
| 1000 | base::GetBoolProperty("debug.sf.prime_shader_cache.image_layers"s, true); |
| 1001 | config.cacheImageDimmedLayers = |
| 1002 | base::GetBoolProperty("debug.sf.prime_shader_cache.image_dimmed_layers"s, true); |
| 1003 | config.cacheClippedLayers = |
| 1004 | base::GetBoolProperty("debug.sf.prime_shader_cache.clipped_layers"s, true); |
| 1005 | config.cacheShadowLayers = |
| 1006 | base::GetBoolProperty("debug.sf.prime_shader_cache.shadow_layers"s, true); |
| 1007 | config.cachePIPImageLayers = |
| 1008 | base::GetBoolProperty("debug.sf.prime_shader_cache.pip_image_layers"s, true); |
| 1009 | config.cacheTransparentImageDimmedLayers = base:: |
| 1010 | GetBoolProperty("debug.sf.prime_shader_cache.transparent_image_dimmed_layers"s, |
| 1011 | true); |
| 1012 | config.cacheClippedDimmedImageLayers = base:: |
| 1013 | GetBoolProperty("debug.sf.prime_shader_cache.clipped_dimmed_image_layers"s, |
| 1014 | true); |
| 1015 | // ro.surface_flinger.prime_chader_cache.ultrahdr exists as a previous ro property |
| 1016 | // which we maintain for backwards compatibility. |
| 1017 | config.cacheUltraHDR = |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 1018 | base::GetBoolProperty("ro.surface_flinger.prime_shader_cache.ultrahdr"s, false); |
Russell Myers | 3348c74 | 2024-04-29 20:22:42 +0000 | [diff] [blame] | 1019 | return getRenderEngine().primeCache(config); |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 1020 | }); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 1021 | |
| 1022 | if (setSchedFifo(true) != NO_ERROR) { |
linkai | d696a4f | 2023-11-14 10:13:36 +0800 | [diff] [blame] | 1023 | ALOGW("Can't set SCHED_FIFO after primeCache"); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 1024 | } |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 1025 | } |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 1026 | |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 1027 | // Avoid blocking the main thread on `init` to set properties. |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 1028 | mInitBootPropsFuture.callOnce([this] { |
| 1029 | return std::async(std::launch::async, &SurfaceFlinger::initBootProperties, this); |
| 1030 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 1032 | initTransactionTraceWriter(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1033 | ALOGV("Done initializing"); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 1036 | // During boot, offload `initBootProperties` to another thread. `property_set` depends on |
| 1037 | // `property_service`, which may be delayed by slow operations like `mount_all --late` in |
| 1038 | // the `init` process. See b/34499826 and b/63844978. |
| 1039 | void SurfaceFlinger::initBootProperties() { |
| 1040 | property_set("service.sf.present_timestamp", mHasReliablePresentFences ? "1" : "0"); |
| 1041 | |
Dominik Laskowski | b0fdfe7 | 2024-02-21 10:42:23 -0500 | [diff] [blame] | 1042 | if (base::GetBoolProperty("debug.sf.boot_animation"s, true)) { |
| 1043 | // Reset and (if needed) start BootAnimation. |
| 1044 | property_set("service.bootanim.exit", "0"); |
| 1045 | property_set("service.bootanim.progress", "0"); |
| 1046 | property_set("ctl.start", "bootanim"); |
| 1047 | } |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 1048 | } |
| 1049 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 1050 | void SurfaceFlinger::initTransactionTraceWriter() { |
| 1051 | if (!mTransactionTracing) { |
| 1052 | return; |
| 1053 | } |
| 1054 | TransactionTraceWriter::getInstance().setWriterFunction( |
| 1055 | [&](const std::string& filename, bool overwrite) { |
| 1056 | auto writeFn = [&]() { |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 1057 | if (!overwrite && fileNewerThan(filename, std::chrono::minutes{10})) { |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 1058 | ALOGD("TransactionTraceWriter: file=%s already exists", filename.c_str()); |
| 1059 | return; |
| 1060 | } |
Wenhui Yang | eafc18a | 2024-05-14 17:15:52 +0000 | [diff] [blame] | 1061 | ALOGD("TransactionTraceWriter: writing file=%s", filename.c_str()); |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 1062 | mTransactionTracing->writeToFile(filename); |
Wenhui Yang | eafc18a | 2024-05-14 17:15:52 +0000 | [diff] [blame] | 1063 | mTransactionTracing->flush(); |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 1064 | }; |
| 1065 | if (std::this_thread::get_id() == mMainThreadId) { |
| 1066 | writeFn(); |
| 1067 | } else { |
| 1068 | mScheduler->schedule(writeFn).get(); |
| 1069 | } |
| 1070 | }); |
| 1071 | } |
| 1072 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 1073 | void SurfaceFlinger::readPersistentProperties() { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 1074 | Mutex::Autolock _l(mStateLock); |
| 1075 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 1076 | char value[PROPERTY_VALUE_MAX]; |
| 1077 | |
| 1078 | property_get("persist.sys.sf.color_saturation", value, "1.0"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 1079 | mGlobalSaturationFactor = atof(value); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 1080 | updateColorMatrixLocked(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 1081 | ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 1082 | |
| 1083 | property_get("persist.sys.sf.native_mode", value, "0"); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 1084 | mDisplayColorSetting = static_cast<DisplayColorSetting>(atoi(value)); |
Peiyong Lin | a3ea559 | 2019-02-10 14:45:00 -0800 | [diff] [blame] | 1085 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1086 | mForceColorMode = |
| 1087 | 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] | 1088 | } |
| 1089 | |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 1090 | status_t SurfaceFlinger::getSupportedFrameTimestamps( |
| 1091 | std::vector<FrameEvent>* outSupported) const { |
| 1092 | *outSupported = { |
| 1093 | FrameEvent::REQUESTED_PRESENT, |
| 1094 | FrameEvent::ACQUIRE, |
| 1095 | FrameEvent::LATCH, |
| 1096 | FrameEvent::FIRST_REFRESH_START, |
| 1097 | FrameEvent::LAST_REFRESH_START, |
| 1098 | FrameEvent::GPU_COMPOSITION_DONE, |
| 1099 | FrameEvent::DEQUEUE_READY, |
| 1100 | FrameEvent::RELEASE, |
| 1101 | }; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1102 | |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 1103 | if (mHasReliablePresentFences) { |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 1104 | outSupported->push_back(FrameEvent::DISPLAY_PRESENT); |
| 1105 | } |
| 1106 | return NO_ERROR; |
| 1107 | } |
| 1108 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1109 | status_t SurfaceFlinger::getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState* state) { |
| 1110 | if (!displayToken || !state) { |
| 1111 | return BAD_VALUE; |
| 1112 | } |
| 1113 | |
| 1114 | Mutex::Autolock lock(mStateLock); |
| 1115 | |
| 1116 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1117 | if (!display) { |
| 1118 | return NAME_NOT_FOUND; |
| 1119 | } |
| 1120 | |
| 1121 | state->layerStack = display->getLayerStack(); |
| 1122 | state->orientation = display->getOrientation(); |
| 1123 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 1124 | const Rect layerStackRect = display->getLayerStackSpaceRect(); |
| 1125 | state->layerStackSpaceRect = |
| 1126 | layerStackRect.isValid() ? layerStackRect.getSize() : display->getSize(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1127 | |
| 1128 | return NO_ERROR; |
| 1129 | } |
| 1130 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1131 | status_t SurfaceFlinger::getStaticDisplayInfo(int64_t displayId, ui::StaticDisplayInfo* info) { |
| 1132 | if (!info) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1133 | return BAD_VALUE; |
| 1134 | } |
| 1135 | |
| 1136 | Mutex::Autolock lock(mStateLock); |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1137 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 1138 | const auto displayOpt = mPhysicalDisplays.get(*id).and_then(getDisplayDeviceAndSnapshot()); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1139 | |
| 1140 | if (!displayOpt) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1141 | return NAME_NOT_FOUND; |
| 1142 | } |
| 1143 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1144 | const auto& [display, snapshotRef] = *displayOpt; |
| 1145 | const auto& snapshot = snapshotRef.get(); |
| 1146 | |
| 1147 | info->connectionType = snapshot.connectionType(); |
| 1148 | info->deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1149 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1150 | if (mEmulatedDisplayDensity) { |
| 1151 | info->density = mEmulatedDisplayDensity; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1152 | } else { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1153 | info->density = info->connectionType == ui::DisplayConnectionType::Internal |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1154 | ? mInternalDisplayDensity |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1155 | : FALLBACK_DENSITY; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1156 | } |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 1157 | info->density /= ACONFIGURATION_DENSITY_MEDIUM; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1158 | |
| 1159 | info->secure = display->isSecure(); |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1160 | info->installOrientation = display->getPhysicalOrientation(); |
Vishnu Nair | d0a8965 | 2022-01-13 12:05:54 -0800 | [diff] [blame] | 1161 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1162 | return NO_ERROR; |
| 1163 | } |
| 1164 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1165 | void SurfaceFlinger::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo*& info, |
| 1166 | const sp<DisplayDevice>& display, |
| 1167 | const display::DisplaySnapshot& snapshot) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1168 | const auto& displayModes = snapshot.displayModes(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1169 | info->supportedDisplayModes.clear(); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1170 | info->supportedDisplayModes.reserve(displayModes.size()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1171 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1172 | for (const auto& [id, mode] : displayModes) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1173 | ui::DisplayMode outMode; |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1174 | outMode.id = ftl::to_underlying(id); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1175 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1176 | auto [width, height] = mode->getResolution(); |
| 1177 | auto [xDpi, yDpi] = mode->getDpi(); |
Yiwei Zhang | 27de5df | 2018-08-23 17:04:51 -0700 | [diff] [blame] | 1178 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1179 | if (const auto physicalOrientation = display->getPhysicalOrientation(); |
| 1180 | physicalOrientation == ui::ROTATION_90 || physicalOrientation == ui::ROTATION_270) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1181 | std::swap(width, height); |
| 1182 | std::swap(xDpi, yDpi); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1185 | outMode.resolution = ui::Size(width, height); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1186 | |
Huan Song | f7eeb10 | 2022-03-28 11:02:38 -0700 | [diff] [blame] | 1187 | outMode.xDpi = xDpi; |
| 1188 | outMode.yDpi = yDpi; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1189 | |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1190 | const auto peakFps = mode->getPeakFps(); |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 1191 | outMode.peakRefreshRate = peakFps.getValue(); |
Alec Mouri | d122a1c | 2023-09-30 01:36:33 +0000 | [diff] [blame] | 1192 | outMode.vsyncRate = mode->getVsyncRate().getValue(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1193 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1194 | const auto vsyncConfigSet = mScheduler->getVsyncConfiguration().getConfigsForRefreshRate( |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 1195 | Fps::fromValue(outMode.peakRefreshRate)); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1196 | outMode.appVsyncOffset = vsyncConfigSet.late.appOffset; |
| 1197 | outMode.sfVsyncOffset = vsyncConfigSet.late.sfOffset; |
| 1198 | outMode.group = mode->getGroup(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1199 | |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1200 | // This is how far in advance a buffer must be queued for |
| 1201 | // presentation at a given time. If you want a buffer to appear |
| 1202 | // on the screen at time N, you must submit the buffer before |
| 1203 | // (N - presentationDeadline). |
| 1204 | // |
| 1205 | // Normally it's one full refresh period (to give SF a chance to |
| 1206 | // latch the buffer), but this can be reduced by configuring a |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 1207 | // VsyncController offset. Any additional delays introduced by the hardware |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1208 | // composer or panel must be accounted for here. |
| 1209 | // |
| 1210 | // We add an additional 1ms to allow for processing time and |
| 1211 | // differences between the ideal and actual refresh rate. |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1212 | outMode.presentationDeadline = peakFps.getPeriodNsecs() - outMode.sfVsyncOffset + 1000000; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1213 | excludeDolbyVisionIf4k30Present(display->getHdrCapabilities().getSupportedHdrTypes(), |
| 1214 | outMode); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1215 | info->supportedDisplayModes.push_back(outMode); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 1216 | } |
| 1217 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1218 | info->supportedColorModes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1219 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1220 | const PhysicalDisplayId displayId = snapshot.displayId(); |
| 1221 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1222 | const auto mode = display->refreshRateSelector().getActiveMode(); |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1223 | info->activeDisplayModeId = ftl::to_underlying(mode.modePtr->getId()); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1224 | info->renderFrameRate = mode.fps.getValue(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1225 | info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1226 | info->hdrCapabilities = filterOut4k30(display->getHdrCapabilities()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1227 | |
Marin Shalamanov | b173f75 | 2021-02-16 19:38:36 +0100 | [diff] [blame] | 1228 | info->autoLowLatencyModeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1229 | getHwComposer().hasDisplayCapability(displayId, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1230 | DisplayCapability::AUTO_LOW_LATENCY_MODE); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1231 | info->gameContentTypeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1232 | getHwComposer().supportsContentType(displayId, hal::ContentType::GAME); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1233 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1234 | info->preferredBootDisplayMode = static_cast<ui::DisplayModeId>(-1); |
Kriti Dang | ac0a74d | 2022-03-16 11:52:35 +0100 | [diff] [blame] | 1235 | |
| 1236 | if (getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG)) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1237 | if (const auto hwcId = getHwComposer().getPreferredBootDisplayMode(displayId)) { |
| 1238 | if (const auto modeId = snapshot.translateModeId(*hwcId)) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1239 | info->preferredBootDisplayMode = ftl::to_underlying(*modeId); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1240 | } |
| 1241 | } |
| 1242 | } |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1243 | } |
Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame] | 1244 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1245 | status_t SurfaceFlinger::getDynamicDisplayInfoFromId(int64_t physicalDisplayId, |
| 1246 | ui::DynamicDisplayInfo* info) { |
| 1247 | if (!info) { |
| 1248 | return BAD_VALUE; |
| 1249 | } |
| 1250 | |
| 1251 | Mutex::Autolock lock(mStateLock); |
| 1252 | |
| 1253 | const auto id_ = |
| 1254 | DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(physicalDisplayId)); |
| 1255 | const auto displayOpt = mPhysicalDisplays.get(*id_).and_then(getDisplayDeviceAndSnapshot()); |
| 1256 | |
| 1257 | if (!displayOpt) { |
| 1258 | return NAME_NOT_FOUND; |
| 1259 | } |
| 1260 | |
| 1261 | const auto& [display, snapshotRef] = *displayOpt; |
| 1262 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
| 1263 | return NO_ERROR; |
| 1264 | } |
| 1265 | |
| 1266 | status_t SurfaceFlinger::getDynamicDisplayInfoFromToken(const sp<IBinder>& displayToken, |
| 1267 | ui::DynamicDisplayInfo* info) { |
| 1268 | if (!displayToken || !info) { |
| 1269 | return BAD_VALUE; |
| 1270 | } |
| 1271 | |
| 1272 | Mutex::Autolock lock(mStateLock); |
| 1273 | |
| 1274 | const auto displayOpt = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1275 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1276 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1277 | |
| 1278 | if (!displayOpt) { |
| 1279 | return NAME_NOT_FOUND; |
| 1280 | } |
| 1281 | |
| 1282 | const auto& [display, snapshotRef] = *displayOpt; |
| 1283 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1284 | return NO_ERROR; |
| 1285 | } |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 1286 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1287 | status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>& displayToken, |
| 1288 | DisplayStatInfo* outStats) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1289 | if (!outStats) { |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1290 | return BAD_VALUE; |
| 1291 | } |
| 1292 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1293 | std::optional<PhysicalDisplayId> displayIdOpt; |
| 1294 | { |
| 1295 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1296 | if (displayToken) { |
| 1297 | displayIdOpt = getPhysicalDisplayIdLocked(displayToken); |
| 1298 | if (!displayIdOpt) { |
| 1299 | ALOGW("%s: Invalid physical display token %p", __func__, displayToken.get()); |
| 1300 | return NAME_NOT_FOUND; |
| 1301 | } |
| 1302 | } else { |
| 1303 | // TODO (b/277364366): Clients should be updated to pass in the display they |
| 1304 | // want, rather than us picking an arbitrary one (the active display, in this |
| 1305 | // case). |
| 1306 | displayIdOpt = mActiveDisplayId; |
| 1307 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1308 | } |
| 1309 | |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1310 | const auto schedule = mScheduler->getVsyncSchedule(displayIdOpt); |
| 1311 | if (!schedule) { |
| 1312 | ALOGE("%s: Missing VSYNC schedule for display %s!", __func__, |
| 1313 | to_string(*displayIdOpt).c_str()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1314 | return NAME_NOT_FOUND; |
| 1315 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1316 | outStats->vsyncTime = schedule->vsyncDeadlineAfter(TimePoint::now()).ns(); |
| 1317 | outStats->vsyncPeriod = schedule->period().ns(); |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1318 | return NO_ERROR; |
| 1319 | } |
| 1320 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1321 | void SurfaceFlinger::setDesiredMode(display::DisplayModeRequest&& desiredMode) { |
| 1322 | const auto mode = desiredMode.mode; |
| 1323 | const auto displayId = mode.modePtr->getPhysicalDisplayId(); |
| 1324 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1325 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
| 1326 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1327 | const bool emitEvent = desiredMode.emitEvent; |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 1328 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1329 | using DesiredModeAction = display::DisplayModeController::DesiredModeAction; |
| 1330 | |
| 1331 | switch (mDisplayModeController.setDesiredMode(displayId, std::move(desiredMode))) { |
| 1332 | case DesiredModeAction::InitiateDisplayModeSwitch: { |
| 1333 | const auto selectorPtr = mDisplayModeController.selectorPtrFor(displayId); |
| 1334 | if (!selectorPtr) break; |
| 1335 | |
| 1336 | const Fps renderRate = selectorPtr->getActiveMode().fps; |
| 1337 | |
| 1338 | // DisplayModeController::setDesiredMode updated the render rate, so inform Scheduler. |
| 1339 | mScheduler->setRenderRate(displayId, renderRate, true /* applyImmediately */); |
Ady Abraham | 95a37e2 | 2023-01-18 22:57:28 -0800 | [diff] [blame] | 1340 | |
| 1341 | // Schedule a new frame to initiate the display mode switch. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1342 | scheduleComposite(FrameHint::kNone); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1343 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1344 | // Start receiving vsync samples now, so that we can detect a period |
| 1345 | // switch. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1346 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 1347 | mode.modePtr.get()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1348 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1349 | // As we called to set period, we will call to onRefreshRateChangeCompleted once |
| 1350 | // VsyncController model is locked. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1351 | mScheduler->modulateVsync(displayId, &VsyncModulator::onRefreshRateChangeInitiated); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1352 | |
| 1353 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1354 | mScheduler->updatePhaseConfiguration(mode.fps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1355 | } |
| 1356 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1357 | mScheduler->setModeChangePending(true); |
| 1358 | break; |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1359 | } |
| 1360 | case DesiredModeAction::InitiateRenderRateSwitch: |
Ady Abraham | ee6365b | 2024-03-06 14:31:45 -0800 | [diff] [blame] | 1361 | mScheduler->setRenderRate(displayId, mode.fps, /*applyImmediately*/ false); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1362 | |
| 1363 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1364 | mScheduler->updatePhaseConfiguration(mode.fps); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1365 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1366 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1367 | if (emitEvent) { |
| 1368 | dispatchDisplayModeChangeEvent(displayId, mode); |
| 1369 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1370 | break; |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1371 | case DesiredModeAction::None: |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1372 | break; |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1373 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1374 | } |
| 1375 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1376 | status_t SurfaceFlinger::setActiveModeFromBackdoor(const sp<display::DisplayToken>& displayToken, |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1377 | DisplayModeId modeId, Fps minFps, Fps maxFps) { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1378 | ATRACE_CALL(); |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1379 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 1380 | if (!displayToken) { |
| 1381 | return BAD_VALUE; |
| 1382 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1383 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1384 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1385 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1386 | const auto displayOpt = |
| 1387 | FTL_FAKE_GUARD(mStateLock, |
| 1388 | ftl::find_if(mPhysicalDisplays, |
| 1389 | PhysicalDisplay::hasToken(displayToken)) |
| 1390 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1391 | .and_then(getDisplayDeviceAndSnapshot())); |
| 1392 | if (!displayOpt) { |
| 1393 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1394 | return NAME_NOT_FOUND; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1395 | } |
| 1396 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1397 | const auto& [display, snapshotRef] = *displayOpt; |
| 1398 | const auto& snapshot = snapshotRef.get(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1399 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1400 | const auto fpsOpt = snapshot.displayModes().get(modeId).transform( |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1401 | [](const DisplayModePtr& mode) { return mode->getPeakFps(); }); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1402 | |
| 1403 | if (!fpsOpt) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1404 | ALOGE("%s: Invalid mode %d for display %s", whence, ftl::to_underlying(modeId), |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1405 | to_string(snapshot.displayId()).c_str()); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1406 | return BAD_VALUE; |
| 1407 | } |
| 1408 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1409 | const Fps fps = *fpsOpt; |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1410 | const FpsRange physical = {fps, fps}; |
| 1411 | const FpsRange render = {minFps.isValid() ? minFps : fps, maxFps.isValid() ? maxFps : fps}; |
| 1412 | const FpsRanges ranges = {physical, render}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1413 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1414 | // Keep the old switching type. |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1415 | const bool allowGroupSwitching = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1416 | display->refreshRateSelector().getCurrentPolicy().allowGroupSwitching; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1417 | |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1418 | const scheduler::RefreshRateSelector::DisplayManagerPolicy policy{modeId, ranges, ranges, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 1419 | allowGroupSwitching}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1420 | |
| 1421 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1422 | }); |
| 1423 | |
| 1424 | return future.get(); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1425 | } |
| 1426 | |
Dominik Laskowski | a515fd5 | 2024-07-15 08:24:49 -0400 | [diff] [blame] | 1427 | // TODO: b/241285876 - Restore thread safety analysis once mStateLock below is unconditional. |
| 1428 | [[clang::no_thread_safety_analysis]] |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1429 | void SurfaceFlinger::finalizeDisplayModeChange(PhysicalDisplayId displayId) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1430 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1431 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1432 | const auto pendingModeOpt = mDisplayModeController.getPendingMode(displayId); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1433 | if (!pendingModeOpt) { |
| 1434 | // There is no pending mode change. This can happen if the active |
| 1435 | // display changed and the mode change happened on a different display. |
| 1436 | return; |
| 1437 | } |
Ady Abraham | faac6da | 2021-07-15 10:04:40 -0700 | [diff] [blame] | 1438 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1439 | const auto& activeMode = pendingModeOpt->mode; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1440 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1441 | if (const auto oldResolution = |
| 1442 | mDisplayModeController.getActiveMode(displayId).modePtr->getResolution(); |
| 1443 | oldResolution != activeMode.modePtr->getResolution()) { |
Dominik Laskowski | a515fd5 | 2024-07-15 08:24:49 -0400 | [diff] [blame] | 1444 | ConditionalLock lock(mStateLock, !FlagManager::getInstance().connected_display()); |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1445 | |
| 1446 | auto& state = mCurrentState.displays.editValueFor(getPhysicalDisplayTokenLocked(displayId)); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1447 | // We need to generate new sequenceId in order to recreate the display (and this |
| 1448 | // way the framebuffer). |
| 1449 | state.sequenceId = DisplayDeviceState{}.sequenceId; |
| 1450 | state.physical->activeMode = activeMode.modePtr.get(); |
| 1451 | processDisplayChangesLocked(); |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1452 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1453 | // processDisplayChangesLocked will update all necessary components so we're done here. |
| 1454 | return; |
| 1455 | } |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 1456 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1457 | mDisplayModeController.finalizeModeChange(displayId, activeMode.modePtr->getId(), |
| 1458 | activeMode.modePtr->getVsyncRate(), activeMode.fps); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1459 | |
| 1460 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1461 | mScheduler->updatePhaseConfiguration(activeMode.fps); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | if (pendingModeOpt->emitEvent) { |
| 1465 | dispatchDisplayModeChangeEvent(displayId, activeMode); |
| 1466 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1467 | } |
| 1468 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1469 | void SurfaceFlinger::dropModeRequest(PhysicalDisplayId displayId) { |
| 1470 | mDisplayModeController.clearDesiredMode(displayId); |
| 1471 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1472 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1473 | mScheduler->setModeChangePending(false); |
| 1474 | } |
Ady Abraham | 53852a5 | 2019-05-28 18:07:44 -0700 | [diff] [blame] | 1475 | } |
| 1476 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1477 | void SurfaceFlinger::applyActiveMode(PhysicalDisplayId displayId) { |
| 1478 | const auto activeModeOpt = mDisplayModeController.getDesiredMode(displayId); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1479 | auto activeModePtr = activeModeOpt->mode.modePtr; |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1480 | const auto renderFps = activeModeOpt->mode.fps; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1481 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1482 | dropModeRequest(displayId); |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1483 | |
| 1484 | constexpr bool kAllowToEnable = true; |
| 1485 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, std::move(activeModePtr).take()); |
Ady Abraham | ee6365b | 2024-03-06 14:31:45 -0800 | [diff] [blame] | 1486 | mScheduler->setRenderRate(displayId, renderFps, /*applyImmediately*/ true); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1487 | |
| 1488 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1489 | mScheduler->updatePhaseConfiguration(renderFps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1490 | } |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1491 | } |
| 1492 | |
Ady Abraham | 0b10360 | 2024-05-21 20:37:49 +0000 | [diff] [blame] | 1493 | void SurfaceFlinger::initiateDisplayModeChanges() { |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1494 | ATRACE_CALL(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1495 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1496 | std::optional<PhysicalDisplayId> displayToUpdateImmediately; |
| 1497 | |
Dominik Laskowski | a515fd5 | 2024-07-15 08:24:49 -0400 | [diff] [blame] | 1498 | for (const auto& [displayId, physical] : mPhysicalDisplays) { |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1499 | auto desiredModeOpt = mDisplayModeController.getDesiredMode(displayId); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1500 | if (!desiredModeOpt) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1501 | continue; |
| 1502 | } |
| 1503 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1504 | const auto desiredModeId = desiredModeOpt->mode.modePtr->getId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1505 | const auto displayModePtrOpt = physical.snapshot().displayModes().get(desiredModeId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1506 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1507 | if (!displayModePtrOpt) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1508 | ALOGW("Desired display mode is no longer supported. Mode ID = %d", |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1509 | ftl::to_underlying(desiredModeId)); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1510 | continue; |
| 1511 | } |
| 1512 | |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1513 | ALOGV("%s changing active mode to %d(%s) for display %s", __func__, |
| 1514 | ftl::to_underlying(desiredModeId), |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1515 | to_string(displayModePtrOpt->get()->getVsyncRate()).c_str(), |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1516 | to_string(displayId).c_str()); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1517 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1518 | if ((!FlagManager::getInstance().connected_display() || !desiredModeOpt->force) && |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1519 | mDisplayModeController.getActiveMode(displayId) == desiredModeOpt->mode) { |
| 1520 | applyActiveMode(displayId); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1521 | continue; |
| 1522 | } |
| 1523 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1524 | const auto selectorPtr = mDisplayModeController.selectorPtrFor(displayId); |
| 1525 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1526 | // Desired active mode was set, it is different than the mode currently in use, however |
| 1527 | // allowed modes might have changed by the time we process the refresh. |
| 1528 | // Make sure the desired mode is still allowed |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1529 | if (!selectorPtr->isModeAllowed(desiredModeOpt->mode)) { |
| 1530 | dropModeRequest(displayId); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1531 | continue; |
| 1532 | } |
| 1533 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1534 | // TODO(b/142753666) use constrains |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1535 | hal::VsyncPeriodChangeConstraints constraints; |
| 1536 | constraints.desiredTimeNanos = systemTime(); |
| 1537 | constraints.seamlessRequired = false; |
| 1538 | hal::VsyncPeriodChangeTimeline outTimeline; |
| 1539 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1540 | if (!mDisplayModeController.initiateModeChange(displayId, std::move(*desiredModeOpt), |
| 1541 | constraints, outTimeline)) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1542 | continue; |
| 1543 | } |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1544 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1545 | selectorPtr->onModeChangeInitiated(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1546 | mScheduler->onNewVsyncPeriodChangeTimeline(outTimeline); |
| 1547 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1548 | if (outTimeline.refreshRequired) { |
Ady Abraham | 0b10360 | 2024-05-21 20:37:49 +0000 | [diff] [blame] | 1549 | scheduleComposite(FrameHint::kNone); |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1550 | } else { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1551 | // TODO(b/255635711): Remove `displayToUpdateImmediately` to `finalizeDisplayModeChange` |
| 1552 | // for all displays. This was only needed when the loop iterated over `mDisplays` rather |
| 1553 | // than `mPhysicalDisplays`. |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1554 | displayToUpdateImmediately = displayId; |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | if (displayToUpdateImmediately) { |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1559 | const auto displayId = *displayToUpdateImmediately; |
| 1560 | finalizeDisplayModeChange(displayId); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1561 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1562 | const auto desiredModeOpt = mDisplayModeController.getDesiredMode(displayId); |
| 1563 | if (desiredModeOpt && |
| 1564 | mDisplayModeController.getActiveMode(displayId) == desiredModeOpt->mode) { |
| 1565 | applyActiveMode(displayId); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1566 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1567 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1568 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1569 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1570 | void SurfaceFlinger::disableExpensiveRendering() { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1571 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1572 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1573 | ATRACE_NAME(whence); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1574 | if (mPowerAdvisor->isUsingExpensiveRendering()) { |
Dominik Laskowski | bc6c860 | 2022-01-11 08:53:24 -0800 | [diff] [blame] | 1575 | for (const auto& [_, display] : mDisplays) { |
| 1576 | constexpr bool kDisable = false; |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1577 | mPowerAdvisor->setExpensiveRenderingExpected(display->getId(), kDisable); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1578 | } |
| 1579 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1580 | }); |
| 1581 | |
| 1582 | future.wait(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1585 | status_t SurfaceFlinger::getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1586 | ui::DisplayPrimaries& primaries) { |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1587 | if (!displayToken) { |
| 1588 | return BAD_VALUE; |
| 1589 | } |
| 1590 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1591 | Mutex::Autolock lock(mStateLock); |
| 1592 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1593 | const auto display = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1594 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>); |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1595 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1596 | return NAME_NOT_FOUND; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1597 | } |
| 1598 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1599 | if (!display.transform(&PhysicalDisplay::isInternal).value()) { |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1600 | return INVALID_OPERATION; |
| 1601 | } |
| 1602 | |
| 1603 | // 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] | 1604 | primaries = mInternalDisplayPrimaries; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1605 | return NO_ERROR; |
| 1606 | } |
| 1607 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1608 | status_t SurfaceFlinger::setActiveColorMode(const sp<IBinder>& displayToken, ui::ColorMode mode) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1609 | if (!displayToken) { |
| 1610 | return BAD_VALUE; |
| 1611 | } |
| 1612 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1613 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1614 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1615 | const auto displayOpt = |
| 1616 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1617 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1618 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1619 | |
| 1620 | if (!displayOpt) { |
| 1621 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1622 | return NAME_NOT_FOUND; |
| 1623 | } |
| 1624 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1625 | const auto& [display, snapshotRef] = *displayOpt; |
| 1626 | const auto& snapshot = snapshotRef.get(); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1627 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1628 | const auto modes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1629 | const bool exists = std::find(modes.begin(), modes.end(), mode) != modes.end(); |
| 1630 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1631 | if (mode < ui::ColorMode::NATIVE || !exists) { |
| 1632 | ALOGE("%s: Invalid color mode %s (%d) for display %s", whence, |
| 1633 | decodeColorMode(mode).c_str(), mode, to_string(snapshot.displayId()).c_str()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1634 | return BAD_VALUE; |
| 1635 | } |
| 1636 | |
| 1637 | display->getCompositionDisplay()->setColorProfile( |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 1638 | {mode, Dataspace::UNKNOWN, RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1639 | |
| 1640 | return NO_ERROR; |
| 1641 | }); |
| 1642 | |
Dominik Laskowski | 0a5f921 | 2021-08-05 17:00:04 -0700 | [diff] [blame] | 1643 | // TODO(b/195698395): Propagate error. |
| 1644 | future.wait(); |
| 1645 | return NO_ERROR; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1646 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1647 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1648 | status_t SurfaceFlinger::getBootDisplayModeSupport(bool* outSupport) const { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1649 | auto future = mScheduler->schedule( |
| 1650 | [this] { return getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG); }); |
| 1651 | |
| 1652 | *outSupport = future.get(); |
| 1653 | return NO_ERROR; |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1654 | } |
| 1655 | |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1656 | status_t SurfaceFlinger::getOverlaySupport(gui::OverlayProperties* outProperties) const { |
| 1657 | const auto& aidlProperties = getHwComposer().getOverlaySupport(); |
| 1658 | // convert aidl OverlayProperties to gui::OverlayProperties |
| 1659 | outProperties->combinations.reserve(aidlProperties.combinations.size()); |
| 1660 | for (const auto& combination : aidlProperties.combinations) { |
| 1661 | std::vector<int32_t> pixelFormats; |
| 1662 | pixelFormats.reserve(combination.pixelFormats.size()); |
| 1663 | std::transform(combination.pixelFormats.cbegin(), combination.pixelFormats.cend(), |
| 1664 | std::back_inserter(pixelFormats), |
| 1665 | [](const auto& val) { return static_cast<int32_t>(val); }); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1666 | std::vector<int32_t> standards; |
| 1667 | standards.reserve(combination.standards.size()); |
| 1668 | std::transform(combination.standards.cbegin(), combination.standards.cend(), |
| 1669 | std::back_inserter(standards), |
| 1670 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1671 | std::vector<int32_t> transfers; |
| 1672 | transfers.reserve(combination.transfers.size()); |
| 1673 | std::transform(combination.transfers.cbegin(), combination.transfers.cend(), |
| 1674 | std::back_inserter(transfers), |
| 1675 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1676 | std::vector<int32_t> ranges; |
| 1677 | ranges.reserve(combination.ranges.size()); |
| 1678 | std::transform(combination.ranges.cbegin(), combination.ranges.cend(), |
| 1679 | std::back_inserter(ranges), |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1680 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1681 | gui::OverlayProperties::SupportedBufferCombinations outCombination; |
| 1682 | outCombination.pixelFormats = std::move(pixelFormats); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1683 | outCombination.standards = std::move(standards); |
| 1684 | outCombination.transfers = std::move(transfers); |
| 1685 | outCombination.ranges = std::move(ranges); |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1686 | outProperties->combinations.emplace_back(outCombination); |
| 1687 | } |
Sally Qi | 8b4cb55 | 2022-12-14 16:24:31 -0800 | [diff] [blame] | 1688 | outProperties->supportMixedColorSpaces = aidlProperties.supportMixedColorSpaces; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 1689 | return NO_ERROR; |
| 1690 | } |
| 1691 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1692 | status_t SurfaceFlinger::setBootDisplayMode(const sp<display::DisplayToken>& displayToken, |
| 1693 | DisplayModeId modeId) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1694 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1695 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1696 | const auto snapshotOpt = |
| 1697 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1698 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1699 | .transform(&PhysicalDisplay::snapshotRef); |
| 1700 | |
| 1701 | if (!snapshotOpt) { |
| 1702 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1703 | return NAME_NOT_FOUND; |
| 1704 | } |
Kriti Dang | f50d677 | 2022-02-18 15:09:12 +0100 | [diff] [blame] | 1705 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1706 | const auto& snapshot = snapshotOpt->get(); |
| 1707 | const auto hwcIdOpt = snapshot.displayModes().get(modeId).transform( |
| 1708 | [](const DisplayModePtr& mode) { return mode->getHwcId(); }); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1709 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1710 | if (!hwcIdOpt) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1711 | ALOGE("%s: Invalid mode %d for display %s", whence, ftl::to_underlying(modeId), |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1712 | to_string(snapshot.displayId()).c_str()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1713 | return BAD_VALUE; |
| 1714 | } |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1715 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1716 | return getHwComposer().setBootDisplayMode(snapshot.displayId(), *hwcIdOpt); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1717 | }); |
| 1718 | return future.get(); |
| 1719 | } |
| 1720 | |
| 1721 | status_t SurfaceFlinger::clearBootDisplayMode(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1722 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1723 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1724 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1725 | return getHwComposer().clearBootDisplayMode(*displayId); |
| 1726 | } else { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1727 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1728 | return BAD_VALUE; |
| 1729 | } |
| 1730 | }); |
| 1731 | return future.get(); |
| 1732 | } |
| 1733 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1734 | status_t SurfaceFlinger::getHdrConversionCapabilities( |
| 1735 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) const { |
| 1736 | bool hdrOutputConversionSupport; |
| 1737 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1738 | if (hdrOutputConversionSupport == false) { |
| 1739 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1740 | return INVALID_OPERATION; |
| 1741 | } |
| 1742 | const auto aidlConversionCapability = getHwComposer().getHdrConversionCapabilities(); |
| 1743 | for (auto capability : aidlConversionCapability) { |
| 1744 | gui::HdrConversionCapability tempCapability; |
Kriti Dang | 3c243dc | 2023-03-07 15:00:13 +0100 | [diff] [blame] | 1745 | tempCapability.sourceType = static_cast<int>(capability.sourceType); |
| 1746 | tempCapability.outputType = static_cast<int>(capability.outputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1747 | tempCapability.addsLatency = capability.addsLatency; |
| 1748 | hdrConversionCapabilities->push_back(tempCapability); |
| 1749 | } |
| 1750 | return NO_ERROR; |
| 1751 | } |
| 1752 | |
| 1753 | status_t SurfaceFlinger::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1754 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 1755 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1756 | bool hdrOutputConversionSupport; |
| 1757 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1758 | if (hdrOutputConversionSupport == false) { |
| 1759 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1760 | return INVALID_OPERATION; |
| 1761 | } |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1762 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) mutable -> status_t { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1763 | using AidlHdrConversionStrategy = |
| 1764 | aidl::android::hardware::graphics::common::HdrConversionStrategy; |
| 1765 | using GuiHdrConversionStrategyTag = gui::HdrConversionStrategy::Tag; |
| 1766 | AidlHdrConversionStrategy aidlConversionStrategy; |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1767 | status_t status; |
| 1768 | aidl::android::hardware::graphics::common::Hdr aidlPreferredHdrOutputType; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1769 | switch (hdrConversionStrategy.getTag()) { |
| 1770 | case GuiHdrConversionStrategyTag::passthrough: { |
| 1771 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::passthrough>( |
| 1772 | hdrConversionStrategy.get<GuiHdrConversionStrategyTag::passthrough>()); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1773 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1774 | &aidlPreferredHdrOutputType); |
| 1775 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1776 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1777 | } |
| 1778 | case GuiHdrConversionStrategyTag::autoAllowedHdrTypes: { |
| 1779 | auto autoHdrTypes = |
| 1780 | hdrConversionStrategy |
| 1781 | .get<GuiHdrConversionStrategyTag::autoAllowedHdrTypes>(); |
| 1782 | std::vector<aidl::android::hardware::graphics::common::Hdr> aidlAutoHdrTypes; |
| 1783 | for (auto type : autoHdrTypes) { |
| 1784 | aidlAutoHdrTypes.push_back( |
| 1785 | static_cast<aidl::android::hardware::graphics::common::Hdr>(type)); |
| 1786 | } |
| 1787 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::autoAllowedHdrTypes>( |
| 1788 | aidlAutoHdrTypes); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1789 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1790 | &aidlPreferredHdrOutputType); |
| 1791 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1792 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1793 | } |
| 1794 | case GuiHdrConversionStrategyTag::forceHdrConversion: { |
| 1795 | auto forceHdrConversion = |
| 1796 | hdrConversionStrategy |
| 1797 | .get<GuiHdrConversionStrategyTag::forceHdrConversion>(); |
| 1798 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::forceHdrConversion>( |
| 1799 | static_cast<aidl::android::hardware::graphics::common::Hdr>( |
| 1800 | forceHdrConversion)); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1801 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1802 | &aidlPreferredHdrOutputType); |
| 1803 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1804 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1805 | } |
| 1806 | } |
| 1807 | }); |
| 1808 | return future.get(); |
| 1809 | } |
| 1810 | |
| 1811 | status_t SurfaceFlinger::getHdrOutputConversionSupport(bool* outSupport) const { |
| 1812 | auto future = mScheduler->schedule([this] { |
| 1813 | return getHwComposer().hasCapability(Capability::HDR_OUTPUT_CONVERSION_CONFIG); |
| 1814 | }); |
| 1815 | |
| 1816 | *outSupport = future.get(); |
| 1817 | return NO_ERROR; |
| 1818 | } |
| 1819 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1820 | void SurfaceFlinger::setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1821 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1822 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1823 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1824 | getHwComposer().setAutoLowLatencyMode(*displayId, on); |
| 1825 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1826 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1827 | } |
| 1828 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1829 | } |
| 1830 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1831 | void SurfaceFlinger::setGameContentType(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1832 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1833 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1834 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1835 | const auto type = on ? hal::ContentType::GAME : hal::ContentType::NONE; |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1836 | getHwComposer().setContentType(*displayId, type); |
| 1837 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1838 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1839 | } |
| 1840 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1841 | } |
| 1842 | |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1843 | status_t SurfaceFlinger::overrideHdrTypes(const sp<IBinder>& displayToken, |
| 1844 | const std::vector<ui::Hdr>& hdrTypes) { |
| 1845 | Mutex::Autolock lock(mStateLock); |
| 1846 | |
| 1847 | auto display = getDisplayDeviceLocked(displayToken); |
| 1848 | if (!display) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1849 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1850 | return NAME_NOT_FOUND; |
| 1851 | } |
| 1852 | |
| 1853 | display->overrideHdrTypes(hdrTypes); |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 1854 | mScheduler->dispatchHotplug(display->getPhysicalId(), scheduler::Scheduler::Hotplug::Connected); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1855 | return NO_ERROR; |
| 1856 | } |
| 1857 | |
Huihong Luo | 30aa437 | 2022-10-03 14:54:12 -0700 | [diff] [blame] | 1858 | status_t SurfaceFlinger::onPullAtom(const int32_t atomId, std::vector<uint8_t>* pulledData, |
| 1859 | bool* success) { |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 1860 | *success = mTimeStats->onPullAtom(atomId, pulledData); |
| 1861 | return NO_ERROR; |
| 1862 | } |
| 1863 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1864 | status_t SurfaceFlinger::getDisplayedContentSamplingAttributes(const sp<IBinder>& displayToken, |
| 1865 | ui::PixelFormat* outFormat, |
| 1866 | ui::Dataspace* outDataspace, |
| 1867 | uint8_t* outComponentMask) const { |
| 1868 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 1869 | return BAD_VALUE; |
| 1870 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1871 | |
| 1872 | Mutex::Autolock lock(mStateLock); |
| 1873 | |
| 1874 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1875 | if (!displayId) { |
| 1876 | return NAME_NOT_FOUND; |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1877 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1878 | |
| 1879 | return getHwComposer().getDisplayedContentSamplingAttributes(*displayId, outFormat, |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1880 | outDataspace, outComponentMask); |
| 1881 | } |
| 1882 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1883 | status_t SurfaceFlinger::setDisplayContentSamplingEnabled(const sp<IBinder>& displayToken, |
| 1884 | bool enable, uint8_t componentMask, |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1885 | uint64_t maxFrames) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1886 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1887 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1888 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1889 | return getHwComposer().setDisplayContentSamplingEnabled(*displayId, enable, |
| 1890 | componentMask, maxFrames); |
| 1891 | } else { |
| 1892 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
| 1893 | return NAME_NOT_FOUND; |
| 1894 | } |
| 1895 | }); |
| 1896 | |
| 1897 | return future.get(); |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1898 | } |
| 1899 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1900 | status_t SurfaceFlinger::getDisplayedContentSample(const sp<IBinder>& displayToken, |
| 1901 | uint64_t maxFrames, uint64_t timestamp, |
| 1902 | DisplayedFrameStats* outStats) const { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1903 | Mutex::Autolock lock(mStateLock); |
| 1904 | |
| 1905 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1906 | if (!displayId) { |
| 1907 | return NAME_NOT_FOUND; |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1908 | } |
| 1909 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1910 | return getHwComposer().getDisplayedContentSample(*displayId, maxFrames, timestamp, outStats); |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
Peiyong Lin | 3c2791e | 2019-01-14 17:05:18 -0800 | [diff] [blame] | 1913 | status_t SurfaceFlinger::getProtectedContentSupport(bool* outSupported) const { |
| 1914 | if (!outSupported) { |
| 1915 | return BAD_VALUE; |
| 1916 | } |
| 1917 | *outSupported = getRenderEngine().supportsProtectedContent(); |
| 1918 | return NO_ERROR; |
| 1919 | } |
| 1920 | |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1921 | status_t SurfaceFlinger::isWideColorDisplay(const sp<IBinder>& displayToken, |
| 1922 | bool* outIsWideColorDisplay) const { |
| 1923 | if (!displayToken || !outIsWideColorDisplay) { |
| 1924 | return BAD_VALUE; |
| 1925 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1926 | |
| 1927 | Mutex::Autolock lock(mStateLock); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1928 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1929 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1930 | return NAME_NOT_FOUND; |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1931 | } |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 1932 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1933 | *outIsWideColorDisplay = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1934 | display->isPrimary() ? mSupportsWideColor : display->hasWideColorGamut(); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1935 | return NO_ERROR; |
| 1936 | } |
| 1937 | |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1938 | status_t SurfaceFlinger::getCompositionPreference( |
| 1939 | Dataspace* outDataspace, ui::PixelFormat* outPixelFormat, |
| 1940 | Dataspace* outWideColorGamutDataspace, |
| 1941 | ui::PixelFormat* outWideColorGamutPixelFormat) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1942 | *outDataspace = mDefaultCompositionDataspace; |
| 1943 | *outPixelFormat = defaultCompositionPixelFormat; |
| 1944 | *outWideColorGamutDataspace = mWideColorGamutCompositionDataspace; |
| 1945 | *outWideColorGamutPixelFormat = wideColorGamutCompositionPixelFormat; |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 1946 | return NO_ERROR; |
| 1947 | } |
| 1948 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1949 | status_t SurfaceFlinger::addRegionSamplingListener(const Rect& samplingArea, |
| 1950 | const sp<IBinder>& stopLayerHandle, |
| 1951 | const sp<IRegionSamplingListener>& listener) { |
Leon Scroggins III | ae16b80 | 2022-01-12 11:42:05 -0500 | [diff] [blame] | 1952 | if (!listener || samplingArea == Rect::INVALID_RECT || samplingArea.isEmpty()) { |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1953 | return BAD_VALUE; |
| 1954 | } |
Alec Mouri | 9a02eda | 2020-04-21 17:39:34 -0700 | [diff] [blame] | 1955 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 1956 | // LayerHandle::getLayer promotes the layer object in a binder thread but we will not destroy |
| 1957 | // 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] | 1958 | const sp<Layer> stopLayer = LayerHandle::getLayer(stopLayerHandle); |
| 1959 | mRegionSamplingThread->addListener(samplingArea, |
| 1960 | stopLayer ? stopLayer->getSequence() : UNASSIGNED_LAYER_ID, |
| 1961 | listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1962 | return NO_ERROR; |
| 1963 | } |
| 1964 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1965 | status_t SurfaceFlinger::removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) { |
tangrobin | af45f01 | 2019-02-26 18:10:10 +0800 | [diff] [blame] | 1966 | if (!listener) { |
| 1967 | return BAD_VALUE; |
| 1968 | } |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1969 | mRegionSamplingThread->removeListener(listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1970 | return NO_ERROR; |
| 1971 | } |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1972 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1973 | status_t SurfaceFlinger::addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) { |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1974 | if (!listener) { |
| 1975 | return BAD_VALUE; |
| 1976 | } |
| 1977 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1978 | mFpsReporter->addListener(listener, taskId); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1979 | return NO_ERROR; |
| 1980 | } |
| 1981 | |
| 1982 | status_t SurfaceFlinger::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 1983 | if (!listener) { |
| 1984 | return BAD_VALUE; |
| 1985 | } |
| 1986 | mFpsReporter->removeListener(listener); |
| 1987 | return NO_ERROR; |
| 1988 | } |
| 1989 | |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 1990 | status_t SurfaceFlinger::addTunnelModeEnabledListener( |
| 1991 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1992 | if (!listener) { |
| 1993 | return BAD_VALUE; |
| 1994 | } |
| 1995 | |
| 1996 | mTunnelModeEnabledReporter->addListener(listener); |
| 1997 | return NO_ERROR; |
| 1998 | } |
| 1999 | |
| 2000 | status_t SurfaceFlinger::removeTunnelModeEnabledListener( |
| 2001 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 2002 | if (!listener) { |
| 2003 | return BAD_VALUE; |
| 2004 | } |
| 2005 | |
| 2006 | mTunnelModeEnabledReporter->removeListener(listener); |
| 2007 | return NO_ERROR; |
| 2008 | } |
| 2009 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2010 | status_t SurfaceFlinger::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 2011 | bool* outSupport) const { |
| 2012 | if (!displayToken || !outSupport) { |
| 2013 | return BAD_VALUE; |
| 2014 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 2015 | |
| 2016 | Mutex::Autolock lock(mStateLock); |
| 2017 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2018 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 2019 | if (!displayId) { |
| 2020 | return NAME_NOT_FOUND; |
| 2021 | } |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 2022 | *outSupport = getHwComposer().hasDisplayCapability(*displayId, DisplayCapability::BRIGHTNESS); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2023 | return NO_ERROR; |
| 2024 | } |
| 2025 | |
John Reck | 22be696 | 2021-03-10 12:59:54 -0500 | [diff] [blame] | 2026 | status_t SurfaceFlinger::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 2027 | const gui::DisplayBrightness& brightness) { |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2028 | if (!displayToken) { |
| 2029 | return BAD_VALUE; |
| 2030 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 2031 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2032 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 2033 | return ftl::Future(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 2034 | // TODO(b/241285876): Validate that the display is physical instead of failing later. |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 2035 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2036 | const bool supportsDisplayBrightnessCommand = |
| 2037 | getHwComposer().getComposer()->isSupported( |
| 2038 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 2039 | // If we support applying display brightness as a command, then we also support |
| 2040 | // dimming SDR layers. |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 2041 | if (supportsDisplayBrightnessCommand) { |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 2042 | auto compositionDisplay = display->getCompositionDisplay(); |
| 2043 | float currentDimmingRatio = |
| 2044 | compositionDisplay->editState().sdrWhitePointNits / |
| 2045 | compositionDisplay->editState().displayBrightnessNits; |
Sally Qi | 0ea47b5 | 2023-06-22 13:27:20 -0700 | [diff] [blame] | 2046 | static constexpr float kDimmingThreshold = 0.02f; |
| 2047 | if (brightness.sdrWhitePointNits == 0.f || |
| 2048 | abs(brightness.sdrWhitePointNits - brightness.displayBrightnessNits) / |
| 2049 | brightness.sdrWhitePointNits >= |
| 2050 | kDimmingThreshold) { |
| 2051 | // to optimize, skip brightness setter if the brightness difference ratio |
| 2052 | // is lower than threshold |
| 2053 | compositionDisplay |
| 2054 | ->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 2055 | brightness.displayBrightnessNits); |
| 2056 | } else { |
| 2057 | compositionDisplay->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 2058 | brightness.sdrWhitePointNits); |
| 2059 | } |
| 2060 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2061 | FTL_FAKE_GUARD(kMainThreadContext, |
| 2062 | display->stageBrightness(brightness.displayBrightness)); |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2063 | float currentHdrSdrRatio = |
| 2064 | compositionDisplay->editState().displayBrightnessNits / |
| 2065 | compositionDisplay->editState().sdrWhitePointNits; |
| 2066 | FTL_FAKE_GUARD(kMainThreadContext, |
| 2067 | display->updateHdrSdrRatioOverlayRatio(currentHdrSdrRatio)); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2068 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 2069 | if (brightness.sdrWhitePointNits / brightness.displayBrightnessNits != |
| 2070 | currentDimmingRatio) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2071 | scheduleComposite(FrameHint::kNone); |
| 2072 | } else { |
| 2073 | scheduleCommit(FrameHint::kNone); |
| 2074 | } |
| 2075 | return ftl::yield<status_t>(OK); |
| 2076 | } else { |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 2077 | return getHwComposer() |
| 2078 | .setDisplayBrightness(display->getPhysicalId(), |
| 2079 | brightness.displayBrightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 2080 | brightness.displayBrightnessNits, |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 2081 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 2082 | .applyImmediately = true}); |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 2083 | } |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2084 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2085 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 2086 | return ftl::yield<status_t>(NAME_NOT_FOUND); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2087 | } |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 2088 | })) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 2089 | .then([](ftl::Future<status_t> task) { return task; }) |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2090 | .get(); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2091 | } |
| 2092 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2093 | status_t SurfaceFlinger::addHdrLayerInfoListener(const sp<IBinder>& displayToken, |
| 2094 | const sp<gui::IHdrLayerInfoListener>& listener) { |
| 2095 | if (!displayToken) { |
| 2096 | return BAD_VALUE; |
| 2097 | } |
| 2098 | |
| 2099 | Mutex::Autolock lock(mStateLock); |
| 2100 | |
| 2101 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2102 | if (!display) { |
| 2103 | return NAME_NOT_FOUND; |
| 2104 | } |
| 2105 | const auto displayId = display->getId(); |
| 2106 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2107 | if (!hdrInfoReporter) { |
| 2108 | hdrInfoReporter = sp<HdrLayerInfoReporter>::make(); |
| 2109 | } |
| 2110 | hdrInfoReporter->addListener(listener); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2111 | |
| 2112 | |
| 2113 | mAddingHDRLayerInfoListener = true; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2114 | return OK; |
| 2115 | } |
| 2116 | |
| 2117 | status_t SurfaceFlinger::removeHdrLayerInfoListener( |
| 2118 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 2119 | if (!displayToken) { |
| 2120 | return BAD_VALUE; |
| 2121 | } |
| 2122 | |
| 2123 | Mutex::Autolock lock(mStateLock); |
| 2124 | |
| 2125 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2126 | if (!display) { |
| 2127 | return NAME_NOT_FOUND; |
| 2128 | } |
| 2129 | const auto displayId = display->getId(); |
| 2130 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2131 | if (hdrInfoReporter) { |
| 2132 | hdrInfoReporter->removeListener(listener); |
| 2133 | } |
| 2134 | return OK; |
| 2135 | } |
| 2136 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2137 | status_t SurfaceFlinger::notifyPowerBoost(int32_t boostId) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 2138 | using aidl::android::hardware::power::Boost; |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2139 | Boost powerBoost = static_cast<Boost>(boostId); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2140 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2141 | if (powerBoost == Boost::INTERACTION) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2142 | mScheduler->onTouchHint(); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | return NO_ERROR; |
| 2146 | } |
| 2147 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2148 | status_t SurfaceFlinger::getDisplayDecorationSupport( |
| 2149 | const sp<IBinder>& displayToken, |
| 2150 | std::optional<DisplayDecorationSupport>* outSupport) const { |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2151 | if (!displayToken || !outSupport) { |
| 2152 | return BAD_VALUE; |
| 2153 | } |
| 2154 | |
| 2155 | Mutex::Autolock lock(mStateLock); |
| 2156 | |
| 2157 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 2158 | if (!displayId) { |
| 2159 | return NAME_NOT_FOUND; |
| 2160 | } |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2161 | getHwComposer().getDisplayDecorationSupport(*displayId, outSupport); |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2162 | return NO_ERROR; |
| 2163 | } |
| 2164 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 2165 | // ---------------------------------------------------------------------------- |
| 2166 | |
Jorim Jaggi | b1e2f8d | 2017-06-08 15:43:59 -0700 | [diff] [blame] | 2167 | sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection( |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 2168 | gui::ISurfaceComposer::VsyncSource vsyncSource, EventRegistrationFlags eventRegistration, |
| 2169 | const sp<IBinder>& layerHandle) { |
Ady Abraham | b334758 | 2024-04-03 01:01:51 +0000 | [diff] [blame] | 2170 | const auto cycle = [&] { |
| 2171 | if (FlagManager::getInstance().deprecate_vsync_sf()) { |
| 2172 | ALOGW_IF(vsyncSource == gui::ISurfaceComposer::VsyncSource::eVsyncSourceSurfaceFlinger, |
| 2173 | "requested unsupported config eVsyncSourceSurfaceFlinger"); |
| 2174 | return scheduler::Cycle::Render; |
| 2175 | } |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 2176 | |
Ady Abraham | b334758 | 2024-04-03 01:01:51 +0000 | [diff] [blame] | 2177 | return vsyncSource == gui::ISurfaceComposer::VsyncSource::eVsyncSourceSurfaceFlinger |
| 2178 | ? scheduler::Cycle::LastComposite |
| 2179 | : scheduler::Cycle::Render; |
| 2180 | }(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 2181 | return mScheduler->createDisplayEventConnection(cycle, eventRegistration, layerHandle); |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 2182 | } |
| 2183 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2184 | void SurfaceFlinger::scheduleCommit(FrameHint hint) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2185 | if (hint == FrameHint::kActive) { |
| 2186 | mScheduler->resetIdleTimer(); |
| 2187 | } |
Matt Buckley | 15ecd1c | 2022-11-01 21:57:16 +0000 | [diff] [blame] | 2188 | mPowerAdvisor->notifyDisplayUpdateImminentAndCpuReset(); |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 2189 | mScheduler->scheduleFrame(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2190 | } |
| 2191 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2192 | void SurfaceFlinger::scheduleComposite(FrameHint hint) { |
| 2193 | mMustComposite = true; |
| 2194 | scheduleCommit(hint); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | void SurfaceFlinger::scheduleRepaint() { |
| 2198 | mGeometryDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2199 | scheduleComposite(FrameHint::kActive); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2200 | } |
| 2201 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2202 | void SurfaceFlinger::scheduleSample() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2203 | static_cast<void>(mScheduler->schedule([this] { sample(); })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2204 | } |
| 2205 | |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 2206 | nsecs_t SurfaceFlinger::getVsyncPeriodFromHWC() const { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2207 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
| 2208 | return display->getVsyncPeriodFromHWC(); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2209 | } |
| 2210 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2211 | return 0; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2212 | } |
| 2213 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2214 | void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp, |
| 2215 | std::optional<hal::VsyncPeriodNanos> vsyncPeriod) { |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2216 | if (FlagManager::getInstance().connected_display() && timestamp < 0 && |
| 2217 | vsyncPeriod.has_value()) { |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2218 | // use ~0 instead of -1 as AidlComposerHal.cpp passes the param as unsigned int32 |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2219 | if (mIsHotplugErrViaNegVsync && vsyncPeriod.value() == ~0) { |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2220 | const auto errorCode = static_cast<int32_t>(-timestamp); |
| 2221 | ALOGD("%s: Hotplug error %d for display %" PRIu64, __func__, errorCode, hwcDisplayId); |
| 2222 | mScheduler->dispatchHotplugError(errorCode); |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2223 | return; |
| 2224 | } |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2225 | |
| 2226 | if (mIsHdcpViaNegVsync && vsyncPeriod.value() == ~1) { |
| 2227 | const int32_t value = static_cast<int32_t>(-timestamp); |
| 2228 | // one byte is good enough to encode android.hardware.drm.HdcpLevel |
| 2229 | const int32_t maxLevel = (value >> 8) & 0xFF; |
| 2230 | const int32_t connectedLevel = value & 0xFF; |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2231 | ALOGD("%s: HDCP levels changed (connected=%d, max=%d) for display %" PRIu64, __func__, |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2232 | connectedLevel, maxLevel, hwcDisplayId); |
| 2233 | updateHdcpLevels(hwcDisplayId, connectedLevel, maxLevel); |
| 2234 | return; |
| 2235 | } |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2236 | } |
| 2237 | |
Dominik Laskowski | 3d48304 | 2023-02-22 17:58:56 -0500 | [diff] [blame] | 2238 | ATRACE_NAME(vsyncPeriod |
| 2239 | ? ftl::Concat(__func__, ' ', hwcDisplayId, ' ', *vsyncPeriod, "ns").c_str() |
| 2240 | : ftl::Concat(__func__, ' ', hwcDisplayId).c_str()); |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 2241 | |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2242 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2243 | if (const auto displayIdOpt = getHwComposer().onVsync(hwcDisplayId, timestamp)) { |
| 2244 | if (mScheduler->addResyncSample(*displayIdOpt, timestamp, vsyncPeriod)) { |
| 2245 | // period flushed |
| 2246 | mScheduler->modulateVsync(displayIdOpt, &VsyncModulator::onRefreshRateChangeCompleted); |
| 2247 | } |
Alec Mouri | 754c98a | 2019-03-18 18:53:42 -0700 | [diff] [blame] | 2248 | } |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 2249 | } |
| 2250 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2251 | void SurfaceFlinger::onComposerHalHotplugEvent(hal::HWDisplayId hwcDisplayId, |
| 2252 | DisplayHotplugEvent event) { |
| 2253 | if (event == DisplayHotplugEvent::CONNECTED || event == DisplayHotplugEvent::DISCONNECTED) { |
| 2254 | hal::Connection connection = (event == DisplayHotplugEvent::CONNECTED) |
| 2255 | ? hal::Connection::CONNECTED |
| 2256 | : hal::Connection::DISCONNECTED; |
| 2257 | { |
| 2258 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 2259 | mPendingHotplugEvents.push_back(HotplugEvent{hwcDisplayId, connection}); |
| 2260 | } |
| 2261 | |
| 2262 | if (mScheduler) { |
| 2263 | mScheduler->scheduleConfigure(); |
| 2264 | } |
| 2265 | |
| 2266 | return; |
Jiwen 'Steve' Cai | ccfd682 | 2018-02-21 16:15:58 -0800 | [diff] [blame] | 2267 | } |
| 2268 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2269 | if (FlagManager::getInstance().hotplug2()) { |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2270 | // TODO(b/311403559): use enum type instead of int |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2271 | const auto errorCode = static_cast<int32_t>(event); |
| 2272 | ALOGD("%s: Hotplug error %d for display %" PRIu64, __func__, errorCode, hwcDisplayId); |
| 2273 | mScheduler->dispatchHotplugError(errorCode); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2274 | } |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 2275 | } |
| 2276 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2277 | void SurfaceFlinger::onComposerHalVsyncPeriodTimingChanged( |
| 2278 | hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline& timeline) { |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2279 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2280 | mScheduler->onNewVsyncPeriodChangeTimeline(timeline); |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2281 | |
| 2282 | if (timeline.refreshRequired) { |
| 2283 | scheduleComposite(FrameHint::kNone); |
| 2284 | } |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2287 | void SurfaceFlinger::onComposerHalSeamlessPossible(hal::HWDisplayId) { |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 2288 | // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and |
Ady Abraham | b0433bc | 2020-01-08 17:31:06 -0800 | [diff] [blame] | 2289 | // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE. |
| 2290 | } |
| 2291 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2292 | void SurfaceFlinger::onComposerHalRefresh(hal::HWDisplayId) { |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2293 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2294 | scheduleComposite(FrameHint::kNone); |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2295 | } |
| 2296 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2297 | void SurfaceFlinger::onComposerHalVsyncIdle(hal::HWDisplayId) { |
Ady Abraham | e9befd7 | 2022-02-24 17:24:44 -0800 | [diff] [blame] | 2298 | ATRACE_CALL(); |
| 2299 | mScheduler->forceNextResync(); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2300 | } |
| 2301 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 2302 | void SurfaceFlinger::onRefreshRateChangedDebug(const RefreshRateChangedDebugData& data) { |
| 2303 | ATRACE_CALL(); |
Dominik Laskowski | 7372a60 | 2024-04-29 16:40:42 -0400 | [diff] [blame] | 2304 | const char* const whence = __func__; |
| 2305 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
| 2306 | kMainThreadContext) { |
| 2307 | if (const auto displayIdOpt = getHwComposer().toPhysicalDisplayId(data.display)) { |
| 2308 | if (const auto display = getDisplayDeviceLocked(*displayIdOpt)) { |
Ying Wei | 22d59cc | 2024-05-11 02:41:08 +0000 | [diff] [blame] | 2309 | const Fps refreshRate = Fps::fromPeriodNsecs( |
| 2310 | getHwComposer().getComposer()->isVrrSupported() ? data.refreshPeriodNanos |
| 2311 | : data.vsyncPeriodNanos); |
| 2312 | ATRACE_FORMAT("%s refresh rate = %d", whence, refreshRate.getIntValue()); |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 2313 | |
| 2314 | const auto renderRate = mDisplayModeController.getActiveMode(*displayIdOpt).fps; |
| 2315 | constexpr bool kSetByHwc = true; |
| 2316 | display->updateRefreshRateOverlayRate(refreshRate, renderRate, kSetByHwc); |
Dominik Laskowski | 7372a60 | 2024-04-29 16:40:42 -0400 | [diff] [blame] | 2317 | } |
| 2318 | } |
| 2319 | })); |
ramindani | 12bfe6b | 2023-02-03 13:29:19 -0800 | [diff] [blame] | 2320 | } |
| 2321 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2322 | void SurfaceFlinger::configure() { |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2323 | Mutex::Autolock lock(mStateLock); |
| 2324 | if (configureLocked()) { |
| 2325 | setTransactionFlags(eDisplayTransactionNeeded); |
| 2326 | } |
| 2327 | } |
| 2328 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2329 | bool SurfaceFlinger::updateLayerSnapshotsLegacy(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2330 | bool flushTransactions, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2331 | bool& outTransactionsAreEmpty) { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2332 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2333 | frontend::Update update; |
| 2334 | if (flushTransactions) { |
| 2335 | update = flushLifecycleUpdates(); |
| 2336 | if (mTransactionTracing) { |
| 2337 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2338 | update, mFrontEndDisplayInfos, |
| 2339 | mFrontEndDisplayInfosChanged); |
| 2340 | } |
| 2341 | } |
| 2342 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2343 | bool needsTraversal = false; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2344 | if (flushTransactions) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2345 | needsTraversal |= commitMirrorDisplays(vsyncId); |
| 2346 | needsTraversal |= commitCreatedLayers(vsyncId, update.layerCreatedStates); |
| 2347 | needsTraversal |= applyTransactions(update.transactions, vsyncId); |
| 2348 | } |
| 2349 | outTransactionsAreEmpty = !needsTraversal; |
| 2350 | const bool shouldCommit = (getTransactionFlags() & ~eTransactionFlushNeeded) || needsTraversal; |
| 2351 | if (shouldCommit) { |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 2352 | commitTransactionsLegacy(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | bool mustComposite = latchBuffers() || shouldCommit; |
| 2356 | updateLayerGeometry(); |
| 2357 | return mustComposite; |
| 2358 | } |
| 2359 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2360 | void SurfaceFlinger::updateLayerHistory(nsecs_t now) { |
| 2361 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 2362 | using Changes = frontend::RequestedLayerState::Changes; |
| 2363 | if (snapshot->path.isClone()) { |
| 2364 | continue; |
| 2365 | } |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 2366 | |
Jerry Chang | 3667800 | 2023-11-29 16:56:17 +0000 | [diff] [blame] | 2367 | const bool updateSmallDirty = FlagManager::getInstance().enable_small_area_detection() && |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2368 | ((snapshot->clientChanges & layer_state_t::eSurfaceDamageRegionChanged) || |
| 2369 | snapshot->changes.any(Changes::Geometry)); |
| 2370 | |
| 2371 | const bool hasChanges = |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 2372 | snapshot->changes.any(Changes::FrameRate | Changes::Buffer | Changes::Animation | |
| 2373 | Changes::Geometry | Changes::Visibility) || |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2374 | (snapshot->clientChanges & layer_state_t::eDefaultFrameRateCompatibilityChanged) != |
| 2375 | 0; |
| 2376 | |
| 2377 | if (!updateSmallDirty && !hasChanges) { |
| 2378 | continue; |
| 2379 | } |
| 2380 | |
| 2381 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 2382 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 2383 | "Couldn't find layer object for %s", |
| 2384 | snapshot->getDebugString().c_str()); |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2385 | |
| 2386 | if (updateSmallDirty) { |
| 2387 | // Update small dirty flag while surface damage region or geometry changed |
| 2388 | it->second->setIsSmallDirty(snapshot.get()); |
| 2389 | } |
| 2390 | |
| 2391 | if (!hasChanges) { |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2392 | continue; |
| 2393 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2394 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2395 | const auto layerProps = scheduler::LayerProps{ |
| 2396 | .visible = snapshot->isVisible, |
| 2397 | .bounds = snapshot->geomLayerBounds, |
| 2398 | .transform = snapshot->geomLayerTransform, |
| 2399 | .setFrameRateVote = snapshot->frameRate, |
| 2400 | .frameRateSelectionPriority = snapshot->frameRateSelectionPriority, |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2401 | .isSmallDirty = snapshot->isSmallDirty, |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 2402 | .isFrontBuffered = snapshot->isFrontBuffered(), |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2403 | }; |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2404 | |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 2405 | if (snapshot->changes.any(Changes::Geometry | Changes::Visibility)) { |
| 2406 | mScheduler->setLayerProperties(snapshot->sequence, layerProps); |
| 2407 | } |
| 2408 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2409 | if (snapshot->clientChanges & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 2410 | mScheduler->setDefaultFrameRateCompatibility(snapshot->sequence, |
| 2411 | snapshot->defaultFrameRateCompatibility); |
| 2412 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2413 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2414 | if (snapshot->changes.test(Changes::Animation)) { |
| 2415 | it->second->recordLayerHistoryAnimationTx(layerProps, now); |
| 2416 | } |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 2417 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2418 | if (snapshot->changes.test(Changes::FrameRate)) { |
| 2419 | it->second->setFrameRateForLayerTree(snapshot->frameRate, layerProps, now); |
| 2420 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2421 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2422 | if (snapshot->changes.test(Changes::Buffer)) { |
| 2423 | it->second->recordLayerHistoryBufferUpdate(layerProps, now); |
| 2424 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2425 | } |
| 2426 | } |
| 2427 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2428 | bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2429 | bool flushTransactions, bool& outTransactionsAreEmpty) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2430 | using Changes = frontend::RequestedLayerState::Changes; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2431 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2432 | frontend::Update update; |
| 2433 | if (flushTransactions) { |
| 2434 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 2435 | // Locking: |
| 2436 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 2437 | // we must keep a copy of the transactions (specifically the composer |
| 2438 | // states) around outside the scope of the lock. |
| 2439 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 2440 | // transactions with layers still in the createdLayer queue, collect the transactions |
| 2441 | // before committing the created layers. |
| 2442 | // 3. Transactions can only be flushed after adding layers, since the layer can be a newly |
| 2443 | // created one |
| 2444 | mTransactionHandler.collectTransactions(); |
| 2445 | { |
| 2446 | // TODO(b/238781169) lockless queue this and keep order. |
| 2447 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 2448 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 2449 | mCreatedLayers.clear(); |
| 2450 | update.newLayers = std::move(mNewLayers); |
| 2451 | mNewLayers.clear(); |
| 2452 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 2453 | mNewLayerArgs.clear(); |
| 2454 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 2455 | mDestroyedHandles.clear(); |
| 2456 | } |
| 2457 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2458 | mLayerLifecycleManager.addLayers(std::move(update.newLayers)); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2459 | update.transactions = mTransactionHandler.flushTransactions(); |
| 2460 | if (mTransactionTracing) { |
| 2461 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2462 | update, mFrontEndDisplayInfos, |
| 2463 | mFrontEndDisplayInfosChanged); |
| 2464 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2465 | mLayerLifecycleManager.applyTransactions(update.transactions); |
| 2466 | mLayerLifecycleManager.onHandlesDestroyed(update.destroyedHandles); |
| 2467 | for (auto& legacyLayer : update.layerCreatedStates) { |
| 2468 | sp<Layer> layer = legacyLayer.layer.promote(); |
| 2469 | if (layer) { |
| 2470 | mLegacyLayers[layer->sequence] = layer; |
| 2471 | } |
| 2472 | } |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 2473 | mLayerHierarchyBuilder.update(mLayerLifecycleManager); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2474 | } |
| 2475 | |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 2476 | // Keep a copy of the drawing state (that is going to be overwritten |
| 2477 | // by commitTransactionsLocked) outside of mStateLock so that the side |
| 2478 | // effects of the State assignment don't happen with mStateLock held, |
| 2479 | // which can cause deadlocks. |
| 2480 | State drawingState(mDrawingState); |
| 2481 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2482 | bool mustComposite = false; |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 2483 | mustComposite |= applyAndCommitDisplayTransactionStatesLocked(update.transactions); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2484 | |
| 2485 | { |
| 2486 | ATRACE_NAME("LayerSnapshotBuilder:update"); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2487 | frontend::LayerSnapshotBuilder::Args |
| 2488 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 2489 | .layerLifecycleManager = mLayerLifecycleManager, |
Melody Hsu | 63e3dcc | 2024-04-03 23:22:20 +0000 | [diff] [blame] | 2490 | .includeMetadata = mCompositionEngine->getFeatureFlags().test( |
| 2491 | compositionengine::Feature::kSnapshotLayerMetadata), |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2492 | .displays = mFrontEndDisplayInfos, |
| 2493 | .displayChanges = mFrontEndDisplayInfosChanged, |
| 2494 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2495 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2496 | .forceFullDamage = mForceFullDamage, |
| 2497 | .supportedLayerGenericMetadata = |
| 2498 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 2499 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 2500 | .skipRoundCornersWhenProtected = |
| 2501 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2502 | mLayerSnapshotBuilder.update(args); |
| 2503 | } |
| 2504 | |
| 2505 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Geometry | Changes::Input | |
Vishnu Nair | 40d0228 | 2023-02-28 21:11:40 +0000 | [diff] [blame] | 2506 | Changes::Hierarchy | Changes::Visibility)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2507 | mUpdateInputInfo = true; |
| 2508 | } |
| 2509 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::VisibleRegion | Changes::Hierarchy | |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2510 | Changes::Visibility | Changes::Geometry)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2511 | mVisibleRegionsDirty = true; |
| 2512 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2513 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Hierarchy | Changes::FrameRate)) { |
| 2514 | // The frame rate of attached choreographers can only change as a result of a |
| 2515 | // FrameRate change (including when Hierarchy changes). |
| 2516 | mUpdateAttachedChoreographer = true; |
| 2517 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2518 | outTransactionsAreEmpty = mLayerLifecycleManager.getGlobalChanges().get() == 0; |
Vishnu Nair | df59f47 | 2024-05-17 16:51:33 +0000 | [diff] [blame] | 2519 | if (FlagManager::getInstance().vrr_bugfix_24q4()) { |
Ady Abraham | 6846ade | 2024-05-20 21:58:27 +0000 | [diff] [blame] | 2520 | mustComposite |= mLayerLifecycleManager.getGlobalChanges().any( |
| 2521 | frontend::RequestedLayerState::kMustComposite); |
Vishnu Nair | df59f47 | 2024-05-17 16:51:33 +0000 | [diff] [blame] | 2522 | } else { |
| 2523 | mustComposite |= mLayerLifecycleManager.getGlobalChanges().get() != 0; |
| 2524 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2525 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2526 | bool newDataLatched = false; |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2527 | ATRACE_NAME("DisplayCallbackAndStatsUpdates"); |
| 2528 | mustComposite |= applyTransactionsLocked(update.transactions, vsyncId); |
| 2529 | traverseLegacyLayers([&](Layer* layer) { layer->commitTransaction(); }); |
| 2530 | const nsecs_t latchTime = systemTime(); |
| 2531 | bool unused = false; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2532 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2533 | for (auto& layer : mLayerLifecycleManager.getLayers()) { |
| 2534 | if (layer->changes.test(frontend::RequestedLayerState::Changes::Created) && |
| 2535 | layer->bgColorLayer) { |
| 2536 | sp<Layer> bgColorLayer = getFactory().createEffectLayer( |
| 2537 | LayerCreationArgs(this, nullptr, layer->name, |
| 2538 | ISurfaceComposerClient::eFXSurfaceEffect, LayerMetadata(), |
| 2539 | std::make_optional(layer->id), true)); |
| 2540 | mLegacyLayers[bgColorLayer->sequence] = bgColorLayer; |
| 2541 | } |
| 2542 | const bool willReleaseBufferOnLatch = layer->willReleaseBufferOnLatch(); |
Matthew DeVore | ce6bde8 | 2024-04-28 16:58:06 +0000 | [diff] [blame] | 2543 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2544 | auto it = mLegacyLayers.find(layer->id); |
| 2545 | if (it == mLegacyLayers.end() && |
| 2546 | layer->changes.test(frontend::RequestedLayerState::Changes::Destroyed)) { |
| 2547 | // Layer handle was created and immediately destroyed. It was destroyed before it |
| 2548 | // was added to the map. |
| 2549 | continue; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2550 | } |
| 2551 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2552 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 2553 | "Couldnt find layer object for %s", |
| 2554 | layer->getDebugString().c_str()); |
| 2555 | if (!layer->hasReadyFrame() && !willReleaseBufferOnLatch) { |
| 2556 | if (!it->second->hasBuffer()) { |
| 2557 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 2558 | // instead of a missed frame. This is used to identify scenarios where we |
| 2559 | // could not latch a buffer or apply a transaction due to backpressure. |
| 2560 | // We only update the latch time for buffer less layers here, the latch time |
| 2561 | // is updated for buffer layers when the buffer is latched. |
| 2562 | it->second->updateLastLatchTime(latchTime); |
| 2563 | } |
| 2564 | continue; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2565 | } |
| 2566 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2567 | const bool bgColorOnly = |
| 2568 | !layer->externalTexture && (layer->bgColorLayerId != UNASSIGNED_LAYER_ID); |
| 2569 | if (willReleaseBufferOnLatch) { |
| 2570 | mLayersWithBuffersRemoved.emplace(it->second); |
Matthew DeVore | ce6bde8 | 2024-04-28 16:58:06 +0000 | [diff] [blame] | 2571 | } |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2572 | it->second->latchBufferImpl(unused, latchTime, bgColorOnly); |
| 2573 | newDataLatched = true; |
Matthew DeVore | ce6bde8 | 2024-04-28 16:58:06 +0000 | [diff] [blame] | 2574 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2575 | mLayersWithQueuedFrames.emplace(it->second); |
| 2576 | mLayersIdsWithQueuedFrames.emplace(it->second->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2577 | } |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2578 | |
| 2579 | updateLayerHistory(latchTime); |
| 2580 | mLayerSnapshotBuilder.forEachVisibleSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 2581 | if (mLayersIdsWithQueuedFrames.find(snapshot.path.id) == mLayersIdsWithQueuedFrames.end()) |
| 2582 | return; |
| 2583 | Region visibleReg; |
| 2584 | visibleReg.set(snapshot.transformedBoundsWithoutTransparentRegion); |
| 2585 | invalidateLayerStack(snapshot.outputFilter, visibleReg); |
| 2586 | }); |
| 2587 | |
| 2588 | for (auto& destroyedLayer : mLayerLifecycleManager.getDestroyedLayers()) { |
| 2589 | mLegacyLayers.erase(destroyedLayer->id); |
| 2590 | } |
| 2591 | |
| 2592 | { |
| 2593 | ATRACE_NAME("LLM:commitChanges"); |
| 2594 | mLayerLifecycleManager.commitChanges(); |
| 2595 | } |
| 2596 | |
| 2597 | // enter boot animation on first buffer latch |
| 2598 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 2599 | ALOGI("Enter boot animation"); |
| 2600 | mBootStage = BootStage::BOOTANIMATION; |
| 2601 | } |
| 2602 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2603 | mustComposite |= (getTransactionFlags() & ~eTransactionFlushNeeded) || newDataLatched; |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2604 | if (mustComposite) { |
Vishnu Nair | 8134c1a | 2023-10-17 22:55:49 -0700 | [diff] [blame] | 2605 | commitTransactions(); |
| 2606 | } |
| 2607 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2608 | return mustComposite; |
| 2609 | } |
| 2610 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2611 | bool SurfaceFlinger::commit(PhysicalDisplayId pacesetterId, |
| 2612 | const scheduler::FrameTargets& frameTargets) { |
| 2613 | const scheduler::FrameTarget& pacesetterFrameTarget = *frameTargets.get(pacesetterId)->get(); |
| 2614 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2615 | const VsyncId vsyncId = pacesetterFrameTarget.vsyncId(); |
| 2616 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2617 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2618 | if (pacesetterFrameTarget.didMissFrame()) { |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2619 | mTimeStats->incrementMissedFrames(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2620 | } |
| 2621 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2622 | // If a mode set is pending and the fence hasn't fired yet, wait for the next commit. |
| 2623 | if (std::any_of(frameTargets.begin(), frameTargets.end(), |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 2624 | [this](const auto& pair) FTL_FAKE_GUARD(kMainThreadContext) { |
| 2625 | const auto [displayId, target] = pair; |
| 2626 | return target->isFramePending() && |
| 2627 | mDisplayModeController.isModeSetPending(displayId); |
| 2628 | })) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2629 | mScheduler->scheduleFrame(); |
| 2630 | return false; |
| 2631 | } |
| 2632 | |
Dominik Laskowski | a515fd5 | 2024-07-15 08:24:49 -0400 | [diff] [blame] | 2633 | { |
| 2634 | ConditionalLock lock(mStateLock, FlagManager::getInstance().connected_display()); |
| 2635 | |
| 2636 | for (const auto [displayId, _] : frameTargets) { |
| 2637 | if (mDisplayModeController.isModeSetPending(displayId)) { |
| 2638 | finalizeDisplayModeChange(displayId); |
| 2639 | } |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2640 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2641 | } |
| 2642 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2643 | if (pacesetterFrameTarget.isFramePending()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2644 | if (mBackpressureGpuComposition || pacesetterFrameTarget.didMissHwcFrame()) { |
Ady Abraham | e988303 | 2023-11-20 17:54:54 -0800 | [diff] [blame] | 2645 | if (FlagManager::getInstance().vrr_config()) { |
| 2646 | mScheduler->getVsyncSchedule()->getTracker().onFrameMissed( |
| 2647 | pacesetterFrameTarget.expectedPresentTime()); |
| 2648 | } |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2649 | scheduleCommit(FrameHint::kNone); |
| 2650 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2651 | } |
| 2652 | } |
| 2653 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2654 | const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); |
| 2655 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2656 | // Save this once per commit + composite to ensure consistency |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2657 | // TODO (b/240619471): consider removing active display check once AOD is fixed |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 2658 | const auto activeDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(mActiveDisplayId)); |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2659 | mPowerHintSessionEnabled = mPowerAdvisor->usePowerHintSession() && activeDisplay && |
| 2660 | activeDisplay->getPowerMode() == hal::PowerMode::ON; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2661 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2662 | mPowerAdvisor->setCommitStart(pacesetterFrameTarget.frameBeginTime()); |
| 2663 | mPowerAdvisor->setExpectedPresentTime(pacesetterFrameTarget.expectedPresentTime()); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2664 | |
| 2665 | // 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] | 2666 | const Duration idealSfWorkDuration = |
| 2667 | mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2668 | const Duration frameDelay = |
| 2669 | idealSfWorkDuration - pacesetterFrameTarget.expectedFrameDuration(); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2670 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2671 | mPowerAdvisor->setFrameDelay(frameDelay); |
| 2672 | mPowerAdvisor->setTotalFrameTargetWorkDuration(idealSfWorkDuration); |
Matt Buckley | 676e439 | 2023-05-25 22:09:26 +0000 | [diff] [blame] | 2673 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 2674 | const Period idealVsyncPeriod = |
| 2675 | mDisplayModeController.getActiveMode(pacesetterId).fps.getPeriod(); |
Matt Buckley | 676e439 | 2023-05-25 22:09:26 +0000 | [diff] [blame] | 2676 | mPowerAdvisor->updateTargetWorkDuration(idealVsyncPeriod); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2677 | } |
| 2678 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2679 | if (mRefreshRateOverlaySpinner || mHdrSdrRatioOverlay) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 2680 | Mutex::Autolock lock(mStateLock); |
| 2681 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2682 | display->animateOverlay(); |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2683 | } |
| 2684 | } |
| 2685 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2686 | // Composite if transactions were committed, or if requested by HWC. |
| 2687 | bool mustComposite = mMustComposite.exchange(false); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2688 | { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2689 | mFrameTimeline->setSfWakeUp(ftl::to_underlying(vsyncId), |
| 2690 | pacesetterFrameTarget.frameBeginTime().ns(), |
Pascal Muetschard | ac7bcd9 | 2023-10-03 15:05:36 +0200 | [diff] [blame] | 2691 | Fps::fromPeriodNsecs(vsyncPeriod.ns()), |
| 2692 | mScheduler->getPacesetterRefreshRate()); |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 2693 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2694 | const bool flushTransactions = clearTransactionFlags(eTransactionFlushNeeded); |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2695 | bool transactionsAreEmpty = false; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2696 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2697 | mustComposite |= |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2698 | updateLayerSnapshots(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2699 | flushTransactions, transactionsAreEmpty); |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2700 | } |
| 2701 | |
Ady Abraham | aa7ebd6 | 2024-03-26 02:27:57 +0000 | [diff] [blame] | 2702 | // Tell VsyncTracker that we are going to present this frame before scheduling |
| 2703 | // setTransactionFlags which will schedule another SF frame. This was if the tracker |
| 2704 | // needs to adjust the vsync timeline, it will be done before the next frame. |
| 2705 | if (FlagManager::getInstance().vrr_config() && mustComposite) { |
| 2706 | mScheduler->getVsyncSchedule()->getTracker().onFrameBegin( |
| 2707 | pacesetterFrameTarget.expectedPresentTime(), |
| 2708 | pacesetterFrameTarget.lastSignaledFrameTime()); |
| 2709 | } |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2710 | if (transactionFlushNeeded()) { |
| 2711 | setTransactionFlags(eTransactionFlushNeeded); |
| 2712 | } |
| 2713 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2714 | // This has to be called after latchBuffers because we want to include the layers that have |
| 2715 | // been latched in the commit callback |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2716 | if (transactionsAreEmpty) { |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2717 | // Invoke empty transaction callbacks early. |
| 2718 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 2719 | } else { |
| 2720 | // Invoke OnCommit callbacks. |
| 2721 | mTransactionCallbackInvoker.sendCallbacks(true /* onCommitOnly */); |
| 2722 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | // Layers need to get updated (in the previous line) before we can use them for |
| 2726 | // choosing the refresh rate. |
| 2727 | // Hold mStateLock as chooseRefreshRateForContent promotes wp<Layer> to sp<Layer> |
| 2728 | // and may eventually call to ~Layer() if it holds the last reference |
| 2729 | { |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2730 | bool updateAttachedChoreographer = mUpdateAttachedChoreographer; |
| 2731 | mUpdateAttachedChoreographer = false; |
| 2732 | |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 2733 | Mutex::Autolock lock(mStateLock); |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2734 | mScheduler->chooseRefreshRateForContent(mLayerLifecycleManagerEnabled |
| 2735 | ? &mLayerHierarchyBuilder.getHierarchy() |
| 2736 | : nullptr, |
| 2737 | updateAttachedChoreographer); |
Dominik Laskowski | a515fd5 | 2024-07-15 08:24:49 -0400 | [diff] [blame] | 2738 | |
| 2739 | if (FlagManager::getInstance().connected_display()) { |
| 2740 | initiateDisplayModeChanges(); |
| 2741 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2742 | } |
| 2743 | |
Dominik Laskowski | a515fd5 | 2024-07-15 08:24:49 -0400 | [diff] [blame] | 2744 | if (!FlagManager::getInstance().connected_display()) { |
| 2745 | ftl::FakeGuard guard(mStateLock); |
| 2746 | initiateDisplayModeChanges(); |
| 2747 | } |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 2748 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2749 | updateCursorAsync(); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2750 | if (!mustComposite) { |
| 2751 | updateInputFlinger(vsyncId, pacesetterFrameTarget.frameBeginTime()); |
| 2752 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2753 | doActiveLayersTracingIfNeeded(false, mVisibleRegionsDirty, |
| 2754 | pacesetterFrameTarget.frameBeginTime(), vsyncId); |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 2755 | |
Pablo Gamito | 6be8244 | 2022-06-13 11:04:34 +0000 | [diff] [blame] | 2756 | mLastCommittedVsyncId = vsyncId; |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2757 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2758 | persistDisplayBrightness(mustComposite); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2759 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2760 | return mustComposite && CC_LIKELY(mBootStage != BootStage::BOOTLOADER); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2761 | } |
| 2762 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2763 | CompositeResultsPerDisplay SurfaceFlinger::composite( |
| 2764 | PhysicalDisplayId pacesetterId, const scheduler::FrameTargeters& frameTargeters) { |
| 2765 | const scheduler::FrameTarget& pacesetterTarget = |
| 2766 | frameTargeters.get(pacesetterId)->get()->target(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2767 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2768 | const VsyncId vsyncId = pacesetterTarget.vsyncId(); |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2769 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2770 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2771 | compositionengine::CompositionRefreshArgs refreshArgs; |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 2772 | refreshArgs.powerCallback = this; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2773 | const auto& displays = FTL_FAKE_GUARD(mStateLock, mDisplays); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2774 | refreshArgs.outputs.reserve(displays.size()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2775 | |
| 2776 | // Add outputs for physical displays. |
| 2777 | for (const auto& [id, targeter] : frameTargeters) { |
| 2778 | ftl::FakeGuard guard(mStateLock); |
| 2779 | |
| 2780 | if (const auto display = getCompositionDisplayLocked(id)) { |
| 2781 | refreshArgs.outputs.push_back(display); |
| 2782 | } |
Leon Scroggins III | 370b8b5 | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 2783 | |
| 2784 | refreshArgs.frameTargets.try_emplace(id, &targeter->target()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2785 | } |
| 2786 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2787 | std::vector<DisplayId> displayIds; |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2788 | for (const auto& [_, display] : displays) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2789 | displayIds.push_back(display->getId()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2790 | display->tracePowerMode(); |
| 2791 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2792 | // Add outputs for virtual displays. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2793 | if (display->isVirtual()) { |
| 2794 | const Fps refreshRate = display->getAdjustedRefreshRate(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2795 | |
| 2796 | if (!refreshRate.isValid() || |
| 2797 | mScheduler->isVsyncInPhase(pacesetterTarget.frameBeginTime(), refreshRate)) { |
| 2798 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2799 | } |
| 2800 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2801 | } |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2802 | mPowerAdvisor->setDisplays(displayIds); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2803 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 2804 | const bool updateTaskMetadata = mCompositionEngine->getFeatureFlags().test( |
| 2805 | compositionengine::Feature::kSnapshotLayerMetadata); |
| 2806 | if (updateTaskMetadata && (mVisibleRegionsDirty || mLayerMetadataSnapshotNeeded)) { |
| 2807 | updateLayerMetadataSnapshot(); |
| 2808 | mLayerMetadataSnapshotNeeded = false; |
| 2809 | } |
| 2810 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 2811 | refreshArgs.bufferIdsToUncache = std::move(mBufferIdsToUncache); |
| 2812 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 2813 | if (!FlagManager::getInstance().ce_fence_promise()) { |
| 2814 | refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); |
| 2815 | for (auto& layer : mLayersWithQueuedFrames) { |
| 2816 | if (const auto& layerFE = layer->getCompositionEngineLayerFE()) |
| 2817 | refreshArgs.layersWithQueuedFrames.push_back(layerFE); |
| 2818 | } |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2819 | } |
| 2820 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 2821 | refreshArgs.outputColorSetting = mDisplayColorSetting; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 2822 | refreshArgs.forceOutputColorMode = mForceColorMode; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2823 | |
| 2824 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
Vishnu Nair | 995f4cf | 2024-03-07 19:40:03 -0800 | [diff] [blame] | 2825 | refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || |
| 2826 | mVisibleRegionsDirty || mDrawingState.colorMatrixChanged; |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 2827 | refreshArgs.internalDisplayRotationFlags = getActiveDisplayRotationFlags(); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2828 | |
| 2829 | if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) { |
| 2830 | refreshArgs.colorTransformMatrix = mDrawingState.colorMatrix; |
| 2831 | mDrawingState.colorMatrixChanged = false; |
| 2832 | } |
| 2833 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2834 | refreshArgs.devOptForceClientComposition = mDebugDisableHWC; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2835 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2836 | if (mDebugFlashDelay != 0) { |
| 2837 | refreshArgs.devOptForceClientComposition = true; |
| 2838 | refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay); |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 2839 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2840 | |
ramindani | 0491e64 | 2023-11-16 17:42:14 -0800 | [diff] [blame] | 2841 | // TODO(b/255601557) Update frameInterval per display |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 2842 | refreshArgs.frameInterval = |
| 2843 | mScheduler->getNextFrameInterval(pacesetterId, pacesetterTarget.expectedPresentTime()); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 2844 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 2845 | const auto scheduledFrameTimeOpt = scheduledFrameResultOpt |
| 2846 | ? std::optional{scheduledFrameResultOpt->callbackTime} |
| 2847 | : std::nullopt; |
| 2848 | refreshArgs.scheduledFrameTime = scheduledFrameTimeOpt; |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 2849 | refreshArgs.hasTrustedPresentationListener = mNumTrustedPresentationListeners > 0; |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2850 | // Store the present time just before calling to the composition engine so we could notify |
| 2851 | // the scheduler. |
| 2852 | const auto presentTime = systemTime(); |
| 2853 | |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2854 | constexpr bool kCursorOnly = false; |
| 2855 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
| 2856 | |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2857 | if (mLayerLifecycleManagerEnabled && !mVisibleRegionsDirty) { |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2858 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 2859 | auto compositionDisplay = display->getCompositionDisplay(); |
| 2860 | if (!compositionDisplay->getState().isEnabled) continue; |
| 2861 | for (auto outputLayer : compositionDisplay->getOutputLayersOrderedByZ()) { |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2862 | if (outputLayer->getLayerFE().getCompositionState() == nullptr) { |
| 2863 | // This is unexpected but instead of crashing, capture traces to disk |
| 2864 | // and recover gracefully by forcing CE to rebuild layer stack. |
| 2865 | ALOGE("Output layer %s for display %s %" PRIu64 " has a null " |
| 2866 | "snapshot. Forcing mVisibleRegionsDirty", |
| 2867 | outputLayer->getLayerFE().getDebugName(), |
| 2868 | compositionDisplay->getName().c_str(), compositionDisplay->getId().value); |
| 2869 | |
| 2870 | TransactionTraceWriter::getInstance().invoke(__func__, /* overwrite= */ false); |
| 2871 | mVisibleRegionsDirty = true; |
| 2872 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
| 2873 | refreshArgs.updatingGeometryThisFrame = mVisibleRegionsDirty; |
| 2874 | } |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2875 | } |
| 2876 | } |
| 2877 | } |
| 2878 | |
Melody Hsu | c949cde | 2024-03-12 01:43:34 +0000 | [diff] [blame] | 2879 | refreshArgs.refreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 2880 | for (auto& [layer, layerFE] : layers) { |
Melody Hsu | c949cde | 2024-03-12 01:43:34 +0000 | [diff] [blame] | 2881 | layer->onPreComposition(refreshArgs.refreshStartTime); |
| 2882 | } |
| 2883 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 2884 | if (FlagManager::getInstance().ce_fence_promise()) { |
| 2885 | for (auto& [layer, layerFE] : layers) { |
| 2886 | attachReleaseFenceFutureToLayer(layer, layerFE, |
| 2887 | layerFE->mSnapshot->outputFilter.layerStack); |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2888 | } |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 2889 | |
| 2890 | refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); |
| 2891 | for (auto& layer : mLayersWithQueuedFrames) { |
| 2892 | if (const auto& layerFE = layer->getCompositionEngineLayerFE()) { |
| 2893 | refreshArgs.layersWithQueuedFrames.push_back(layerFE); |
| 2894 | // Some layers are not displayed and do not yet have a future release fence |
| 2895 | if (layerFE->getReleaseFencePromiseStatus() == |
| 2896 | LayerFE::ReleaseFencePromiseStatus::UNINITIALIZED || |
| 2897 | layerFE->getReleaseFencePromiseStatus() == |
| 2898 | LayerFE::ReleaseFencePromiseStatus::FULFILLED) { |
| 2899 | // layerStack is invalid because layer is not on a display |
| 2900 | attachReleaseFenceFutureToLayer(layer.get(), layerFE.get(), |
| 2901 | ui::INVALID_LAYER_STACK); |
| 2902 | } |
| 2903 | } |
| 2904 | } |
| 2905 | |
| 2906 | mCompositionEngine->present(refreshArgs); |
| 2907 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
| 2908 | |
| 2909 | for (auto& [layer, layerFE] : layers) { |
| 2910 | CompositionResult compositionResult{layerFE->stealCompositionResult()}; |
| 2911 | if (compositionResult.lastClientCompositionFence) { |
| 2912 | layer->setWasClientComposed(compositionResult.lastClientCompositionFence); |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | } else { |
| 2917 | mCompositionEngine->present(refreshArgs); |
| 2918 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
| 2919 | |
| 2920 | for (auto [layer, layerFE] : layers) { |
| 2921 | CompositionResult compositionResult{layerFE->stealCompositionResult()}; |
| 2922 | for (auto& [releaseFence, layerStack] : compositionResult.releaseFences) { |
| 2923 | Layer* clonedFrom = layer->getClonedFrom().get(); |
| 2924 | auto owningLayer = clonedFrom ? clonedFrom : layer; |
| 2925 | owningLayer->onLayerDisplayed(std::move(releaseFence), layerStack); |
| 2926 | } |
| 2927 | if (compositionResult.lastClientCompositionFence) { |
| 2928 | layer->setWasClientComposed(compositionResult.lastClientCompositionFence); |
| 2929 | } |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2930 | } |
| 2931 | } |
| 2932 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2933 | mTimeStats->recordFrameDuration(pacesetterTarget.frameBeginTime().ns(), systemTime()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2934 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2935 | // Send a power hint after presentation is finished. |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2936 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2937 | // Now that the current frame has been presented above, PowerAdvisor needs the present time |
| 2938 | // of the previous frame (whose fence is signaled by now) to determine how long the HWC had |
| 2939 | // waited on that fence to retire before presenting. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2940 | const auto& previousPresentFence = pacesetterTarget.presentFenceForPreviousFrame(); |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2941 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2942 | mPowerAdvisor->setSfPresentTiming(TimePoint::fromNs(previousPresentFence->getSignalTime()), |
| 2943 | TimePoint::now()); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 2944 | mPowerAdvisor->reportActualWorkDuration(); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2945 | } |
| 2946 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2947 | if (mScheduler->onCompositionPresented(presentTime)) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2948 | scheduleComposite(FrameHint::kNone); |
| 2949 | } |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2950 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 2951 | mNotifyExpectedPresentMap[pacesetterId].hintStatus = NotifyExpectedPresentHintStatus::Start; |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2952 | onCompositionPresented(pacesetterId, frameTargeters, presentTime); |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 2953 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2954 | const bool hadGpuComposited = |
| 2955 | multiDisplayUnion(mCompositionCoverage).test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2956 | mCompositionCoverage.clear(); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2957 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2958 | TimeStats::ClientCompositionRecord clientCompositionRecord; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2959 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2960 | for (const auto& [_, display] : displays) { |
| 2961 | const auto& state = display->getCompositionDisplay()->getState(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2962 | CompositionCoverageFlags& flags = |
| 2963 | mCompositionCoverage.try_emplace(display->getId()).first->second; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2964 | |
| 2965 | if (state.usesDeviceComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2966 | flags |= CompositionCoverage::Hwc; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | if (state.reusedClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2970 | flags |= CompositionCoverage::GpuReuse; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2971 | } else if (state.usesClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2972 | flags |= CompositionCoverage::Gpu; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2973 | } |
| 2974 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2975 | clientCompositionRecord.predicted |= |
| 2976 | (state.strategyPrediction != CompositionStrategyPredictionState::DISABLED); |
| 2977 | clientCompositionRecord.predictionSucceeded |= |
| 2978 | (state.strategyPrediction == CompositionStrategyPredictionState::SUCCESS); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2979 | } |
| 2980 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2981 | const auto coverage = multiDisplayUnion(mCompositionCoverage); |
| 2982 | const bool hasGpuComposited = coverage.test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2983 | |
| 2984 | clientCompositionRecord.hadClientComposition = hasGpuComposited; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2985 | clientCompositionRecord.reused = coverage.test(CompositionCoverage::GpuReuse); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2986 | clientCompositionRecord.changed = hadGpuComposited != hasGpuComposited; |
| 2987 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2988 | mTimeStats->pushCompositionStrategyState(clientCompositionRecord); |
| 2989 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2990 | using namespace ftl::flag_operators; |
| 2991 | |
| 2992 | // TODO(b/160583065): Enable skip validation when SF caches all client composition layers. |
| 2993 | const bool hasGpuUseOrReuse = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2994 | coverage.any(CompositionCoverage::Gpu | CompositionCoverage::GpuReuse); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2995 | mScheduler->modulateVsync({}, &VsyncModulator::onDisplayRefresh, hasGpuUseOrReuse); |
Dan Stoza | 14cd37c | 2015-07-09 12:43:33 -0700 | [diff] [blame] | 2996 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 2997 | mLayersWithQueuedFrames.clear(); |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2998 | mLayersIdsWithQueuedFrames.clear(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2999 | doActiveLayersTracingIfNeeded(true, mVisibleRegionsDirty, pacesetterTarget.frameBeginTime(), |
| 3000 | vsyncId); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3001 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3002 | updateInputFlinger(vsyncId, pacesetterTarget.frameBeginTime()); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 3003 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3004 | if (mVisibleRegionsDirty) mHdrLayerInfoChanged = true; |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 3005 | mVisibleRegionsDirty = false; |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 3006 | |
| 3007 | if (mCompositionEngine->needsAnotherUpdate()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 3008 | scheduleCommit(FrameHint::kNone); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 3009 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 3010 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 3011 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 3012 | mPowerAdvisor->setCompositeEnd(TimePoint::now()); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 3013 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 3014 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3015 | CompositeResultsPerDisplay resultsPerDisplay; |
| 3016 | |
| 3017 | // Filter out virtual displays. |
| 3018 | for (const auto& [id, coverage] : mCompositionCoverage) { |
| 3019 | if (const auto idOpt = PhysicalDisplayId::tryCast(id)) { |
| 3020 | resultsPerDisplay.try_emplace(*idOpt, CompositeResult{coverage}); |
| 3021 | } |
| 3022 | } |
| 3023 | |
| 3024 | return resultsPerDisplay; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 3025 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3026 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 3027 | void SurfaceFlinger::updateLayerGeometry() { |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 3028 | ATRACE_CALL(); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 3029 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3030 | if (mVisibleRegionsDirty) { |
| 3031 | computeLayerBounds(); |
| 3032 | } |
| 3033 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3034 | for (auto& layer : mLayersPendingRefresh) { |
| 3035 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3036 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3037 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3038 | } |
| 3039 | mLayersPendingRefresh.clear(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 3042 | bool SurfaceFlinger::isHdrLayer(const frontend::LayerSnapshot& snapshot) const { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3043 | // Even though the camera layer may be using an HDR transfer function or otherwise be "HDR" |
| 3044 | // the device may need to avoid boosting the brightness as a result of these layers to |
| 3045 | // reduce power consumption during camera recording |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3046 | if (mIgnoreHdrCameraLayers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 3047 | if (snapshot.externalTexture && |
| 3048 | (snapshot.externalTexture->getUsage() & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) { |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 3049 | return false; |
| 3050 | } |
| 3051 | } |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 3052 | // RANGE_EXTENDED layer may identify themselves as being "HDR" |
| 3053 | // via a desired hdr/sdr ratio |
| 3054 | auto pixelFormat = snapshot.buffer |
| 3055 | ? std::make_optional(static_cast<ui::PixelFormat>(snapshot.buffer->getPixelFormat())) |
| 3056 | : std::nullopt; |
| 3057 | |
| 3058 | if (getHdrRenderType(snapshot.dataspace, pixelFormat, snapshot.desiredHdrSdrRatio) != |
| 3059 | HdrRenderType::SDR) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3060 | return true; |
| 3061 | } |
| 3062 | // If the layer is not allowed to be dimmed, treat it as HDR. WindowManager may disable |
| 3063 | // dimming in order to keep animations invoking SDR screenshots of HDR layers seamless. |
| 3064 | // Treat such tagged layers as HDR so that DisplayManagerService does not try to change |
| 3065 | // the screen brightness |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 3066 | if (!snapshot.dimmingEnabled) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3067 | return true; |
| 3068 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3069 | return false; |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 3070 | } |
| 3071 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3072 | ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId, |
| 3073 | bool isPrimary) const { |
| 3074 | const auto id = PhysicalDisplayId::tryCast(displayId); |
| 3075 | if (!id) { |
| 3076 | return ui::ROTATION_0; |
| 3077 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3078 | if (!mIgnoreHwcPhysicalDisplayOrientation && |
Neha Jain | 7b31cca | 2023-01-09 23:10:42 +0000 | [diff] [blame] | 3079 | getHwComposer().getComposer()->isSupported( |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3080 | Hwc2::Composer::OptionalFeature::PhysicalDisplayOrientation)) { |
| 3081 | switch (getHwComposer().getPhysicalDisplayOrientation(*id)) { |
| 3082 | case Hwc2::AidlTransform::ROT_90: |
| 3083 | return ui::ROTATION_90; |
| 3084 | case Hwc2::AidlTransform::ROT_180: |
| 3085 | return ui::ROTATION_180; |
| 3086 | case Hwc2::AidlTransform::ROT_270: |
| 3087 | return ui::ROTATION_270; |
| 3088 | default: |
| 3089 | return ui::ROTATION_0; |
| 3090 | } |
| 3091 | } |
| 3092 | |
| 3093 | if (isPrimary) { |
| 3094 | using Values = SurfaceFlingerProperties::primary_display_orientation_values; |
| 3095 | switch (primary_display_orientation(Values::ORIENTATION_0)) { |
| 3096 | case Values::ORIENTATION_90: |
| 3097 | return ui::ROTATION_90; |
| 3098 | case Values::ORIENTATION_180: |
| 3099 | return ui::ROTATION_180; |
| 3100 | case Values::ORIENTATION_270: |
| 3101 | return ui::ROTATION_270; |
| 3102 | default: |
| 3103 | break; |
| 3104 | } |
| 3105 | } |
| 3106 | return ui::ROTATION_0; |
| 3107 | } |
| 3108 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 3109 | void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId, |
| 3110 | const scheduler::FrameTargeters& frameTargeters, |
| 3111 | nsecs_t presentStartTime) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 3112 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 3113 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3114 | ui::PhysicalDisplayMap<PhysicalDisplayId, std::shared_ptr<FenceTime>> presentFences; |
| 3115 | ui::PhysicalDisplayMap<PhysicalDisplayId, const sp<Fence>> gpuCompositionDoneFences; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3116 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3117 | for (const auto& [id, targeter] : frameTargeters) { |
| 3118 | auto presentFence = getHwComposer().getPresentFence(id); |
| 3119 | |
| 3120 | if (id == pacesetterId) { |
| 3121 | mTransactionCallbackInvoker.addPresentFence(presentFence); |
| 3122 | } |
| 3123 | |
| 3124 | if (auto fenceTime = targeter->setPresentFence(std::move(presentFence)); |
| 3125 | fenceTime->isValid()) { |
| 3126 | presentFences.try_emplace(id, std::move(fenceTime)); |
| 3127 | } |
| 3128 | |
| 3129 | ftl::FakeGuard guard(mStateLock); |
| 3130 | if (const auto display = getCompositionDisplayLocked(id); |
| 3131 | display && display->getState().usesClientComposition) { |
| 3132 | gpuCompositionDoneFences |
| 3133 | .try_emplace(id, display->getRenderSurface()->getClientTargetAcquireFence()); |
| 3134 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3135 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3136 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3137 | const auto pacesetterDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(pacesetterId)); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3138 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3139 | std::shared_ptr<FenceTime> pacesetterPresentFenceTime = |
| 3140 | presentFences.get(pacesetterId) |
| 3141 | .transform([](const FenceTimePtr& ptr) { return ptr; }) |
| 3142 | .value_or(FenceTime::NO_FENCE); |
| 3143 | |
| 3144 | std::shared_ptr<FenceTime> pacesetterGpuCompositionDoneFenceTime = |
| 3145 | gpuCompositionDoneFences.get(pacesetterId) |
| 3146 | .transform([](sp<Fence> fence) { |
| 3147 | return std::make_shared<FenceTime>(std::move(fence)); |
| 3148 | }) |
| 3149 | .value_or(FenceTime::NO_FENCE); |
| 3150 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 3151 | const TimePoint presentTime = TimePoint::now(); |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 3152 | |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 3153 | // Set presentation information before calling Layer::releasePendingBuffer, such that jank |
| 3154 | // information from previous' frame classification is already available when sending jank info |
| 3155 | // to clients, so they get jank classification as early as possible. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3156 | mFrameTimeline->setSfPresent(presentTime.ns(), pacesetterPresentFenceTime, |
| 3157 | pacesetterGpuCompositionDoneFenceTime); |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 3158 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 3159 | // We use the CompositionEngine::getLastFrameRefreshTimestamp() which might |
| 3160 | // 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] | 3161 | // but that should be okay since CompositorTiming has snapping logic. |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 3162 | const TimePoint compositeTime = |
| 3163 | TimePoint::fromNs(mCompositionEngine->getLastFrameRefreshTimestamp()); |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 3164 | const Duration presentLatency = mHasReliablePresentFences |
| 3165 | ? mPresentLatencyTracker.trackPendingFrame(compositeTime, pacesetterPresentFenceTime) |
| 3166 | : Duration::zero(); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3167 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3168 | const auto schedule = mScheduler->getVsyncSchedule(); |
| 3169 | const TimePoint vsyncDeadline = schedule->vsyncDeadlineAfter(presentTime); |
| 3170 | const Period vsyncPeriod = schedule->period(); |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 3171 | const nsecs_t vsyncPhase = |
| 3172 | mScheduler->getVsyncConfiguration().getCurrentConfigs().late.sfOffset; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3173 | |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 3174 | const CompositorTiming compositorTiming(vsyncDeadline.ns(), vsyncPeriod.ns(), vsyncPhase, |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 3175 | presentLatency.ns()); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 3176 | |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 3177 | ui::DisplayMap<ui::LayerStack, const DisplayDevice*> layerStackToDisplay; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3178 | { |
| 3179 | if (!mLayersWithBuffersRemoved.empty() || mNumTrustedPresentationListeners > 0) { |
| 3180 | Mutex::Autolock lock(mStateLock); |
| 3181 | for (const auto& [token, display] : mDisplays) { |
| 3182 | layerStackToDisplay.emplace_or_replace(display->getLayerStack(), display.get()); |
| 3183 | } |
| 3184 | } |
| 3185 | } |
| 3186 | |
| 3187 | for (auto layer : mLayersWithBuffersRemoved) { |
Vishnu Nair | f10a87b | 2023-05-01 14:02:51 -0700 | [diff] [blame] | 3188 | std::vector<ui::LayerStack> previouslyPresentedLayerStacks = |
| 3189 | std::move(layer->mPreviouslyPresentedLayerStacks); |
| 3190 | layer->mPreviouslyPresentedLayerStacks.clear(); |
| 3191 | for (auto layerStack : previouslyPresentedLayerStacks) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3192 | auto optDisplay = layerStackToDisplay.get(layerStack); |
| 3193 | if (optDisplay && !optDisplay->get()->isVirtual()) { |
| 3194 | auto fence = getHwComposer().getPresentFence(optDisplay->get()->getPhysicalId()); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3195 | if (FlagManager::getInstance().ce_fence_promise()) { |
| 3196 | layer->prepareReleaseCallbacks(ftl::yield<FenceResult>(fence), |
| 3197 | ui::INVALID_LAYER_STACK); |
| 3198 | } else { |
| 3199 | layer->onLayerDisplayed(ftl::yield<FenceResult>(fence).share(), |
| 3200 | ui::INVALID_LAYER_STACK); |
| 3201 | } |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3202 | } |
| 3203 | } |
| 3204 | layer->releasePendingBuffer(presentTime.ns()); |
| 3205 | } |
| 3206 | mLayersWithBuffersRemoved.clear(); |
| 3207 | |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 3208 | for (const auto& layer: mLayersWithQueuedFrames) { |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 3209 | layer->onCompositionPresented(pacesetterDisplay.get(), |
| 3210 | pacesetterGpuCompositionDoneFenceTime, |
| 3211 | pacesetterPresentFenceTime, compositorTiming); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3212 | layer->releasePendingBuffer(presentTime.ns()); |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 3213 | } |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 3214 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3215 | std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>> |
| 3216 | hdrInfoListeners; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3217 | bool haveNewListeners = false; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3218 | { |
| 3219 | Mutex::Autolock lock(mStateLock); |
| 3220 | if (mFpsReporter) { |
Andy Yu | aef688b | 2024-01-23 17:14:23 -0800 | [diff] [blame] | 3221 | mFpsReporter->dispatchLayerFps(mLayerHierarchyBuilder.getHierarchy()); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3222 | } |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 3223 | |
| 3224 | if (mTunnelModeEnabledReporter) { |
| 3225 | mTunnelModeEnabledReporter->updateTunnelModeStatus(); |
| 3226 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3227 | hdrInfoListeners.reserve(mHdrLayerInfoListeners.size()); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 3228 | for (const auto& [displayId, reporter] : mHdrLayerInfoListeners) { |
| 3229 | if (reporter && reporter->hasListeners()) { |
| 3230 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 3231 | hdrInfoListeners.emplace_back(display->getCompositionDisplay(), reporter); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3232 | } |
| 3233 | } |
| 3234 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3235 | haveNewListeners = mAddingHDRLayerInfoListener; // grab this with state lock |
| 3236 | mAddingHDRLayerInfoListener = false; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3237 | } |
| 3238 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3239 | if (haveNewListeners || mHdrLayerInfoChanged) { |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3240 | for (auto& [compositionDisplay, listener] : hdrInfoListeners) { |
| 3241 | HdrLayerInfoReporter::HdrLayerInfo info; |
| 3242 | int32_t maxArea = 0; |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 3243 | |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3244 | auto updateInfoFn = |
| 3245 | [&](const std::shared_ptr<compositionengine::Display>& compositionDisplay, |
| 3246 | const frontend::LayerSnapshot& snapshot, const sp<LayerFE>& layerFe) { |
| 3247 | if (snapshot.isVisible && |
| 3248 | compositionDisplay->includesLayer(snapshot.outputFilter)) { |
| 3249 | if (isHdrLayer(snapshot)) { |
| 3250 | const auto* outputLayer = |
| 3251 | compositionDisplay->getOutputLayerForLayer(layerFe); |
| 3252 | if (outputLayer) { |
| 3253 | const float desiredHdrSdrRatio = |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 3254 | snapshot.desiredHdrSdrRatio < 1.f |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3255 | ? std::numeric_limits<float>::infinity() |
| 3256 | : snapshot.desiredHdrSdrRatio; |
| 3257 | info.mergeDesiredRatio(desiredHdrSdrRatio); |
| 3258 | info.numberOfHdrLayers++; |
| 3259 | const auto displayFrame = outputLayer->getState().displayFrame; |
| 3260 | const int32_t area = |
| 3261 | displayFrame.width() * displayFrame.height(); |
| 3262 | if (area > maxArea) { |
| 3263 | maxArea = area; |
| 3264 | info.maxW = displayFrame.width(); |
| 3265 | info.maxH = displayFrame.height(); |
| 3266 | } |
| 3267 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3268 | } |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 3269 | } |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3270 | }; |
| 3271 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3272 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3273 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 3274 | [&, compositionDisplay = compositionDisplay]( |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 3275 | std::unique_ptr<frontend::LayerSnapshot>& |
| 3276 | snapshot) FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3277 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 3278 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 3279 | "Couldnt find layer object for %s", |
| 3280 | snapshot->getDebugString().c_str()); |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3281 | auto& legacyLayer = it->second; |
| 3282 | sp<LayerFE> layerFe = |
| 3283 | legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
| 3284 | |
| 3285 | updateInfoFn(compositionDisplay, *snapshot, layerFe); |
| 3286 | }); |
| 3287 | } else { |
| 3288 | mDrawingState.traverse([&, compositionDisplay = compositionDisplay](Layer* layer) { |
| 3289 | const auto layerFe = layer->getCompositionEngineLayerFE(); |
| 3290 | const frontend::LayerSnapshot& snapshot = *layer->getLayerSnapshot(); |
| 3291 | updateInfoFn(compositionDisplay, snapshot, layerFe); |
| 3292 | }); |
| 3293 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3294 | listener->dispatchHdrLayerInfo(info); |
| 3295 | } |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3296 | } |
| 3297 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3298 | mHdrLayerInfoChanged = false; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3299 | |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 3300 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 3301 | mTransactionCallbackInvoker.clearCompletedTransactions(); |
| 3302 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3303 | mTimeStats->incrementTotalFrames(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3304 | mTimeStats->setPresentFenceGlobal(pacesetterPresentFenceTime); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3305 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3306 | for (auto&& [id, presentFence] : presentFences) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3307 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3308 | const bool isInternalDisplay = |
| 3309 | mPhysicalDisplays.get(id).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 3310 | |
| 3311 | if (isInternalDisplay) { |
| 3312 | mScheduler->addPresentFence(id, std::move(presentFence)); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3313 | } |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3314 | } |
| 3315 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3316 | const bool hasPacesetterDisplay = |
| 3317 | pacesetterDisplay && getHwComposer().isConnected(pacesetterId); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3318 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3319 | if (!hasSyncFramework) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3320 | if (hasPacesetterDisplay && pacesetterDisplay->isPoweredOn()) { |
| 3321 | mScheduler->enableHardwareVsync(pacesetterId); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3322 | } |
| 3323 | } |
| 3324 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3325 | if (hasPacesetterDisplay && !pacesetterDisplay->isPoweredOn()) { |
Lars Svensson | d9e5469 | 2021-12-21 07:41:57 +0100 | [diff] [blame] | 3326 | getRenderEngine().cleanupPostRender(); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 3327 | return; |
| 3328 | } |
| 3329 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 3330 | // Cleanup any outstanding resources due to rendering a prior frame. |
| 3331 | getRenderEngine().cleanupPostRender(); |
| 3332 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3333 | if (mNumTrustedPresentationListeners > 0) { |
| 3334 | // We avoid any reverse traversal upwards so this shouldn't be too expensive |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 3335 | traverseLegacyLayers([&](Layer* layer) FTL_FAKE_GUARD(kMainThreadContext) { |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3336 | if (!layer->hasTrustedPresentationListener()) { |
| 3337 | return; |
| 3338 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3339 | const frontend::LayerSnapshot* snapshot = mLayerLifecycleManagerEnabled |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3340 | ? mLayerSnapshotBuilder.getSnapshot(layer->sequence) |
| 3341 | : layer->getLayerSnapshot(); |
| 3342 | std::optional<const DisplayDevice*> displayOpt = std::nullopt; |
| 3343 | if (snapshot) { |
| 3344 | displayOpt = layerStackToDisplay.get(snapshot->outputFilter.layerStack); |
| 3345 | } |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 3346 | const DisplayDevice* display = displayOpt.value_or(nullptr); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3347 | layer->updateTrustedPresentationState(display, snapshot, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 3348 | nanoseconds_to_milliseconds(presentStartTime), |
| 3349 | false); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3350 | }); |
| 3351 | } |
| 3352 | |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3353 | // Even though ATRACE_INT64 already checks if tracing is enabled, it doesn't prevent the |
| 3354 | // side-effect of getTotalSize(), so we check that again here |
| 3355 | if (ATRACE_ENABLED()) { |
Marissa Wall | 22b2de1 | 2019-12-02 18:11:43 -0800 | [diff] [blame] | 3356 | // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3357 | ATRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize()); |
| 3358 | } |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3359 | |
| 3360 | logFrameStats(presentTime); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 3361 | } |
| 3362 | |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3363 | FloatRect SurfaceFlinger::getMaxDisplayBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3364 | const ui::Size maxSize = [this] { |
| 3365 | ftl::FakeGuard guard(mStateLock); |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3366 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3367 | // The LayerTraceGenerator tool runs without displays. |
| 3368 | if (mDisplays.empty()) return ui::Size{5000, 5000}; |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3369 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3370 | return std::accumulate(mDisplays.begin(), mDisplays.end(), ui::kEmptySize, |
| 3371 | [](ui::Size size, const auto& pair) -> ui::Size { |
| 3372 | const auto& display = pair.second; |
| 3373 | return {std::max(size.getWidth(), display->getWidth()), |
| 3374 | std::max(size.getHeight(), display->getHeight())}; |
| 3375 | }); |
| 3376 | }(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3377 | |
| 3378 | // Ignore display bounds for now since they will be computed later. Use a large Rect bound |
| 3379 | // to ensure it's bigger than an actual display will be. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3380 | const float xMax = maxSize.getWidth() * 10.f; |
| 3381 | const float yMax = maxSize.getHeight() * 10.f; |
| 3382 | |
| 3383 | return {-xMax, -yMax, xMax, yMax}; |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | void SurfaceFlinger::computeLayerBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3387 | const FloatRect maxBounds = getMaxDisplayBounds(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3388 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 3389 | layer->computeBounds(maxBounds, ui::Transform(), 0.f /* shadowRadius */); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3390 | } |
| 3391 | } |
| 3392 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3393 | void SurfaceFlinger::commitTransactions() { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 3394 | ATRACE_CALL(); |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 3395 | mDebugInTransaction = systemTime(); |
| 3396 | |
| 3397 | // Here we're guaranteed that some transaction flags are set |
| 3398 | // so we can call commitTransactionsLocked unconditionally. |
| 3399 | // We clear the flags with mStateLock held to guarantee that |
| 3400 | // mCurrentState won't change until the transaction is committed. |
| 3401 | mScheduler->modulateVsync({}, &VsyncModulator::onTransactionCommit); |
| 3402 | commitTransactionsLocked(clearTransactionFlags(eTransactionMask)); |
| 3403 | mDebugInTransaction = 0; |
| 3404 | } |
| 3405 | |
| 3406 | void SurfaceFlinger::commitTransactionsLegacy() { |
| 3407 | ATRACE_CALL(); |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 3408 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3409 | // Keep a copy of the drawing state (that is going to be overwritten |
| 3410 | // by commitTransactionsLocked) outside of mStateLock so that the side |
| 3411 | // effects of the State assignment don't happen with mStateLock held, |
| 3412 | // which can cause deadlocks. |
Mathias Agopian | 7cc6df5 | 2013-06-05 14:30:54 -0700 | [diff] [blame] | 3413 | State drawingState(mDrawingState); |
| 3414 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3415 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 3416 | mDebugInTransaction = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3417 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3418 | // Here we're guaranteed that some transaction flags are set |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3419 | // so we can call commitTransactionsLocked unconditionally. |
| 3420 | // We clear the flags with mStateLock held to guarantee that |
| 3421 | // mCurrentState won't change until the transaction is committed. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3422 | mScheduler->modulateVsync({}, &VsyncModulator::onTransactionCommit); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3423 | commitTransactionsLocked(clearTransactionFlags(eTransactionMask)); |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 3424 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3425 | mDebugInTransaction = 0; |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 3426 | } |
| 3427 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3428 | std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes( |
| 3429 | PhysicalDisplayId displayId) const { |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3430 | std::vector<HWComposer::HWCDisplayMode> hwcModes; |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3431 | std::optional<hal::HWConfigId> activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3432 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3433 | const bool isExternalDisplay = FlagManager::getInstance().connected_display() && |
| 3434 | getHwComposer().getDisplayConnectionType(displayId) == |
| 3435 | ui::DisplayConnectionType::External; |
| 3436 | |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3437 | int attempt = 0; |
| 3438 | constexpr int kMaxAttempts = 3; |
| 3439 | do { |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 3440 | hwcModes = getHwComposer().getModes(displayId, |
| 3441 | scheduler::RefreshRateSelector::kMinSupportedFrameRate |
| 3442 | .getPeriodNsecs()); |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3443 | const auto activeModeHwcIdExp = getHwComposer().getActiveMode(displayId); |
| 3444 | activeModeHwcIdOpt = activeModeHwcIdExp.value_opt(); |
| 3445 | |
| 3446 | if (isExternalDisplay && |
| 3447 | activeModeHwcIdExp.has_error([](status_t error) { return error == NO_INIT; })) { |
| 3448 | constexpr nsecs_t k59HzVsyncPeriod = 16949153; |
| 3449 | constexpr nsecs_t k60HzVsyncPeriod = 16666667; |
| 3450 | |
| 3451 | // DM sets the initial mode for an external display to 1080p@60, but |
| 3452 | // this comes after SF creates its own state (including the |
| 3453 | // DisplayDevice). For now, pick the same mode in order to avoid |
| 3454 | // inconsistent state and unnecessary mode switching. |
| 3455 | // TODO (b/318534874): Let DM decide the initial mode. |
| 3456 | // |
| 3457 | // Try to find 1920x1080 @ 60 Hz |
| 3458 | if (const auto iter = std::find_if(hwcModes.begin(), hwcModes.end(), |
| 3459 | [](const auto& mode) { |
| 3460 | return mode.width == 1920 && |
| 3461 | mode.height == 1080 && |
| 3462 | mode.vsyncPeriod == k60HzVsyncPeriod; |
| 3463 | }); |
| 3464 | iter != hwcModes.end()) { |
| 3465 | activeModeHwcIdOpt = iter->hwcId; |
| 3466 | break; |
| 3467 | } |
| 3468 | |
| 3469 | // Try to find 1920x1080 @ 59-60 Hz |
| 3470 | if (const auto iter = std::find_if(hwcModes.begin(), hwcModes.end(), |
| 3471 | [](const auto& mode) { |
| 3472 | return mode.width == 1920 && |
| 3473 | mode.height == 1080 && |
| 3474 | mode.vsyncPeriod >= k60HzVsyncPeriod && |
| 3475 | mode.vsyncPeriod <= k59HzVsyncPeriod; |
| 3476 | }); |
| 3477 | iter != hwcModes.end()) { |
| 3478 | activeModeHwcIdOpt = iter->hwcId; |
| 3479 | break; |
| 3480 | } |
| 3481 | |
| 3482 | // The display does not support 1080p@60, and this is the last attempt to pick a display |
| 3483 | // mode. Prefer 60 Hz if available, with the closest resolution to 1080p. |
| 3484 | if (attempt + 1 == kMaxAttempts) { |
| 3485 | std::vector<HWComposer::HWCDisplayMode> hwcModeOpts; |
| 3486 | |
| 3487 | for (const auto& mode : hwcModes) { |
| 3488 | if (mode.width <= 1920 && mode.height <= 1080 && |
| 3489 | mode.vsyncPeriod >= k60HzVsyncPeriod && |
| 3490 | mode.vsyncPeriod <= k59HzVsyncPeriod) { |
| 3491 | hwcModeOpts.push_back(mode); |
| 3492 | } |
| 3493 | } |
| 3494 | |
| 3495 | if (const auto iter = std::max_element(hwcModeOpts.begin(), hwcModeOpts.end(), |
| 3496 | [](const auto& a, const auto& b) { |
| 3497 | const auto aSize = a.width * a.height; |
| 3498 | const auto bSize = b.width * b.height; |
| 3499 | if (aSize < bSize) |
| 3500 | return true; |
| 3501 | else if (aSize == bSize) |
| 3502 | return a.vsyncPeriod > b.vsyncPeriod; |
| 3503 | else |
| 3504 | return false; |
| 3505 | }); |
| 3506 | iter != hwcModeOpts.end()) { |
| 3507 | activeModeHwcIdOpt = iter->hwcId; |
| 3508 | break; |
| 3509 | } |
| 3510 | |
| 3511 | // hwcModeOpts was empty, use hwcModes[0] as the last resort |
| 3512 | activeModeHwcIdOpt = hwcModes[0].hwcId; |
| 3513 | } |
| 3514 | } |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3515 | |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3516 | const auto isActiveMode = [activeModeHwcIdOpt](const HWComposer::HWCDisplayMode& mode) { |
| 3517 | return mode.hwcId == activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3518 | }; |
| 3519 | |
| 3520 | if (std::any_of(hwcModes.begin(), hwcModes.end(), isActiveMode)) { |
| 3521 | break; |
| 3522 | } |
| 3523 | } while (++attempt < kMaxAttempts); |
| 3524 | |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3525 | if (attempt == kMaxAttempts) { |
| 3526 | const std::string activeMode = |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3527 | activeModeHwcIdOpt ? std::to_string(*activeModeHwcIdOpt) : "unknown"s; |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3528 | ALOGE("HWC failed to report an active mode that is supported: activeModeHwcId=%s, " |
| 3529 | "hwcModes={%s}", |
| 3530 | activeMode.c_str(), base::Join(hwcModes, ", ").c_str()); |
| 3531 | return {}; |
| 3532 | } |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3533 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3534 | const DisplayModes oldModes = mPhysicalDisplays.get(displayId) |
| 3535 | .transform([](const PhysicalDisplay& display) { |
| 3536 | return display.snapshot().displayModes(); |
| 3537 | }) |
| 3538 | .value_or(DisplayModes{}); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3539 | |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 3540 | DisplayModeId nextModeId = std::accumulate(oldModes.begin(), oldModes.end(), DisplayModeId(-1), |
| 3541 | [](DisplayModeId max, const auto& pair) { |
| 3542 | return std::max(max, pair.first); |
| 3543 | }); |
| 3544 | ++nextModeId; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3545 | |
| 3546 | DisplayModes newModes; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3547 | for (const auto& hwcMode : hwcModes) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 3548 | const auto id = nextModeId++; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3549 | newModes.try_emplace(id, |
| 3550 | DisplayMode::Builder(hwcMode.hwcId) |
| 3551 | .setId(id) |
| 3552 | .setPhysicalDisplayId(displayId) |
| 3553 | .setResolution({hwcMode.width, hwcMode.height}) |
| 3554 | .setVsyncPeriod(hwcMode.vsyncPeriod) |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 3555 | .setVrrConfig(hwcMode.vrrConfig) |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3556 | .setDpiX(hwcMode.dpiX) |
| 3557 | .setDpiY(hwcMode.dpiY) |
| 3558 | .setGroup(hwcMode.configGroup) |
| 3559 | .build()); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3560 | } |
| 3561 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3562 | const bool sameModes = |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3563 | std::equal(newModes.begin(), newModes.end(), oldModes.begin(), oldModes.end(), |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3564 | [](const auto& lhs, const auto& rhs) { |
| 3565 | return equalsExceptDisplayModeId(*lhs.second, *rhs.second); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3566 | }); |
| 3567 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3568 | // Keep IDs if modes have not changed. |
| 3569 | const auto& modes = sameModes ? oldModes : newModes; |
| 3570 | const DisplayModePtr activeMode = |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3571 | std::find_if(modes.begin(), modes.end(), [activeModeHwcIdOpt](const auto& pair) { |
| 3572 | return pair.second->getHwcId() == activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3573 | })->second; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3574 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3575 | if (isExternalDisplay) { |
| 3576 | ALOGI("External display %s initial mode: {%s}", to_string(displayId).c_str(), |
| 3577 | to_string(*activeMode).c_str()); |
| 3578 | } |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3579 | return {modes, activeMode}; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3580 | } |
| 3581 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3582 | bool SurfaceFlinger::configureLocked() { |
| 3583 | std::vector<HotplugEvent> events; |
| 3584 | { |
| 3585 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 3586 | events = std::move(mPendingHotplugEvents); |
| 3587 | } |
| 3588 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3589 | for (const auto [hwcDisplayId, connection] : events) { |
| 3590 | if (auto info = getHwComposer().onHotplug(hwcDisplayId, connection)) { |
| 3591 | const auto displayId = info->id; |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3592 | const ftl::Concat displayString("display ", displayId.value, "(HAL ID ", hwcDisplayId, |
| 3593 | ')'); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3594 | |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3595 | if (connection == hal::Connection::CONNECTED) { |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3596 | const auto activeModeIdOpt = |
| 3597 | processHotplugConnect(displayId, hwcDisplayId, std::move(*info), |
| 3598 | displayString.c_str()); |
| 3599 | if (!activeModeIdOpt) { |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3600 | if (FlagManager::getInstance().hotplug2()) { |
| 3601 | mScheduler->dispatchHotplugError( |
| 3602 | static_cast<int32_t>(DisplayHotplugEvent::ERROR_UNKNOWN)); |
| 3603 | } |
| 3604 | getHwComposer().disconnectDisplay(displayId); |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3605 | continue; |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3606 | } |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3607 | |
| 3608 | const auto [kernelIdleTimerController, idleTimerTimeoutMs] = |
| 3609 | getKernelIdleTimerProperties(displayId); |
| 3610 | |
| 3611 | using Config = scheduler::RefreshRateSelector::Config; |
| 3612 | const Config config = |
| 3613 | {.enableFrameRateOverride = sysprop::enable_frame_rate_override(true) |
| 3614 | ? Config::FrameRateOverride::Enabled |
| 3615 | : Config::FrameRateOverride::Disabled, |
| 3616 | .frameRateMultipleThreshold = |
| 3617 | base::GetIntProperty("debug.sf.frame_rate_multiple_threshold"s, 0), |
| 3618 | .legacyIdleTimerTimeout = idleTimerTimeoutMs, |
| 3619 | .kernelIdleTimerController = kernelIdleTimerController}; |
| 3620 | |
| 3621 | const auto snapshotOpt = |
| 3622 | mPhysicalDisplays.get(displayId).transform(&PhysicalDisplay::snapshotRef); |
| 3623 | LOG_ALWAYS_FATAL_IF(!snapshotOpt); |
| 3624 | |
| 3625 | mDisplayModeController.registerDisplay(*snapshotOpt, *activeModeIdOpt, config); |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3626 | } else { |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3627 | // Unregister before destroying the DisplaySnapshot below. |
| 3628 | mDisplayModeController.unregisterDisplay(displayId); |
| 3629 | |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3630 | processHotplugDisconnect(displayId, displayString.c_str()); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3631 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3632 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3633 | } |
| 3634 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3635 | return !events.empty(); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3636 | } |
| 3637 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3638 | std::optional<DisplayModeId> SurfaceFlinger::processHotplugConnect(PhysicalDisplayId displayId, |
| 3639 | hal::HWDisplayId hwcDisplayId, |
| 3640 | DisplayIdentificationInfo&& info, |
| 3641 | const char* displayString) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3642 | auto [displayModes, activeMode] = loadDisplayModes(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3643 | if (!activeMode) { |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3644 | ALOGE("Failed to hotplug %s", displayString); |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3645 | return std::nullopt; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3646 | } |
| 3647 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3648 | const DisplayModeId activeModeId = activeMode->getId(); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3649 | ui::ColorModes colorModes = getHwComposer().getColorModes(displayId); |
| 3650 | |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3651 | if (const auto displayOpt = mPhysicalDisplays.get(displayId)) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3652 | const auto& display = displayOpt->get(); |
| 3653 | const auto& snapshot = display.snapshot(); |
| 3654 | |
| 3655 | std::optional<DeviceProductInfo> deviceProductInfo; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3656 | if (getHwComposer().updatesDeviceProductInfoOnHotplugReconnect()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3657 | deviceProductInfo = std::move(info.deviceProductInfo); |
| 3658 | } else { |
| 3659 | deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3660 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3661 | |
| 3662 | const auto it = |
| 3663 | mPhysicalDisplays.try_replace(displayId, display.token(), displayId, |
| 3664 | snapshot.connectionType(), std::move(displayModes), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3665 | std::move(colorModes), std::move(deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3666 | |
| 3667 | auto& state = mCurrentState.displays.editValueFor(it->second.token()); |
| 3668 | state.sequenceId = DisplayDeviceState{}.sequenceId; // Generate new sequenceId. |
| 3669 | state.physical->activeMode = std::move(activeMode); |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3670 | ALOGI("Reconnecting %s", displayString); |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3671 | return activeModeId; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3672 | } |
| 3673 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3674 | const sp<IBinder> token = sp<BBinder>::make(); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3675 | const ui::DisplayConnectionType connectionType = |
| 3676 | getHwComposer().getDisplayConnectionType(displayId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3677 | |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3678 | mPhysicalDisplays.try_emplace(displayId, token, displayId, connectionType, |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3679 | std::move(displayModes), std::move(colorModes), |
| 3680 | std::move(info.deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3681 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3682 | DisplayDeviceState state; |
| 3683 | state.physical = {.id = displayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3684 | .hwcDisplayId = hwcDisplayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3685 | .activeMode = std::move(activeMode)}; |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3686 | state.isSecure = connectionType == ui::DisplayConnectionType::Internal; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3687 | state.isProtected = true; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3688 | state.displayName = std::move(info.name); |
| 3689 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3690 | mCurrentState.displays.add(token, state); |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3691 | ALOGI("Connecting %s", displayString); |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3692 | return activeModeId; |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | void SurfaceFlinger::processHotplugDisconnect(PhysicalDisplayId displayId, |
| 3696 | const char* displayString) { |
| 3697 | ALOGI("Disconnecting %s", displayString); |
| 3698 | |
| 3699 | const auto displayOpt = mPhysicalDisplays.get(displayId); |
| 3700 | LOG_ALWAYS_FATAL_IF(!displayOpt); |
| 3701 | const auto& display = displayOpt->get(); |
| 3702 | |
| 3703 | if (const ssize_t index = mCurrentState.displays.indexOfKey(display.token()); index >= 0) { |
| 3704 | mCurrentState.displays.removeItemsAt(index); |
| 3705 | } |
| 3706 | |
| 3707 | mPhysicalDisplays.erase(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3708 | } |
| 3709 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3710 | void SurfaceFlinger::dispatchDisplayModeChangeEvent(PhysicalDisplayId displayId, |
| 3711 | const scheduler::FrameRateMode& mode) { |
| 3712 | // TODO(b/255635821): Merge code paths and move to Scheduler. |
| 3713 | const auto onDisplayModeChanged = displayId == mActiveDisplayId |
| 3714 | ? &scheduler::Scheduler::onPrimaryDisplayModeChanged |
| 3715 | : &scheduler::Scheduler::onNonPrimaryDisplayModeChanged; |
| 3716 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 3717 | ((*mScheduler).*onDisplayModeChanged)(scheduler::Cycle::Render, mode); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3718 | } |
| 3719 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3720 | sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3721 | const wp<IBinder>& displayToken, |
| 3722 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3723 | const DisplayDeviceState& state, |
| 3724 | const sp<compositionengine::DisplaySurface>& displaySurface, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3725 | const sp<IGraphicBufferProducer>& producer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3726 | DisplayDeviceCreationArgs creationArgs(sp<SurfaceFlinger>::fromExisting(this), getHwComposer(), |
| 3727 | displayToken, compositionDisplay); |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 3728 | creationArgs.sequenceId = state.sequenceId; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3729 | creationArgs.isSecure = state.isSecure; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3730 | creationArgs.isProtected = state.isProtected; |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3731 | creationArgs.displaySurface = displaySurface; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3732 | creationArgs.hasWideColorGamut = false; |
| 3733 | creationArgs.supportedPerFrameMetadata = 0; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 3734 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3735 | if (const auto physicalIdOpt = PhysicalDisplayId::tryCast(compositionDisplay->getId())) { |
| 3736 | const auto physicalId = *physicalIdOpt; |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3737 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3738 | creationArgs.isPrimary = physicalId == getPrimaryDisplayIdLocked(); |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3739 | creationArgs.refreshRateSelector = |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3740 | FTL_FAKE_GUARD(kMainThreadContext, |
| 3741 | mDisplayModeController.selectorPtrFor(physicalId)); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3742 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3743 | mPhysicalDisplays.get(physicalId) |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 3744 | .transform(&PhysicalDisplay::snapshotRef) |
| 3745 | .transform(ftl::unit_fn([&](const display::DisplaySnapshot& snapshot) { |
| 3746 | for (const auto mode : snapshot.colorModes()) { |
| 3747 | creationArgs.hasWideColorGamut |= ui::isWideColorMode(mode); |
| 3748 | creationArgs.hwcColorModes |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3749 | .emplace(mode, getHwComposer().getRenderIntents(physicalId, mode)); |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 3750 | } |
| 3751 | })); |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 3752 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3753 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3754 | if (const auto id = HalDisplayId::tryCast(compositionDisplay->getId())) { |
| 3755 | getHwComposer().getHdrCapabilities(*id, &creationArgs.hdrCapabilities); |
| 3756 | creationArgs.supportedPerFrameMetadata = getHwComposer().getSupportedPerFrameMetadata(*id); |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 3757 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3758 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 3759 | auto nativeWindowSurface = getFactory().createNativeWindowSurface(producer); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3760 | auto nativeWindow = nativeWindowSurface->getNativeWindow(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3761 | creationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3762 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3763 | // Make sure that composition can never be stalled by a virtual display |
| 3764 | // 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] | 3765 | // here, in case the display is composed entirely by HWC. |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 3766 | if (state.isVirtual()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3767 | nativeWindow->setSwapInterval(nativeWindow.get(), 0); |
| 3768 | } |
| 3769 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 3770 | creationArgs.physicalOrientation = |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3771 | getPhysicalDisplayOrientation(compositionDisplay->getId(), creationArgs.isPrimary); |
| 3772 | ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 3773 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 3774 | creationArgs.initialPowerMode = state.isVirtual() ? hal::PowerMode::ON : hal::PowerMode::OFF; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3775 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3776 | creationArgs.requestedRefreshRate = state.requestedRefreshRate; |
| 3777 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3778 | sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3779 | |
Ady Abraham | 8565ad2 | 2021-06-22 17:45:44 -0700 | [diff] [blame] | 3780 | nativeWindowSurface->preallocateBuffers(); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3781 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3782 | ui::ColorMode defaultColorMode = ui::ColorMode::NATIVE; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 3783 | Dataspace defaultDataSpace = Dataspace::UNKNOWN; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3784 | if (display->hasWideColorGamut()) { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3785 | defaultColorMode = ui::ColorMode::SRGB; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 3786 | defaultDataSpace = Dataspace::V0_SRGB; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3787 | } |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 3788 | display->getCompositionDisplay()->setColorProfile( |
| 3789 | compositionengine::Output::ColorProfile{defaultColorMode, defaultDataSpace, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 3790 | RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3791 | |
| 3792 | if (const auto& physical = state.physical) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3793 | const auto& mode = *physical->activeMode; |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 3794 | mDisplayModeController.setActiveMode(physical->id, mode.getId(), mode.getVsyncRate(), |
| 3795 | mode.getVsyncRate()); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 3796 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3797 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3798 | display->setLayerFilter(makeLayerFilterForDisplay(display->getId(), state.layerStack)); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3799 | display->setProjection(state.orientation, state.layerStackSpaceRect, |
| 3800 | state.orientedDisplaySpaceRect); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3801 | display->setDisplayName(state.displayName); |
Vishnu Nair | a119aaa | 2021-09-24 07:19:35 -0700 | [diff] [blame] | 3802 | display->setFlags(state.flags); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3803 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3804 | return display; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3805 | } |
| 3806 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3807 | void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, |
| 3808 | const DisplayDeviceState& state) { |
dianlujitao | b38ee07 | 2020-05-25 18:23:49 +0800 | [diff] [blame^] | 3809 | #ifdef QCOM_UM_FAMILY |
Ramakant Singh | f7e8191 | 2020-04-11 16:02:43 +0530 | [diff] [blame] | 3810 | bool canAllocateHwcForVDS = false; |
dianlujitao | b38ee07 | 2020-05-25 18:23:49 +0800 | [diff] [blame^] | 3811 | #else |
| 3812 | bool canAllocateHwcForVDS = true; |
| 3813 | #endif |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3814 | ui::Size resolution(0, 0); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3815 | ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN); |
| 3816 | if (state.physical) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3817 | resolution = state.physical->activeMode->getResolution(); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3818 | pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888); |
| 3819 | } else if (state.surface != nullptr) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3820 | int status = state.surface->query(NATIVE_WINDOW_WIDTH, &resolution.width); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3821 | ALOGE_IF(status != NO_ERROR, "Unable to query width (%d)", status); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3822 | status = state.surface->query(NATIVE_WINDOW_HEIGHT, &resolution.height); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3823 | ALOGE_IF(status != NO_ERROR, "Unable to query height (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3824 | int format; |
| 3825 | status = state.surface->query(NATIVE_WINDOW_FORMAT, &format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3826 | ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3827 | pixelFormat = static_cast<ui::PixelFormat>(format); |
dianlujitao | b38ee07 | 2020-05-25 18:23:49 +0800 | [diff] [blame^] | 3828 | #ifdef QCOM_UM_FAMILY |
Rheygine Medel | 9be9d5f | 2022-05-25 19:20:55 -0700 | [diff] [blame] | 3829 | // Check if VDS is allowed to use HWC |
| 3830 | size_t maxVirtualDisplaySize = getHwComposer().getMaxVirtualDisplayDimension(); |
| 3831 | if (maxVirtualDisplaySize == 0 || ((uint64_t)resolution.width <= maxVirtualDisplaySize && |
| 3832 | (uint64_t)resolution.height <= maxVirtualDisplaySize)) { |
| 3833 | uint64_t usage = 0; |
| 3834 | // Replace with native_window_get_consumer_usage ? |
| 3835 | status = state .surface->getConsumerUsage(&usage); |
| 3836 | ALOGW_IF(status != NO_ERROR, "Unable to query usage (%d)", status); |
| 3837 | if ((status == NO_ERROR) && canAllocateHwcDisplayIdForVDS(usage)) { |
| 3838 | canAllocateHwcForVDS = true; |
Ramakant Singh | f7e8191 | 2020-04-11 16:02:43 +0530 | [diff] [blame] | 3839 | } |
| 3840 | } |
dianlujitao | b38ee07 | 2020-05-25 18:23:49 +0800 | [diff] [blame^] | 3841 | #endif |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3842 | } else { |
| 3843 | // Virtual displays without a surface are dormant: |
| 3844 | // they have external state (layer stack, projection, |
| 3845 | // etc.) but no internal state (i.e. a DisplayDevice). |
| 3846 | return; |
| 3847 | } |
| 3848 | |
| 3849 | compositionengine::DisplayCreationArgsBuilder builder; |
| 3850 | if (const auto& physical = state.physical) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3851 | builder.setId(physical->id); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3852 | } else { |
Rajat Yadav | bc0c03d | 2021-07-05 19:32:01 +0530 | [diff] [blame] | 3853 | builder.setId(acquireVirtualDisplay(resolution, pixelFormat, canAllocateHwcForVDS)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3854 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3855 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3856 | builder.setPixels(resolution); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3857 | builder.setIsSecure(state.isSecure); |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3858 | builder.setIsProtected(state.isProtected); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 3859 | builder.setPowerAdvisor(mPowerAdvisor.get()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3860 | builder.setName(state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3861 | auto compositionDisplay = getCompositionEngine().createDisplay(builder.build()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3862 | compositionDisplay->setLayerCachingEnabled(mLayerCachingEnabled); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3863 | |
| 3864 | sp<compositionengine::DisplaySurface> displaySurface; |
| 3865 | sp<IGraphicBufferProducer> producer; |
| 3866 | sp<IGraphicBufferProducer> bqProducer; |
| 3867 | sp<IGraphicBufferConsumer> bqConsumer; |
| 3868 | getFactory().createBufferQueue(&bqProducer, &bqConsumer, /*consumerIsSurfaceFlinger =*/false); |
| 3869 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3870 | if (state.isVirtual()) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3871 | const auto displayId = VirtualDisplayId::tryCast(compositionDisplay->getId()); |
| 3872 | LOG_FATAL_IF(!displayId); |
| 3873 | auto surface = sp<VirtualDisplaySurface>::make(getHwComposer(), *displayId, state.surface, |
Ramakant Singh | f7e8191 | 2020-04-11 16:02:43 +0530 | [diff] [blame] | 3874 | bqProducer, bqConsumer, state.displayName, |
| 3875 | state.isSecure); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3876 | displaySurface = surface; |
| 3877 | producer = std::move(surface); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3878 | } else { |
| 3879 | ALOGE_IF(state.surface != nullptr, |
| 3880 | "adding a supported display, but rendering " |
| 3881 | "surface is provided (%p), ignoring it", |
| 3882 | state.surface.get()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3883 | const auto displayId = PhysicalDisplayId::tryCast(compositionDisplay->getId()); |
| 3884 | LOG_FATAL_IF(!displayId); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3885 | displaySurface = |
| 3886 | sp<FramebufferSurface>::make(getHwComposer(), *displayId, bqConsumer, |
| 3887 | state.physical->activeMode->getResolution(), |
| 3888 | ui::Size(maxGraphicsWidth, maxGraphicsHeight)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3889 | producer = bqProducer; |
| 3890 | } |
| 3891 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3892 | LOG_FATAL_IF(!displaySurface); |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3893 | auto display = setupNewDisplayDeviceInternal(displayToken, std::move(compositionDisplay), state, |
| 3894 | displaySurface, producer); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3895 | |
| 3896 | if (mScheduler && !display->isVirtual()) { |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3897 | // TODO(b/241285876): Annotate `processDisplayAdded` instead. |
| 3898 | ftl::FakeGuard guard(kMainThreadContext); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3899 | |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3900 | // For hotplug reconnect, renew the registration since display modes have been reloaded. |
Dominik Laskowski | 575aa72 | 2024-06-17 11:03:30 -0400 | [diff] [blame] | 3901 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector(), |
| 3902 | mActiveDisplayId); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3903 | } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3904 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3905 | if (display->isVirtual()) { |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 3906 | display->adjustRefreshRate(mScheduler->getPacesetterRefreshRate()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3909 | mDisplays.try_emplace(displayToken, std::move(display)); |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3910 | |
| 3911 | // For an external display, loadDisplayModes already attempted to select the same mode |
| 3912 | // as DM, but SF still needs to be updated to match. |
| 3913 | // TODO (b/318534874): Let DM decide the initial mode. |
| 3914 | if (const auto& physical = state.physical; |
| 3915 | mScheduler && physical && FlagManager::getInstance().connected_display()) { |
| 3916 | const bool isInternalDisplay = mPhysicalDisplays.get(physical->id) |
| 3917 | .transform(&PhysicalDisplay::isInternal) |
| 3918 | .value_or(false); |
| 3919 | |
| 3920 | if (!isInternalDisplay) { |
| 3921 | auto activeModePtr = physical->activeMode; |
| 3922 | const auto fps = activeModePtr->getPeakFps(); |
| 3923 | |
| 3924 | setDesiredMode( |
| 3925 | {.mode = scheduler::FrameRateMode{fps, |
| 3926 | ftl::as_non_null(std::move(activeModePtr))}, |
| 3927 | .emitEvent = false, |
| 3928 | .force = true}); |
| 3929 | } |
| 3930 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3931 | } |
| 3932 | |
| 3933 | void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3934 | auto display = getDisplayDeviceLocked(displayToken); |
| 3935 | if (display) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3936 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3937 | |
| 3938 | if (display->isVirtual()) { |
| 3939 | releaseVirtualDisplay(display->getVirtualId()); |
| 3940 | } else { |
Dominik Laskowski | 575aa72 | 2024-06-17 11:03:30 -0400 | [diff] [blame] | 3941 | mScheduler->unregisterDisplay(display->getPhysicalId(), mActiveDisplayId); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3942 | } |
| 3943 | } |
| 3944 | |
| 3945 | mDisplays.erase(displayToken); |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3946 | |
| 3947 | if (display && display->isVirtual()) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 3948 | static_cast<void>(mScheduler->schedule([display = std::move(display)] { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3949 | // Destroy the display without holding the mStateLock. |
| 3950 | // This is a temporary solution until we can manage transaction queues without |
| 3951 | // holding the mStateLock. |
| 3952 | // With blast, the IGBP that is passed to the VirtualDisplaySurface is owned by the |
| 3953 | // client. When the IGBP is disconnected, its buffer cache in SF will be cleared |
| 3954 | // via SurfaceComposerClient::doUncacheBufferTransaction. This call from the client |
| 3955 | // ends up running on the main thread causing a deadlock since setTransactionstate |
| 3956 | // will try to acquire the mStateLock. Instead we extend the lifetime of |
| 3957 | // DisplayDevice and destroy it in the main thread without holding the mStateLock. |
| 3958 | // The display will be disconnected and removed from the mDisplays list so it will |
| 3959 | // not be accessible. |
| 3960 | })); |
| 3961 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3962 | } |
| 3963 | |
| 3964 | void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, |
| 3965 | const DisplayDeviceState& currentState, |
| 3966 | const DisplayDeviceState& drawingState) { |
| 3967 | const sp<IBinder> currentBinder = IInterface::asBinder(currentState.surface); |
| 3968 | const sp<IBinder> drawingBinder = IInterface::asBinder(drawingState.surface); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3969 | |
| 3970 | // Recreate the DisplayDevice if the surface or sequence ID changed. |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3971 | if (currentBinder != drawingBinder || currentState.sequenceId != drawingState.sequenceId) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3972 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3973 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3974 | if (display->isVirtual()) { |
| 3975 | releaseVirtualDisplay(display->getVirtualId()); |
| 3976 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3977 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3978 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3979 | mDisplays.erase(displayToken); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3980 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3981 | if (const auto& physical = currentState.physical) { |
| 3982 | getHwComposer().allocatePhysicalDisplay(physical->hwcDisplayId, physical->id); |
| 3983 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3984 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3985 | processDisplayAdded(displayToken, currentState); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3986 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3987 | if (currentState.physical) { |
Marin Shalamanov | 4c5e301 | 2020-06-04 21:41:42 +0200 | [diff] [blame] | 3988 | const auto display = getDisplayDeviceLocked(displayToken); |
Robert Horvath | dce110a | 2022-09-16 11:08:47 +0200 | [diff] [blame] | 3989 | if (!mSkipPowerOnForQuiescent) { |
| 3990 | setPowerModeInternal(display, hal::PowerMode::ON); |
| 3991 | } |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3992 | |
| 3993 | // TODO(b/175678251) Call a listener instead. |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 3994 | if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) { |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 3995 | const Fps refreshRate = |
| 3996 | mDisplayModeController.getActiveMode(display->getPhysicalId()).fps; |
| 3997 | mScheduler->resetPhaseConfiguration(refreshRate); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3998 | } |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3999 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 4000 | return; |
| 4001 | } |
| 4002 | |
| 4003 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 4004 | if (currentState.layerStack != drawingState.layerStack) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 4005 | display->setLayerFilter( |
| 4006 | makeLayerFilterForDisplay(display->getId(), currentState.layerStack)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 4007 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 4008 | if (currentState.flags != drawingState.flags) { |
| 4009 | display->setFlags(currentState.flags); |
| 4010 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 4011 | if ((currentState.orientation != drawingState.orientation) || |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 4012 | (currentState.layerStackSpaceRect != drawingState.layerStackSpaceRect) || |
| 4013 | (currentState.orientedDisplaySpaceRect != drawingState.orientedDisplaySpaceRect)) { |
| 4014 | display->setProjection(currentState.orientation, currentState.layerStackSpaceRect, |
| 4015 | currentState.orientedDisplaySpaceRect); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 4016 | if (display->getId() == mActiveDisplayId) { |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 4017 | mActiveDisplayTransformHint = display->getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 4018 | sActiveDisplayRotationFlags = |
| 4019 | ui::Transform::toRotationFlags(display->getOrientation()); |
Arthur Hung | b6aa9a0 | 2021-06-09 14:23:01 +0800 | [diff] [blame] | 4020 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 4021 | } |
| 4022 | if (currentState.width != drawingState.width || |
| 4023 | currentState.height != drawingState.height) { |
| 4024 | display->setDisplaySize(currentState.width, currentState.height); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 4025 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 4026 | if (display->getId() == mActiveDisplayId) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 4027 | onActiveDisplaySizeChanged(*display); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 4028 | } |
| 4029 | } |
| 4030 | } |
| 4031 | } |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 4032 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 4033 | void SurfaceFlinger::processDisplayChangesLocked() { |
| 4034 | // here we take advantage of Vector's copy-on-write semantics to |
| 4035 | // improve performance by skipping the transaction entirely when |
| 4036 | // know that the lists are identical |
| 4037 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays); |
| 4038 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays); |
| 4039 | if (!curr.isIdenticalTo(draw)) { |
| 4040 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4041 | mUpdateInputInfo = true; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 4042 | |
Dominik Laskowski | 01f191c | 2024-01-29 11:51:23 -0500 | [diff] [blame] | 4043 | // Apply the current color matrix to any added or changed display. |
| 4044 | mCurrentState.colorMatrixChanged = true; |
| 4045 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 4046 | // find the displays that were removed |
| 4047 | // (ie: in drawing state but not in current state) |
| 4048 | // also handle displays that changed |
| 4049 | // (ie: displays that are in both lists) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 4050 | for (size_t i = 0; i < draw.size(); i++) { |
| 4051 | const wp<IBinder>& displayToken = draw.keyAt(i); |
| 4052 | const ssize_t j = curr.indexOfKey(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 4053 | if (j < 0) { |
| 4054 | // in drawing state but not in current state |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 4055 | processDisplayRemoved(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 4056 | } else { |
| 4057 | // this display is in both lists. see if something changed. |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 4058 | const DisplayDeviceState& currentState = curr[j]; |
| 4059 | const DisplayDeviceState& drawingState = draw[i]; |
| 4060 | processDisplayChanged(displayToken, currentState, drawingState); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 4061 | } |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 4062 | } |
| 4063 | |
| 4064 | // find displays that were added |
| 4065 | // (ie: in current state but not in drawing state) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 4066 | for (size_t i = 0; i < curr.size(); i++) { |
| 4067 | const wp<IBinder>& displayToken = curr.keyAt(i); |
| 4068 | if (draw.indexOfKey(displayToken) < 0) { |
| 4069 | processDisplayAdded(displayToken, curr[i]); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 4070 | } |
| 4071 | } |
| 4072 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 4073 | |
| 4074 | mDrawingState.displays = mCurrentState.displays; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 4075 | } |
| 4076 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4077 | void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { |
| 4078 | // Commit display transactions. |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 4079 | const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4080 | mFrontEndDisplayInfosChanged = displayTransactionNeeded; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4081 | if (displayTransactionNeeded && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 4082 | processDisplayChangesLocked(); |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 4083 | mFrontEndDisplayInfos.clear(); |
| 4084 | for (const auto& [_, display] : mDisplays) { |
| 4085 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 4086 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 4087 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4088 | mForceTransactionDisplayChange = displayTransactionNeeded; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4089 | |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 4090 | if (mSomeChildrenChanged) { |
| 4091 | mVisibleRegionsDirty = true; |
| 4092 | mSomeChildrenChanged = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4093 | mUpdateInputInfo = true; |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 4094 | } |
| 4095 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4096 | // Update transform hint. |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 4097 | if (transactionFlags & (eTransformHintUpdateNeeded | eDisplayTransactionNeeded)) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4098 | // 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] | 4099 | // |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 4100 | // 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] | 4101 | // the hint is set before we acquire a buffer from the surface texture. |
| 4102 | // |
| 4103 | // NOTE: layer transactions have taken place already, so we use their |
| 4104 | // drawing state. However, SurfaceFlinger's own transaction has not |
| 4105 | // happened yet, so we must use the current state layer list |
| 4106 | // (soon to become the drawing state list). |
| 4107 | // |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 4108 | sp<const DisplayDevice> hintDisplay; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4109 | ui::LayerStack layerStack; |
| 4110 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 4111 | mCurrentState.traverse([&](Layer* layer) REQUIRES(mStateLock) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 4112 | // NOTE: we rely on the fact that layers are sorted by |
| 4113 | // layerStack first (so we don't have to traverse the list |
| 4114 | // of displays for every layer). |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4115 | if (const auto filter = layer->getOutputFilter(); layerStack != filter.layerStack) { |
| 4116 | layerStack = filter.layerStack; |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 4117 | hintDisplay = nullptr; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4118 | |
| 4119 | // Find the display that includes the layer. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 4120 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4121 | if (!display->getCompositionDisplay()->includesLayer(filter)) { |
| 4122 | continue; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 4123 | } |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4124 | |
| 4125 | // Pick the primary display if another display mirrors the layer. |
| 4126 | if (hintDisplay) { |
| 4127 | hintDisplay = nullptr; |
| 4128 | break; |
| 4129 | } |
| 4130 | |
| 4131 | hintDisplay = display; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 4132 | } |
| 4133 | } |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 4134 | |
Melody Hsu | 9af3070 | 2024-04-17 18:23:43 +0000 | [diff] [blame] | 4135 | if (hintDisplay) { |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 4136 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 4137 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4138 | }); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 4139 | } |
| 4140 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4141 | if (mLayersAdded) { |
| 4142 | mLayersAdded = false; |
| 4143 | // Layers have been added. |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 4144 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4145 | mUpdateInputInfo = true; |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 4146 | } |
| 4147 | |
| 4148 | // some layers might have been removed, so |
| 4149 | // we need to update the regions they're exposing. |
| 4150 | if (mLayersRemoved) { |
| 4151 | mLayersRemoved = false; |
| 4152 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4153 | mUpdateInputInfo = true; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4154 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4155 | if (mLayersPendingRemoval.indexOf(sp<Layer>::fromExisting(layer)) >= 0) { |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 4156 | // this layer is not visible anymore |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4157 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 4158 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4159 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 4160 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4161 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4162 | } |
| 4163 | |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 4164 | if (transactionFlags & eInputInfoUpdateNeeded) { |
| 4165 | mUpdateInputInfo = true; |
| 4166 | } |
| 4167 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4168 | doCommitTransactions(); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 4169 | } |
| 4170 | |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4171 | void SurfaceFlinger::updateInputFlinger(VsyncId vsyncId, TimePoint frameTime) { |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4172 | if (!mInputFlinger || (!mUpdateInputInfo && mInputWindowCommands.empty())) { |
Vishnu Nair | 42a27b5 | 2021-11-18 15:35:22 -0800 | [diff] [blame] | 4173 | return; |
| 4174 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4175 | ATRACE_CALL(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4176 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4177 | std::vector<WindowInfo> windowInfos; |
| 4178 | std::vector<DisplayInfo> displayInfos; |
| 4179 | bool updateWindowInfo = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4180 | if (mUpdateInputInfo) { |
| 4181 | mUpdateInputInfo = false; |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4182 | updateWindowInfo = true; |
| 4183 | buildWindowInfos(windowInfos, displayInfos); |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4184 | } |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4185 | |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4186 | std::unordered_set<int32_t> visibleWindowIds; |
| 4187 | for (WindowInfo& windowInfo : windowInfos) { |
| 4188 | if (!windowInfo.inputConfig.test(WindowInfo::InputConfig::NOT_VISIBLE)) { |
| 4189 | visibleWindowIds.insert(windowInfo.id); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4190 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4191 | } |
| 4192 | bool visibleWindowsChanged = false; |
| 4193 | if (visibleWindowIds != mVisibleWindowIds) { |
| 4194 | visibleWindowsChanged = true; |
| 4195 | mVisibleWindowIds = std::move(visibleWindowIds); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4196 | } |
| 4197 | |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 4198 | BackgroundExecutor::getInstance().sendCallbacks({[updateWindowInfo, |
| 4199 | windowInfos = std::move(windowInfos), |
| 4200 | displayInfos = std::move(displayInfos), |
| 4201 | inputWindowCommands = |
| 4202 | std::move(mInputWindowCommands), |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4203 | inputFlinger = mInputFlinger, this, |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4204 | visibleWindowsChanged, vsyncId, frameTime]() { |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4205 | ATRACE_NAME("BackgroundExecutor::updateInputFlinger"); |
| 4206 | if (updateWindowInfo) { |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 4207 | mWindowInfosListenerInvoker |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4208 | ->windowInfosChanged(gui::WindowInfosUpdate{std::move(windowInfos), |
| 4209 | std::move(displayInfos), |
| 4210 | ftl::to_underlying(vsyncId), |
| 4211 | frameTime.ns()}, |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4212 | std::move( |
| 4213 | inputWindowCommands.windowInfosReportedListeners), |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4214 | /* forceImmediateCall= */ visibleWindowsChanged || |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4215 | !inputWindowCommands.focusRequests.empty()); |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 4216 | } else { |
| 4217 | // If there are listeners but no changes to input windows, call the listeners |
| 4218 | // immediately. |
| 4219 | for (const auto& listener : inputWindowCommands.windowInfosReportedListeners) { |
| 4220 | if (IInterface::asBinder(listener)->isBinderAlive()) { |
| 4221 | listener->onWindowInfosReported(); |
| 4222 | } |
| 4223 | } |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4224 | } |
| 4225 | for (const auto& focusRequest : inputWindowCommands.focusRequests) { |
| 4226 | inputFlinger->setFocusedWindow(focusRequest); |
| 4227 | } |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 4228 | }}); |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 4229 | |
Arthur Hung | 6cbb975 | 2019-09-05 16:38:18 +0800 | [diff] [blame] | 4230 | mInputWindowCommands.clear(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4231 | } |
| 4232 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4233 | void SurfaceFlinger::persistDisplayBrightness(bool needsComposite) { |
| 4234 | const bool supportsDisplayBrightnessCommand = getHwComposer().getComposer()->isSupported( |
| 4235 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 4236 | if (!supportsDisplayBrightnessCommand) { |
| 4237 | return; |
| 4238 | } |
| 4239 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4240 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4241 | if (const auto brightness = display->getStagedBrightness(); brightness) { |
| 4242 | if (!needsComposite) { |
| 4243 | const status_t error = |
| 4244 | getHwComposer() |
| 4245 | .setDisplayBrightness(display->getPhysicalId(), *brightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 4246 | display->getCompositionDisplay() |
| 4247 | ->getState() |
| 4248 | .displayBrightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4249 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 4250 | .applyImmediately = true}) |
| 4251 | .get(); |
| 4252 | |
| 4253 | ALOGE_IF(error != NO_ERROR, |
| 4254 | "Error setting display brightness for display %s: %d (%s)", |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 4255 | to_string(display->getId()).c_str(), error, strerror(error)); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4256 | } |
| 4257 | display->persistBrightness(needsComposite); |
| 4258 | } |
| 4259 | } |
| 4260 | } |
| 4261 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4262 | void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, |
| 4263 | std::vector<DisplayInfo>& outDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4264 | static size_t sNumWindowInfos = 0; |
| 4265 | outWindowInfos.reserve(sNumWindowInfos); |
| 4266 | sNumWindowInfos = 0; |
| 4267 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4268 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4269 | mLayerSnapshotBuilder.forEachInputSnapshot( |
| 4270 | [&outWindowInfos](const frontend::LayerSnapshot& snapshot) { |
| 4271 | outWindowInfos.push_back(snapshot.inputInfo); |
| 4272 | }); |
| 4273 | } else { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4274 | mDrawingState.traverseInReverseZOrder([&](Layer* layer) FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4275 | if (!layer->needsInputInfo()) return; |
| 4276 | const auto opt = |
| 4277 | mFrontEndDisplayInfos.get(layer->getLayerStack()) |
| 4278 | .transform([](const frontend::DisplayInfo& info) { |
| 4279 | return Layer::InputDisplayArgs{&info.transform, info.isSecure}; |
| 4280 | }); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4281 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4282 | outWindowInfos.push_back(layer->fillInputInfo(opt.value_or(Layer::InputDisplayArgs{}))); |
| 4283 | }); |
| 4284 | } |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 4285 | |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4286 | sNumWindowInfos = outWindowInfos.size(); |
| 4287 | |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 4288 | outDisplayInfos.reserve(mFrontEndDisplayInfos.size()); |
| 4289 | for (const auto& [_, info] : mFrontEndDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4290 | outDisplayInfos.push_back(info.info); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 4291 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 4292 | } |
| 4293 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 4294 | void SurfaceFlinger::updateCursorAsync() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4295 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4296 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 4297 | if (HalDisplayId::tryCast(display->getId())) { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4298 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 4299 | } |
| 4300 | } |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 4301 | |
| 4302 | constexpr bool kCursorOnly = true; |
| 4303 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4304 | mCompositionEngine->updateCursorAsync(refreshArgs); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4305 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4306 | } |
| 4307 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 4308 | void SurfaceFlinger::requestHardwareVsync(PhysicalDisplayId displayId, bool enable) { |
| 4309 | getHwComposer().setVsyncEnabled(displayId, enable ? hal::Vsync::ENABLE : hal::Vsync::DISABLE); |
| 4310 | } |
| 4311 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4312 | void SurfaceFlinger::requestDisplayModes(std::vector<display::DisplayModeRequest> modeRequests) { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 4313 | if (mBootStage != BootStage::FINISHED) { |
| 4314 | ALOGV("Currently in the boot stage, skipping display mode changes"); |
| 4315 | return; |
| 4316 | } |
| 4317 | |
| 4318 | ATRACE_CALL(); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4319 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 4320 | // If this is called from the main thread mStateLock must be locked before |
| 4321 | // 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] | 4322 | // Scheduler::chooseRefreshRateForContent |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 4323 | |
| 4324 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
Marin Shalamanov | a63f9ae | 2021-11-03 15:05:16 +0100 | [diff] [blame] | 4325 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4326 | for (auto& request : modeRequests) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4327 | const auto& modePtr = request.mode.modePtr; |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 4328 | |
| 4329 | const auto displayId = modePtr->getPhysicalDisplayId(); |
| 4330 | const auto display = getDisplayDeviceLocked(displayId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4331 | |
| 4332 | if (!display) continue; |
| 4333 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4334 | if (display->refreshRateSelector().isModeAllowed(request.mode)) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 4335 | setDesiredMode(std::move(request)); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4336 | } else { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 4337 | ALOGV("%s: Mode %d is disallowed for display %s", __func__, |
| 4338 | ftl::to_underlying(modePtr->getId()), to_string(displayId).c_str()); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4339 | } |
| 4340 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 4341 | } |
| 4342 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 4343 | void SurfaceFlinger::triggerOnFrameRateOverridesChanged() { |
| 4344 | PhysicalDisplayId displayId = [&]() { |
| 4345 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 4346 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 4347 | }(); |
| 4348 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4349 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 4350 | } |
| 4351 | |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 4352 | void SurfaceFlinger::notifyCpuLoadUp() { |
| 4353 | mPowerAdvisor->notifyCpuLoadUp(); |
| 4354 | } |
| 4355 | |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 4356 | void SurfaceFlinger::onChoreographerAttached() { |
| 4357 | ATRACE_CALL(); |
| 4358 | if (mLayerLifecycleManagerEnabled) { |
| 4359 | mUpdateAttachedChoreographer = true; |
| 4360 | scheduleCommit(FrameHint::kNone); |
| 4361 | } |
| 4362 | } |
| 4363 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4364 | void SurfaceFlinger::onExpectedPresentTimePosted(TimePoint expectedPresentTime, |
| 4365 | ftl::NonNull<DisplayModePtr> modePtr, |
| 4366 | Fps renderRate) { |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4367 | const auto vsyncPeriod = modePtr->getVsyncRate().getPeriod(); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4368 | const auto timeoutOpt = [&]() -> std::optional<Period> { |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4369 | const auto vrrConfig = modePtr->getVrrConfig(); |
| 4370 | if (!vrrConfig) return std::nullopt; |
| 4371 | |
| 4372 | const auto notifyExpectedPresentConfig = |
| 4373 | modePtr->getVrrConfig()->notifyExpectedPresentConfig; |
| 4374 | if (!notifyExpectedPresentConfig) return std::nullopt; |
ramindani | cbd7a6d | 2023-12-19 16:00:30 -0800 | [diff] [blame] | 4375 | return Period::fromNs(notifyExpectedPresentConfig->timeoutNs); |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4376 | }(); |
| 4377 | |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4378 | notifyExpectedPresentIfRequired(modePtr->getPhysicalDisplayId(), vsyncPeriod, |
| 4379 | expectedPresentTime, renderRate, timeoutOpt); |
| 4380 | } |
| 4381 | |
| 4382 | void SurfaceFlinger::notifyExpectedPresentIfRequired(PhysicalDisplayId displayId, |
| 4383 | Period vsyncPeriod, |
| 4384 | TimePoint expectedPresentTime, |
| 4385 | Fps frameInterval, |
| 4386 | std::optional<Period> timeoutOpt) { |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4387 | auto& data = mNotifyExpectedPresentMap[displayId]; |
| 4388 | const auto lastExpectedPresentTimestamp = data.lastExpectedPresentTimestamp; |
| 4389 | const auto lastFrameInterval = data.lastFrameInterval; |
| 4390 | data.lastFrameInterval = frameInterval; |
| 4391 | data.lastExpectedPresentTimestamp = expectedPresentTime; |
| 4392 | const auto threshold = Duration::fromNs(vsyncPeriod.ns() / 2); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4393 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4394 | const constexpr nsecs_t kOneSecondNs = |
| 4395 | std::chrono::duration_cast<std::chrono::nanoseconds>(1s).count(); |
| 4396 | const auto timeout = |
| 4397 | Period::fromNs(timeoutOpt && timeoutOpt->ns() > 0 ? timeoutOpt->ns() : kOneSecondNs); |
| 4398 | const bool frameIntervalIsOnCadence = |
| 4399 | isFrameIntervalOnCadence(expectedPresentTime, lastExpectedPresentTimestamp, |
| 4400 | lastFrameInterval, timeout, threshold); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4401 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4402 | const bool expectedPresentWithinTimeout = |
| 4403 | isExpectedPresentWithinTimeout(expectedPresentTime, lastExpectedPresentTimestamp, |
| 4404 | timeoutOpt, threshold); |
| 4405 | if (expectedPresentWithinTimeout && frameIntervalIsOnCadence) { |
| 4406 | return; |
| 4407 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4408 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4409 | auto hintStatus = data.hintStatus.load(); |
| 4410 | if (!expectedPresentWithinTimeout) { |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4411 | if ((hintStatus != NotifyExpectedPresentHintStatus::Sent && |
| 4412 | hintStatus != NotifyExpectedPresentHintStatus::ScheduleOnTx) || |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4413 | (timeoutOpt && timeoutOpt->ns() == 0)) { |
| 4414 | // Send the hint immediately if timeout, as the hint gets |
| 4415 | // delayed otherwise, as the frame is scheduled close |
| 4416 | // to the actual present. |
| 4417 | if (data.hintStatus |
| 4418 | .compare_exchange_strong(hintStatus, |
| 4419 | NotifyExpectedPresentHintStatus::ScheduleOnTx)) { |
| 4420 | scheduleNotifyExpectedPresentHint(displayId); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4421 | return; |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4422 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4423 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4424 | } |
| 4425 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4426 | if (hintStatus == NotifyExpectedPresentHintStatus::Sent && |
| 4427 | data.hintStatus.compare_exchange_strong(hintStatus, |
| 4428 | NotifyExpectedPresentHintStatus::ScheduleOnTx)) { |
| 4429 | return; |
| 4430 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4431 | if (hintStatus != NotifyExpectedPresentHintStatus::Start) { |
| 4432 | return; |
| 4433 | } |
| 4434 | data.hintStatus.store(NotifyExpectedPresentHintStatus::ScheduleOnPresent); |
| 4435 | mScheduler->scheduleFrame(); |
| 4436 | } |
| 4437 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4438 | void SurfaceFlinger::scheduleNotifyExpectedPresentHint(PhysicalDisplayId displayId, |
| 4439 | VsyncId vsyncId) { |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4440 | auto itr = mNotifyExpectedPresentMap.find(displayId); |
| 4441 | if (itr == mNotifyExpectedPresentMap.end()) { |
| 4442 | return; |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4443 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4444 | |
| 4445 | const char* const whence = __func__; |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4446 | const auto sendHint = [=, this]() { |
| 4447 | auto& data = mNotifyExpectedPresentMap.at(displayId); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4448 | TimePoint expectedPresentTime = data.lastExpectedPresentTimestamp; |
| 4449 | if (ftl::to_underlying(vsyncId) != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 4450 | const auto predictionOpt = mFrameTimeline->getTokenManager()->getPredictionsForToken( |
| 4451 | ftl::to_underlying(vsyncId)); |
| 4452 | const auto expectedPresentTimeOnPredictor = TimePoint::fromNs( |
| 4453 | predictionOpt ? predictionOpt->presentTime : expectedPresentTime.ns()); |
| 4454 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 4455 | const auto expectedPresentTimeOnScheduler = scheduledFrameResultOpt.has_value() |
| 4456 | ? scheduledFrameResultOpt->vsyncTime |
| 4457 | : TimePoint::fromNs(0); |
| 4458 | expectedPresentTime = |
| 4459 | std::max(expectedPresentTimeOnPredictor, expectedPresentTimeOnScheduler); |
| 4460 | } |
| 4461 | |
| 4462 | if (expectedPresentTime < TimePoint::now()) { |
| 4463 | expectedPresentTime = |
| 4464 | mScheduler->getVsyncSchedule()->vsyncDeadlineAfter(TimePoint::now()); |
| 4465 | if (mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration > |
| 4466 | mScheduler->getVsyncSchedule(displayId)->period()) { |
| 4467 | expectedPresentTime += mScheduler->getVsyncSchedule(displayId)->period(); |
| 4468 | } |
| 4469 | } |
| 4470 | const auto status = getHwComposer().notifyExpectedPresent(displayId, expectedPresentTime, |
| 4471 | data.lastFrameInterval); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4472 | if (status != NO_ERROR) { |
| 4473 | ALOGE("%s failed to notifyExpectedPresentHint for display %" PRId64, whence, |
| 4474 | displayId.value); |
| 4475 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4476 | }; |
| 4477 | |
| 4478 | if (itr->second.hintStatus == NotifyExpectedPresentHintStatus::ScheduleOnTx) { |
| 4479 | return static_cast<void>(mScheduler->schedule([=, |
| 4480 | this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 4481 | auto& data = mNotifyExpectedPresentMap.at(displayId); |
| 4482 | auto scheduleHintOnTx = NotifyExpectedPresentHintStatus::ScheduleOnTx; |
| 4483 | if (data.hintStatus.compare_exchange_strong(scheduleHintOnTx, |
| 4484 | NotifyExpectedPresentHintStatus::Sent)) { |
| 4485 | sendHint(); |
| 4486 | } |
| 4487 | })); |
| 4488 | } |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4489 | auto scheduleHintOnPresent = NotifyExpectedPresentHintStatus::ScheduleOnPresent; |
| 4490 | if (itr->second.hintStatus.compare_exchange_strong(scheduleHintOnPresent, |
| 4491 | NotifyExpectedPresentHintStatus::Sent)) { |
| 4492 | sendHint(); |
| 4493 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4494 | } |
| 4495 | |
| 4496 | void SurfaceFlinger::sendNotifyExpectedPresentHint(PhysicalDisplayId displayId) { |
| 4497 | if (auto itr = mNotifyExpectedPresentMap.find(displayId); |
| 4498 | itr == mNotifyExpectedPresentMap.end() || |
| 4499 | itr->second.hintStatus != NotifyExpectedPresentHintStatus::ScheduleOnPresent) { |
| 4500 | return; |
| 4501 | } |
| 4502 | scheduleNotifyExpectedPresentHint(displayId); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4503 | } |
| 4504 | |
Ady Abraham | 14beed7 | 2024-05-15 17:16:45 -0700 | [diff] [blame] | 4505 | void SurfaceFlinger::onCommitNotComposited(PhysicalDisplayId pacesetterDisplayId) { |
| 4506 | if (FlagManager::getInstance().commit_not_composited()) { |
| 4507 | mFrameTimeline->onCommitNotComposited(); |
| 4508 | } |
| 4509 | } |
| 4510 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 4511 | void SurfaceFlinger::initScheduler(const sp<const DisplayDevice>& display) { |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4512 | using namespace scheduler; |
| 4513 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 4514 | LOG_ALWAYS_FATAL_IF(mScheduler); |
| 4515 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4516 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 4517 | const Fps activeRefreshRate = activeMode.fps; |
Ady Abraham | 9e16a48 | 2019-12-03 17:19:41 -0800 | [diff] [blame] | 4518 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4519 | FeatureFlags features; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4520 | |
Ady Abraham | 3f84c50 | 2023-11-30 18:18:06 -0800 | [diff] [blame] | 4521 | const auto defaultContentDetectionValue = |
| 4522 | FlagManager::getInstance().enable_fro_dependent_features() && |
| 4523 | sysprop::enable_frame_rate_override(true); |
| 4524 | if (sysprop::use_content_detection_for_refresh_rate(defaultContentDetectionValue)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4525 | features |= Feature::kContentDetection; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 4526 | if (FlagManager::getInstance().enable_small_area_detection()) { |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 4527 | features |= Feature::kSmallDirtyContentDetection; |
| 4528 | } |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4529 | } |
| 4530 | if (base::GetBoolProperty("debug.sf.show_predicted_vsync"s, false)) { |
| 4531 | features |= Feature::kTracePredictedVsync; |
| 4532 | } |
| 4533 | if (!base::GetBoolProperty("debug.sf.vsync_reactor_ignore_present_fences"s, false) && |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 4534 | mHasReliablePresentFences) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4535 | features |= Feature::kPresentFences; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4536 | } |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4537 | if (display->refreshRateSelector().kernelIdleTimerController()) { |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4538 | features |= Feature::kKernelIdleTimer; |
| 4539 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4540 | if (mBackpressureGpuComposition) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4541 | features |= Feature::kBackpressureGpuComposition; |
| 4542 | } |
Leon Scroggins III | 0bd0d4c | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 4543 | if (getHwComposer().getComposer()->isSupported( |
| 4544 | Hwc2::Composer::OptionalFeature::ExpectedPresentTime)) { |
| 4545 | features |= Feature::kExpectedPresentTime; |
| 4546 | } |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4547 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4548 | mScheduler = std::make_unique<Scheduler>(static_cast<ICompositor&>(*this), |
| 4549 | static_cast<ISchedulerCallback&>(*this), features, |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4550 | getFactory(), activeRefreshRate, *mTimeStats); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4551 | |
| 4552 | // The pacesetter must be registered before EventThread creation below. |
Dominik Laskowski | 575aa72 | 2024-06-17 11:03:30 -0400 | [diff] [blame] | 4553 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector(), |
| 4554 | mActiveDisplayId); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4555 | if (FlagManager::getInstance().vrr_config()) { |
Ady Abraham | ee6365b | 2024-03-06 14:31:45 -0800 | [diff] [blame] | 4556 | mScheduler->setRenderRate(display->getPhysicalId(), activeMode.fps, |
| 4557 | /*applyImmediately*/ true); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4558 | } |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4559 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 4560 | const auto configs = mScheduler->getVsyncConfiguration().getCurrentConfigs(); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4561 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4562 | mScheduler->createEventThread(scheduler::Cycle::Render, mFrameTimeline->getTokenManager(), |
| 4563 | /* workDuration */ configs.late.appWorkDuration, |
| 4564 | /* readyDuration */ configs.late.sfWorkDuration); |
| 4565 | mScheduler->createEventThread(scheduler::Cycle::LastComposite, |
| 4566 | mFrameTimeline->getTokenManager(), |
| 4567 | /* workDuration */ activeRefreshRate.getPeriod(), |
| 4568 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4569 | |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 4570 | // Dispatch after EventThread creation, since registerDisplay above skipped dispatch. |
| 4571 | mScheduler->dispatchHotplug(display->getPhysicalId(), scheduler::Scheduler::Hotplug::Connected); |
| 4572 | |
Leon Scroggins III | a7be94e | 2024-01-23 12:24:30 -0500 | [diff] [blame] | 4573 | mScheduler->initVsync(*mFrameTimeline->getTokenManager(), configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4574 | |
| 4575 | mRegionSamplingThread = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4576 | sp<RegionSamplingThread>::make(*this, |
| 4577 | RegionSamplingThread::EnvironmentTimingTunables()); |
Andy Yu | aef688b | 2024-01-23 17:14:23 -0800 | [diff] [blame] | 4578 | mFpsReporter = sp<FpsReporter>::make(*mFrameTimeline); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4579 | |
| 4580 | // Timer callbacks may fire, so do this last. |
| 4581 | mScheduler->startTimers(); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4582 | } |
| 4583 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4584 | void SurfaceFlinger::doCommitTransactions() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 4585 | ATRACE_CALL(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4586 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4587 | if (!mLayersPendingRemoval.isEmpty()) { |
| 4588 | // Notify removed layers now that they can't be drawn from |
| 4589 | for (const auto& l : mLayersPendingRemoval) { |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4590 | // Ensure any buffers set to display on any children are released. |
| 4591 | if (l->isRemovedFromCurrentState()) { |
| 4592 | l->latchAndReleaseBuffer(); |
| 4593 | } |
| 4594 | |
chaviw | 6852bff | 2022-04-19 17:35:11 -0500 | [diff] [blame] | 4595 | // If a layer has a parent, we allow it to out-live it's handle |
| 4596 | // with the idea that the parent holds a reference and will eventually |
| 4597 | // be cleaned up. However no one cleans up the top-level so we do so |
| 4598 | // here. |
| 4599 | if (l->isAtRoot()) { |
| 4600 | l->setIsAtRoot(false); |
| 4601 | mCurrentState.layersSortedByZ.remove(l); |
| 4602 | } |
| 4603 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4604 | // If the layer has been removed and has no parent, then it will not be reachable |
| 4605 | // when traversing layers on screen. Add the layer to the offscreenLayers set to |
| 4606 | // ensure we can copy its current to drawing state. |
| 4607 | if (!l->getParent()) { |
| 4608 | mOffscreenLayers.emplace(l.get()); |
| 4609 | } |
| 4610 | } |
| 4611 | mLayersPendingRemoval.clear(); |
| 4612 | } |
| 4613 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4614 | mDrawingState = mCurrentState; |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4615 | mCurrentState.colorMatrixChanged = false; |
| 4616 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4617 | if (mVisibleRegionsDirty) { |
| 4618 | for (const auto& rootLayer : mDrawingState.layersSortedByZ) { |
| 4619 | rootLayer->commitChildList(); |
| 4620 | } |
Andrei Stanciu | dadac5a | 2020-08-05 17:02:34 +0300 | [diff] [blame] | 4621 | } |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4622 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4623 | commitOffscreenLayers(); |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4624 | if (mLayerMirrorRoots.size() > 0) { |
| 4625 | std::deque<Layer*> pendingUpdates; |
| 4626 | pendingUpdates.insert(pendingUpdates.end(), mLayerMirrorRoots.begin(), |
| 4627 | mLayerMirrorRoots.end()); |
| 4628 | std::vector<Layer*> needsUpdating; |
| 4629 | for (Layer* cloneRoot : mLayerMirrorRoots) { |
| 4630 | pendingUpdates.pop_front(); |
| 4631 | if (cloneRoot->isRemovedFromCurrentState()) { |
| 4632 | continue; |
| 4633 | } |
| 4634 | if (cloneRoot->updateMirrorInfo(pendingUpdates)) { |
| 4635 | } else { |
| 4636 | needsUpdating.push_back(cloneRoot); |
| 4637 | } |
| 4638 | } |
| 4639 | for (Layer* cloneRoot : needsUpdating) { |
| 4640 | cloneRoot->updateMirrorInfo({}); |
| 4641 | } |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4642 | } |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4643 | } |
| 4644 | |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4645 | void SurfaceFlinger::commitOffscreenLayers() { |
| 4646 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4647 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, [](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4648 | if (layer->clearTransactionFlags(eTransactionNeeded)) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4649 | layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4650 | layer->commitChildList(); |
| 4651 | } |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4652 | }); |
| 4653 | } |
| 4654 | } |
| 4655 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4656 | void SurfaceFlinger::invalidateLayerStack(const ui::LayerFilter& layerFilter, const Region& dirty) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4657 | for (const auto& [token, displayDevice] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4658 | auto display = displayDevice->getCompositionDisplay(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4659 | if (display->includesLayer(layerFilter)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4660 | display->editState().dirtyRegion.orSelf(dirty); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 4661 | } |
| 4662 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 4663 | } |
| 4664 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4665 | bool SurfaceFlinger::latchBuffers() { |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 4666 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 4667 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4668 | const nsecs_t latchTime = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4669 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4670 | bool visibleRegions = false; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4671 | bool frameQueued = false; |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4672 | bool newDataLatched = false; |
Eric Penner | 51c59cd | 2014-07-28 19:51:58 -0700 | [diff] [blame] | 4673 | |
| 4674 | // Store the set of layers that need updates. This set must not change as |
| 4675 | // buffers are being latched, as this could result in a deadlock. |
| 4676 | // Example: Two producers share the same command stream and: |
| 4677 | // 1.) Layer 0 is latched |
| 4678 | // 2.) Layer 0 gets a new frame |
| 4679 | // 2.) Layer 1 gets a new frame |
| 4680 | // 3.) Layer 1 is latched. |
| 4681 | // Display is now waiting on Layer 1's frame, which is behind layer 0's |
| 4682 | // 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] | 4683 | mDrawingState.traverse([&](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4684 | if (layer->clearTransactionFlags(eTransactionNeeded) || mForceTransactionDisplayChange) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4685 | const uint32_t flags = layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4686 | if (flags & Layer::eVisibleRegion) { |
| 4687 | mVisibleRegionsDirty = true; |
| 4688 | } |
| 4689 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4690 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4691 | if (layer->hasReadyFrame() || layer->willReleaseBufferOnLatch()) { |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4692 | frameQueued = true; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4693 | mLayersWithQueuedFrames.emplace(sp<Layer>::fromExisting(layer)); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4694 | } else { |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 4695 | layer->useEmptyDamage(); |
Vishnu Nair | c09c023 | 2023-03-02 03:22:35 +0000 | [diff] [blame] | 4696 | if (!layer->hasBuffer()) { |
| 4697 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 4698 | // instead of a missed frame. This is used to identify scenarios where we |
| 4699 | // could not latch a buffer or apply a transaction due to backpressure. |
| 4700 | // We only update the latch time for buffer less layers here, the latch time |
| 4701 | // is updated for buffer layers when the buffer is latched. |
| 4702 | layer->updateLastLatchTime(latchTime); |
| 4703 | } |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4704 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4705 | }); |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4706 | mForceTransactionDisplayChange = false; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4707 | |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4708 | // The client can continue submitting buffers for offscreen layers, but they will not |
| 4709 | // be shown on screen. Therefore, we need to latch and release buffers of offscreen |
| 4710 | // layers to ensure dequeueBuffer doesn't block indefinitely. |
| 4711 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4712 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4713 | [&](Layer* l) { l->latchAndReleaseBuffer(); }); |
| 4714 | } |
| 4715 | |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4716 | if (!mLayersWithQueuedFrames.empty()) { |
| 4717 | // mStateLock is needed for latchBuffer as LayerRejecter::reject() |
| 4718 | // writes to Layer current state. See also b/119481871 |
| 4719 | Mutex::Autolock lock(mStateLock); |
| 4720 | |
Alec Mouri | 2f7d9ae | 2020-11-30 19:32:33 -0800 | [diff] [blame] | 4721 | for (const auto& layer : mLayersWithQueuedFrames) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4722 | if (layer->willReleaseBufferOnLatch()) { |
| 4723 | mLayersWithBuffersRemoved.emplace(layer); |
| 4724 | } |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 4725 | if (layer->latchBuffer(visibleRegions, latchTime)) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4726 | mLayersPendingRefresh.push_back(layer); |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4727 | newDataLatched = true; |
| 4728 | } |
Vishnu Nair | 1b70019 | 2022-02-04 10:09:47 -0800 | [diff] [blame] | 4729 | layer->useSurfaceDamage(); |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4730 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4731 | } |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 4732 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 4733 | mVisibleRegionsDirty |= visibleRegions; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4734 | |
| 4735 | // If we will need to wake up at some time in the future to deal with a |
| 4736 | // queued frame that shouldn't be displayed during this vsync period, wake |
| 4737 | // up during the next vsync period to check again. |
Chia-I Wu | a36bf92 | 2017-06-30 12:51:05 -0700 | [diff] [blame] | 4738 | if (frameQueued && (mLayersWithQueuedFrames.empty() || !newDataLatched)) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4739 | scheduleCommit(FrameHint::kNone); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4740 | } |
| 4741 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 4742 | // enter boot animation on first buffer latch |
| 4743 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 4744 | ALOGI("Enter boot animation"); |
| 4745 | mBootStage = BootStage::BOOTANIMATION; |
| 4746 | } |
| 4747 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4748 | if (mLayerMirrorRoots.size() > 0) { |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4749 | mDrawingState.traverse([&](Layer* layer) { layer->updateCloneBufferInfo(); }); |
| 4750 | } |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 4751 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4752 | // 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] | 4753 | return !mLayersWithQueuedFrames.empty() && newDataLatched; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4754 | } |
| 4755 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4756 | status_t SurfaceFlinger::addClientLayer(LayerCreationArgs& args, const sp<IBinder>& handle, |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4757 | const sp<Layer>& layer, const wp<Layer>& parent, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4758 | uint32_t* outTransformHint) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4759 | if (mNumLayers >= MAX_LAYERS) { |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4760 | ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(), |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4761 | MAX_LAYERS); |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 4762 | static_cast<void>(mScheduler->schedule([=, this] { |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4763 | ALOGE("Dumping layer keeping > 20 children alive:"); |
| 4764 | bool leakingParentLayerFound = false; |
| 4765 | mDrawingState.traverse([&](Layer* layer) { |
| 4766 | if (leakingParentLayerFound) { |
| 4767 | return; |
| 4768 | } |
| 4769 | if (layer->getChildrenCount() > 20) { |
| 4770 | leakingParentLayerFound = true; |
| 4771 | sp<Layer> parent = sp<Layer>::fromExisting(layer); |
| 4772 | while (parent) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4773 | ALOGE("Parent Layer: %s%s", parent->getName().c_str(), |
| 4774 | (parent->isHandleAlive() ? "handleAlive" : "")); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4775 | parent = parent->getParent(); |
| 4776 | } |
| 4777 | // Sample up to 100 layers |
| 4778 | ALOGE("Dumping random sampling of child layers total(%zu): ", |
| 4779 | layer->getChildrenCount()); |
| 4780 | int sampleSize = (layer->getChildrenCount() / 100) + 1; |
| 4781 | layer->traverseChildren([&](Layer* layer) { |
| 4782 | if (rand() % sampleSize == 0) { |
jiayongqiang | c476a34 | 2023-12-06 17:04:54 +0800 | [diff] [blame] | 4783 | ALOGE("Child Layer: %s%s", layer->getName().c_str(), |
| 4784 | (layer->isHandleAlive() ? "handleAlive" : "")); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4785 | } |
| 4786 | }); |
| 4787 | } |
| 4788 | }); |
| 4789 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4790 | int numLayers = 0; |
| 4791 | mDrawingState.traverse([&](Layer* layer) { numLayers++; }); |
| 4792 | |
| 4793 | ALOGE("Dumping random sampling of on-screen layers total(%u):", numLayers); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4794 | mDrawingState.traverse([&](Layer* layer) { |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4795 | // Aim to dump about 200 layers to avoid totally trashing |
| 4796 | // logcat. On the other hand, if there really are 4096 layers |
| 4797 | // something has gone totally wrong its probably the most |
| 4798 | // useful information in logcat. |
| 4799 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4800 | ALOGE("Layer: %s%s", layer->getName().c_str(), |
| 4801 | (layer->isHandleAlive() ? "handleAlive" : "")); |
| 4802 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4803 | } |
| 4804 | }); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4805 | ALOGE("Dumping random sampling of off-screen layers total(%zu): ", |
| 4806 | mOffscreenLayers.size()); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4807 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 4808 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4809 | ALOGE("Offscreen-layer: %s%s", offscreenLayer->getName().c_str(), |
| 4810 | (offscreenLayer->isHandleAlive() ? "handleAlive" : "")); |
| 4811 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4812 | } |
| 4813 | } |
| 4814 | })); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4815 | return NO_MEMORY; |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4816 | } |
| 4817 | |
Vishnu Nair | 86e1190 | 2022-09-06 16:03:27 +0000 | [diff] [blame] | 4818 | layer->updateTransformHint(mActiveDisplayTransformHint); |
| 4819 | if (outTransformHint) { |
| 4820 | *outTransformHint = mActiveDisplayTransformHint; |
| 4821 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4822 | args.parentId = LayerHandle::getLayerId(args.parentHandle.promote()); |
| 4823 | args.layerIdToMirror = LayerHandle::getLayerId(args.mirrorLayerHandle.promote()); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4824 | { |
| 4825 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4826 | mCreatedLayers.emplace_back(layer, parent, args.addToRoot); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4827 | mNewLayers.emplace_back(std::make_unique<frontend::RequestedLayerState>(args)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 4828 | args.mirrorLayerHandle.clear(); |
| 4829 | args.parentHandle.clear(); |
| 4830 | mNewLayerArgs.emplace_back(std::move(args)); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4831 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4832 | |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4833 | setTransactionFlags(eTransactionNeeded); |
| 4834 | return NO_ERROR; |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 4835 | } |
| 4836 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4837 | uint32_t SurfaceFlinger::getTransactionFlags() const { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 4838 | return mTransactionFlags; |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 4839 | } |
| 4840 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4841 | uint32_t SurfaceFlinger::clearTransactionFlags(uint32_t mask) { |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4842 | uint32_t transactionFlags = mTransactionFlags.fetch_and(~mask); |
| 4843 | ATRACE_INT("mTransactionFlags", transactionFlags); |
| 4844 | return transactionFlags & mask; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4845 | } |
| 4846 | |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4847 | void SurfaceFlinger::setTransactionFlags(uint32_t mask, TransactionSchedule schedule, |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4848 | const sp<IBinder>& applyToken, FrameHint frameHint) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4849 | mScheduler->modulateVsync({}, &VsyncModulator::setTransactionSchedule, schedule, applyToken); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4850 | uint32_t transactionFlags = mTransactionFlags.fetch_or(mask); |
| 4851 | ATRACE_INT("mTransactionFlags", transactionFlags); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4852 | |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4853 | if (const bool scheduled = transactionFlags & mask; !scheduled) { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4854 | scheduleCommit(frameHint); |
Ady Abraham | 27bcb55 | 2023-01-21 04:34:22 +0000 | [diff] [blame] | 4855 | } else if (frameHint == FrameHint::kActive) { |
| 4856 | // Even if the next frame is already scheduled, we should reset the idle timer |
| 4857 | // as a new activity just happened. |
| 4858 | mScheduler->resetIdleTimer(); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4859 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4860 | } |
| 4861 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4862 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyTimelineCheck( |
| 4863 | const TransactionHandler::TransactionFlushState& flushState) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 4864 | const auto& transaction = *flushState.transaction; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4865 | |
| 4866 | const TimePoint desiredPresentTime = TimePoint::fromNs(transaction.desiredPresentTime); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 4867 | const TimePoint expectedPresentTime = mScheduler->expectedPresentTimeForPacesetter(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4868 | |
| 4869 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4870 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4871 | // Do not present if the desiredPresentTime has not passed unless it is more than |
| 4872 | // one second in the future. We ignore timestamps more than 1 second in the future |
| 4873 | // for stability reasons. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4874 | if (!transaction.isAutoTimestamp && desiredPresentTime >= expectedPresentTime && |
| 4875 | desiredPresentTime < expectedPresentTime + 1s) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4876 | ATRACE_FORMAT("not current desiredPresentTime: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4877 | desiredPresentTime, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4878 | return TransactionReadiness::NotReady; |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4879 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4880 | |
Ady Abraham | 20024aa | 2024-03-05 01:32:49 +0000 | [diff] [blame] | 4881 | const auto vsyncId = VsyncId{transaction.frameTimelineInfo.vsyncId}; |
| 4882 | |
| 4883 | // Transactions with VsyncId are already throttled by the vsyncId (i.e. Choreographer issued |
| 4884 | // the vsyncId according to the frame rate override cadence) so we shouldn't throttle again |
| 4885 | // when applying the transaction. Otherwise we might throttle older transactions |
| 4886 | // incorrectly as the frame rate of SF changed before it drained the older transactions. |
| 4887 | if (ftl::to_underlying(vsyncId) == FrameTimelineInfo::INVALID_VSYNC_ID && |
| 4888 | !mScheduler->isVsyncValid(expectedPresentTime, transaction.originUid)) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4889 | ATRACE_FORMAT("!isVsyncValid expectedPresentTime: %" PRId64 " uid: %d", expectedPresentTime, |
| 4890 | transaction.originUid); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4891 | return TransactionReadiness::NotReady; |
| 4892 | } |
| 4893 | |
| 4894 | // If the client didn't specify desiredPresentTime, use the vsyncId to determine the |
| 4895 | // expected present time of this transaction. |
Ady Abraham | 20024aa | 2024-03-05 01:32:49 +0000 | [diff] [blame] | 4896 | if (transaction.isAutoTimestamp && frameIsEarly(expectedPresentTime, vsyncId)) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4897 | ATRACE_FORMAT("frameIsEarly vsyncId: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4898 | transaction.frameTimelineInfo.vsyncId, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4899 | return TransactionReadiness::NotReady; |
| 4900 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4901 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4902 | return TransactionReadiness::Ready; |
| 4903 | } |
| 4904 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4905 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheckLegacy( |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4906 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4907 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4908 | auto ready = TransactionReadiness::Ready; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4909 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const ResolvedComposerState& |
| 4910 | resolvedState) -> bool { |
| 4911 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 4912 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4913 | const auto& transaction = *flushState.transaction; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4914 | const auto& s = resolvedState.state; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4915 | // check for barrier frames |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4916 | if (s.bufferData->hasBarrier) { |
| 4917 | // The current producerId is already a newer producer than the buffer that has a |
| 4918 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4919 | // 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] | 4920 | if (layer->getDrawingState().barrierProducerId > s.bufferData->producerId) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4921 | layer->callReleaseBufferCallback(s.bufferData->releaseBufferListener, |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4922 | resolvedState.externalTexture->getBuffer(), |
Chavi Weingarten | c8bcb68 | 2023-03-06 22:20:42 +0000 | [diff] [blame] | 4923 | s.bufferData->frameNumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4924 | s.bufferData->acquireFence); |
| 4925 | // Delete the entire state at this point and not just release the buffer because |
| 4926 | // 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] | 4927 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", |
| 4928 | layer->getDebugName(), layer->getDrawingState().barrierProducerId, |
| 4929 | s.bufferData->producerId); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4930 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4931 | } |
| 4932 | |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 4933 | if (layer->getDrawingState().barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4934 | const bool willApplyBarrierFrame = |
| 4935 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4936 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4937 | s.bufferData->barrierFrameNumber)); |
| 4938 | if (!willApplyBarrierFrame) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4939 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4940 | layer->getDebugName(), |
| 4941 | layer->getDrawingState().barrierFrameNumber, |
| 4942 | s.bufferData->barrierFrameNumber); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4943 | ready = TransactionReadiness::NotReadyBarrier; |
| 4944 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4945 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4946 | } |
| 4947 | } |
| 4948 | |
| 4949 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4950 | // the transaction in the queue. |
| 4951 | const bool hasPendingBuffer = |
| 4952 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4953 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4954 | ATRACE_FORMAT("hasPendingBuffer %s", layer->getDebugName()); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4955 | ready = TransactionReadiness::NotReady; |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4956 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4957 | } |
| 4958 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4959 | const bool acquireFenceAvailable = s.bufferData && |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4960 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4961 | s.bufferData->acquireFence; |
Ying Wei | 1fd9bfc | 2023-06-29 16:47:00 +0000 | [diff] [blame] | 4962 | const bool fenceSignaled = !acquireFenceAvailable || |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4963 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4964 | if (!fenceSignaled) { |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4965 | // check fence status |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4966 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(s, transaction.states.size(), |
| 4967 | flushState.firstTransaction) && |
| 4968 | layer->isSimpleBufferUpdate(s); |
| 4969 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4970 | if (allowLatchUnsignaled) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4971 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", |
| 4972 | layer->getDebugName()); |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4973 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4974 | } else { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4975 | ready = TransactionReadiness::NotReady; |
| 4976 | auto& listener = s.bufferData->releaseBufferListener; |
| 4977 | if (listener && |
| 4978 | (flushState.queueProcessTime - transaction.postTime) > |
| 4979 | std::chrono::nanoseconds(4s).count()) { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4980 | // Used to add a stalled transaction which uses an internal lock. |
| 4981 | ftl::FakeGuard guard(kMainThreadContext); |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 4982 | mTransactionHandler |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 4983 | .onTransactionQueueStalled(transaction.id, |
| 4984 | {.pid = layer->getOwnerPid(), |
| 4985 | .layerId = static_cast<uint32_t>( |
| 4986 | layer->getSequence()), |
| 4987 | .layerName = layer->getDebugName(), |
| 4988 | .bufferId = s.bufferData->getId(), |
| 4989 | .frameNumber = s.bufferData->frameNumber}); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4990 | } |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4991 | ATRACE_FORMAT("fence unsignaled %s", layer->getDebugName()); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4992 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4993 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4994 | } |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4995 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4996 | }); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4997 | return ready; |
| 4998 | } |
| 4999 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5000 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheck( |
| 5001 | const TransactionHandler::TransactionFlushState& flushState) { |
| 5002 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 5003 | auto ready = TransactionReadiness::Ready; |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 5004 | flushState.transaction->traverseStatesWithBuffersWhileTrue( |
| 5005 | [&](const ResolvedComposerState& resolvedState) FTL_FAKE_GUARD( |
| 5006 | kMainThreadContext) -> bool { |
| 5007 | const frontend::RequestedLayerState* layer = |
| 5008 | mLayerLifecycleManager.getLayerFromId(resolvedState.layerId); |
| 5009 | const auto& transaction = *flushState.transaction; |
| 5010 | const auto& s = resolvedState.state; |
| 5011 | // check for barrier frames |
| 5012 | if (s.bufferData->hasBarrier) { |
| 5013 | // The current producerId is already a newer producer than the buffer that has a |
| 5014 | // barrier. This means the incoming buffer is older and we can release it here. |
| 5015 | // We don't wait on the barrier since we know that's stale information. |
| 5016 | if (layer->barrierProducerId > s.bufferData->producerId) { |
| 5017 | if (s.bufferData->releaseBufferListener) { |
| 5018 | uint32_t currentMaxAcquiredBufferCount = |
| 5019 | getMaxAcquiredBufferCountForCurrentRefreshRate( |
| 5020 | layer->ownerUid.val()); |
| 5021 | ATRACE_FORMAT_INSTANT("callReleaseBufferCallback %s - %" PRIu64, |
| 5022 | layer->name.c_str(), s.bufferData->frameNumber); |
| 5023 | s.bufferData->releaseBufferListener |
| 5024 | ->onReleaseBuffer({resolvedState.externalTexture->getBuffer() |
| 5025 | ->getId(), |
| 5026 | s.bufferData->frameNumber}, |
| 5027 | s.bufferData->acquireFence |
| 5028 | ? s.bufferData->acquireFence |
| 5029 | : Fence::NO_FENCE, |
| 5030 | currentMaxAcquiredBufferCount); |
| 5031 | } |
| 5032 | |
| 5033 | // Delete the entire state at this point and not just release the buffer |
| 5034 | // because everything associated with the Layer in this Transaction is now |
| 5035 | // out of date. |
| 5036 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", |
| 5037 | layer->name.c_str(), layer->barrierProducerId, |
| 5038 | s.bufferData->producerId); |
| 5039 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 5040 | } |
| 5041 | |
| 5042 | if (layer->barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
| 5043 | const bool willApplyBarrierFrame = |
| 5044 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 5045 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 5046 | s.bufferData->barrierFrameNumber)); |
| 5047 | if (!willApplyBarrierFrame) { |
| 5048 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 |
| 5049 | " > %" PRId64, |
| 5050 | layer->name.c_str(), layer->barrierFrameNumber, |
| 5051 | s.bufferData->barrierFrameNumber); |
| 5052 | ready = TransactionReadiness::NotReadyBarrier; |
| 5053 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 5054 | } |
| 5055 | } |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5056 | } |
| 5057 | |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 5058 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 5059 | // the transaction in the queue. |
| 5060 | const bool hasPendingBuffer = |
| 5061 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 5062 | if (layer->backpressureEnabled() && hasPendingBuffer && |
| 5063 | transaction.isAutoTimestamp) { |
| 5064 | ATRACE_FORMAT("hasPendingBuffer %s", layer->name.c_str()); |
| 5065 | ready = TransactionReadiness::NotReady; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5066 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 5067 | } |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5068 | |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 5069 | const bool acquireFenceAvailable = s.bufferData && |
| 5070 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 5071 | s.bufferData->acquireFence; |
| 5072 | const bool fenceSignaled = !acquireFenceAvailable || |
| 5073 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
| 5074 | if (!fenceSignaled) { |
| 5075 | // check fence status |
| 5076 | const bool allowLatchUnsignaled = |
| 5077 | shouldLatchUnsignaled(s, transaction.states.size(), |
| 5078 | flushState.firstTransaction) && |
| 5079 | layer->isSimpleBufferUpdate(s); |
| 5080 | if (allowLatchUnsignaled) { |
| 5081 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", |
| 5082 | layer->name.c_str()); |
| 5083 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 5084 | } else { |
| 5085 | ready = TransactionReadiness::NotReady; |
| 5086 | auto& listener = s.bufferData->releaseBufferListener; |
| 5087 | if (listener && |
| 5088 | (flushState.queueProcessTime - transaction.postTime) > |
| 5089 | std::chrono::nanoseconds(4s).count()) { |
| 5090 | mTransactionHandler |
| 5091 | .onTransactionQueueStalled(transaction.id, |
| 5092 | {.pid = layer->ownerPid.val(), |
| 5093 | .layerId = layer->id, |
| 5094 | .layerName = layer->name, |
| 5095 | .bufferId = s.bufferData->getId(), |
| 5096 | .frameNumber = |
| 5097 | s.bufferData->frameNumber}); |
| 5098 | } |
| 5099 | ATRACE_FORMAT("fence unsignaled %s", layer->name.c_str()); |
| 5100 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 5101 | } |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5102 | } |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 5103 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
| 5104 | }); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5105 | return ready; |
| 5106 | } |
| 5107 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5108 | void SurfaceFlinger::addTransactionReadyFilters() { |
| 5109 | mTransactionHandler.addTransactionReadyFilter( |
| 5110 | std::bind(&SurfaceFlinger::transactionReadyTimelineCheck, this, std::placeholders::_1)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5111 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5112 | mTransactionHandler.addTransactionReadyFilter( |
| 5113 | std::bind(&SurfaceFlinger::transactionReadyBufferCheck, this, |
| 5114 | std::placeholders::_1)); |
| 5115 | } else { |
| 5116 | mTransactionHandler.addTransactionReadyFilter( |
| 5117 | std::bind(&SurfaceFlinger::transactionReadyBufferCheckLegacy, this, |
| 5118 | std::placeholders::_1)); |
| 5119 | } |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 5120 | } |
| 5121 | |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 5122 | // For tests only |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5123 | bool SurfaceFlinger::flushTransactionQueues(VsyncId vsyncId) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5124 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5125 | std::vector<TransactionState> transactions = mTransactionHandler.flushTransactions(); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 5126 | return applyTransactions(transactions, vsyncId); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 5127 | } |
| 5128 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5129 | bool SurfaceFlinger::applyTransactions(std::vector<TransactionState>& transactions, |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5130 | VsyncId vsyncId) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5131 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 5132 | return applyTransactionsLocked(transactions, vsyncId); |
| 5133 | } |
| 5134 | |
| 5135 | bool SurfaceFlinger::applyTransactionsLocked(std::vector<TransactionState>& transactions, |
| 5136 | VsyncId vsyncId) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 5137 | bool needsTraversal = false; |
| 5138 | // Now apply all transactions. |
Robert Carr | ff7663b | 2022-02-08 12:46:49 -0800 | [diff] [blame] | 5139 | for (auto& transaction : transactions) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 5140 | needsTraversal |= |
| 5141 | applyTransactionState(transaction.frameTimelineInfo, transaction.states, |
| 5142 | transaction.displays, transaction.flags, |
| 5143 | transaction.inputWindowCommands, |
| 5144 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5145 | std::move(transaction.uncacheBufferIds), transaction.postTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5146 | transaction.hasListenerCallbacks, |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 5147 | transaction.listenerCallbacks, transaction.originPid, |
| 5148 | transaction.originUid, transaction.id); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 5149 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5150 | return needsTraversal; |
Marissa Wall | e6e3c0d | 2019-03-29 10:28:30 -0700 | [diff] [blame] | 5151 | } |
| 5152 | |
| 5153 | bool SurfaceFlinger::transactionFlushNeeded() { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5154 | return mTransactionHandler.hasPendingTransactions(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 5155 | } |
| 5156 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5157 | bool SurfaceFlinger::frameIsEarly(TimePoint expectedPresentTime, VsyncId vsyncId) const { |
| 5158 | const auto prediction = |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 5159 | mFrameTimeline->getTokenManager()->getPredictionsForToken(ftl::to_underlying(vsyncId)); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5160 | if (!prediction) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5161 | return false; |
| 5162 | } |
| 5163 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5164 | const auto predictedPresentTime = TimePoint::fromNs(prediction->presentTime); |
| 5165 | |
Rachel Lee | 0655a91 | 2023-04-20 19:54:18 -0700 | [diff] [blame] | 5166 | if (std::chrono::abs(predictedPresentTime - expectedPresentTime) >= |
| 5167 | scheduler::VsyncConfig::kEarlyLatchMaxThreshold) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5168 | return false; |
| 5169 | } |
| 5170 | |
Ady Abraham | 3db8a3c | 2023-11-20 17:53:47 -0800 | [diff] [blame] | 5171 | const Duration earlyLatchVsyncThreshold = mScheduler->getVsyncSchedule()->minFramePeriod() / 2; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5172 | |
| 5173 | return predictedPresentTime >= expectedPresentTime && |
| 5174 | predictedPresentTime - expectedPresentTime >= earlyLatchVsyncThreshold; |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5175 | } |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5176 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5177 | bool SurfaceFlinger::shouldLatchUnsignaled(const layer_state_t& state, size_t numStates, |
| 5178 | bool firstTransaction) const { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5179 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Disabled) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 5180 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::Disabled)", __func__); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5181 | return false; |
| 5182 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5183 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5184 | // We only want to latch unsignaled when a single layer is updated in this |
| 5185 | // transaction (i.e. not a blast sync transaction). |
| 5186 | if (numStates != 1) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 5187 | ATRACE_FORMAT_INSTANT("%s: false (numStates=%zu)", __func__, numStates); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5188 | return false; |
| 5189 | } |
| 5190 | |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 5191 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::AutoSingleLayer) { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5192 | if (!firstTransaction) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 5193 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; not first " |
| 5194 | "transaction)", |
| 5195 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 5196 | return false; |
| 5197 | } |
| 5198 | |
| 5199 | // We don't want to latch unsignaled if are in early / client composition |
| 5200 | // as it leads to jank due to RenderEngine waiting for unsignaled buffer |
| 5201 | // or window animations being slow. |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 5202 | if (mScheduler->vsyncModulator().isVsyncConfigEarly()) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 5203 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; " |
| 5204 | "isVsyncConfigEarly)", |
| 5205 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 5206 | return false; |
| 5207 | } |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5208 | } |
| 5209 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5210 | return true; |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5211 | } |
| 5212 | |
chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 5213 | status_t SurfaceFlinger::setTransactionState( |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5214 | const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 5215 | const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5216 | InputWindowCommands inputWindowCommands, int64_t desiredPresentTime, bool isAutoTimestamp, |
| 5217 | const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 5218 | const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId, |
| 5219 | const std::vector<uint64_t>& mergedTransactionIds) { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 5220 | ATRACE_CALL(); |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 5221 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5222 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5223 | const int originPid = ipc->getCallingPid(); |
| 5224 | const int originUid = ipc->getCallingUid(); |
| 5225 | uint32_t permissions = LayerStatePermissions::getTransactionPermissions(originPid, originUid); |
Patrick Williams | 04e4176 | 2024-04-23 19:05:38 -0500 | [diff] [blame] | 5226 | for (auto& composerState : states) { |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5227 | composerState.state.sanitize(permissions); |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 5228 | } |
| 5229 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5230 | for (DisplayState display : displays) { |
| 5231 | display.sanitize(permissions); |
| 5232 | } |
| 5233 | |
| 5234 | if (!inputWindowCommands.empty() && |
| 5235 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) == 0) { |
| 5236 | ALOGE("Only privileged callers are allowed to send input commands."); |
| 5237 | inputWindowCommands.clear(); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 5238 | } |
| 5239 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 5240 | if (flags & (eEarlyWakeupStart | eEarlyWakeupEnd)) { |
| 5241 | const bool hasPermission = |
| 5242 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) || |
| 5243 | callingThreadHasPermission(sWakeupSurfaceFlinger); |
| 5244 | if (!hasPermission) { |
| 5245 | ALOGE("Caller needs permission android.permission.WAKEUP_SURFACE_FLINGER to use " |
| 5246 | "eEarlyWakeup[Start|End] flags"); |
| 5247 | flags &= ~(eEarlyWakeupStart | eEarlyWakeupEnd); |
| 5248 | } |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 5249 | } |
| 5250 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 5251 | const int64_t postTime = systemTime(); |
| 5252 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5253 | std::vector<uint64_t> uncacheBufferIds; |
| 5254 | uncacheBufferIds.reserve(uncacheBuffers.size()); |
| 5255 | for (const auto& uncacheBuffer : uncacheBuffers) { |
| 5256 | sp<GraphicBuffer> buffer = ClientCache::getInstance().erase(uncacheBuffer); |
| 5257 | if (buffer != nullptr) { |
| 5258 | uncacheBufferIds.push_back(buffer->getId()); |
| 5259 | } |
| 5260 | } |
| 5261 | |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5262 | std::vector<ResolvedComposerState> resolvedStates; |
| 5263 | resolvedStates.reserve(states.size()); |
| 5264 | for (auto& state : states) { |
| 5265 | resolvedStates.emplace_back(std::move(state)); |
| 5266 | auto& resolvedState = resolvedStates.back(); |
| 5267 | if (resolvedState.state.hasBufferChanges() && resolvedState.state.hasValidBuffer() && |
| 5268 | resolvedState.state.surface) { |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 5269 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 5270 | std::string layerName = (layer) ? |
| 5271 | layer->getDebugName() : std::to_string(resolvedState.state.layerId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5272 | resolvedState.externalTexture = |
| 5273 | getExternalTextureFromBufferData(*resolvedState.state.bufferData, |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 5274 | layerName.c_str(), transactionId); |
Patrick Williams | 38d920e | 2023-08-31 17:31:18 -0500 | [diff] [blame] | 5275 | if (resolvedState.externalTexture) { |
| 5276 | resolvedState.state.bufferData->buffer = resolvedState.externalTexture->getBuffer(); |
| 5277 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5278 | mBufferCountTracker.increment(resolvedState.state.surface->localBinder()); |
| 5279 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 5280 | resolvedState.layerId = LayerHandle::getLayerId(resolvedState.state.surface); |
| 5281 | if (resolvedState.state.what & layer_state_t::eReparent) { |
| 5282 | resolvedState.parentId = |
| 5283 | getLayerIdFromSurfaceControl(resolvedState.state.parentSurfaceControlForChild); |
| 5284 | } |
| 5285 | if (resolvedState.state.what & layer_state_t::eRelativeLayerChanged) { |
| 5286 | resolvedState.relativeParentId = |
| 5287 | getLayerIdFromSurfaceControl(resolvedState.state.relativeLayerSurfaceControl); |
| 5288 | } |
| 5289 | if (resolvedState.state.what & layer_state_t::eInputInfoChanged) { |
| 5290 | wp<IBinder>& touchableRegionCropHandle = |
| 5291 | resolvedState.state.windowInfoHandle->editInfo()->touchableRegionCropHandle; |
| 5292 | resolvedState.touchCropId = |
| 5293 | LayerHandle::getLayerId(touchableRegionCropHandle.promote()); |
| 5294 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5295 | } |
| 5296 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5297 | TransactionState state{frameTimelineInfo, |
| 5298 | resolvedStates, |
| 5299 | displays, |
| 5300 | flags, |
| 5301 | applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5302 | std::move(inputWindowCommands), |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5303 | desiredPresentTime, |
| 5304 | isAutoTimestamp, |
| 5305 | std::move(uncacheBufferIds), |
| 5306 | postTime, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5307 | hasListenerCallbacks, |
| 5308 | listenerCallbacks, |
| 5309 | originPid, |
| 5310 | originUid, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 5311 | transactionId, |
| 5312 | mergedTransactionIds}; |
Vishnu Nair | 83df034 | 2021-03-30 11:50:44 -0700 | [diff] [blame] | 5313 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 5314 | if (mTransactionTracing) { |
| 5315 | mTransactionTracing->addQueuedTransaction(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5316 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5317 | |
| 5318 | const auto schedule = [](uint32_t flags) { |
| 5319 | if (flags & eEarlyWakeupEnd) return TransactionSchedule::EarlyEnd; |
| 5320 | if (flags & eEarlyWakeupStart) return TransactionSchedule::EarlyStart; |
| 5321 | return TransactionSchedule::Late; |
| 5322 | }(state.flags); |
| 5323 | |
| 5324 | const auto frameHint = state.isFrameActive() ? FrameHint::kActive : FrameHint::kNone; |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 5325 | { |
| 5326 | // Transactions are added via a lockless queue and does not need to be added from the main |
| 5327 | // thread. |
| 5328 | ftl::FakeGuard guard(kMainThreadContext); |
| 5329 | mTransactionHandler.queueTransaction(std::move(state)); |
| 5330 | } |
| 5331 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 5332 | for (const auto& [displayId, data] : mNotifyExpectedPresentMap) { |
| 5333 | if (data.hintStatus.load() == NotifyExpectedPresentHintStatus::ScheduleOnTx) { |
| 5334 | scheduleNotifyExpectedPresentHint(displayId, VsyncId{frameTimelineInfo.vsyncId}); |
| 5335 | } |
| 5336 | } |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 5337 | setTransactionFlags(eTransactionFlushNeeded, schedule, applyToken, frameHint); |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 5338 | return NO_ERROR; |
| 5339 | } |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 5340 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5341 | bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5342 | std::vector<ResolvedComposerState>& states, |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 5343 | Vector<DisplayState>& displays, uint32_t flags, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5344 | const InputWindowCommands& inputWindowCommands, |
| 5345 | const int64_t desiredPresentTime, bool isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5346 | const std::vector<uint64_t>& uncacheBufferIds, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5347 | const int64_t postTime, bool hasListenerCallbacks, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5348 | const std::vector<ListenerCallbacks>& listenerCallbacks, |
| 5349 | int originPid, int originUid, uint64_t transactionId) { |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 5350 | uint32_t transactionFlags = 0; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5351 | if (!mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5352 | for (DisplayState& display : displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5353 | transactionFlags |= setDisplayStateLocked(display); |
| 5354 | } |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 5355 | } |
| 5356 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5357 | // start and end registration for listeners w/ no surface so they can get their callback. Note |
| 5358 | // that listeners with SurfaceControls will start registration during setClientStateLocked |
| 5359 | // below. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5360 | for (const auto& listener : listenerCallbacks) { |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5361 | mTransactionCallbackInvoker.addEmptyTransaction(listener); |
Marissa Wall | d600d57 | 2019-03-26 15:38:50 -0700 | [diff] [blame] | 5362 | } |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 5363 | nsecs_t now = systemTime(); |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5364 | uint32_t clientStateFlags = 0; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5365 | for (auto& resolvedState : states) { |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 5366 | clientStateFlags |= |
| 5367 | updateLayerCallbacksAndStats(frameTimelineInfo, resolvedState, desiredPresentTime, |
| 5368 | isAutoTimestamp, postTime, transactionId); |
Melody Hsu | 2606ec0 | 2024-04-04 22:31:34 +0000 | [diff] [blame] | 5369 | if (!mLayerLifecycleManagerEnabled) { |
| 5370 | if ((flags & eAnimation) && resolvedState.state.surface) { |
| 5371 | if (const auto layer = LayerHandle::getLayer(resolvedState.state.surface)) { |
| 5372 | const auto layerProps = scheduler::LayerProps{ |
| 5373 | .visible = layer->isVisible(), |
| 5374 | .bounds = layer->getBounds(), |
| 5375 | .transform = layer->getTransform(), |
| 5376 | .setFrameRateVote = layer->getFrameRateForLayerTree(), |
| 5377 | .frameRateSelectionPriority = layer->getFrameRateSelectionPriority(), |
| 5378 | .isFrontBuffered = layer->isFrontBuffered(), |
| 5379 | }; |
| 5380 | layer->recordLayerHistoryAnimationTx(layerProps, now); |
| 5381 | } |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 5382 | } |
| 5383 | } |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 5384 | } |
| 5385 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5386 | transactionFlags |= clientStateFlags; |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5387 | transactionFlags |= addInputWindowCommands(inputWindowCommands); |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5388 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5389 | for (uint64_t uncacheBufferId : uncacheBufferIds) { |
| 5390 | mBufferIdsToUncache.push_back(uncacheBufferId); |
Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 5391 | } |
| 5392 | |
Jorim Jaggi | bdcf09c | 2017-08-08 15:22:08 +0200 | [diff] [blame] | 5393 | // If a synchronous transaction is explicitly requested without any changes, force a transaction |
| 5394 | // anyway. This can be used as a flush mechanism for previous async transactions. |
| 5395 | // Empty animation transaction can be used to simulate back-pressure, so also force a |
| 5396 | // transaction for empty animation transactions. |
Vishnu Nair | 1523dad | 2022-09-29 16:05:18 -0700 | [diff] [blame] | 5397 | if (transactionFlags == 0 && (flags & eAnimation)) { |
Robert Carr | 2a7dbb4 | 2016-05-24 11:41:28 -0700 | [diff] [blame] | 5398 | transactionFlags = eTransactionNeeded; |
| 5399 | } |
| 5400 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5401 | bool needsTraversal = false; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 5402 | if (transactionFlags) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5403 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 5404 | // 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] | 5405 | if (transactionFlags & eTraversalNeeded) { |
| 5406 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5407 | needsTraversal = true; |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 5408 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5409 | if (transactionFlags) { |
| 5410 | setTransactionFlags(transactionFlags); |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 5411 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5412 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5413 | |
| 5414 | return needsTraversal; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5415 | } |
| 5416 | |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 5417 | bool SurfaceFlinger::applyAndCommitDisplayTransactionStatesLocked( |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5418 | std::vector<TransactionState>& transactions) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5419 | bool needsTraversal = false; |
| 5420 | uint32_t transactionFlags = 0; |
| 5421 | for (auto& transaction : transactions) { |
| 5422 | for (DisplayState& display : transaction.displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5423 | transactionFlags |= setDisplayStateLocked(display); |
| 5424 | } |
| 5425 | } |
| 5426 | |
| 5427 | if (transactionFlags) { |
| 5428 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 5429 | // so we don't have to wake up again next frame to perform an unnecessary traversal. |
| 5430 | if (transactionFlags & eTraversalNeeded) { |
| 5431 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
| 5432 | needsTraversal = true; |
| 5433 | } |
| 5434 | if (transactionFlags) { |
| 5435 | setTransactionFlags(transactionFlags); |
| 5436 | } |
| 5437 | } |
| 5438 | |
| 5439 | mFrontEndDisplayInfosChanged = mTransactionFlags & eDisplayTransactionNeeded; |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 5440 | if (mFrontEndDisplayInfosChanged) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5441 | processDisplayChangesLocked(); |
| 5442 | mFrontEndDisplayInfos.clear(); |
| 5443 | for (const auto& [_, display] : mDisplays) { |
| 5444 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 5445 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5446 | needsTraversal = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5447 | } |
| 5448 | |
| 5449 | return needsTraversal; |
| 5450 | } |
| 5451 | |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5452 | uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s) { |
| 5453 | const ssize_t index = mCurrentState.displays.indexOfKey(s.token); |
| 5454 | if (index < 0) return 0; |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 5455 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5456 | uint32_t flags = 0; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5457 | DisplayDeviceState& state = mCurrentState.displays.editValueAt(index); |
| 5458 | |
| 5459 | const uint32_t what = s.what; |
| 5460 | if (what & DisplayState::eSurfaceChanged) { |
| 5461 | if (IInterface::asBinder(state.surface) != IInterface::asBinder(s.surface)) { |
| 5462 | state.surface = s.surface; |
| 5463 | flags |= eDisplayTransactionNeeded; |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 5464 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5465 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5466 | if (what & DisplayState::eLayerStackChanged) { |
| 5467 | if (state.layerStack != s.layerStack) { |
| 5468 | state.layerStack = s.layerStack; |
| 5469 | flags |= eDisplayTransactionNeeded; |
| 5470 | } |
| 5471 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 5472 | if (what & DisplayState::eFlagsChanged) { |
| 5473 | if (state.flags != s.flags) { |
| 5474 | state.flags = s.flags; |
| 5475 | flags |= eDisplayTransactionNeeded; |
| 5476 | } |
| 5477 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5478 | if (what & DisplayState::eDisplayProjectionChanged) { |
| 5479 | if (state.orientation != s.orientation) { |
| 5480 | state.orientation = s.orientation; |
| 5481 | flags |= eDisplayTransactionNeeded; |
| 5482 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5483 | if (state.orientedDisplaySpaceRect != s.orientedDisplaySpaceRect) { |
| 5484 | state.orientedDisplaySpaceRect = s.orientedDisplaySpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5485 | flags |= eDisplayTransactionNeeded; |
| 5486 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5487 | if (state.layerStackSpaceRect != s.layerStackSpaceRect) { |
| 5488 | state.layerStackSpaceRect = s.layerStackSpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5489 | flags |= eDisplayTransactionNeeded; |
| 5490 | } |
| 5491 | } |
| 5492 | if (what & DisplayState::eDisplaySizeChanged) { |
| 5493 | if (state.width != s.width) { |
| 5494 | state.width = s.width; |
| 5495 | flags |= eDisplayTransactionNeeded; |
| 5496 | } |
| 5497 | if (state.height != s.height) { |
| 5498 | state.height = s.height; |
| 5499 | flags |= eDisplayTransactionNeeded; |
| 5500 | } |
| 5501 | } |
| 5502 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5503 | return flags; |
| 5504 | } |
| 5505 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5506 | bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5507 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5508 | const int pid = ipc->getCallingPid(); |
| 5509 | const int uid = ipc->getCallingUid(); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5510 | if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) && |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5511 | (usePermissionCache ? !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid) |
| 5512 | : !checkPermission(sAccessSurfaceFlinger, pid, uid))) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5513 | return false; |
| 5514 | } |
| 5515 | return true; |
| 5516 | } |
| 5517 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5518 | uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5519 | ResolvedComposerState& composerState, |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5520 | int64_t desiredPresentTime, bool isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5521 | int64_t postTime, uint64_t transactionId) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5522 | layer_state_t& s = composerState.state; |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5523 | |
| 5524 | std::vector<ListenerCallbacks> filteredListeners; |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5525 | for (auto& listener : s.listeners) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5526 | // Starts a registration but separates the callback ids according to callback type. This |
| 5527 | // allows the callback invoker to send on latch callbacks earlier. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5528 | // note that startRegistration will not re-register if the listener has |
| 5529 | // already be registered for a prior surface control |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5530 | |
| 5531 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5532 | if (!onCommitCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5533 | filteredListeners.push_back(onCommitCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5534 | } |
| 5535 | |
| 5536 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5537 | if (!onCompleteCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5538 | filteredListeners.push_back(onCompleteCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5539 | } |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5540 | } |
| 5541 | |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 5542 | const uint64_t what = s.what; |
| 5543 | uint32_t flags = 0; |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 5544 | sp<Layer> layer = nullptr; |
| 5545 | if (s.surface) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5546 | layer = LayerHandle::getLayer(s.surface); |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 5547 | } else { |
| 5548 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5549 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5550 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5551 | if (layer == nullptr) { |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5552 | for (auto& [listener, callbackIds] : s.listeners) { |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 5553 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5554 | callbackIds, |
| 5555 | s.surface), |
| 5556 | std::vector<JankData>()); |
Marissa Wall | 88e2048 | 2019-06-24 10:49:42 -0700 | [diff] [blame] | 5557 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5558 | return 0; |
| 5559 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 5560 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5561 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 5562 | ui::LayerStack oldLayerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5563 | |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 5564 | // Only set by BLAST adapter layers |
| 5565 | if (what & layer_state_t::eProducerDisconnect) { |
| 5566 | layer->onDisconnect(); |
| 5567 | } |
| 5568 | |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5569 | if (what & layer_state_t::ePositionChanged) { |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 5570 | if (layer->setPosition(s.x, s.y)) { |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5571 | flags |= eTraversalNeeded; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5572 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5573 | } |
| 5574 | if (what & layer_state_t::eLayerChanged) { |
| 5575 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5576 | const auto& p = layer->getParent(); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5577 | if (p == nullptr) { |
chaviw | 64f7b42 | 2017-07-12 10:31:58 -0700 | [diff] [blame] | 5578 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5579 | if (layer->setLayer(s.z) && idx >= 0) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5580 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5581 | mCurrentState.layersSortedByZ.add(layer); |
| 5582 | // we need traversal (state changed) |
| 5583 | // AND transaction (list changed) |
| 5584 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5585 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5586 | } else { |
| 5587 | if (p->setChildLayer(layer, s.z)) { |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 5588 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5589 | } |
| 5590 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5591 | } |
| 5592 | if (what & layer_state_t::eRelativeLayerChanged) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5593 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5594 | const auto& p = layer->getParent(); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5595 | const auto& relativeHandle = s.relativeLayerSurfaceControl ? |
| 5596 | s.relativeLayerSurfaceControl->getHandle() : nullptr; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5597 | if (p == nullptr) { |
| 5598 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5599 | if (layer->setRelativeLayer(relativeHandle, s.z) && |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5600 | idx >= 0) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5601 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5602 | mCurrentState.layersSortedByZ.add(layer); |
| 5603 | // we need traversal (state changed) |
| 5604 | // AND transaction (list changed) |
| 5605 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5606 | } |
| 5607 | } else { |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5608 | if (p->setChildRelativeLayer(layer, relativeHandle, s.z)) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5609 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5610 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5611 | } |
| 5612 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5613 | if (what & layer_state_t::eAlphaChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5614 | if (layer->setAlpha(s.color.a)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5615 | } |
| 5616 | if (what & layer_state_t::eColorChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5617 | if (layer->setColor(s.color.rgb)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5618 | } |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 5619 | if (what & layer_state_t::eColorTransformChanged) { |
| 5620 | if (layer->setColorTransform(s.colorTransform)) { |
| 5621 | flags |= eTraversalNeeded; |
| 5622 | } |
| 5623 | } |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5624 | if (what & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5625 | if (layer->setBackgroundColor(s.bgColor.rgb, s.bgColor.a, s.bgColorDataspace)) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5626 | flags |= eTraversalNeeded; |
| 5627 | } |
| 5628 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5629 | if (what & layer_state_t::eMatrixChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5630 | if (layer->setMatrix(s.matrix)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5631 | } |
| 5632 | if (what & layer_state_t::eTransparentRegionChanged) { |
| 5633 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 5634 | flags |= eTraversalNeeded; |
| 5635 | } |
| 5636 | if (what & layer_state_t::eFlagsChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5637 | if (layer->setFlags(s.flags, s.mask)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5638 | } |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 5639 | if (what & layer_state_t::eCornerRadiusChanged) { |
| 5640 | if (layer->setCornerRadius(s.cornerRadius)) |
| 5641 | flags |= eTraversalNeeded; |
| 5642 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5643 | if (what & layer_state_t::eBackgroundBlurRadiusChanged && mSupportsBlur) { |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5644 | if (layer->setBackgroundBlurRadius(s.backgroundBlurRadius)) flags |= eTraversalNeeded; |
| 5645 | } |
Galia Peycheva | e11d575 | 2021-01-22 13:50:16 +0000 | [diff] [blame] | 5646 | if (what & layer_state_t::eBlurRegionsChanged) { |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5647 | if (layer->setBlurRegions(s.blurRegions)) flags |= eTraversalNeeded; |
| 5648 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5649 | if (what & layer_state_t::eLayerStackChanged) { |
| 5650 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 5651 | // We only allow setting layer stacks for top level layers, |
| 5652 | // everything else inherits layer stack from its parent. |
| 5653 | if (layer->hasParent()) { |
| 5654 | 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] | 5655 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5656 | } else if (idx < 0) { |
| 5657 | ALOGE("Attempt to set layer stack on layer without parent (%s) that " |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5658 | "that also does not appear in the top level layer list. Something" |
| 5659 | " has gone wrong.", |
| 5660 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5661 | } else if (layer->setLayerStack(s.layerStack)) { |
| 5662 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5663 | mCurrentState.layersSortedByZ.add(layer); |
| 5664 | // we need traversal (state changed) |
| 5665 | // AND transaction (list changed) |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5666 | flags |= eTransactionNeeded | eTraversalNeeded | eTransformHintUpdateNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5667 | } |
| 5668 | } |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5669 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5670 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5671 | } |
| 5672 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5673 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5674 | flags |= eTraversalNeeded; |
| 5675 | } |
| 5676 | if (what & layer_state_t::eCropChanged) { |
| 5677 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5678 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5679 | if (what & layer_state_t::eDataspaceChanged) { |
| 5680 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5681 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5682 | if (what & layer_state_t::eSurfaceDamageRegionChanged) { |
| 5683 | if (layer->setSurfaceDamageRegion(s.surfaceDamageRegion)) flags |= eTraversalNeeded; |
| 5684 | } |
| 5685 | if (what & layer_state_t::eApiChanged) { |
| 5686 | if (layer->setApi(s.api)) flags |= eTraversalNeeded; |
| 5687 | } |
| 5688 | if (what & layer_state_t::eSidebandStreamChanged) { |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 5689 | if (layer->setSidebandStream(s.sidebandStream, frameTimelineInfo, postTime)) |
| 5690 | flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5691 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5692 | if (what & layer_state_t::eInputInfoChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5693 | layer->setInputInfo(*s.windowInfoHandle->getInfo()); |
| 5694 | flags |= eTraversalNeeded; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5695 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5696 | if (what & layer_state_t::eMetadataChanged) { |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5697 | if (const int32_t gameMode = s.metadata.getInt32(gui::METADATA_GAME_MODE, -1); |
| 5698 | gameMode != -1) { |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5699 | // The transaction will be received on the Task layer and needs to be applied to all |
| 5700 | // child layers. Child layers that are added at a later point will obtain the game mode |
| 5701 | // info through addChild(). |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5702 | layer->setGameModeForTree(static_cast<GameMode>(gameMode)); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5703 | } |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5704 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 5705 | if (layer->setMetadata(s.metadata)) { |
| 5706 | flags |= eTraversalNeeded; |
| 5707 | mLayerMetadataSnapshotNeeded = true; |
| 5708 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5709 | } |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 5710 | if (what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 5711 | if (layer->setColorSpaceAgnostic(s.colorSpaceAgnostic)) { |
| 5712 | flags |= eTraversalNeeded; |
| 5713 | } |
| 5714 | } |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 5715 | if (what & layer_state_t::eShadowRadiusChanged) { |
| 5716 | if (layer->setShadowRadius(s.shadowRadius)) flags |= eTraversalNeeded; |
| 5717 | } |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 5718 | if (what & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 5719 | const auto compatibility = |
| 5720 | Layer::FrameRate::convertCompatibility(s.defaultFrameRateCompatibility); |
| 5721 | |
| 5722 | if (layer->setDefaultFrameRateCompatibility(compatibility)) { |
| 5723 | flags |= eTraversalNeeded; |
| 5724 | } |
| 5725 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5726 | if (what & layer_state_t::eFrameRateSelectionPriority) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5727 | if (layer->setFrameRateSelectionPriority(s.frameRateSelectionPriority)) { |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5728 | flags |= eTraversalNeeded; |
| 5729 | } |
| 5730 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5731 | if (what & layer_state_t::eFrameRateChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5732 | const auto compatibility = |
| 5733 | Layer::FrameRate::convertCompatibility(s.frameRateCompatibility); |
| 5734 | const auto strategy = |
| 5735 | Layer::FrameRate::convertChangeFrameRateStrategy(s.changeFrameRateStrategy); |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 5736 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 5737 | if (layer->setFrameRate(Layer::FrameRate::FrameRateVote(Fps::fromValue(s.frameRate), |
| 5738 | compatibility, strategy))) { |
| 5739 | flags |= eTraversalNeeded; |
| 5740 | } |
| 5741 | } |
| 5742 | if (what & layer_state_t::eFrameRateCategoryChanged) { |
| 5743 | const FrameRateCategory category = Layer::FrameRate::convertCategory(s.frameRateCategory); |
Rachel Lee | 67afbea | 2023-09-28 15:35:07 -0700 | [diff] [blame] | 5744 | if (layer->setFrameRateCategory(category, s.frameRateCategorySmoothSwitchOnly)) { |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 5745 | flags |= eTraversalNeeded; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 5746 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5747 | } |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 5748 | if (what & layer_state_t::eFrameRateSelectionStrategyChanged) { |
| 5749 | const scheduler::LayerInfo::FrameRateSelectionStrategy strategy = |
| 5750 | scheduler::LayerInfo::convertFrameRateSelectionStrategy( |
| 5751 | s.frameRateSelectionStrategy); |
| 5752 | if (layer->setFrameRateSelectionStrategy(strategy)) { |
| 5753 | flags |= eTraversalNeeded; |
| 5754 | } |
| 5755 | } |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5756 | if (what & layer_state_t::eFixedTransformHintChanged) { |
| 5757 | if (layer->setFixedTransformHint(s.fixedTransformHint)) { |
| 5758 | flags |= eTraversalNeeded | eTransformHintUpdateNeeded; |
| 5759 | } |
| 5760 | } |
Vishnu Nair | cf26a0a | 2020-11-13 12:56:20 -0800 | [diff] [blame] | 5761 | if (what & layer_state_t::eAutoRefreshChanged) { |
| 5762 | layer->setAutoRefresh(s.autoRefresh); |
| 5763 | } |
Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 5764 | if (what & layer_state_t::eDimmingEnabledChanged) { |
| 5765 | if (layer->setDimmingEnabled(s.dimmingEnabled)) flags |= eTraversalNeeded; |
| 5766 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5767 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 5768 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5769 | flags |= eTraversalNeeded; |
| 5770 | } |
| 5771 | } |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 5772 | if (what & layer_state_t::eDesiredHdrHeadroomChanged) { |
| 5773 | if (layer->setDesiredHdrHeadroom(s.desiredHdrSdrRatio)) { |
| 5774 | flags |= eTraversalNeeded; |
| 5775 | } |
| 5776 | } |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 5777 | if (what & layer_state_t::eCachingHintChanged) { |
| 5778 | if (layer->setCachingHint(s.cachingHint)) { |
| 5779 | flags |= eTraversalNeeded; |
| 5780 | } |
| 5781 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5782 | if (what & layer_state_t::eHdrMetadataChanged) { |
| 5783 | if (layer->setHdrMetadata(s.hdrMetadata)) flags |= eTraversalNeeded; |
| 5784 | } |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5785 | if (what & layer_state_t::eTrustedOverlayChanged) { |
Vishnu Nair | 9e0017e | 2024-05-22 19:02:44 +0000 | [diff] [blame] | 5786 | if (layer->setTrustedOverlay(s.trustedOverlay == gui::TrustedOverlay::ENABLED)) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5787 | flags |= eTraversalNeeded; |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5788 | } |
| 5789 | } |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 5790 | if (what & layer_state_t::eStretchChanged) { |
| 5791 | if (layer->setStretchEffect(s.stretchEffect)) { |
| 5792 | flags |= eTraversalNeeded; |
| 5793 | } |
| 5794 | } |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 5795 | if (what & layer_state_t::eBufferCropChanged) { |
| 5796 | if (layer->setBufferCrop(s.bufferCrop)) { |
| 5797 | flags |= eTraversalNeeded; |
| 5798 | } |
| 5799 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 5800 | if (what & layer_state_t::eDestinationFrameChanged) { |
| 5801 | if (layer->setDestinationFrame(s.destinationFrame)) { |
| 5802 | flags |= eTraversalNeeded; |
| 5803 | } |
| 5804 | } |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5805 | if (what & layer_state_t::eDropInputModeChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5806 | if (layer->setDropInputMode(s.dropInputMode)) { |
| 5807 | flags |= eTraversalNeeded; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 5808 | mUpdateInputInfo = true; |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5809 | } |
| 5810 | } |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5811 | // This has to happen after we reparent children because when we reparent to null we remove |
| 5812 | // child layers from current state and remove its relative z. If the children are reparented in |
| 5813 | // the same transaction, then we have to make sure we reparent the children first so we do not |
| 5814 | // lose its relative z order. |
| 5815 | if (what & layer_state_t::eReparent) { |
| 5816 | bool hadParent = layer->hasParent(); |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5817 | auto parentHandle = (s.parentSurfaceControlForChild) |
| 5818 | ? s.parentSurfaceControlForChild->getHandle() |
| 5819 | : nullptr; |
| 5820 | if (layer->reparent(parentHandle)) { |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5821 | if (!hadParent) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 5822 | layer->setIsAtRoot(false); |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5823 | mCurrentState.layersSortedByZ.remove(layer); |
| 5824 | } |
| 5825 | flags |= eTransactionNeeded | eTraversalNeeded; |
| 5826 | } |
| 5827 | } |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5828 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5829 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5830 | for (auto& [listener, callbackIds] : filteredListeners) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 5831 | callbackHandles.emplace_back( |
| 5832 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5833 | } |
| 5834 | } |
Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 5835 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5836 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5837 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
Nergi Rahardi | 39f510f | 2024-05-23 15:16:54 +0900 | [diff] [blame] | 5838 | desiredPresentTime, isAutoTimestamp, frameTimelineInfo)) { |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5839 | flags |= eTraversalNeeded; |
| 5840 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5841 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5842 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 5843 | } |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 5844 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5845 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5846 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5847 | } |
| 5848 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5849 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5850 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5851 | s.trustedPresentationListener)) { |
| 5852 | flags |= eTraversalNeeded; |
| 5853 | } |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5854 | } |
| 5855 | |
Pascal Muetschard | b39918f | 2023-01-27 11:36:11 +0100 | [diff] [blame] | 5856 | if (what & layer_state_t::eFlushJankData) { |
| 5857 | // Do nothing. Processing the transaction completed listeners currently cause the flush. |
| 5858 | } |
| 5859 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5860 | if (layer->setTransactionCompletedListeners(callbackHandles, |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5861 | layer->willPresentCurrentTransaction() || |
| 5862 | layer->willReleaseBufferOnLatch())) { |
Vishnu Nair | d691322 | 2023-02-01 22:56:21 +0000 | [diff] [blame] | 5863 | flags |= eTraversalNeeded; |
| 5864 | } |
| 5865 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5866 | // Do not put anything that updates layer state or modifies flags after |
| 5867 | // setTransactionCompletedListener |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5868 | |
| 5869 | // 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] | 5870 | if (((flags & eTransformHintUpdateNeeded) == 0) && |
| 5871 | oldLayerStack != layer->getLayerStack(LayerVector::StateSet::Current)) { |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5872 | flags |= eTransformHintUpdateNeeded; |
| 5873 | } |
| 5874 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5875 | return flags; |
| 5876 | } |
| 5877 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5878 | uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& frameTimelineInfo, |
| 5879 | ResolvedComposerState& composerState, |
| 5880 | int64_t desiredPresentTime, |
| 5881 | bool isAutoTimestamp, int64_t postTime, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5882 | uint64_t transactionId) { |
| 5883 | layer_state_t& s = composerState.state; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5884 | |
| 5885 | std::vector<ListenerCallbacks> filteredListeners; |
| 5886 | for (auto& listener : s.listeners) { |
| 5887 | // Starts a registration but separates the callback ids according to callback type. This |
| 5888 | // allows the callback invoker to send on latch callbacks earlier. |
| 5889 | // note that startRegistration will not re-register if the listener has |
| 5890 | // already be registered for a prior surface control |
| 5891 | |
| 5892 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5893 | if (!onCommitCallbacks.callbackIds.empty()) { |
| 5894 | filteredListeners.push_back(onCommitCallbacks); |
| 5895 | } |
| 5896 | |
| 5897 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5898 | if (!onCompleteCallbacks.callbackIds.empty()) { |
| 5899 | filteredListeners.push_back(onCompleteCallbacks); |
| 5900 | } |
| 5901 | } |
| 5902 | |
| 5903 | const uint64_t what = s.what; |
| 5904 | uint32_t flags = 0; |
| 5905 | sp<Layer> layer = nullptr; |
| 5906 | if (s.surface) { |
| 5907 | layer = LayerHandle::getLayer(s.surface); |
| 5908 | } else { |
| 5909 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5910 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5911 | } |
| 5912 | if (layer == nullptr) { |
| 5913 | for (auto& [listener, callbackIds] : s.listeners) { |
| 5914 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5915 | callbackIds, |
| 5916 | s.surface), |
| 5917 | std::vector<JankData>()); |
| 5918 | } |
| 5919 | return 0; |
| 5920 | } |
| 5921 | if (what & layer_state_t::eProducerDisconnect) { |
| 5922 | layer->onDisconnect(); |
| 5923 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5924 | |
| 5925 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5926 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5927 | for (auto& [listener, callbackIds] : filteredListeners) { |
| 5928 | callbackHandles.emplace_back( |
| 5929 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
| 5930 | } |
| 5931 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5932 | // TODO(b/238781169) remove after screenshot refactor, currently screenshots |
| 5933 | // requires to read drawing state from binder thread. So we need to fix that |
| 5934 | // before removing this. |
Vishnu Nair | aeaf9d7 | 2023-09-12 15:47:41 -0700 | [diff] [blame] | 5935 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5936 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
| 5937 | } |
| 5938 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5939 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5940 | flags |= eTraversalNeeded; |
| 5941 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5942 | if (what & layer_state_t::eCropChanged) { |
| 5943 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5944 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5945 | if (what & layer_state_t::eSidebandStreamChanged) { |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 5946 | if (layer->setSidebandStream(s.sidebandStream, frameTimelineInfo, postTime)) |
| 5947 | flags |= eTraversalNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5948 | } |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 5949 | if (what & layer_state_t::eDataspaceChanged) { |
| 5950 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5951 | } |
Vishnu Nair | c5e3416 | 2023-08-22 13:21:20 -0700 | [diff] [blame] | 5952 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
| 5953 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
| 5954 | flags |= eTraversalNeeded; |
| 5955 | } |
| 5956 | } |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 5957 | if (what & layer_state_t::eDesiredHdrHeadroomChanged) { |
| 5958 | if (layer->setDesiredHdrHeadroom(s.desiredHdrSdrRatio)) { |
| 5959 | flags |= eTraversalNeeded; |
| 5960 | } |
| 5961 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5962 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 5963 | std::optional<ui::Transform::RotationFlags> transformHint = std::nullopt; |
| 5964 | frontend::LayerSnapshot* snapshot = mLayerSnapshotBuilder.getSnapshot(layer->sequence); |
| 5965 | if (snapshot) { |
| 5966 | transformHint = snapshot->transformHint; |
| 5967 | } |
| 5968 | layer->setTransformHint(transformHint); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5969 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
Nergi Rahardi | 39f510f | 2024-05-23 15:16:54 +0900 | [diff] [blame] | 5970 | desiredPresentTime, isAutoTimestamp, frameTimelineInfo)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5971 | flags |= eTraversalNeeded; |
| 5972 | } |
| 5973 | mLayersWithQueuedFrames.emplace(layer); |
| 5974 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5975 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
| 5976 | } |
| 5977 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5978 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5979 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5980 | } |
| 5981 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5982 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5983 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5984 | s.trustedPresentationListener)) { |
| 5985 | flags |= eTraversalNeeded; |
| 5986 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5987 | } |
| 5988 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5989 | const auto& requestedLayerState = mLayerLifecycleManager.getLayerFromId(layer->getSequence()); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5990 | bool willPresentCurrentTransaction = requestedLayerState && |
| 5991 | (requestedLayerState->hasReadyFrame() || |
| 5992 | requestedLayerState->willReleaseBufferOnLatch()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5993 | if (layer->setTransactionCompletedListeners(callbackHandles, willPresentCurrentTransaction)) |
| 5994 | flags |= eTraversalNeeded; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5995 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5996 | return flags; |
| 5997 | } |
| 5998 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5999 | uint32_t SurfaceFlinger::addInputWindowCommands(const InputWindowCommands& inputWindowCommands) { |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 6000 | bool hasChanges = mInputWindowCommands.merge(inputWindowCommands); |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 6001 | return hasChanges ? eTraversalNeeded : 0; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 6002 | } |
| 6003 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 6004 | status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 6005 | const sp<IBinder>& mirrorFromHandle, |
| 6006 | gui::CreateSurfaceResult& outResult) { |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 6007 | if (!mirrorFromHandle) { |
| 6008 | return NAME_NOT_FOUND; |
| 6009 | } |
| 6010 | |
| 6011 | sp<Layer> mirrorLayer; |
| 6012 | sp<Layer> mirrorFrom; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 6013 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 6014 | { |
| 6015 | Mutex::Autolock _l(mStateLock); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 6016 | mirrorFrom = LayerHandle::getLayer(mirrorFromHandle); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 6017 | if (!mirrorFrom) { |
| 6018 | return NAME_NOT_FOUND; |
| 6019 | } |
Vishnu Nair | b21272e | 2022-07-01 22:47:33 +0000 | [diff] [blame] | 6020 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 6021 | mirrorArgs.mirrorLayerHandle = mirrorFromHandle; |
| 6022 | mirrorArgs.addToRoot = false; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 6023 | status_t result = createEffectLayer(mirrorArgs, &outResult.handle, &mirrorLayer); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 6024 | if (result != NO_ERROR) { |
| 6025 | return result; |
| 6026 | } |
| 6027 | |
Melody Hsu | 12ecd08 | 2024-04-17 19:03:13 +0000 | [diff] [blame] | 6028 | mirrorLayer->setClonedChild(mirrorFrom->createClone()); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 6029 | } |
| 6030 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 6031 | outResult.layerId = mirrorLayer->sequence; |
| 6032 | outResult.layerName = String16(mirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 6033 | return addClientLayer(mirrorArgs, outResult.handle, mirrorLayer /* layer */, |
| 6034 | nullptr /* parent */, nullptr /* outTransformHint */); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 6035 | } |
| 6036 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 6037 | status_t SurfaceFlinger::mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 6038 | gui::CreateSurfaceResult& outResult) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 6039 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6040 | const int uid = ipc->getCallingUid(); |
| 6041 | if (uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM && uid != AID_SHELL) { |
| 6042 | ALOGE("Permission denied when trying to mirror display"); |
| 6043 | return PERMISSION_DENIED; |
| 6044 | } |
| 6045 | |
| 6046 | ui::LayerStack layerStack; |
| 6047 | sp<Layer> rootMirrorLayer; |
| 6048 | status_t result = 0; |
| 6049 | |
| 6050 | { |
| 6051 | Mutex::Autolock lock(mStateLock); |
| 6052 | |
| 6053 | const auto display = getDisplayDeviceLocked(displayId); |
| 6054 | if (!display) { |
| 6055 | return NAME_NOT_FOUND; |
| 6056 | } |
| 6057 | |
| 6058 | layerStack = display->getLayerStack(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 6059 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 6060 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 6061 | mirrorArgs.addToRoot = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 6062 | mirrorArgs.layerStackToMirror = layerStack; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 6063 | result = createEffectLayer(mirrorArgs, &outResult.handle, &rootMirrorLayer); |
| 6064 | outResult.layerId = rootMirrorLayer->sequence; |
| 6065 | outResult.layerName = String16(rootMirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 6066 | result |= addClientLayer(mirrorArgs, outResult.handle, rootMirrorLayer /* layer */, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 6067 | nullptr /* parent */, nullptr /* outTransformHint */); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 6068 | } |
| 6069 | |
| 6070 | if (result != NO_ERROR) { |
| 6071 | return result; |
| 6072 | } |
| 6073 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 6074 | setTransactionFlags(eTransactionFlushNeeded); |
| 6075 | return NO_ERROR; |
| 6076 | } |
| 6077 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 6078 | status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, gui::CreateSurfaceResult& outResult) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 6079 | status_t result = NO_ERROR; |
| 6080 | |
| 6081 | sp<Layer> layer; |
| 6082 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 6083 | switch (args.flags & ISurfaceComposerClient::eFXSurfaceMask) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 6084 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 6085 | case ISurfaceComposerClient::eFXSurfaceContainer: |
| 6086 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 6087 | args.flags |= ISurfaceComposerClient::eNoColorFill; |
Siarhei Vishniakou | 8d66013 | 2024-01-11 16:48:44 -0800 | [diff] [blame] | 6088 | [[fallthrough]]; |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 6089 | case ISurfaceComposerClient::eFXSurfaceEffect: { |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 6090 | result = createBufferStateLayer(args, &outResult.handle, &layer); |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 6091 | std::atomic<int32_t>* pendingBufferCounter = layer->getPendingBufferCounter(); |
| 6092 | if (pendingBufferCounter) { |
| 6093 | std::string counterName = layer->getPendingBufferCounterName(); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 6094 | mBufferCountTracker.add(outResult.handle->localBinder(), counterName, |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 6095 | pendingBufferCounter); |
| 6096 | } |
| 6097 | } break; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 6098 | default: |
| 6099 | result = BAD_VALUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6100 | break; |
| 6101 | } |
| 6102 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 6103 | if (result != NO_ERROR) { |
| 6104 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6105 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 6106 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 6107 | args.addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess(); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 6108 | // We can safely promote the parent layer in binder thread because we have a strong reference |
| 6109 | // to the layer's handle inside this scope. |
| 6110 | sp<Layer> parent = LayerHandle::getLayer(args.parentHandle.promote()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 6111 | if (args.parentHandle != nullptr && parent == nullptr) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 6112 | ALOGE("Invalid parent handle %p", args.parentHandle.promote().get()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 6113 | args.addToRoot = false; |
Garfield Tan | dbc93d7 | 2021-10-26 18:28:57 -0700 | [diff] [blame] | 6114 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 6115 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 6116 | uint32_t outTransformHint; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 6117 | result = addClientLayer(args, outResult.handle, layer, parent, &outTransformHint); |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 6118 | if (result != NO_ERROR) { |
| 6119 | return result; |
| 6120 | } |
| 6121 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 6122 | outResult.transformHint = static_cast<int32_t>(outTransformHint); |
| 6123 | outResult.layerId = layer->sequence; |
| 6124 | outResult.layerName = String16(layer->getDebugName()); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 6125 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6126 | } |
| 6127 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 6128 | status_t SurfaceFlinger::createBufferStateLayer(LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 6129 | sp<Layer>* outLayer) { |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 6130 | *outLayer = getFactory().createBufferStateLayer(args); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 6131 | *handle = (*outLayer)->getHandle(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 6132 | return NO_ERROR; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 6133 | } |
| 6134 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 6135 | status_t SurfaceFlinger::createEffectLayer(const LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 6136 | sp<Layer>* outLayer) { |
| 6137 | *outLayer = getFactory().createEffectLayer(args); |
| 6138 | *handle = (*outLayer)->getHandle(); |
| 6139 | return NO_ERROR; |
| 6140 | } |
| 6141 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 6142 | void SurfaceFlinger::markLayerPendingRemovalLocked(const sp<Layer>& layer) { |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 6143 | mLayersPendingRemoval.add(layer); |
| 6144 | mLayersRemoved = true; |
| 6145 | setTransactionFlags(eTransactionNeeded); |
| 6146 | } |
| 6147 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 6148 | void SurfaceFlinger::onHandleDestroyed(BBinder* handle, sp<Layer>& layer, uint32_t layerId) { |
| 6149 | { |
| 6150 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | 606d9d0 | 2023-08-19 14:20:18 -0700 | [diff] [blame] | 6151 | mDestroyedHandles.emplace_back(layerId, layer->getDebugName()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 6152 | } |
| 6153 | |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 6154 | { |
| 6155 | // Used to remove stalled transactions which uses an internal lock. |
| 6156 | ftl::FakeGuard guard(kMainThreadContext); |
| 6157 | mTransactionHandler.onLayerDestroyed(layerId); |
| 6158 | } |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 6159 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 6160 | Mutex::Autolock lock(mStateLock); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 6161 | markLayerPendingRemovalLocked(layer); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 6162 | layer->onHandleDestroyed(); |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 6163 | mBufferCountTracker.remove(handle); |
Robert Carr | 695d528 | 2018-12-18 15:27:58 -0800 | [diff] [blame] | 6164 | layer.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 6165 | |
| 6166 | setTransactionFlags(eTransactionFlushNeeded); |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 6167 | } |
| 6168 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 6169 | void SurfaceFlinger::initializeDisplays() { |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6170 | TransactionState state; |
| 6171 | state.inputWindowCommands = mInputWindowCommands; |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6172 | const nsecs_t now = systemTime(); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6173 | state.desiredPresentTime = now; |
| 6174 | state.postTime = now; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6175 | state.originPid = mPid; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6176 | state.originUid = static_cast<int>(getuid()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6177 | const uint64_t transactionId = (static_cast<uint64_t>(mPid) << 32) | mUniqueTransactionId++; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6178 | state.id = transactionId; |
| 6179 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6180 | auto layerStack = ui::DEFAULT_LAYER_STACK.id; |
| 6181 | for (const auto& [id, display] : FTL_FAKE_GUARD(mStateLock, mPhysicalDisplays)) { |
| 6182 | state.displays.push(DisplayState(display.token(), ui::LayerStack::fromValue(layerStack++))); |
| 6183 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 6184 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6185 | std::vector<TransactionState> transactions; |
| 6186 | transactions.emplace_back(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 6187 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 6188 | { |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 6189 | Mutex::Autolock lock(mStateLock); |
| 6190 | applyAndCommitDisplayTransactionStatesLocked(transactions); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6191 | } |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 6192 | |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6193 | { |
| 6194 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6195 | |
| 6196 | // In case of a restart, ensure all displays are off. |
| 6197 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6198 | setPowerModeInternal(getDisplayDeviceLocked(id), hal::PowerMode::OFF); |
| 6199 | } |
| 6200 | |
| 6201 | // Power on all displays. The primary display is first, so becomes the active display. Also, |
| 6202 | // the DisplayCapability set of a display is populated on its first powering on. Do this now |
| 6203 | // before responding to any Binder query from DisplayManager about display capabilities. |
Robert Horvath | dce110a | 2022-09-16 11:08:47 +0200 | [diff] [blame] | 6204 | // Additionally, do not turn on displays if the boot should be quiescent. |
| 6205 | if (!mSkipPowerOnForQuiescent) { |
| 6206 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6207 | setPowerModeInternal(getDisplayDeviceLocked(id), hal::PowerMode::ON); |
| 6208 | } |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6209 | } |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6210 | } |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 6211 | } |
| 6212 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6213 | void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6214 | if (display->isVirtual()) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6215 | // TODO(b/241285876): This code path should not be reachable, so enforce this at compile |
| 6216 | // time. |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 6217 | ALOGE("%s: Invalid operation on virtual display", __func__); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6218 | return; |
| 6219 | } |
| 6220 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6221 | const auto displayId = display->getPhysicalId(); |
| 6222 | 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] | 6223 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6224 | const auto currentMode = display->getPowerMode(); |
| 6225 | if (currentMode == mode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6226 | return; |
| 6227 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6228 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6229 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 6230 | .transform(&PhysicalDisplay::isInternal) |
| 6231 | .value_or(false); |
| 6232 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 6233 | const auto activeDisplay = getDisplayDeviceLocked(mActiveDisplayId); |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 6234 | |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6235 | ALOGW_IF(display != activeDisplay && isInternalDisplay && activeDisplay && |
| 6236 | activeDisplay->isPoweredOn(), |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 6237 | "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] | 6238 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6239 | display->setPowerMode(mode); |
| 6240 | |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 6241 | const auto activeMode = display->refreshRateSelector().getActiveMode().modePtr; |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6242 | if (currentMode == hal::PowerMode::OFF) { |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 6243 | // Turn on the display |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6244 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 6245 | // Activate the display (which involves a modeset to the active mode) when the inner or |
| 6246 | // outer display of a foldable is powered on. This condition relies on the above |
| 6247 | // DisplayDevice::setPowerMode. If `display` and `activeDisplay` are the same display, |
| 6248 | // then the `activeDisplay->isPoweredOn()` below is true, such that the display is not |
| 6249 | // activated every time it is powered on. |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6250 | // |
| 6251 | // TODO(b/255635821): Remove the concept of active display. |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 6252 | if (isInternalDisplay && (!activeDisplay || !activeDisplay->isPoweredOn())) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 6253 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 6254 | } |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6255 | |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6256 | if (displayId == mActiveDisplayId) { |
| 6257 | // TODO(b/281692563): Merge the syscalls. For now, keep uclamp in a separate syscall and |
| 6258 | // set it before SCHED_FIFO due to b/190237315. |
| 6259 | if (setSchedAttr(true) != NO_ERROR) { |
| 6260 | ALOGW("Failed to set uclamp.min after powering on active display: %s", |
| 6261 | strerror(errno)); |
| 6262 | } |
| 6263 | if (setSchedFifo(true) != NO_ERROR) { |
| 6264 | ALOGW("Failed to set SCHED_FIFO after powering on active display: %s", |
| 6265 | strerror(errno)); |
| 6266 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 6267 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6268 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6269 | getHwComposer().setPowerMode(displayId, mode); |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6270 | if (mode != hal::PowerMode::DOZE_SUSPEND && |
| 6271 | (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present())) { |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6272 | const bool enable = |
| 6273 | mScheduler->getVsyncSchedule(displayId)->getPendingHardwareVsyncState(); |
| 6274 | requestHardwareVsync(displayId, enable); |
| 6275 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6276 | if (displayId == mActiveDisplayId) { |
| 6277 | mScheduler->enableSyntheticVsync(false); |
| 6278 | } |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6279 | |
| 6280 | constexpr bool kAllowToEnable = true; |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 6281 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, activeMode.get()); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6282 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6283 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6284 | mVisibleRegionsDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6285 | scheduleComposite(FrameHint::kActive); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6286 | } else if (mode == hal::PowerMode::OFF) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6287 | const bool currentModeNotDozeSuspend = (currentMode != hal::PowerMode::DOZE_SUSPEND); |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 6288 | // Turn off the display |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6289 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 6290 | if (const auto display = getActivatableDisplay()) { |
| 6291 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
| 6292 | } else { |
| 6293 | if (setSchedFifo(false) != NO_ERROR) { |
| 6294 | ALOGW("Failed to set SCHED_OTHER after powering off active display: %s", |
| 6295 | strerror(errno)); |
| 6296 | } |
| 6297 | if (setSchedAttr(false) != NO_ERROR) { |
| 6298 | ALOGW("Failed set uclamp.min after powering off active display: %s", |
| 6299 | strerror(errno)); |
| 6300 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6301 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6302 | if (currentModeNotDozeSuspend) { |
| 6303 | if (!FlagManager::getInstance().multithreaded_present()) { |
| 6304 | mScheduler->disableHardwareVsync(displayId, true); |
| 6305 | } |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 6306 | mScheduler->enableSyntheticVsync(); |
| 6307 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6308 | } |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 6309 | } |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6310 | if (currentModeNotDozeSuspend && FlagManager::getInstance().multithreaded_present()) { |
| 6311 | constexpr bool kDisallow = true; |
| 6312 | mScheduler->disableHardwareVsync(displayId, kDisallow); |
| 6313 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6314 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6315 | // We must disable VSYNC *before* turning off the display. The call to |
| 6316 | // disableHardwareVsync, above, schedules a task to turn it off after |
| 6317 | // this method returns. But by that point, the display is OFF, so the |
| 6318 | // call just updates the pending state, without actually disabling |
| 6319 | // VSYNC. |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6320 | requestHardwareVsync(displayId, false); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6321 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6322 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6323 | mVisibleRegionsDirty = true; |
| 6324 | // from this point on, SF will stop drawing on this display |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6325 | } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6326 | // Update display while dozing |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6327 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6328 | if (currentMode == hal::PowerMode::DOZE_SUSPEND && |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6329 | (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present())) { |
| 6330 | if (displayId == mActiveDisplayId) { |
| 6331 | ALOGI("Force repainting for DOZE_SUSPEND -> DOZE or ON."); |
| 6332 | mVisibleRegionsDirty = true; |
| 6333 | scheduleRepaint(); |
| 6334 | mScheduler->enableSyntheticVsync(false); |
| 6335 | } |
| 6336 | constexpr bool kAllowToEnable = true; |
| 6337 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, activeMode.get()); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6338 | } |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6339 | } else if (mode == hal::PowerMode::DOZE_SUSPEND) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6340 | // Leave display going to doze |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6341 | if (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present()) { |
| 6342 | constexpr bool kDisallow = true; |
| 6343 | mScheduler->disableHardwareVsync(displayId, kDisallow); |
| 6344 | } |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6345 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6346 | mScheduler->enableSyntheticVsync(); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6347 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6348 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6349 | } else { |
Matthew Bouyack | 38d4961 | 2017-05-12 12:49:32 -0700 | [diff] [blame] | 6350 | ALOGE("Attempting to set unknown power mode: %d\n", mode); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6351 | getHwComposer().setPowerMode(displayId, mode); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6352 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6353 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6354 | if (displayId == mActiveDisplayId) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 6355 | mTimeStats->setPowerMode(mode); |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 6356 | mScheduler->setActiveDisplayPowerModeForRefreshRateStats(mode); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 6357 | } |
| 6358 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6359 | mScheduler->setDisplayPowerMode(displayId, mode); |
| 6360 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6361 | 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] | 6362 | } |
| 6363 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6364 | void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) { |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 6365 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 6366 | kMainThreadContext) { |
Robert Horvath | dce110a | 2022-09-16 11:08:47 +0200 | [diff] [blame] | 6367 | mSkipPowerOnForQuiescent = false; |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 6368 | const auto display = getDisplayDeviceLocked(displayToken); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6369 | if (!display) { |
| 6370 | ALOGE("Attempt to set power mode %d for invalid display token %p", mode, |
| 6371 | displayToken.get()); |
| 6372 | } else if (display->isVirtual()) { |
| 6373 | ALOGW("Attempt to set power mode %d for virtual display", mode); |
| 6374 | } else { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6375 | setPowerModeInternal(display, static_cast<hal::PowerMode>(mode)); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6376 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6377 | }); |
| 6378 | |
| 6379 | future.wait(); |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 6380 | } |
| 6381 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 6382 | status_t SurfaceFlinger::doDump(int fd, const DumpArgs& args, bool asProto) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6383 | std::string result; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 6384 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 6385 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6386 | const int pid = ipc->getCallingPid(); |
| 6387 | const int uid = ipc->getCallingUid(); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 6388 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 6389 | if ((uid != AID_SHELL) && |
| 6390 | !PermissionCache::checkPermission(sDump, pid, uid)) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6391 | StringAppendF(&result, "Permission Denial: can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 6392 | pid, uid); |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6393 | write(fd, result.c_str(), result.size()); |
| 6394 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6395 | } |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 6396 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6397 | if (asProto && args.empty()) { |
| 6398 | perfetto::protos::LayersTraceFileProto traceFileProto = |
| 6399 | mLayerTracing.createTraceFileProto(); |
| 6400 | perfetto::protos::LayersSnapshotProto* layersTrace = traceFileProto.add_entry(); |
| 6401 | perfetto::protos::LayersProto layersProto = dumpProtoFromMainThread(); |
| 6402 | layersTrace->mutable_layers()->Swap(&layersProto); |
| 6403 | auto displayProtos = dumpDisplayProto(); |
| 6404 | layersTrace->mutable_displays()->Swap(&displayProtos); |
| 6405 | result.append(traceFileProto.SerializeAsString()); |
| 6406 | write(fd, result.c_str(), result.size()); |
| 6407 | return NO_ERROR; |
| 6408 | } |
| 6409 | |
| 6410 | static const std::unordered_map<std::string, Dumper> dumpers = { |
| 6411 | {"--comp-displays"s, dumper(&SurfaceFlinger::dumpCompositionDisplays)}, |
| 6412 | {"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)}, |
| 6413 | {"--displays"s, dumper(&SurfaceFlinger::dumpDisplays)}, |
| 6414 | {"--edid"s, argsDumper(&SurfaceFlinger::dumpRawDisplayIdentificationData)}, |
| 6415 | {"--events"s, dumper(&SurfaceFlinger::dumpEvents)}, |
| 6416 | {"--frametimeline"s, argsDumper(&SurfaceFlinger::dumpFrameTimeline)}, |
| 6417 | {"--frontend"s, mainThreadDumper(&SurfaceFlinger::dumpFrontEnd)}, |
| 6418 | {"--hdrinfo"s, dumper(&SurfaceFlinger::dumpHdrInfo)}, |
| 6419 | {"--hwclayers"s, mainThreadDumper(&SurfaceFlinger::dumpHwcLayersMinidump)}, |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 6420 | {"--latency"s, argsMainThreadDumper(&SurfaceFlinger::dumpStats)}, |
| 6421 | {"--latency-clear"s, argsMainThreadDumper(&SurfaceFlinger::clearStats)}, |
| 6422 | {"--list"s, mainThreadDumper(&SurfaceFlinger::listLayers)}, |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6423 | {"--planner"s, argsDumper(&SurfaceFlinger::dumpPlannerInfo)}, |
| 6424 | {"--scheduler"s, dumper(&SurfaceFlinger::dumpScheduler)}, |
| 6425 | {"--timestats"s, protoDumper(&SurfaceFlinger::dumpTimeStats)}, |
| 6426 | {"--vsync"s, dumper(&SurfaceFlinger::dumpVsync)}, |
| 6427 | {"--wide-color"s, dumper(&SurfaceFlinger::dumpWideColorInfo)}, |
| 6428 | }; |
| 6429 | |
| 6430 | const auto flag = args.empty() ? ""s : std::string(String8(args[0])); |
| 6431 | if (const auto it = dumpers.find(flag); it != dumpers.end()) { |
| 6432 | (it->second)(args, asProto, result); |
| 6433 | write(fd, result.c_str(), result.size()); |
| 6434 | return NO_ERROR; |
| 6435 | } |
| 6436 | |
| 6437 | // Traversal of drawing state must happen on the main thread. |
| 6438 | // Otherwise, SortedVector may have shared ownership during concurrent |
| 6439 | // traversals, which can result in use-after-frees. |
| 6440 | std::string compositionLayers; |
| 6441 | mScheduler |
| 6442 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 6443 | dumpVisibleFrontEnd(compositionLayers); |
| 6444 | }) |
| 6445 | .get(); |
| 6446 | dumpAll(args, compositionLayers, result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6447 | write(fd, result.c_str(), result.size()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6448 | return NO_ERROR; |
| 6449 | } |
| 6450 | |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 6451 | status_t SurfaceFlinger::dumpCritical(int fd, const DumpArgs&, bool asProto) { |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 6452 | return doDump(fd, DumpArgs(), asProto); |
| 6453 | } |
| 6454 | |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 6455 | void SurfaceFlinger::listLayers(std::string& result) const { |
| 6456 | for (const auto& layer : mLayerLifecycleManager.getLayers()) { |
| 6457 | StringAppendF(&result, "%s\n", layer->getDebugString().c_str()); |
| 6458 | } |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6459 | } |
| 6460 | |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 6461 | void SurfaceFlinger::dumpStats(const DumpArgs& args, std::string& result) const { |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 6462 | StringAppendF(&result, "%" PRId64 "\n", getVsyncPeriodFromHWC()); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6463 | if (args.size() < 2) return; |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 6464 | |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6465 | const auto name = String8(args[1]); |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 6466 | traverseLegacyLayers([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 6467 | if (layer->getName() == name.c_str()) { |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6468 | layer->dumpFrameStats(result); |
| 6469 | } |
| 6470 | }); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6471 | } |
| 6472 | |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 6473 | void SurfaceFlinger::clearStats(const DumpArgs& args, std::string&) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 6474 | const bool clearAll = args.size() < 2; |
| 6475 | const auto name = clearAll ? String8() : String8(args[1]); |
| 6476 | |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 6477 | traverseLegacyLayers([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 6478 | if (clearAll || layer->getName() == name.c_str()) { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 6479 | layer->clearFrameStats(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6480 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 6481 | }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6482 | } |
| 6483 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6484 | void SurfaceFlinger::dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const { |
| 6485 | mTimeStats->parseArgs(asProto, args, result); |
| 6486 | } |
| 6487 | |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 6488 | void SurfaceFlinger::dumpFrameTimeline(const DumpArgs& args, std::string& result) const { |
| 6489 | mFrameTimeline->parseArgs(args, result); |
| 6490 | } |
| 6491 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6492 | void SurfaceFlinger::logFrameStats(TimePoint now) { |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6493 | static TimePoint sTimestamp = now; |
| 6494 | if (now - sTimestamp < 30min) return; |
| 6495 | sTimestamp = now; |
| 6496 | |
| 6497 | ATRACE_CALL(); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6498 | mDrawingState.traverse([&](Layer* layer) { layer->logFrameStats(); }); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 6499 | } |
| 6500 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6501 | void SurfaceFlinger::appendSfConfigString(std::string& result) const { |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 6502 | result.append(" [sf"); |
Fabien Sanglard | c93afd5 | 2017-03-13 13:02:42 -0700 | [diff] [blame] | 6503 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6504 | StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); |
| 6505 | StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 6506 | StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%zu", |
| 6507 | getHwComposer().getMaxVirtualDisplayDimension()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6508 | StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6509 | StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6510 | maxFrameBufferAcquiredBuffers); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 6511 | result.append("]"); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6512 | } |
| 6513 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6514 | void SurfaceFlinger::dumpScheduler(std::string& result) const { |
| 6515 | utils::Dumper dumper{result}; |
| 6516 | |
| 6517 | mScheduler->dump(dumper); |
| 6518 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6519 | // TODO(b/241285876): Move to DisplayModeController. |
| 6520 | dumper.dump("debugDisplayModeSetByBackdoor"sv, mDebugDisplayModeSetByBackdoor); |
| 6521 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6522 | |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6523 | StringAppendF(&result, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6524 | " present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64 |
| 6525 | " ns\n\n", |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6526 | dispSyncPresentTimeOffset, getVsyncPeriodFromHWC()); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6527 | } |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6528 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6529 | void SurfaceFlinger::dumpEvents(std::string& result) const { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 6530 | mScheduler->dump(scheduler::Cycle::Render, result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6531 | } |
| 6532 | |
| 6533 | void SurfaceFlinger::dumpVsync(std::string& result) const { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 6534 | mScheduler->dumpVsync(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6535 | } |
| 6536 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 6537 | void SurfaceFlinger::dumpPlannerInfo(const DumpArgs& args, std::string& result) const { |
| 6538 | for (const auto& [token, display] : mDisplays) { |
| 6539 | const auto compositionDisplay = display->getCompositionDisplay(); |
| 6540 | compositionDisplay->dumpPlannerInfo(args, result); |
| 6541 | } |
| 6542 | } |
| 6543 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6544 | void SurfaceFlinger::dumpCompositionDisplays(std::string& result) const { |
| 6545 | for (const auto& [token, display] : mDisplays) { |
| 6546 | display->getCompositionDisplay()->dump(result); |
| 6547 | result += '\n'; |
| 6548 | } |
| 6549 | } |
| 6550 | |
| 6551 | void SurfaceFlinger::dumpDisplays(std::string& result) const { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6552 | utils::Dumper dumper{result}; |
| 6553 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6554 | for (const auto& [id, display] : mPhysicalDisplays) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6555 | utils::Dumper::Section section(dumper, ftl::Concat("Display ", id.value).str()); |
| 6556 | |
| 6557 | display.snapshot().dump(dumper); |
| 6558 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6559 | if (const auto device = getDisplayDeviceLocked(id)) { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6560 | device->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6561 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6562 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6563 | |
| 6564 | for (const auto& [token, display] : mDisplays) { |
| 6565 | if (display->isVirtual()) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6566 | const auto displayId = display->getId(); |
| 6567 | utils::Dumper::Section section(dumper, |
| 6568 | ftl::Concat("Virtual Display ", displayId.value).str()); |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6569 | display->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6570 | } |
| 6571 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6572 | } |
| 6573 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6574 | void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 6575 | for (const auto& [token, display] : mDisplays) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6576 | const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6577 | if (!displayId) { |
| 6578 | continue; |
| 6579 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6580 | const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId); |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6581 | if (!hwcDisplayId) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6582 | continue; |
| 6583 | } |
| 6584 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6585 | StringAppendF(&result, |
| 6586 | "Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), |
| 6587 | *hwcDisplayId); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6588 | uint8_t port; |
| 6589 | DisplayIdentificationData data; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6590 | if (!getHwComposer().getDisplayIdentificationData(*hwcDisplayId, &port, &data)) { |
Brian Lindahl | 8a96ef9 | 2024-05-24 14:46:29 +0000 | [diff] [blame] | 6591 | result.append("no display identification data\n"); |
| 6592 | continue; |
| 6593 | } |
| 6594 | |
| 6595 | if (data.empty()) { |
| 6596 | result.append("empty display identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6597 | continue; |
| 6598 | } |
| 6599 | |
| 6600 | if (!isEdid(data)) { |
Brian Lindahl | 8a96ef9 | 2024-05-24 14:46:29 +0000 | [diff] [blame] | 6601 | result.append("unknown format for display identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6602 | continue; |
| 6603 | } |
| 6604 | |
| 6605 | const auto edid = parseEdid(data); |
| 6606 | if (!edid) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6607 | result.append("invalid EDID\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6608 | continue; |
| 6609 | } |
| 6610 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6611 | StringAppendF(&result, "port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6612 | result.append(edid->displayName.data(), edid->displayName.length()); |
| 6613 | result.append("\"\n"); |
| 6614 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6615 | } |
| 6616 | |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6617 | void SurfaceFlinger::dumpRawDisplayIdentificationData(const DumpArgs& args, |
| 6618 | std::string& result) const { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 6619 | hal::HWDisplayId hwcDisplayId; |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6620 | uint8_t port; |
| 6621 | DisplayIdentificationData data; |
| 6622 | |
| 6623 | if (args.size() > 1 && base::ParseUint(String8(args[1]), &hwcDisplayId) && |
| 6624 | getHwComposer().getDisplayIdentificationData(hwcDisplayId, &port, &data)) { |
| 6625 | result.append(reinterpret_cast<const char*>(data.data()), data.size()); |
| 6626 | } |
| 6627 | } |
| 6628 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6629 | void SurfaceFlinger::dumpWideColorInfo(std::string& result) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6630 | StringAppendF(&result, "Device supports wide color: %d\n", mSupportsWideColor); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6631 | StringAppendF(&result, "DisplayColorSetting: %s\n", |
| 6632 | decodeDisplayColorSetting(mDisplayColorSetting).c_str()); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6633 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 6634 | // TODO: print out if wide-color mode is active or not. |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6635 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6636 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6637 | StringAppendF(&result, "Display %s color modes:\n", to_string(id).c_str()); |
| 6638 | for (const auto mode : display.snapshot().colorModes()) { |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 6639 | StringAppendF(&result, " %s (%d)\n", decodeColorMode(mode).c_str(), |
| 6640 | fmt::underlying(mode)); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6641 | } |
| 6642 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6643 | if (const auto display = getDisplayDeviceLocked(id)) { |
| 6644 | ui::ColorMode currentMode = display->getCompositionDisplay()->getState().colorMode; |
| 6645 | StringAppendF(&result, " Current color mode: %s (%d)\n", |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 6646 | decodeColorMode(currentMode).c_str(), fmt::underlying(currentMode)); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6647 | } |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6648 | } |
| 6649 | result.append("\n"); |
| 6650 | } |
| 6651 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6652 | void SurfaceFlinger::dumpHdrInfo(std::string& result) const { |
| 6653 | for (const auto& [displayId, listener] : mHdrLayerInfoListeners) { |
| 6654 | StringAppendF(&result, "HDR events for display %" PRIu64 "\n", displayId.value); |
| 6655 | listener->dump(result); |
| 6656 | result.append("\n"); |
| 6657 | } |
| 6658 | } |
| 6659 | |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6660 | void SurfaceFlinger::dumpFrontEnd(std::string& result) { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6661 | std::ostringstream out; |
| 6662 | out << "\nComposition list\n"; |
| 6663 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6664 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 6665 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 6666 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 6667 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6668 | } |
| 6669 | out << " " << *snapshot << "\n"; |
| 6670 | } |
| 6671 | |
| 6672 | out << "\nInput list\n"; |
| 6673 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6674 | mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6675 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 6676 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 6677 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6678 | } |
| 6679 | out << " " << snapshot << "\n"; |
| 6680 | }); |
| 6681 | |
| 6682 | out << "\nLayer Hierarchy\n" |
| 6683 | << mLayerHierarchyBuilder.getHierarchy().dump() << "\nOffscreen Hierarchy\n" |
| 6684 | << mLayerHierarchyBuilder.getOffscreenHierarchy().dump() << "\n\n"; |
| 6685 | result.append(out.str()); |
| 6686 | } |
| 6687 | |
| 6688 | void SurfaceFlinger::dumpVisibleFrontEnd(std::string& result) { |
| 6689 | if (!mLayerLifecycleManagerEnabled) { |
| 6690 | StringAppendF(&result, "Composition layers\n"); |
| 6691 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 6692 | auto* compositionState = layer->getCompositionState(); |
| 6693 | if (!compositionState || !compositionState->isVisible) return; |
| 6694 | android::base::StringAppendF(&result, "* Layer %p (%s)\n", layer, |
| 6695 | layer->getDebugName() ? layer->getDebugName() |
| 6696 | : "<unknown>"); |
| 6697 | compositionState->dump(result); |
| 6698 | }); |
| 6699 | |
| 6700 | StringAppendF(&result, "Offscreen Layers\n"); |
| 6701 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6702 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
| 6703 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
| 6704 | } |
| 6705 | } else { |
| 6706 | std::ostringstream out; |
| 6707 | out << "\nComposition list\n"; |
| 6708 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6709 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 6710 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 6711 | if (snapshot->hasSomethingToDraw()) { |
| 6712 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 6713 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 6714 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6715 | } |
| 6716 | out << " " << *snapshot << "\n"; |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6717 | } |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6718 | }); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6719 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6720 | out << "\nInput list\n"; |
| 6721 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6722 | mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6723 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 6724 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 6725 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6726 | } |
| 6727 | out << " " << snapshot << "\n"; |
| 6728 | }); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6729 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6730 | out << "\nLayer Hierarchy\n" |
| 6731 | << mLayerHierarchyBuilder.getHierarchy() << "\nOffscreen Hierarchy\n" |
| 6732 | << mLayerHierarchyBuilder.getOffscreenHierarchy() << "\n\n"; |
| 6733 | result = out.str(); |
| 6734 | dumpHwcLayersMinidump(result); |
| 6735 | } |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6736 | } |
| 6737 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6738 | perfetto::protos::LayersProto SurfaceFlinger::dumpDrawingStateProto(uint32_t traceFlags) const { |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 6739 | std::unordered_set<uint64_t> stackIdsToSkip; |
| 6740 | |
| 6741 | // Determine if virtual layers display should be skipped |
| 6742 | if ((traceFlags & LayerTracing::TRACE_VIRTUAL_DISPLAYS) == 0) { |
| 6743 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 6744 | if (display->isVirtual()) { |
| 6745 | stackIdsToSkip.insert(display->getLayerStack().id); |
| 6746 | } |
| 6747 | } |
| 6748 | } |
| 6749 | |
Vishnu Nair | 22be349 | 2023-04-20 10:08:21 -0700 | [diff] [blame] | 6750 | return LayerProtoFromSnapshotGenerator(mLayerSnapshotBuilder, mFrontEndDisplayInfos, |
| 6751 | mLegacyLayers, traceFlags) |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 6752 | .generate(mLayerHierarchyBuilder.getHierarchy()); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6753 | } |
| 6754 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6755 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> |
| 6756 | SurfaceFlinger::dumpDisplayProto() const { |
| 6757 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> displays; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6758 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6759 | perfetto::protos::DisplayProto* displayProto = displays.Add(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6760 | displayProto->set_id(display->getId().value); |
| 6761 | displayProto->set_name(display->getDisplayName()); |
| 6762 | displayProto->set_layer_stack(display->getLayerStack().id); |
DoÄŸancan Emek | fc4b6ed | 2023-07-26 15:24:04 +0000 | [diff] [blame] | 6763 | |
| 6764 | if (!display->isVirtual()) { |
| 6765 | const auto dpi = display->refreshRateSelector().getActiveMode().modePtr->getDpi(); |
| 6766 | displayProto->set_dpi_x(dpi.x); |
| 6767 | displayProto->set_dpi_y(dpi.y); |
| 6768 | } |
| 6769 | |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6770 | LayerProtoHelper::writeSizeToProto(display->getWidth(), display->getHeight(), |
| 6771 | [&]() { return displayProto->mutable_size(); }); |
| 6772 | LayerProtoHelper::writeToProto(display->getLayerStackSpaceRect(), [&]() { |
| 6773 | return displayProto->mutable_layer_stack_space_rect(); |
| 6774 | }); |
| 6775 | LayerProtoHelper::writeTransformToProto(display->getTransform(), |
| 6776 | displayProto->mutable_transform()); |
Vishnu Nair | 791d48a | 2021-12-02 16:55:13 -0800 | [diff] [blame] | 6777 | displayProto->set_is_virtual(display->isVirtual()); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6778 | } |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 6779 | return displays; |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6780 | } |
| 6781 | |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 6782 | void SurfaceFlinger::dumpHwc(std::string& result) const { |
| 6783 | getHwComposer().dump(result); |
| 6784 | } |
| 6785 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6786 | void SurfaceFlinger::dumpOffscreenLayersProto(perfetto::protos::LayersProto& layersProto, |
| 6787 | uint32_t traceFlags) const { |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6788 | // Add a fake invisible root layer to the proto output and parent all the offscreen layers to |
| 6789 | // it. |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6790 | perfetto::protos::LayerProto* rootProto = layersProto.add_layers(); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6791 | const int32_t offscreenRootLayerId = INT32_MAX - 2; |
| 6792 | rootProto->set_id(offscreenRootLayerId); |
| 6793 | rootProto->set_name("Offscreen Root"); |
Vishnu Nair | d5aeb61 | 2019-09-20 14:39:39 -0700 | [diff] [blame] | 6794 | rootProto->set_parent(-1); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6795 | |
| 6796 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6797 | // Add layer as child of the fake root |
| 6798 | rootProto->add_children(offscreenLayer->sequence); |
| 6799 | |
| 6800 | // Add layer |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6801 | auto* layerProto = offscreenLayer->writeToProto(layersProto, traceFlags); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6802 | layerProto->set_parent(offscreenRootLayerId); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6803 | } |
| 6804 | } |
| 6805 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6806 | perfetto::protos::LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 6807 | return mScheduler |
| 6808 | ->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 6809 | return dumpDrawingStateProto(traceFlags); |
| 6810 | }) |
| 6811 | .get(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 6812 | } |
| 6813 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6814 | void SurfaceFlinger::dumpOffscreenLayers(std::string& result) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6815 | auto future = mScheduler->schedule([this] { |
| 6816 | std::string result; |
| 6817 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6818 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
Vishnu Nair | 76554eb | 2022-12-09 03:38:36 +0000 | [diff] [blame] | 6819 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6820 | } |
| 6821 | return result; |
| 6822 | }); |
| 6823 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6824 | result.append("Offscreen Layers:\n"); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6825 | result.append(future.get()); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6826 | } |
| 6827 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6828 | void SurfaceFlinger::dumpHwcLayersMinidumpLockedLegacy(std::string& result) const { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6829 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6830 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6831 | if (!displayId) { |
| 6832 | continue; |
| 6833 | } |
| 6834 | |
| 6835 | 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] | 6836 | displayId == mActiveDisplayId ? "active" : "inactive"); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6837 | Layer::miniDumpHeader(result); |
| 6838 | |
| 6839 | const DisplayDevice& ref = *display; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6840 | mDrawingState.traverseInZOrder([&](Layer* layer) { layer->miniDumpLegacy(result, ref); }); |
| 6841 | result.append("\n"); |
| 6842 | } |
| 6843 | } |
| 6844 | |
| 6845 | void SurfaceFlinger::dumpHwcLayersMinidump(std::string& result) const { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6846 | if (!mLayerLifecycleManagerEnabled) { |
| 6847 | return dumpHwcLayersMinidumpLockedLegacy(result); |
| 6848 | } |
| 6849 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6850 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6851 | if (!displayId) { |
| 6852 | continue; |
| 6853 | } |
| 6854 | |
| 6855 | StringAppendF(&result, "Display %s (%s) HWC layers:\n", to_string(*displayId).c_str(), |
| 6856 | displayId == mActiveDisplayId ? "active" : "inactive"); |
| 6857 | Layer::miniDumpHeader(result); |
| 6858 | |
| 6859 | const DisplayDevice& ref = *display; |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 6860 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 6861 | [&](const frontend::LayerSnapshot& snapshot) FTL_FAKE_GUARD(kMainThreadContext) { |
| 6862 | if (!snapshot.hasSomethingToDraw() || |
| 6863 | ref.getLayerStack() != snapshot.outputFilter.layerStack) { |
| 6864 | return; |
| 6865 | } |
| 6866 | auto it = mLegacyLayers.find(snapshot.sequence); |
| 6867 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 6868 | "Couldnt find layer object for %s", |
| 6869 | snapshot.getDebugString().c_str()); |
| 6870 | it->second->miniDump(result, snapshot, ref); |
| 6871 | }); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6872 | result.append("\n"); |
| 6873 | } |
| 6874 | } |
| 6875 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6876 | void SurfaceFlinger::dumpAll(const DumpArgs& args, const std::string& compositionLayers, |
| 6877 | std::string& result) const { |
| 6878 | TimedLock lock(mStateLock, s2ns(1), __func__); |
| 6879 | if (!lock.locked()) { |
| 6880 | StringAppendF(&result, "Dumping without lock after timeout: %s (%d)\n", |
| 6881 | strerror(-lock.status), lock.status); |
| 6882 | } |
| 6883 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6884 | const bool colorize = !args.empty() && args[0] == String16("--color"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6885 | Colorizer colorizer(colorize); |
| 6886 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6887 | // figure out if we're stuck somewhere |
| 6888 | const nsecs_t now = systemTime(); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6889 | const nsecs_t inTransaction(mDebugInTransaction); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6890 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 6891 | |
| 6892 | /* |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6893 | * Dump library configuration. |
| 6894 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6895 | |
| 6896 | colorizer.bold(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6897 | result.append("Build configuration:"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6898 | colorizer.reset(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6899 | appendSfConfigString(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6900 | result.append("\n"); |
| 6901 | |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6902 | result.append("\nDisplay identification data:\n"); |
| 6903 | dumpDisplayIdentificationData(result); |
| 6904 | |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6905 | result.append("\nWide-Color information:\n"); |
| 6906 | dumpWideColorInfo(result); |
| 6907 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6908 | dumpHdrInfo(result); |
| 6909 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6910 | colorizer.bold(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6911 | result.append("Sync configuration: "); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6912 | colorizer.reset(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6913 | result.append(SyncFeatures::getInstance().toString()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6914 | result.append("\n\n"); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6915 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6916 | colorizer.bold(result); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6917 | result.append("Scheduler:\n"); |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6918 | colorizer.reset(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6919 | dumpScheduler(result); |
| 6920 | dumpEvents(result); |
| 6921 | dumpVsync(result); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 6922 | result.append("\n"); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6923 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6924 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6925 | * Dump the visible layer list |
| 6926 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6927 | colorizer.bold(result); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6928 | StringAppendF(&result, "SurfaceFlinger New Frontend Enabled:%s\n", |
| 6929 | mLayerLifecycleManagerEnabled ? "true" : "false"); |
| 6930 | StringAppendF(&result, "Active Layers - layers with client handles (count = %zu)\n", |
| 6931 | mNumLayers.load()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6932 | colorizer.reset(result); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6933 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 6934 | result.append(compositionLayers); |
Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 6935 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6936 | colorizer.bold(result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6937 | StringAppendF(&result, "Displays (%zu entries)\n", mDisplays.size()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6938 | colorizer.reset(result); |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6939 | dumpDisplays(result); |
| 6940 | dumpCompositionDisplays(result); |
| 6941 | result.push_back('\n'); |
Lloyd Pique | c3cb729 | 2019-05-17 15:25:14 -0700 | [diff] [blame] | 6942 | |
| 6943 | mCompositionEngine->dump(result); |
| 6944 | |
| 6945 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6946 | * Dump SurfaceFlinger global state |
| 6947 | */ |
| 6948 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6949 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6950 | result.append("SurfaceFlinger global state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6951 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6952 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 6953 | getRenderEngine().dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6954 | |
Robert Carr | beba6f0 | 2021-02-10 21:06:27 -0800 | [diff] [blame] | 6955 | result.append("ClientCache state:\n"); |
| 6956 | ClientCache::getInstance().dump(result); |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 6957 | DebugEGLImageTracker::getInstance()->dump(result); |
| 6958 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6959 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 6960 | display->getCompositionDisplay()->getState().undefinedRegion.dump(result, |
| 6961 | "undefinedRegion"); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 6962 | StringAppendF(&result, " orientation=%s, isPoweredOn=%d\n", |
| 6963 | toCString(display->getOrientation()), display->isPoweredOn()); |
Lloyd Pique | 2ae2b3b | 2017-12-14 17:18:17 -0800 | [diff] [blame] | 6964 | } |
Carlos Martinez Romero | 779dc1f | 2022-10-27 23:23:30 +0000 | [diff] [blame] | 6965 | StringAppendF(&result, " transaction-flags : %08x\n", mTransactionFlags.load()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6966 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 6967 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Ying Wei | 784a8e7 | 2024-04-20 08:46:42 +0000 | [diff] [blame] | 6968 | std::string peakFps, xDpi, yDpi; |
| 6969 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 6970 | if (const auto activeModePtr = activeMode.modePtr.get()) { |
| 6971 | peakFps = to_string(activeMode.modePtr->getPeakFps()); |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6972 | const auto dpi = activeModePtr->getDpi(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6973 | xDpi = base::StringPrintf("%.2f", dpi.x); |
| 6974 | yDpi = base::StringPrintf("%.2f", dpi.y); |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6975 | } else { |
Ying Wei | 784a8e7 | 2024-04-20 08:46:42 +0000 | [diff] [blame] | 6976 | peakFps = "unknown"; |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6977 | xDpi = "unknown"; |
| 6978 | yDpi = "unknown"; |
| 6979 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6980 | StringAppendF(&result, |
Ying Wei | 784a8e7 | 2024-04-20 08:46:42 +0000 | [diff] [blame] | 6981 | " peak-refresh-rate : %s\n" |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6982 | " x-dpi : %s\n" |
| 6983 | " y-dpi : %s\n", |
Ying Wei | 784a8e7 | 2024-04-20 08:46:42 +0000 | [diff] [blame] | 6984 | peakFps.c_str(), xDpi.c_str(), yDpi.c_str()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6985 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6986 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6987 | StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6988 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6989 | result.append("\nTransaction tracing: "); |
| 6990 | if (mTransactionTracing) { |
| 6991 | result.append("enabled\n"); |
| 6992 | mTransactionTracing->dump(result); |
| 6993 | } else { |
| 6994 | result.append("disabled\n"); |
| 6995 | } |
| 6996 | result.push_back('\n'); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6997 | |
Ady Abraham | 2790e9f | 2021-04-28 13:14:20 -0700 | [diff] [blame] | 6998 | { |
| 6999 | DumpArgs plannerArgs; |
| 7000 | plannerArgs.add(); // first argument is ignored |
| 7001 | plannerArgs.add(String16("--layers")); |
| 7002 | dumpPlannerInfo(plannerArgs, result); |
| 7003 | } |
| 7004 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 7005 | /* |
| 7006 | * Dump HWComposer state |
| 7007 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 7008 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 7009 | result.append("h/w composer state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 7010 | colorizer.reset(result); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7011 | const bool hwcDisabled = mDebugDisableHWC || mDebugFlashDelay; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 7012 | StringAppendF(&result, " h/w composer %s\n", hwcDisabled ? "disabled" : "enabled"); |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 7013 | dumpHwc(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 7014 | |
| 7015 | /* |
| 7016 | * Dump gralloc state |
| 7017 | */ |
| 7018 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 7019 | alloc.dump(result); |
Karthik Ravi Shankar | 171155a | 2017-06-28 15:40:24 -0700 | [diff] [blame] | 7020 | |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 7021 | /* |
| 7022 | * Dump flag/property manager state |
| 7023 | */ |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 7024 | FlagManager::getInstance().dump(result); |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 7025 | |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 7026 | result.append(mTimeStats->miniDump()); |
| 7027 | result.append("\n"); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 7028 | |
| 7029 | result.append("Window Infos:\n"); |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 7030 | auto windowInfosDebug = mWindowInfosListenerInvoker->getDebugInfo(); |
| 7031 | StringAppendF(&result, " max send vsync id: %" PRId64 "\n", |
| 7032 | ftl::to_underlying(windowInfosDebug.maxSendDelayVsyncId)); |
| 7033 | StringAppendF(&result, " max send delay (ns): %" PRId64 " ns\n", |
| 7034 | windowInfosDebug.maxSendDelayDuration); |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 7035 | StringAppendF(&result, " unsent messages: %zu\n", windowInfosDebug.pendingMessageCount); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 7036 | result.append("\n"); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 7037 | } |
| 7038 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7039 | mat4 SurfaceFlinger::calculateColorMatrix(float saturation) { |
| 7040 | if (saturation == 1) { |
| 7041 | return mat4(); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7042 | } |
| 7043 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7044 | float3 luminance{0.213f, 0.715f, 0.072f}; |
| 7045 | luminance *= 1.0f - saturation; |
| 7046 | mat4 saturationMatrix = mat4(vec4{luminance.r + saturation, luminance.r, luminance.r, 0.0f}, |
| 7047 | vec4{luminance.g, luminance.g + saturation, luminance.g, 0.0f}, |
| 7048 | vec4{luminance.b, luminance.b, luminance.b + saturation, 0.0f}, |
| 7049 | vec4{0.0f, 0.0f, 0.0f, 1.0f}); |
| 7050 | return saturationMatrix; |
| 7051 | } |
| 7052 | |
| 7053 | void SurfaceFlinger::updateColorMatrixLocked() { |
| 7054 | mat4 colorMatrix = |
| 7055 | mClientColorMatrix * calculateColorMatrix(mGlobalSaturationFactor) * mDaltonizer(); |
| 7056 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7057 | if (mCurrentState.colorMatrix != colorMatrix) { |
| 7058 | mCurrentState.colorMatrix = colorMatrix; |
| 7059 | mCurrentState.colorMatrixChanged = true; |
| 7060 | setTransactionFlags(eTransactionNeeded); |
| 7061 | } |
| 7062 | } |
| 7063 | |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 7064 | status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7065 | #pragma clang diagnostic push |
| 7066 | #pragma clang diagnostic error "-Wswitch-enum" |
| 7067 | switch (static_cast<ISurfaceComposerTag>(code)) { |
| 7068 | // These methods should at minimum make sure that the client requested |
| 7069 | // access to SF. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7070 | case GET_HDR_CAPABILITIES: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 7071 | case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 7072 | case GET_GAME_CONTENT_TYPE_SUPPORT: |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 7073 | case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7074 | // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary |
| 7075 | // permission dynamically. Don't use the permission cache for this check. |
| 7076 | bool usePermissionCache = code != OVERRIDE_HDR_TYPES; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 7077 | if (!callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 7078 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7079 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", |
| 7080 | ipc->getCallingPid(), ipc->getCallingUid()); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 7081 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7082 | } |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 7083 | return OK; |
| 7084 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7085 | // The following calls are currently used by clients that do not |
| 7086 | // request necessary permissions. However, they do not expose any secret |
| 7087 | // information, so it is OK to pass them. |
Peiyong Lin | d1fedb4 | 2019-03-11 17:48:41 -0700 | [diff] [blame] | 7088 | case GET_ACTIVE_COLOR_MODE: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7089 | case GET_ACTIVE_DISPLAY_MODE: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7090 | case GET_DISPLAY_COLOR_MODES: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7091 | case GET_DISPLAY_MODES: |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 7092 | case GET_SCHEDULING_POLICY: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7093 | // Calling setTransactionState is safe, because you need to have been |
| 7094 | // granted a reference to Client* and Handle* to do anything with it. |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 7095 | case SET_TRANSACTION_STATE: { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 7096 | // This is not sensitive information, so should not require permission control. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7097 | return OK; |
| 7098 | } |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 7099 | case BOOT_FINISHED: |
| 7100 | // Used by apps to hook Choreographer to SurfaceFlinger. |
| 7101 | case CREATE_DISPLAY_EVENT_CONNECTION: |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 7102 | case CREATE_CONNECTION: |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 7103 | case CREATE_VIRTUAL_DISPLAY: |
| 7104 | case DESTROY_VIRTUAL_DISPLAY: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 7105 | case GET_PRIMARY_PHYSICAL_DISPLAY_ID: |
| 7106 | case GET_PHYSICAL_DISPLAY_IDS: |
| 7107 | case GET_PHYSICAL_DISPLAY_TOKEN: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7108 | case AUTHENTICATE_SURFACE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7109 | case SET_POWER_MODE: |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 7110 | case GET_SUPPORTED_FRAME_TIMESTAMPS: |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7111 | case GET_DISPLAY_STATE: |
| 7112 | case GET_DISPLAY_STATS: |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 7113 | case GET_STATIC_DISPLAY_INFO: |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 7114 | case GET_DYNAMIC_DISPLAY_INFO: |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 7115 | case GET_DISPLAY_NATIVE_PRIMARIES: |
| 7116 | case SET_ACTIVE_COLOR_MODE: |
| 7117 | case SET_BOOT_DISPLAY_MODE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7118 | case CLEAR_BOOT_DISPLAY_MODE: |
| 7119 | case GET_BOOT_DISPLAY_MODE_SUPPORT: |
| 7120 | case SET_AUTO_LOW_LATENCY_MODE: |
| 7121 | case SET_GAME_CONTENT_TYPE: |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 7122 | case CAPTURE_LAYERS: |
| 7123 | case CAPTURE_DISPLAY: |
| 7124 | case CAPTURE_DISPLAY_BY_ID: |
Huihong Luo | 4ed1c91 | 2022-02-22 14:30:01 -0800 | [diff] [blame] | 7125 | case CLEAR_ANIMATION_FRAME_STATS: |
| 7126 | case GET_ANIMATION_FRAME_STATS: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7127 | case OVERRIDE_HDR_TYPES: |
| 7128 | case ON_PULL_ATOM: |
| 7129 | case ENABLE_VSYNC_INJECTIONS: |
| 7130 | case INJECT_VSYNC: |
| 7131 | case GET_LAYER_DEBUG_INFO: |
| 7132 | case GET_COLOR_MANAGEMENT: |
| 7133 | case GET_COMPOSITION_PREFERENCE: |
| 7134 | case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: |
| 7135 | case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7136 | case GET_DISPLAYED_CONTENT_SAMPLE: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7137 | case GET_PROTECTED_CONTENT_SUPPORT: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7138 | case IS_WIDE_COLOR_DISPLAY: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7139 | case ADD_REGION_SAMPLING_LISTENER: |
| 7140 | case REMOVE_REGION_SAMPLING_LISTENER: |
| 7141 | case ADD_FPS_LISTENER: |
| 7142 | case REMOVE_FPS_LISTENER: |
| 7143 | case ADD_TUNNEL_MODE_ENABLED_LISTENER: |
| 7144 | case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: |
| 7145 | case ADD_WINDOW_INFOS_LISTENER: |
| 7146 | case REMOVE_WINDOW_INFOS_LISTENER: |
| 7147 | case SET_DESIRED_DISPLAY_MODE_SPECS: |
| 7148 | case GET_DESIRED_DISPLAY_MODE_SPECS: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7149 | case GET_DISPLAY_BRIGHTNESS_SUPPORT: |
| 7150 | case SET_DISPLAY_BRIGHTNESS: |
| 7151 | case ADD_HDR_LAYER_INFO_LISTENER: |
| 7152 | case REMOVE_HDR_LAYER_INFO_LISTENER: |
| 7153 | case NOTIFY_POWER_BOOST: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7154 | case SET_GLOBAL_SHADOW_SETTINGS: |
| 7155 | case GET_DISPLAY_DECORATION_SUPPORT: |
| 7156 | case SET_FRAME_RATE: |
| 7157 | case SET_OVERRIDE_FRAME_RATE: |
| 7158 | case SET_FRAME_TIMELINE_INFO: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7159 | case ADD_TRANSACTION_TRACE_LISTENER: |
| 7160 | case GET_GPU_CONTEXT_PRIORITY: |
| 7161 | case GET_MAX_ACQUIRED_BUFFER_COUNT: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 7162 | LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 7163 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7164 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7165 | |
| 7166 | // These codes are used for the IBinder protocol to either interrogate the recipient |
| 7167 | // side of the transaction for its canonical interface descriptor or to dump its state. |
| 7168 | // We let them pass by default. |
| 7169 | if (code == IBinder::INTERFACE_TRANSACTION || code == IBinder::DUMP_TRANSACTION || |
| 7170 | code == IBinder::PING_TRANSACTION || code == IBinder::SHELL_COMMAND_TRANSACTION || |
| 7171 | code == IBinder::SYSPROPS_TRANSACTION) { |
| 7172 | return OK; |
| 7173 | } |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7174 | // Numbers from 1000 to 1045 are currently used for backdoors. The code |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7175 | // 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] | 7176 | if (code >= 1000 && code <= 1045) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7177 | ALOGV("Accessing SurfaceFlinger through backdoor code: %u", code); |
| 7178 | return OK; |
| 7179 | } |
| 7180 | ALOGE("Permission Denial: SurfaceFlinger did not recognize request code: %u", code); |
| 7181 | return PERMISSION_DENIED; |
| 7182 | #pragma clang diagnostic pop |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 7183 | } |
| 7184 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7185 | status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 7186 | uint32_t flags) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7187 | if (const status_t error = CheckTransactCodeCredentials(code); error != OK) { |
| 7188 | return error; |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 7189 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 7190 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7191 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 7192 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 7193 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Romain Guy | 8c6bbd6 | 2017-06-05 13:51:43 -0700 | [diff] [blame] | 7194 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7195 | const int uid = ipc->getCallingUid(); |
| 7196 | if (CC_UNLIKELY(uid != AID_SYSTEM |
| 7197 | && !PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 7198 | const int pid = ipc->getCallingPid(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 7199 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 7200 | "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] | 7201 | return PERMISSION_DENIED; |
| 7202 | } |
| 7203 | int n; |
| 7204 | switch (code) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7205 | case 1000: // Unused. |
| 7206 | case 1001: |
| 7207 | return NAME_NOT_FOUND; |
| 7208 | case 1002: // Toggle flashing on surface damage. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7209 | sfdo_setDebugFlash(data.readInt32()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7210 | return NO_ERROR; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 7211 | case 1004: // Force composite ahead of next VSYNC. |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 7212 | case 1006: |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7213 | sfdo_scheduleComposite(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7214 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7215 | case 1005: { // Force commit ahead of next VSYNC. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7216 | sfdo_scheduleCommit(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 7217 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7218 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7219 | case 1007: // Unused. |
| 7220 | return NAME_NOT_FOUND; |
| 7221 | case 1008: // Toggle forced GPU composition. |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 7222 | sfdo_forceClientComposition(data.readInt32() != 0); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 7223 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7224 | case 1009: // Toggle use of transform hint. |
| 7225 | mDebugDisableTransformHint = data.readInt32() != 0; |
| 7226 | scheduleRepaint(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 7227 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7228 | case 1010: // Interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 7229 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7230 | reply->writeInt32(0); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7231 | reply->writeInt32(mDebugFlashDelay); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 7232 | reply->writeInt32(0); |
Dianne Hackborn | 12839be | 2012-02-06 21:21:05 -0800 | [diff] [blame] | 7233 | reply->writeInt32(mDebugDisableHWC); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7234 | return NO_ERROR; |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 7235 | case 1013: // Unused. |
| 7236 | return NAME_NOT_FOUND; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7237 | case 1014: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7238 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7239 | // daltonize |
| 7240 | n = data.readInt32(); |
Isaac Chai | 1ec2d9a | 2024-04-11 20:10:34 +0000 | [diff] [blame] | 7241 | mDaltonizer.setLevel(data.readInt32()); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7242 | switch (n % 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7243 | case 1: |
| 7244 | mDaltonizer.setType(ColorBlindnessType::Protanomaly); |
| 7245 | break; |
| 7246 | case 2: |
| 7247 | mDaltonizer.setType(ColorBlindnessType::Deuteranomaly); |
| 7248 | break; |
| 7249 | case 3: |
| 7250 | mDaltonizer.setType(ColorBlindnessType::Tritanomaly); |
| 7251 | break; |
| 7252 | default: |
| 7253 | mDaltonizer.setType(ColorBlindnessType::None); |
| 7254 | break; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7255 | } |
| 7256 | if (n >= 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7257 | mDaltonizer.setMode(ColorBlindnessMode::Correction); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7258 | } else { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7259 | mDaltonizer.setMode(ColorBlindnessMode::Simulation); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7260 | } |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7261 | |
| 7262 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7263 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7264 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7265 | case 1015: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7266 | Mutex::Autolock _l(mStateLock); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7267 | // apply a color matrix |
| 7268 | n = data.readInt32(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7269 | if (n) { |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7270 | // color matrix is sent as a column-major mat4 matrix |
Alan Viverette | 794c5ba | 2013-10-03 16:40:52 -0700 | [diff] [blame] | 7271 | for (size_t i = 0 ; i < 4; i++) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7272 | for (size_t j = 0; j < 4; j++) { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7273 | mClientColorMatrix[i][j] = data.readFloat(); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7274 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7275 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7276 | } else { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7277 | mClientColorMatrix = mat4(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7278 | } |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 7279 | |
| 7280 | // Check that supplied matrix's last row is {0,0,0,1} so we can avoid |
| 7281 | // the division by w in the fragment shader |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7282 | float4 lastRow(transpose(mClientColorMatrix)[3]); |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 7283 | if (any(greaterThan(abs(lastRow - float4{0, 0, 0, 1}), float4{1e-4f}))) { |
| 7284 | ALOGE("The color transform's last row must be (0, 0, 0, 1)"); |
| 7285 | } |
| 7286 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7287 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7288 | return NO_ERROR; |
| 7289 | } |
Dominik Laskowski | 8d32ddc | 2019-08-07 11:25:35 -0700 | [diff] [blame] | 7290 | case 1016: { // Unused. |
| 7291 | return NAME_NOT_FOUND; |
Ruchi Kandoi | f52b3c8 | 2014-04-24 16:42:35 -0700 | [diff] [blame] | 7292 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 7293 | case 1017: { |
| 7294 | n = data.readInt32(); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 7295 | mForceFullDamage = n != 0; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 7296 | return NO_ERROR; |
| 7297 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7298 | case 1018: { // Set the render deadline as a duration until VSYNC. |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7299 | n = data.readInt32(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7300 | mScheduler->setDuration(scheduler::Cycle::Render, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7301 | return NO_ERROR; |
| 7302 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7303 | case 1019: { // Set the deadline of the last composite as a duration until VSYNC. |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7304 | n = data.readInt32(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7305 | mScheduler->setDuration(scheduler::Cycle::LastComposite, |
| 7306 | std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7307 | return NO_ERROR; |
| 7308 | } |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 7309 | case 1020: { // Unused |
| 7310 | return NAME_NOT_FOUND; |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 7311 | } |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 7312 | case 1021: { // Disable HWC virtual displays |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 7313 | const bool enable = data.readInt32() != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7314 | static_cast<void>( |
| 7315 | mScheduler->schedule([this, enable] { enableHalVirtualDisplays(enable); })); |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 7316 | return NO_ERROR; |
| 7317 | } |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7318 | case 1022: { // Set saturation boost |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7319 | Mutex::Autolock _l(mStateLock); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7320 | mGlobalSaturationFactor = std::max(0.0f, std::min(data.readFloat(), 2.0f)); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7321 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7322 | updateColorMatrixLocked(); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7323 | return NO_ERROR; |
| 7324 | } |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7325 | case 1023: { // Set color mode. |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7326 | mDisplayColorSetting = static_cast<DisplayColorSetting>(data.readInt32()); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7327 | |
| 7328 | if (int32_t colorMode; data.readInt32(&colorMode) == NO_ERROR) { |
| 7329 | mForceColorMode = static_cast<ui::ColorMode>(colorMode); |
Daniel Solomon | 7c7ede2 | 2019-07-11 16:35:40 -0700 | [diff] [blame] | 7330 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7331 | scheduleRepaint(); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 7332 | return NO_ERROR; |
| 7333 | } |
Peiyong Lin | 4bac91c | 2018-10-25 09:48:33 -0700 | [diff] [blame] | 7334 | // Deprecate, use 1030 to check whether the device is color managed. |
| 7335 | case 1024: { |
| 7336 | return NAME_NOT_FOUND; |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 7337 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7338 | // Deprecated, use perfetto to start/stop the layer tracing |
| 7339 | case 1025: { |
| 7340 | return NAME_NOT_FOUND; |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 7341 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7342 | // Deprecated, execute "adb shell perfetto --query" to see the ongoing tracing sessions |
| 7343 | case 1026: { |
| 7344 | return NAME_NOT_FOUND; |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 7345 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7346 | // Is a DisplayColorSetting supported? |
| 7347 | case 1027: { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7348 | const auto display = getDefaultDisplayDevice(); |
| 7349 | if (!display) { |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7350 | return NAME_NOT_FOUND; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7351 | } |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7352 | |
| 7353 | DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32()); |
| 7354 | switch (setting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7355 | case DisplayColorSetting::kManaged: |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7356 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7357 | reply->writeBool(true); |
| 7358 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7359 | case DisplayColorSetting::kEnhanced: |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7360 | reply->writeBool(display->hasRenderIntent(RenderIntent::ENHANCE)); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7361 | break; |
| 7362 | default: // vendor display color setting |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7363 | reply->writeBool( |
| 7364 | display->hasRenderIntent(static_cast<RenderIntent>(setting))); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7365 | break; |
| 7366 | } |
| 7367 | return NO_ERROR; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7368 | } |
Alec Mouri | 9c58bcd | 2020-09-09 18:57:07 -0700 | [diff] [blame] | 7369 | case 1028: { // Unused. |
| 7370 | return NAME_NOT_FOUND; |
Steven Thomas | 97f1f4c | 2018-06-01 12:04:16 -0700 | [diff] [blame] | 7371 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7372 | // Deprecated, use perfetto to set the active layer tracing buffer size |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 7373 | case 1029: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7374 | return NAME_NOT_FOUND; |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 7375 | } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 7376 | // Is device color managed? |
| 7377 | case 1030: { |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 7378 | // ColorDisplayManager stil calls this |
| 7379 | reply->writeBool(true); |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 7380 | return NO_ERROR; |
| 7381 | } |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7382 | // Override default composition data space |
| 7383 | // adb shell service call SurfaceFlinger 1031 i32 1 DATASPACE_NUMBER DATASPACE_NUMBER \ |
| 7384 | // && adb shell stop zygote && adb shell start zygote |
| 7385 | // to restore: adb shell service call SurfaceFlinger 1031 i32 0 && \ |
| 7386 | // adb shell stop zygote && adb shell start zygote |
| 7387 | case 1031: { |
| 7388 | Mutex::Autolock _l(mStateLock); |
| 7389 | n = data.readInt32(); |
| 7390 | if (n) { |
| 7391 | n = data.readInt32(); |
| 7392 | if (n) { |
| 7393 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 7394 | if (!validateCompositionDataspace(dataspace)) { |
| 7395 | return BAD_VALUE; |
| 7396 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7397 | mDefaultCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7398 | } |
| 7399 | n = data.readInt32(); |
| 7400 | if (n) { |
| 7401 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 7402 | if (!validateCompositionDataspace(dataspace)) { |
| 7403 | return BAD_VALUE; |
| 7404 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7405 | mWideColorGamutCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7406 | } |
| 7407 | } else { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7408 | // restore composition data space. |
| 7409 | mDefaultCompositionDataspace = defaultCompositionDataspace; |
| 7410 | mWideColorGamutCompositionDataspace = wideColorGamutCompositionDataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7411 | } |
| 7412 | return NO_ERROR; |
| 7413 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7414 | // Deprecated, use perfetto to set layer trace flags |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 7415 | case 1033: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7416 | return NAME_NOT_FOUND; |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 7417 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 7418 | case 1034: { |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7419 | n = data.readInt32(); |
| 7420 | if (n == 0 || n == 1) { |
| 7421 | sfdo_enableRefreshRateOverlay(static_cast<bool>(n)); |
| 7422 | } else { |
| 7423 | Mutex::Autolock lock(mStateLock); |
| 7424 | reply->writeBool(isRefreshRateOverlayEnabled()); |
| 7425 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 7426 | return NO_ERROR; |
| 7427 | } |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 7428 | case 1035: { |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7429 | // Parameters: |
| 7430 | // - (required) i32 mode id. |
| 7431 | // - (optional) i64 display id. Using default display if not provided. |
| 7432 | // - (optional) f min render rate. Using mode's fps is not provided. |
| 7433 | // - (optional) f max render rate. Using mode's fps is not provided. |
| 7434 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 7435 | const int modeId = data.readInt32(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 7436 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7437 | const auto display = [&]() -> sp<IBinder> { |
| 7438 | uint64_t value; |
| 7439 | if (data.readUint64(&value) != NO_ERROR) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7440 | return getDefaultDisplayDevice()->getDisplayToken().promote(); |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7441 | } |
| 7442 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7443 | if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(value)) { |
| 7444 | return getPhysicalDisplayToken(*id); |
| 7445 | } |
| 7446 | |
| 7447 | ALOGE("Invalid physical display ID"); |
| 7448 | return nullptr; |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7449 | }(); |
| 7450 | |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7451 | const auto getFps = [&] { |
| 7452 | float value; |
| 7453 | if (data.readFloat(&value) == NO_ERROR) { |
| 7454 | return Fps::fromValue(value); |
| 7455 | } |
| 7456 | |
| 7457 | return Fps(); |
| 7458 | }; |
| 7459 | |
| 7460 | const auto minFps = getFps(); |
| 7461 | const auto maxFps = getFps(); |
| 7462 | |
Shiyong Li | 2bcece9 | 2021-08-30 20:38:50 +0000 | [diff] [blame] | 7463 | mDebugDisplayModeSetByBackdoor = false; |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7464 | const status_t result = |
| 7465 | setActiveModeFromBackdoor(display, DisplayModeId{modeId}, minFps, maxFps); |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7466 | mDebugDisplayModeSetByBackdoor = result == NO_ERROR; |
| 7467 | return result; |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 7468 | } |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7469 | // Turn on/off frame rate flexibility mode. When turned on it overrides the display |
| 7470 | // manager frame rate policy a new policy which allows switching between all refresh |
| 7471 | // rates. |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7472 | case 1036: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7473 | if (data.readInt32() > 0) { // turn on |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7474 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7475 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7476 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7477 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7478 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7479 | // This is a little racy, but not in a way that hurts anything. As |
| 7480 | // we grab the defaultMode from the display manager policy, we could |
| 7481 | // be setting a new display manager policy, leaving us using a stale |
| 7482 | // defaultMode. The defaultMode doesn't matter for the override |
| 7483 | // policy though, since we set allowGroupSwitching to true, so it's |
| 7484 | // not a problem. |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7485 | scheduler::RefreshRateSelector::OverridePolicy overridePolicy; |
| 7486 | overridePolicy.defaultMode = display->refreshRateSelector() |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7487 | .getDisplayManagerPolicy() |
| 7488 | .defaultMode; |
| 7489 | overridePolicy.allowGroupSwitching = true; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7490 | return setDesiredDisplayModeSpecsInternal(display, overridePolicy); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7491 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7492 | .get(); |
| 7493 | } else { // turn off |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7494 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7495 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7496 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7497 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7498 | return setDesiredDisplayModeSpecsInternal( |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7499 | display, |
| 7500 | scheduler::RefreshRateSelector::NoOverridePolicy{}); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7501 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7502 | .get(); |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7503 | } |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7504 | } |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 7505 | // Inject a hotplug connected event for the primary display. This will deallocate and |
| 7506 | // reallocate the display state including framebuffers. |
| 7507 | case 1037: { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7508 | const hal::HWDisplayId hwcId = |
| 7509 | (Mutex::Autolock(mStateLock), getHwComposer().getPrimaryHwcDisplayId()); |
| 7510 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 7511 | onComposerHalHotplugEvent(hwcId, DisplayHotplugEvent::CONNECTED); |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 7512 | return NO_ERROR; |
| 7513 | } |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 7514 | // Modify the max number of display frames stored within FrameTimeline |
| 7515 | case 1038: { |
| 7516 | n = data.readInt32(); |
| 7517 | if (n < 0 || n > MAX_ALLOWED_DISPLAY_FRAMES) { |
| 7518 | ALOGW("Invalid max size. Maximum allowed is %d", MAX_ALLOWED_DISPLAY_FRAMES); |
| 7519 | return BAD_VALUE; |
| 7520 | } |
| 7521 | if (n == 0) { |
| 7522 | // restore to default |
| 7523 | mFrameTimeline->reset(); |
| 7524 | return NO_ERROR; |
| 7525 | } |
| 7526 | mFrameTimeline->setMaxDisplayFrames(n); |
| 7527 | return NO_ERROR; |
| 7528 | } |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 7529 | case 1039: { |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 7530 | PhysicalDisplayId displayId = [&]() { |
| 7531 | Mutex::Autolock lock(mStateLock); |
| 7532 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 7533 | }(); |
| 7534 | |
| 7535 | auto inUid = static_cast<uid_t>(data.readInt32()); |
| 7536 | const auto refreshRate = data.readFloat(); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 7537 | mScheduler->setPreferredRefreshRateForUid(FrameRateOverride{inUid, refreshRate}); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7538 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 7539 | return NO_ERROR; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 7540 | } |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7541 | // Toggle caching feature |
| 7542 | // First argument is an int32 - nonzero enables caching and zero disables caching |
| 7543 | // Second argument is an optional uint64 - if present, then limits enabling/disabling |
| 7544 | // caching to a particular physical display |
| 7545 | case 1040: { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7546 | auto future = mScheduler->schedule([&] { |
| 7547 | n = data.readInt32(); |
| 7548 | std::optional<PhysicalDisplayId> inputId = std::nullopt; |
| 7549 | if (uint64_t inputDisplayId; data.readUint64(&inputDisplayId) == NO_ERROR) { |
| 7550 | inputId = DisplayId::fromValue<PhysicalDisplayId>(inputDisplayId); |
| 7551 | if (!inputId || getPhysicalDisplayToken(*inputId)) { |
| 7552 | ALOGE("No display with id: %" PRIu64, inputDisplayId); |
| 7553 | return NAME_NOT_FOUND; |
| 7554 | } |
| 7555 | } |
| 7556 | { |
| 7557 | Mutex::Autolock lock(mStateLock); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7558 | mLayerCachingEnabled = n != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7559 | for (const auto& [_, display] : mDisplays) { |
| 7560 | if (!inputId || *inputId == display->getPhysicalId()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7561 | display->enableLayerCaching(mLayerCachingEnabled); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7562 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7563 | } |
| 7564 | } |
| 7565 | return OK; |
| 7566 | }); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7567 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7568 | if (const status_t error = future.get(); error != OK) { |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7569 | return error; |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7570 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7571 | scheduleRepaint(); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7572 | return NO_ERROR; |
| 7573 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 7574 | case 1041: { // Transaction tracing |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7575 | if (mTransactionTracing) { |
Vishnu Nair | 640261c | 2023-09-21 21:22:51 -0700 | [diff] [blame] | 7576 | int arg = data.readInt32(); |
| 7577 | if (arg == -1) { |
Vishnu Nair | 50858e6 | 2023-10-13 23:28:24 +0000 | [diff] [blame] | 7578 | mScheduler->schedule([&]() { mTransactionTracing.reset(); }).get(); |
Vishnu Nair | 640261c | 2023-09-21 21:22:51 -0700 | [diff] [blame] | 7579 | } else if (arg > 0) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7580 | // Transaction tracing is always running but allow the user to temporarily |
| 7581 | // increase the buffer when actively debugging. |
| 7582 | mTransactionTracing->setBufferSize( |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 7583 | TransactionTracing::LEGACY_ACTIVE_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7584 | } else { |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 7585 | TransactionTraceWriter::getInstance().invoke("", /* overwrite= */ true); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7586 | mTransactionTracing->setBufferSize( |
| 7587 | TransactionTracing::CONTINUOUS_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7588 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 7589 | } |
| 7590 | reply->writeInt32(NO_ERROR); |
| 7591 | return NO_ERROR; |
| 7592 | } |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 7593 | case 1042: { // Write transaction trace to file |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7594 | if (mTransactionTracing) { |
| 7595 | mTransactionTracing->writeToFile(); |
| 7596 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7597 | reply->writeInt32(NO_ERROR); |
| 7598 | return NO_ERROR; |
| 7599 | } |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 7600 | // hdr sdr ratio overlay |
| 7601 | case 1043: { |
| 7602 | auto future = mScheduler->schedule( |
| 7603 | [&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 7604 | n = data.readInt32(); |
Sally Qi | 0cd9e86 | 2024-05-15 18:37:02 -0700 | [diff] [blame] | 7605 | if (n == 0 || n == 1) { |
| 7606 | mHdrSdrRatioOverlay = n != 0; |
| 7607 | enableHdrSdrRatioOverlay(mHdrSdrRatioOverlay); |
| 7608 | } else { |
| 7609 | reply->writeBool(isHdrSdrRatioOverlayEnabled()); |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 7610 | } |
| 7611 | }); |
| 7612 | future.wait(); |
| 7613 | return NO_ERROR; |
| 7614 | } |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 7615 | |
| 7616 | case 1044: { // Enable/Disable mirroring from one display to another |
| 7617 | /* |
| 7618 | * Mirror one display onto another. |
| 7619 | * Ensure the source and destination displays are on. |
| 7620 | * Commands: |
| 7621 | * 0: Mirror one display to another |
| 7622 | * 1: Disable mirroring to a previously mirrored display |
| 7623 | * 2: Disable mirroring on previously mirrored displays |
| 7624 | * |
| 7625 | * Ex: |
| 7626 | * Get the display ids: |
| 7627 | * adb shell dumpsys SurfaceFlinger --display-id |
| 7628 | * Mirror first display to the second: |
| 7629 | * adb shell service call SurfaceFlinger 1044 i64 0 i64 4619827677550801152 i64 |
| 7630 | * 4619827677550801153 |
| 7631 | * Stop mirroring: |
| 7632 | * adb shell service call SurfaceFlinger 1044 i64 1 |
| 7633 | */ |
| 7634 | |
| 7635 | int64_t arg0 = data.readInt64(); |
| 7636 | |
| 7637 | switch (arg0) { |
| 7638 | case 0: { |
| 7639 | // Mirror arg1 to arg2 |
| 7640 | int64_t arg1 = data.readInt64(); |
| 7641 | int64_t arg2 = data.readInt64(); |
| 7642 | // Enable mirroring for one display |
| 7643 | const auto display1id = DisplayId::fromValue(arg1); |
| 7644 | auto mirrorRoot = SurfaceComposerClient::getDefault()->mirrorDisplay( |
| 7645 | display1id.value()); |
| 7646 | auto id2 = DisplayId::fromValue<PhysicalDisplayId>(arg2); |
| 7647 | const auto token2 = getPhysicalDisplayToken(*id2); |
| 7648 | ui::LayerStack layerStack; |
| 7649 | { |
| 7650 | Mutex::Autolock lock(mStateLock); |
| 7651 | sp<DisplayDevice> display = getDisplayDeviceLocked(token2); |
| 7652 | layerStack = display->getLayerStack(); |
| 7653 | } |
| 7654 | SurfaceComposerClient::Transaction t; |
| 7655 | t.setDisplayLayerStack(token2, layerStack); |
| 7656 | t.setLayer(mirrorRoot, INT_MAX); // Top-most layer |
| 7657 | t.setLayerStack(mirrorRoot, layerStack); |
| 7658 | t.apply(); |
| 7659 | |
| 7660 | mMirrorMapForDebug.emplace_or_replace(arg2, mirrorRoot); |
| 7661 | break; |
| 7662 | } |
| 7663 | |
| 7664 | case 1: { |
| 7665 | // Disable mirroring for arg1 |
| 7666 | int64_t arg1 = data.readInt64(); |
| 7667 | mMirrorMapForDebug.erase(arg1); |
| 7668 | break; |
| 7669 | } |
| 7670 | |
| 7671 | case 2: { |
| 7672 | // Disable mirroring for all displays |
| 7673 | mMirrorMapForDebug.clear(); |
| 7674 | break; |
| 7675 | } |
| 7676 | |
| 7677 | default: |
| 7678 | return BAD_VALUE; |
| 7679 | } |
| 7680 | return NO_ERROR; |
| 7681 | } |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7682 | // Inject jank |
| 7683 | // First argument is a float that describes the fraction of frame duration to jank by. |
| 7684 | // Second argument is a delay in ms for triggering the jank. This is useful for working |
| 7685 | // with tools that steal the adb connection. This argument is optional. |
| 7686 | case 1045: { |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 7687 | if (FlagManager::getInstance().vrr_config()) { |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7688 | float jankAmount = data.readFloat(); |
| 7689 | int32_t jankDelayMs = 0; |
| 7690 | if (data.readInt32(&jankDelayMs) != NO_ERROR) { |
| 7691 | jankDelayMs = 0; |
| 7692 | } |
| 7693 | |
| 7694 | const auto jankDelayDuration = Duration(std::chrono::milliseconds(jankDelayMs)); |
| 7695 | |
| 7696 | const bool jankAmountValid = jankAmount > 0.0 && jankAmount < 100.0; |
| 7697 | |
| 7698 | if (!jankAmountValid) { |
| 7699 | ALOGD("Ignoring invalid jank amount: %f", jankAmount); |
| 7700 | reply->writeInt32(BAD_VALUE); |
| 7701 | return BAD_VALUE; |
| 7702 | } |
| 7703 | |
| 7704 | (void)mScheduler->scheduleDelayed( |
| 7705 | [&, jankAmount]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 7706 | mScheduler->injectPacesetterDelay(jankAmount); |
| 7707 | scheduleComposite(FrameHint::kActive); |
| 7708 | }, |
| 7709 | jankDelayDuration.ns()); |
| 7710 | reply->writeInt32(NO_ERROR); |
| 7711 | return NO_ERROR; |
| 7712 | } |
| 7713 | return err; |
| 7714 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7715 | } |
| 7716 | } |
| 7717 | return err; |
| 7718 | } |
| 7719 | |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7720 | void SurfaceFlinger::kernelTimerChanged(bool expired) { |
| 7721 | static bool updateOverlay = |
| 7722 | property_get_bool("debug.sf.kernel_idle_timer_update_overlay", true); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7723 | if (!updateOverlay) return; |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7724 | |
| 7725 | // Update the overlay on the main thread to avoid race conditions with |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 7726 | // RefreshRateSelector::getActiveMode |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 7727 | static_cast<void>(mScheduler->schedule([=, this] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7728 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7729 | if (!display) { |
| 7730 | ALOGW("%s: default display is null", __func__); |
| 7731 | return; |
| 7732 | } |
Adrian Salido | a942af8 | 2022-02-17 19:22:31 -0800 | [diff] [blame] | 7733 | if (!display->isRefreshRateOverlayEnabled()) return; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7734 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7735 | const auto desiredModeIdOpt = |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 7736 | mDisplayModeController.getDesiredMode(display->getPhysicalId()) |
| 7737 | .transform([](const display::DisplayModeRequest& request) { |
| 7738 | return request.mode.modePtr->getId(); |
| 7739 | }); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7740 | |
| 7741 | const bool timerExpired = mKernelIdleTimerEnabled && expired; |
| 7742 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7743 | if (display->onKernelTimerChanged(desiredModeIdOpt, timerExpired)) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 7744 | mScheduler->scheduleFrame(); |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7745 | } |
| 7746 | })); |
| 7747 | } |
| 7748 | |
Ady Abraham | e294632 | 2024-07-10 17:45:29 -0700 | [diff] [blame] | 7749 | void SurfaceFlinger::vrrDisplayIdle(bool idle) { |
| 7750 | // Update the overlay on the main thread to avoid race conditions with |
| 7751 | // RefreshRateSelector::getActiveMode |
| 7752 | static_cast<void>(mScheduler->schedule([=, this] { |
| 7753 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
| 7754 | if (!display) { |
| 7755 | ALOGW("%s: default display is null", __func__); |
| 7756 | return; |
| 7757 | } |
| 7758 | if (!display->isRefreshRateOverlayEnabled()) return; |
| 7759 | |
| 7760 | display->onVrrIdle(idle); |
| 7761 | mScheduler->scheduleFrame(); |
| 7762 | })); |
| 7763 | } |
| 7764 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7765 | std::pair<std::optional<KernelIdleTimerController>, std::chrono::milliseconds> |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 7766 | SurfaceFlinger::getKernelIdleTimerProperties(PhysicalDisplayId displayId) { |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7767 | const bool isKernelIdleTimerHwcSupported = getHwComposer().getComposer()->isSupported( |
| 7768 | android::Hwc2::Composer::OptionalFeature::KernelIdleTimer); |
| 7769 | const auto timeout = getIdleTimerTimeout(displayId); |
| 7770 | if (isKernelIdleTimerHwcSupported) { |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 7771 | if (getHwComposer().hasDisplayIdleTimerCapability(displayId)) { |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7772 | // In order to decide if we can use the HWC api for idle timer |
| 7773 | // we query DisplayCapability::DISPLAY_IDLE_TIMER directly on the composer |
| 7774 | // without relying on hasDisplayCapability. |
| 7775 | // hasDisplayCapability relies on DisplayCapabilities |
| 7776 | // which are updated after we set the PowerMode::ON. |
| 7777 | // DISPLAY_IDLE_TIMER is a display driver property |
| 7778 | // and is available before the PowerMode::ON |
| 7779 | return {KernelIdleTimerController::HwcApi, timeout}; |
| 7780 | } |
| 7781 | return {std::nullopt, timeout}; |
| 7782 | } |
| 7783 | if (getKernelIdleTimerSyspropConfig(displayId)) { |
| 7784 | return {KernelIdleTimerController::Sysprop, timeout}; |
| 7785 | } |
| 7786 | |
| 7787 | return {std::nullopt, timeout}; |
| 7788 | } |
| 7789 | |
| 7790 | void SurfaceFlinger::updateKernelIdleTimer(std::chrono::milliseconds timeout, |
| 7791 | KernelIdleTimerController controller, |
| 7792 | PhysicalDisplayId displayId) { |
| 7793 | switch (controller) { |
| 7794 | case KernelIdleTimerController::HwcApi: { |
| 7795 | getHwComposer().setIdleTimerEnabled(displayId, timeout); |
| 7796 | break; |
| 7797 | } |
| 7798 | case KernelIdleTimerController::Sysprop: { |
| 7799 | base::SetProperty(KERNEL_IDLE_TIMER_PROP, timeout > 0ms ? "true" : "false"); |
| 7800 | break; |
| 7801 | } |
| 7802 | } |
| 7803 | } |
| 7804 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7805 | void SurfaceFlinger::toggleKernelIdleTimer() { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7806 | using KernelIdleTimerAction = scheduler::RefreshRateSelector::KernelIdleTimerAction; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7807 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7808 | const auto display = getDefaultDisplayDeviceLocked(); |
| 7809 | if (!display) { |
| 7810 | ALOGW("%s: default display is null", __func__); |
| 7811 | return; |
| 7812 | } |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7813 | |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7814 | // If the support for kernel idle timer is disabled for the active display, |
| 7815 | // don't do anything. |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7816 | const std::optional<KernelIdleTimerController> kernelIdleTimerController = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7817 | display->refreshRateSelector().kernelIdleTimerController(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7818 | if (!kernelIdleTimerController.has_value()) { |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7819 | return; |
| 7820 | } |
| 7821 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7822 | const KernelIdleTimerAction action = display->refreshRateSelector().getIdleTimerAction(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7823 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7824 | switch (action) { |
| 7825 | case KernelIdleTimerAction::TurnOff: |
| 7826 | if (mKernelIdleTimerEnabled) { |
| 7827 | ATRACE_INT("KernelIdleTimer", 0); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7828 | std::chrono::milliseconds constexpr kTimerDisabledTimeout = 0ms; |
| 7829 | updateKernelIdleTimer(kTimerDisabledTimeout, kernelIdleTimerController.value(), |
| 7830 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7831 | mKernelIdleTimerEnabled = false; |
| 7832 | } |
| 7833 | break; |
| 7834 | case KernelIdleTimerAction::TurnOn: |
| 7835 | if (!mKernelIdleTimerEnabled) { |
| 7836 | ATRACE_INT("KernelIdleTimer", 1); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7837 | const std::chrono::milliseconds timeout = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7838 | display->refreshRateSelector().getIdleTimerTimeout(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7839 | updateKernelIdleTimer(timeout, kernelIdleTimerController.value(), |
| 7840 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7841 | mKernelIdleTimerEnabled = true; |
| 7842 | } |
| 7843 | break; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7844 | } |
| 7845 | } |
| 7846 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7847 | // A simple RAII class to disconnect from an ANativeWindow* when it goes out of scope |
| 7848 | class WindowDisconnector { |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7849 | public: |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7850 | WindowDisconnector(ANativeWindow* window, int api) : mWindow(window), mApi(api) {} |
| 7851 | ~WindowDisconnector() { |
| 7852 | native_window_api_disconnect(mWindow, mApi); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7853 | } |
| 7854 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7855 | private: |
| 7856 | ANativeWindow* mWindow; |
| 7857 | const int mApi; |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7858 | }; |
| 7859 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7860 | static bool hasCaptureBlackoutContentPermission() { |
| 7861 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7862 | const int pid = ipc->getCallingPid(); |
| 7863 | const int uid = ipc->getCallingUid(); |
| 7864 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 7865 | PermissionCache::checkPermission(sCaptureBlackoutContent, pid, uid); |
| 7866 | } |
| 7867 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7868 | static status_t validateScreenshotPermissions(const CaptureArgs& captureArgs) { |
| 7869 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7870 | const int pid = ipc->getCallingPid(); |
| 7871 | const int uid = ipc->getCallingUid(); |
| 7872 | if (uid == AID_GRAPHICS || PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 7873 | return OK; |
| 7874 | } |
| 7875 | |
| 7876 | // If the caller doesn't have the correct permissions but is only attempting to screenshot |
| 7877 | // itself, we allow it to continue. |
| 7878 | if (captureArgs.uid == uid) { |
| 7879 | return OK; |
| 7880 | } |
| 7881 | |
| 7882 | ALOGE("Permission Denial: can't take screenshot pid=%d, uid=%d", pid, uid); |
| 7883 | return PERMISSION_DENIED; |
| 7884 | } |
| 7885 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7886 | status_t SurfaceFlinger::setSchedFifo(bool enabled) { |
| 7887 | static constexpr int kFifoPriority = 2; |
| 7888 | static constexpr int kOtherPriority = 0; |
| 7889 | |
| 7890 | struct sched_param param = {0}; |
| 7891 | int sched_policy; |
| 7892 | if (enabled) { |
| 7893 | sched_policy = SCHED_FIFO; |
| 7894 | param.sched_priority = kFifoPriority; |
| 7895 | } else { |
| 7896 | sched_policy = SCHED_OTHER; |
| 7897 | param.sched_priority = kOtherPriority; |
| 7898 | } |
| 7899 | |
| 7900 | if (sched_setscheduler(0, sched_policy, ¶m) != 0) { |
| 7901 | return -errno; |
| 7902 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7903 | |
| 7904 | return NO_ERROR; |
| 7905 | } |
| 7906 | |
| 7907 | status_t SurfaceFlinger::setSchedAttr(bool enabled) { |
| 7908 | static const unsigned int kUclampMin = |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 7909 | base::GetUintProperty<unsigned int>("ro.surface_flinger.uclamp.min"s, 0U); |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7910 | |
| 7911 | if (!kUclampMin) { |
| 7912 | // uclamp.min set to 0 (default), skip setting |
| 7913 | return NO_ERROR; |
| 7914 | } |
| 7915 | |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7916 | sched_attr attr = {}; |
| 7917 | attr.size = sizeof(attr); |
| 7918 | |
| 7919 | attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP); |
| 7920 | attr.sched_util_min = enabled ? kUclampMin : 0; |
| 7921 | attr.sched_util_max = 1024; |
| 7922 | |
| 7923 | if (syscall(__NR_sched_setattr, 0, &attr, 0)) { |
| 7924 | return -errno; |
| 7925 | } |
| 7926 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7927 | return NO_ERROR; |
| 7928 | } |
| 7929 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7930 | namespace { |
| 7931 | |
Melody Hsu | 683fe04 | 2024-06-04 17:22:04 +0000 | [diff] [blame] | 7932 | ui::Dataspace pickBestDataspace(ui::Dataspace requestedDataspace, |
| 7933 | const compositionengine::impl::OutputCompositionState& state, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7934 | bool capturingHdrLayers, bool hintForSeamlessTransition) { |
Melody Hsu | 683fe04 | 2024-06-04 17:22:04 +0000 | [diff] [blame] | 7935 | if (requestedDataspace != ui::Dataspace::UNKNOWN) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7936 | return requestedDataspace; |
| 7937 | } |
| 7938 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7939 | const auto dataspaceForColorMode = ui::pickDataspaceFor(state.colorMode); |
| 7940 | |
Alec Mouri | 2964072 | 2023-05-16 23:22:41 +0000 | [diff] [blame] | 7941 | // TODO: Enable once HDR screenshots are ready. |
| 7942 | if constexpr (/* DISABLES CODE */ (false)) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7943 | // For now since we only support 8-bit screenshots, just use HLG and |
| 7944 | // assume that 1.0 >= display max luminance. This isn't quite as future |
| 7945 | // proof as PQ is, but is good enough. |
| 7946 | // Consider using PQ once we support 16-bit screenshots and we're able |
| 7947 | // to consistently supply metadata to image encoders. |
| 7948 | return ui::Dataspace::BT2020_HLG; |
| 7949 | } |
| 7950 | |
| 7951 | return dataspaceForColorMode; |
| 7952 | } |
| 7953 | |
| 7954 | } // namespace |
| 7955 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7956 | static void invokeScreenCaptureError(const status_t status, |
| 7957 | const sp<IScreenCaptureListener>& captureListener) { |
| 7958 | ScreenCaptureResults captureResults; |
| 7959 | captureResults.fenceResult = base::unexpected(status); |
| 7960 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7961 | } |
| 7962 | |
| 7963 | void SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, |
| 7964 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7965 | ATRACE_CALL(); |
| 7966 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7967 | status_t validate = validateScreenshotPermissions(args); |
| 7968 | if (validate != OK) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7969 | ALOGD("Permission denied to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7970 | invokeScreenCaptureError(validate, captureListener); |
| 7971 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7972 | } |
| 7973 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7974 | if (!args.displayToken) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7975 | ALOGD("Invalid display token to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7976 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7977 | return; |
| 7978 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7979 | |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 7980 | if (args.captureSecureLayers && !hasCaptureBlackoutContentPermission()) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7981 | ALOGD("Attempting to capture secure layers without CAPTURE_BLACKOUT_CONTENT"); |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 7982 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 7983 | return; |
| 7984 | } |
| 7985 | |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7986 | wp<const DisplayDevice> displayWeak; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7987 | ui::LayerStack layerStack; |
| 7988 | ui::Size reqSize(args.width, args.height); |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7989 | std::unordered_set<uint32_t> excludeLayerIds; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7990 | { |
| 7991 | Mutex::Autolock lock(mStateLock); |
| 7992 | sp<DisplayDevice> display = getDisplayDeviceLocked(args.displayToken); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7993 | if (!display) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7994 | ALOGD("Unable to find display device for captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7995 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7996 | return; |
| 7997 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7998 | displayWeak = display; |
| 7999 | layerStack = display->getLayerStack(); |
| 8000 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 8001 | // 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] | 8002 | if (args.width == 0 || args.height == 0) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 8003 | reqSize = display->getLayerStackSpaceRect().getSize(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 8004 | } |
| 8005 | |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8006 | for (const auto& handle : args.excludeHandles) { |
| 8007 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 8008 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 8009 | excludeLayerIds.emplace(excludeLayer); |
| 8010 | } else { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8011 | ALOGD("Invalid layer handle passed as excludeLayer to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8012 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 8013 | return; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8014 | } |
| 8015 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 8016 | } |
| 8017 | |
Melody Hsu | eddfe93 | 2024-06-04 18:10:41 +0000 | [diff] [blame] | 8018 | GetLayerSnapshotsFunction getLayerSnapshotsFn = |
| 8019 | getLayerSnapshotsForScreenshots(layerStack, args.uid, std::move(excludeLayerIds)); |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 8020 | |
Vishnu Nair | 96a5aaf | 2024-06-26 17:17:51 -0700 | [diff] [blame] | 8021 | ftl::Flags<RenderArea::Options> options; |
| 8022 | if (args.captureSecureLayers) options |= RenderArea::Options::CAPTURE_SECURE_LAYERS; |
| 8023 | if (args.hintForSeamlessTransition) |
| 8024 | options |= RenderArea::Options::HINT_FOR_SEAMLESS_TRANSITION; |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8025 | captureScreenCommon(RenderAreaBuilderVariant(std::in_place_type<DisplayRenderAreaBuilder>, |
| 8026 | args.sourceCrop, reqSize, args.dataspace, |
Vishnu Nair | 96a5aaf | 2024-06-26 17:17:51 -0700 | [diff] [blame] | 8027 | displayWeak, options), |
Melody Hsu | eddfe93 | 2024-06-04 18:10:41 +0000 | [diff] [blame] | 8028 | getLayerSnapshotsFn, reqSize, args.pixelFormat, args.allowProtected, |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8029 | args.grayscale, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 8030 | } |
| 8031 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 8032 | void SurfaceFlinger::captureDisplay(DisplayId displayId, const CaptureArgs& args, |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8033 | const sp<IScreenCaptureListener>& captureListener) { |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 8034 | ui::LayerStack layerStack; |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 8035 | wp<const DisplayDevice> displayWeak; |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 8036 | ui::Size size; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 8037 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 8038 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 8039 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 8040 | const auto display = getDisplayDeviceLocked(displayId); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 8041 | if (!display) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8042 | ALOGD("Unable to find display device for captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8043 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 8044 | return; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 8045 | } |
| 8046 | |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 8047 | displayWeak = display; |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 8048 | layerStack = display->getLayerStack(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 8049 | size = display->getLayerStackSpaceRect().getSize(); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 8050 | } |
| 8051 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 8052 | size.width *= args.frameScaleX; |
| 8053 | size.height *= args.frameScaleY; |
| 8054 | |
| 8055 | // We could query a real value for this but it'll be a long, long time until we support |
| 8056 | // displays that need upwards of 1GB per buffer so... |
| 8057 | constexpr auto kMaxTextureSize = 16384; |
| 8058 | if (size.width <= 0 || size.height <= 0 || size.width >= kMaxTextureSize || |
| 8059 | size.height >= kMaxTextureSize) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8060 | ALOGD("captureDisplay resolved to invalid size %d x %d", size.width, size.height); |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 8061 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8062 | return; |
| 8063 | } |
| 8064 | |
Melody Hsu | eddfe93 | 2024-06-04 18:10:41 +0000 | [diff] [blame] | 8065 | GetLayerSnapshotsFunction getLayerSnapshotsFn = |
| 8066 | getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID, |
| 8067 | /*snapshotFilterFn=*/nullptr); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 8068 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 8069 | if (captureListener == nullptr) { |
| 8070 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8071 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8072 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 8073 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8074 | |
| 8075 | constexpr bool kAllowProtected = false; |
| 8076 | constexpr bool kGrayscale = false; |
| 8077 | |
Vishnu Nair | 96a5aaf | 2024-06-26 17:17:51 -0700 | [diff] [blame] | 8078 | ftl::Flags<RenderArea::Options> options; |
| 8079 | if (args.hintForSeamlessTransition) |
| 8080 | options |= RenderArea::Options::HINT_FOR_SEAMLESS_TRANSITION; |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8081 | captureScreenCommon(RenderAreaBuilderVariant(std::in_place_type<DisplayRenderAreaBuilder>, |
Vishnu Nair | 96a5aaf | 2024-06-26 17:17:51 -0700 | [diff] [blame] | 8082 | Rect(), size, args.dataspace, displayWeak, |
| 8083 | options), |
Melody Hsu | eddfe93 | 2024-06-04 18:10:41 +0000 | [diff] [blame] | 8084 | getLayerSnapshotsFn, size, args.pixelFormat, kAllowProtected, kGrayscale, |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8085 | captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 8086 | } |
| 8087 | |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 8088 | ScreenCaptureResults SurfaceFlinger::captureLayersSync(const LayerCaptureArgs& args) { |
| 8089 | sp<SyncScreenCaptureListener> captureListener = sp<SyncScreenCaptureListener>::make(); |
| 8090 | captureLayers(args, captureListener); |
| 8091 | return captureListener->waitForResults(); |
| 8092 | } |
| 8093 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8094 | void SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, |
| 8095 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8096 | ATRACE_CALL(); |
| 8097 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8098 | status_t validate = validateScreenshotPermissions(args); |
| 8099 | if (validate != OK) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8100 | ALOGD("Permission denied to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8101 | invokeScreenCaptureError(validate, captureListener); |
| 8102 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8103 | } |
| 8104 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 8105 | ui::Size reqSize; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8106 | sp<Layer> parent; |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 8107 | Rect crop(args.sourceCrop); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8108 | std::unordered_set<uint32_t> excludeLayerIds; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8109 | ui::Dataspace dataspace = args.dataspace; |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 8110 | |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 8111 | if (args.captureSecureLayers && !hasCaptureBlackoutContentPermission()) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8112 | ALOGD("Attempting to capture secure layers without CAPTURE_BLACKOUT_CONTENT"); |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 8113 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 8114 | return; |
| 8115 | } |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 8116 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8117 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 8118 | Mutex::Autolock lock(mStateLock); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 8119 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 8120 | parent = LayerHandle::getLayer(args.layerHandle); |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 8121 | if (parent == nullptr) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8122 | ALOGD("captureLayers called with an invalid or removed parent"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8123 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 8124 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8125 | } |
| 8126 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 8127 | Rect parentSourceBounds = parent->getCroppedBufferSize(parent->getDrawingState()); |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 8128 | if (args.sourceCrop.width() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8129 | crop.left = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 8130 | crop.right = parentSourceBounds.getWidth(); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8131 | } |
| 8132 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 8133 | if (args.sourceCrop.height() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8134 | crop.top = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 8135 | crop.bottom = parentSourceBounds.getHeight(); |
| 8136 | } |
| 8137 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 8138 | if (crop.isEmpty() || args.frameScaleX <= 0.0f || args.frameScaleY <= 0.0f) { |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 8139 | // Error out if the layer has no source bounds (i.e. they are boundless) and a source |
| 8140 | // crop was not specified, or an invalid frame scale was provided. |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8141 | ALOGD("Boundless layer, unspecified crop, or invalid frame scale to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8142 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8143 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8144 | } |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 8145 | reqSize = ui::Size(crop.width() * args.frameScaleX, crop.height() * args.frameScaleY); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8146 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 8147 | for (const auto& handle : args.excludeHandles) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8148 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 8149 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 8150 | excludeLayerIds.emplace(excludeLayer); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8151 | } else { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8152 | ALOGD("Invalid layer handle passed as excludeLayer to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8153 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 8154 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8155 | } |
| 8156 | } |
| 8157 | } // mStateLock |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 8158 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 8159 | // really small crop or frameScale |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 8160 | if (reqSize.width <= 0 || reqSize.height <= 0) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8161 | ALOGD("Failed to captureLayers: crop or scale too small"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8162 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8163 | return; |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 8164 | } |
| 8165 | |
Melody Hsu | eddfe93 | 2024-06-04 18:10:41 +0000 | [diff] [blame] | 8166 | std::optional<FloatRect> parentCrop = std::nullopt; |
| 8167 | if (args.childrenOnly) { |
| 8168 | parentCrop = crop.isEmpty() ? FloatRect(0, 0, reqSize.width, reqSize.height) |
| 8169 | : crop.toFloatRect(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8170 | } |
Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 8171 | |
Melody Hsu | eddfe93 | 2024-06-04 18:10:41 +0000 | [diff] [blame] | 8172 | GetLayerSnapshotsFunction getLayerSnapshotsFn = |
| 8173 | getLayerSnapshotsForScreenshots(parent->sequence, args.uid, std::move(excludeLayerIds), |
| 8174 | args.childrenOnly, parentCrop); |
| 8175 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 8176 | if (captureListener == nullptr) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8177 | ALOGD("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8178 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8179 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 8180 | } |
| 8181 | |
Vishnu Nair | 96a5aaf | 2024-06-26 17:17:51 -0700 | [diff] [blame] | 8182 | ftl::Flags<RenderArea::Options> options; |
| 8183 | if (args.captureSecureLayers) options |= RenderArea::Options::CAPTURE_SECURE_LAYERS; |
| 8184 | if (args.hintForSeamlessTransition) |
| 8185 | options |= RenderArea::Options::HINT_FOR_SEAMLESS_TRANSITION; |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8186 | captureScreenCommon(RenderAreaBuilderVariant(std::in_place_type<LayerRenderAreaBuilder>, crop, |
Vishnu Nair | 96a5aaf | 2024-06-26 17:17:51 -0700 | [diff] [blame] | 8187 | reqSize, dataspace, parent, args.childrenOnly, |
| 8188 | options), |
Melody Hsu | eddfe93 | 2024-06-04 18:10:41 +0000 | [diff] [blame] | 8189 | getLayerSnapshotsFn, reqSize, args.pixelFormat, args.allowProtected, |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8190 | args.grayscale, captureListener); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8191 | } |
| 8192 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 8193 | // Creates a Future release fence for a layer and keeps track of it in a list to |
| 8194 | // release the buffer when the Future is complete. Calls from composittion |
| 8195 | // involve needing to refresh the composition start time for stats. |
| 8196 | void SurfaceFlinger::attachReleaseFenceFutureToLayer(Layer* layer, LayerFE* layerFE, |
| 8197 | ui::LayerStack layerStack) { |
| 8198 | ftl::Future<FenceResult> futureFence = layerFE->createReleaseFenceFuture(); |
| 8199 | Layer* clonedFrom = layer->getClonedFrom().get(); |
| 8200 | auto owningLayer = clonedFrom ? clonedFrom : layer; |
| 8201 | owningLayer->prepareReleaseCallbacks(std::move(futureFence), layerStack); |
| 8202 | } |
| 8203 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8204 | // Loop over all visible layers to see whether there's any protected layer. A protected layer is |
| 8205 | // typically a layer with DRM contents, or have the GRALLOC_USAGE_PROTECTED set on the buffer. |
| 8206 | // A protected layer has no implication on whether it's secure, which is explicitly set by |
| 8207 | // application to avoid being screenshot or drawn via unsecure display. |
| 8208 | bool SurfaceFlinger::layersHasProtectedLayer(const std::vector<sp<LayerFE>>& layers) const { |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8209 | bool protectedLayerFound = false; |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8210 | for (auto& layerFE : layers) { |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8211 | protectedLayerFound |= |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8212 | (layerFE->mSnapshot->isVisible && layerFE->mSnapshot->hasProtectedContent); |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8213 | if (protectedLayerFound) { |
| 8214 | break; |
| 8215 | } |
| 8216 | } |
| 8217 | return protectedLayerFound; |
| 8218 | } |
| 8219 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8220 | // Getting layer snapshots and display should take place on main thread. |
| 8221 | // Accessing display requires mStateLock, and contention for this lock |
| 8222 | // is reduced when grabbed from the main thread, thus also reducing |
| 8223 | // risk of deadlocks. |
| 8224 | std::optional<SurfaceFlinger::OutputCompositionState> |
| 8225 | SurfaceFlinger::getDisplayAndLayerSnapshotsFromMainThread( |
| 8226 | RenderAreaBuilderVariant& renderAreaBuilder, GetLayerSnapshotsFunction getLayerSnapshotsFn, |
| 8227 | std::vector<sp<LayerFE>>& layerFEs) { |
| 8228 | return mScheduler |
| 8229 | ->schedule([=, this, &renderAreaBuilder, &layerFEs]() REQUIRES(kMainThreadContext) { |
| 8230 | auto layers = getLayerSnapshotsFn(); |
| 8231 | for (auto& [layer, layerFE] : layers) { |
| 8232 | attachReleaseFenceFutureToLayer(layer, layerFE.get(), ui::INVALID_LAYER_STACK); |
| 8233 | } |
| 8234 | layerFEs = extractLayerFEs(layers); |
| 8235 | return getDisplayStateFromRenderAreaBuilder(renderAreaBuilder); |
| 8236 | }) |
| 8237 | .get(); |
| 8238 | } |
| 8239 | |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8240 | void SurfaceFlinger::captureScreenCommon(RenderAreaBuilderVariant renderAreaBuilder, |
Melody Hsu | eddfe93 | 2024-06-04 18:10:41 +0000 | [diff] [blame] | 8241 | GetLayerSnapshotsFunction getLayerSnapshotsFn, |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8242 | ui::Size bufferSize, ui::PixelFormat reqPixelFormat, |
| 8243 | bool allowProtected, bool grayscale, |
| 8244 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8245 | ATRACE_CALL(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 8246 | |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 8247 | if (exceedsMaxRenderTargetSize(bufferSize.getWidth(), bufferSize.getHeight())) { |
| 8248 | ALOGE("Attempted to capture screen with size (%" PRId32 ", %" PRId32 |
| 8249 | ") that exceeds render target size limit.", |
| 8250 | bufferSize.getWidth(), bufferSize.getHeight()); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8251 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8252 | return; |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 8253 | } |
| 8254 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8255 | if (FlagManager::getInstance().single_hop_screenshot() && |
Vishnu Nair | 454f7f2 | 2024-06-29 01:17:02 +0000 | [diff] [blame] | 8256 | FlagManager::getInstance().ce_fence_promise() && mRenderEngine->isThreaded()) { |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8257 | std::vector<sp<LayerFE>> layerFEs; |
| 8258 | auto displayState = |
| 8259 | getDisplayAndLayerSnapshotsFromMainThread(renderAreaBuilder, getLayerSnapshotsFn, |
| 8260 | layerFEs); |
Alec Mouri | 7013b6f | 2021-02-12 11:16:54 -0800 | [diff] [blame] | 8261 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8262 | const bool supportsProtected = getRenderEngine().supportsProtectedContent(); |
| 8263 | bool hasProtectedLayer = false; |
| 8264 | if (allowProtected && supportsProtected) { |
| 8265 | hasProtectedLayer = layersHasProtectedLayer(layerFEs); |
| 8266 | } |
| 8267 | const bool isProtected = hasProtectedLayer && allowProtected && supportsProtected; |
| 8268 | const uint32_t usage = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER | |
| 8269 | GRALLOC_USAGE_HW_TEXTURE | |
| 8270 | (isProtected ? GRALLOC_USAGE_PROTECTED |
| 8271 | : GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
| 8272 | sp<GraphicBuffer> buffer = |
| 8273 | getFactory().createGraphicBuffer(bufferSize.getWidth(), bufferSize.getHeight(), |
| 8274 | static_cast<android_pixel_format>(reqPixelFormat), |
| 8275 | 1 /* layerCount */, usage, "screenshot"); |
| 8276 | |
| 8277 | const status_t bufferStatus = buffer->initCheck(); |
| 8278 | if (bufferStatus != OK) { |
| 8279 | // Animations may end up being really janky, but don't crash here. |
| 8280 | // Otherwise an irreponsible process may cause an SF crash by allocating |
| 8281 | // too much. |
| 8282 | ALOGE("%s: Buffer failed to allocate: %d", __func__, bufferStatus); |
| 8283 | invokeScreenCaptureError(bufferStatus, captureListener); |
| 8284 | return; |
| 8285 | } |
| 8286 | const std::shared_ptr<renderengine::ExternalTexture> texture = std::make_shared< |
| 8287 | renderengine::impl::ExternalTexture>(buffer, getRenderEngine(), |
| 8288 | renderengine::impl::ExternalTexture::Usage:: |
| 8289 | WRITEABLE); |
| 8290 | auto futureFence = |
| 8291 | captureScreenshot(renderAreaBuilder, texture, false /* regionSampling */, grayscale, |
| 8292 | isProtected, captureListener, displayState, layerFEs); |
| 8293 | futureFence.get(); |
| 8294 | |
| 8295 | } else { |
| 8296 | const bool supportsProtected = getRenderEngine().supportsProtectedContent(); |
| 8297 | bool hasProtectedLayer = false; |
| 8298 | if (allowProtected && supportsProtected) { |
| 8299 | auto layers = mScheduler->schedule([=]() { return getLayerSnapshotsFn(); }).get(); |
| 8300 | hasProtectedLayer = layersHasProtectedLayer(extractLayerFEs(layers)); |
| 8301 | } |
| 8302 | const bool isProtected = hasProtectedLayer && allowProtected && supportsProtected; |
| 8303 | const uint32_t usage = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER | |
| 8304 | GRALLOC_USAGE_HW_TEXTURE | |
| 8305 | (isProtected ? GRALLOC_USAGE_PROTECTED |
| 8306 | : GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
| 8307 | sp<GraphicBuffer> buffer = |
| 8308 | getFactory().createGraphicBuffer(bufferSize.getWidth(), bufferSize.getHeight(), |
| 8309 | static_cast<android_pixel_format>(reqPixelFormat), |
| 8310 | 1 /* layerCount */, usage, "screenshot"); |
| 8311 | |
| 8312 | const status_t bufferStatus = buffer->initCheck(); |
| 8313 | if (bufferStatus != OK) { |
| 8314 | // Animations may end up being really janky, but don't crash here. |
| 8315 | // Otherwise an irreponsible process may cause an SF crash by allocating |
| 8316 | // too much. |
| 8317 | ALOGE("%s: Buffer failed to allocate: %d", __func__, bufferStatus); |
| 8318 | invokeScreenCaptureError(bufferStatus, captureListener); |
| 8319 | return; |
| 8320 | } |
| 8321 | const std::shared_ptr<renderengine::ExternalTexture> texture = std::make_shared< |
| 8322 | renderengine::impl::ExternalTexture>(buffer, getRenderEngine(), |
| 8323 | renderengine::impl::ExternalTexture::Usage:: |
| 8324 | WRITEABLE); |
| 8325 | auto futureFence = captureScreenshotLegacy(renderAreaBuilder, getLayerSnapshotsFn, texture, |
| 8326 | false /* regionSampling */, grayscale, |
| 8327 | isProtected, captureListener); |
| 8328 | futureFence.get(); |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 8329 | } |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 8330 | } |
| 8331 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8332 | std::optional<SurfaceFlinger::OutputCompositionState> |
| 8333 | SurfaceFlinger::getDisplayStateFromRenderAreaBuilder(RenderAreaBuilderVariant& renderAreaBuilder) { |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8334 | sp<const DisplayDevice> display = nullptr; |
| 8335 | { |
| 8336 | Mutex::Autolock lock(mStateLock); |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8337 | if (auto* layerRenderAreaBuilder = |
| 8338 | std::get_if<LayerRenderAreaBuilder>(&renderAreaBuilder)) { |
| 8339 | // LayerSnapshotBuilder should only be accessed from the main thread. |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8340 | const frontend::LayerSnapshot* snapshot = |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8341 | mLayerSnapshotBuilder.getSnapshot(layerRenderAreaBuilder->layer->getSequence()); |
| 8342 | if (!snapshot) { |
| 8343 | ALOGW("Couldn't find layer snapshot for %d", |
| 8344 | layerRenderAreaBuilder->layer->getSequence()); |
| 8345 | } else { |
Melody Hsu | 50c151a | 2024-05-14 06:11:12 +0000 | [diff] [blame] | 8346 | layerRenderAreaBuilder->setLayerSnapshot(*snapshot); |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8347 | display = findDisplay( |
| 8348 | [layerStack = snapshot->outputFilter.layerStack](const auto& display) { |
| 8349 | return display.getLayerStack() == layerStack; |
| 8350 | }); |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8351 | } |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8352 | } else if (auto* displayRenderAreaBuilder = |
| 8353 | std::get_if<DisplayRenderAreaBuilder>(&renderAreaBuilder)) { |
| 8354 | display = displayRenderAreaBuilder->displayWeak.promote(); |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8355 | } |
| 8356 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8357 | if (display == nullptr) { |
| 8358 | display = getDefaultDisplayDeviceLocked(); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 8359 | } |
| 8360 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8361 | if (display != nullptr) { |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8362 | return std::optional{display->getCompositionDisplay()->getState()}; |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8363 | } |
| 8364 | } |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8365 | return std::nullopt; |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8366 | } |
| 8367 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8368 | std::vector<sp<LayerFE>> SurfaceFlinger::extractLayerFEs( |
| 8369 | const std::vector<std::pair<Layer*, sp<LayerFE>>>& layers) const { |
| 8370 | std::vector<sp<LayerFE>> layerFEs; |
| 8371 | layerFEs.reserve(layers.size()); |
| 8372 | for (const auto& [_, layerFE] : layers) { |
| 8373 | layerFEs.push_back(layerFE); |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8374 | } |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8375 | return layerFEs; |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8376 | } |
| 8377 | |
| 8378 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenshot( |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8379 | const RenderAreaBuilderVariant& renderAreaBuilder, |
| 8380 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
| 8381 | bool grayscale, bool isProtected, const sp<IScreenCaptureListener>& captureListener, |
| 8382 | std::optional<OutputCompositionState>& displayState, std::vector<sp<LayerFE>>& layerFEs) { |
| 8383 | ATRACE_CALL(); |
| 8384 | |
| 8385 | ScreenCaptureResults captureResults; |
| 8386 | std::unique_ptr<const RenderArea> renderArea = |
| 8387 | std::visit([](auto&& arg) -> std::unique_ptr<RenderArea> { return arg.build(); }, |
| 8388 | renderAreaBuilder); |
| 8389 | |
| 8390 | if (!renderArea) { |
| 8391 | ALOGW("Skipping screen capture because of invalid render area."); |
| 8392 | if (captureListener) { |
| 8393 | captureResults.fenceResult = base::unexpected(NO_MEMORY); |
| 8394 | captureListener->onScreenCaptureCompleted(captureResults); |
| 8395 | } |
| 8396 | return ftl::yield<FenceResult>(base::unexpected(NO_ERROR)).share(); |
| 8397 | } |
| 8398 | |
| 8399 | // Empty vector needed to pass into renderScreenImpl for legacy path |
| 8400 | std::vector<std::pair<Layer*, sp<android::LayerFE>>> layers; |
| 8401 | ftl::SharedFuture<FenceResult> renderFuture = |
| 8402 | renderScreenImpl(std::move(renderArea), buffer, regionSampling, grayscale, isProtected, |
| 8403 | captureResults, displayState, layers, layerFEs); |
| 8404 | |
| 8405 | if (captureListener) { |
| 8406 | // Defer blocking on renderFuture back to the Binder thread. |
| 8407 | return ftl::Future(std::move(renderFuture)) |
| 8408 | .then([captureListener, captureResults = std::move(captureResults)]( |
| 8409 | FenceResult fenceResult) mutable -> FenceResult { |
| 8410 | captureResults.fenceResult = std::move(fenceResult); |
| 8411 | captureListener->onScreenCaptureCompleted(captureResults); |
| 8412 | return base::unexpected(NO_ERROR); |
| 8413 | }) |
| 8414 | .share(); |
| 8415 | } |
| 8416 | return renderFuture; |
| 8417 | } |
| 8418 | |
| 8419 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenshotLegacy( |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8420 | RenderAreaBuilderVariant renderAreaBuilder, GetLayerSnapshotsFunction getLayerSnapshotsFn, |
| 8421 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
| 8422 | bool grayscale, bool isProtected, const sp<IScreenCaptureListener>& captureListener) { |
| 8423 | ATRACE_CALL(); |
| 8424 | |
| 8425 | auto takeScreenshotFn = [=, this, renderAreaBuilder = std::move(renderAreaBuilder)]() REQUIRES( |
| 8426 | kMainThreadContext) mutable -> ftl::SharedFuture<FenceResult> { |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8427 | auto layers = getLayerSnapshotsFn(); |
| 8428 | if (FlagManager::getInstance().ce_fence_promise()) { |
| 8429 | for (auto& [layer, layerFE] : layers) { |
| 8430 | attachReleaseFenceFutureToLayer(layer, layerFE.get(), ui::INVALID_LAYER_STACK); |
| 8431 | } |
| 8432 | } |
| 8433 | auto displayState = getDisplayStateFromRenderAreaBuilder(renderAreaBuilder); |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8434 | |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8435 | ScreenCaptureResults captureResults; |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8436 | std::unique_ptr<const RenderArea> renderArea = |
| 8437 | std::visit([](auto&& arg) -> std::unique_ptr<RenderArea> { return arg.build(); }, |
| 8438 | renderAreaBuilder); |
| 8439 | |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8440 | if (!renderArea) { |
| 8441 | ALOGW("Skipping screen capture because of invalid render area."); |
| 8442 | if (captureListener) { |
| 8443 | captureResults.fenceResult = base::unexpected(NO_MEMORY); |
| 8444 | captureListener->onScreenCaptureCompleted(captureResults); |
| 8445 | } |
| 8446 | return ftl::yield<FenceResult>(base::unexpected(NO_ERROR)).share(); |
| 8447 | } |
| 8448 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8449 | auto layerFEs = extractLayerFEs(layers); |
Melody Hsu | 9db32ff | 2024-04-17 19:52:55 +0000 | [diff] [blame] | 8450 | ftl::SharedFuture<FenceResult> renderFuture = |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8451 | renderScreenImpl(std::move(renderArea), buffer, regionSampling, grayscale, |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8452 | isProtected, captureResults, displayState, layers, layerFEs); |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8453 | |
| 8454 | if (captureListener) { |
| 8455 | // Defer blocking on renderFuture back to the Binder thread. |
| 8456 | return ftl::Future(std::move(renderFuture)) |
| 8457 | .then([captureListener, captureResults = std::move(captureResults)]( |
| 8458 | FenceResult fenceResult) mutable -> FenceResult { |
| 8459 | captureResults.fenceResult = std::move(fenceResult); |
Nolan Scobie | 1d2deb2 | 2022-11-18 12:57:47 -0500 | [diff] [blame] | 8460 | captureListener->onScreenCaptureCompleted(captureResults); |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8461 | return base::unexpected(NO_ERROR); |
| 8462 | }) |
| 8463 | .share(); |
| 8464 | } |
| 8465 | return renderFuture; |
| 8466 | }; |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 8467 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 8468 | // TODO(b/294936197): Run takeScreenshotsFn() in a binder thread to reduce the number |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8469 | // of calls on the main thread. |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8470 | auto future = |
| 8471 | mScheduler->schedule(FTL_FAKE_GUARD(kMainThreadContext, std::move(takeScreenshotFn))); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 8472 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8473 | // Flatten nested futures. |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 8474 | auto chain = ftl::Future(std::move(future)).then([](ftl::SharedFuture<FenceResult> future) { |
| 8475 | return future; |
| 8476 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8477 | |
| 8478 | return chain.share(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 8479 | } |
| 8480 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 8481 | ftl::SharedFuture<FenceResult> SurfaceFlinger::renderScreenImpl( |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8482 | std::unique_ptr<const RenderArea> renderArea, |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 8483 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
| 8484 | bool grayscale, bool isProtected, ScreenCaptureResults& captureResults, |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8485 | std::optional<OutputCompositionState>& displayState, |
| 8486 | std::vector<std::pair<Layer*, sp<LayerFE>>>& layers, std::vector<sp<LayerFE>>& layerFEs) { |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 8487 | ATRACE_CALL(); |
Alec Mouri | b4814de | 2023-09-11 22:09:03 +0000 | [diff] [blame] | 8488 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8489 | for (auto& layerFE : layerFEs) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8490 | frontend::LayerSnapshot* snapshot = layerFE->mSnapshot.get(); |
| 8491 | captureResults.capturedSecureLayers |= (snapshot->isVisible && snapshot->isSecure); |
| 8492 | captureResults.capturedHdrLayers |= isHdrLayer(*snapshot); |
| 8493 | layerFE->mSnapshot->geomLayerTransform = |
| 8494 | renderArea->getTransform() * layerFE->mSnapshot->geomLayerTransform; |
Patrick Williams | c6e0cce | 2023-02-28 23:04:45 -0600 | [diff] [blame] | 8495 | layerFE->mSnapshot->geomInverseLayerTransform = |
| 8496 | layerFE->mSnapshot->geomLayerTransform.inverse(); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8497 | } |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8498 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8499 | auto capturedBuffer = buffer; |
| 8500 | |
| 8501 | auto requestedDataspace = renderArea->getReqDataSpace(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8502 | auto parent = renderArea->getParentLayer(); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 8503 | auto renderIntent = RenderIntent::TONE_MAP_COLORIMETRIC; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 8504 | auto sdrWhitePointNits = DisplayDevice::sDefaultMaxLumiance; |
| 8505 | auto displayBrightnessNits = DisplayDevice::sDefaultMaxLumiance; |
| 8506 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8507 | captureResults.capturedDataspace = requestedDataspace; |
| 8508 | |
Alec Mouri | a7e752e | 2024-05-24 18:21:21 +0000 | [diff] [blame] | 8509 | const bool enableLocalTonemapping = FlagManager::getInstance().local_tonemap_screenshots() && |
| 8510 | !renderArea->getHintForSeamlessTransition(); |
| 8511 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8512 | if (displayState) { |
| 8513 | const auto& state = displayState.value(); |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8514 | captureResults.capturedDataspace = |
Melody Hsu | 683fe04 | 2024-06-04 17:22:04 +0000 | [diff] [blame] | 8515 | pickBestDataspace(requestedDataspace, state, captureResults.capturedHdrLayers, |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8516 | renderArea->getHintForSeamlessTransition()); |
| 8517 | sdrWhitePointNits = state.sdrWhitePointNits; |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8518 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8519 | if (!captureResults.capturedHdrLayers) { |
| 8520 | displayBrightnessNits = sdrWhitePointNits; |
| 8521 | } else { |
| 8522 | displayBrightnessNits = state.displayBrightnessNits; |
| 8523 | if (!enableLocalTonemapping) { |
| 8524 | // Only clamp the display brightness if this is not a seamless transition. |
| 8525 | // Otherwise for seamless transitions it's important to match the current |
| 8526 | // display state as the buffer will be shown under these same conditions, and we |
| 8527 | // want to avoid any flickers |
| 8528 | if (sdrWhitePointNits > 1.0f && !renderArea->getHintForSeamlessTransition()) { |
| 8529 | // Restrict the amount of HDR "headroom" in the screenshot to avoid |
| 8530 | // over-dimming the SDR portion. 2.0 chosen by experimentation |
| 8531 | constexpr float kMaxScreenshotHeadroom = 2.0f; |
| 8532 | displayBrightnessNits = std::min(sdrWhitePointNits * kMaxScreenshotHeadroom, |
| 8533 | displayBrightnessNits); |
Alec Mouri | b4814de | 2023-09-11 22:09:03 +0000 | [diff] [blame] | 8534 | } |
Alec Mouri | 5e488f8 | 2023-09-15 01:27:49 +0000 | [diff] [blame] | 8535 | } |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8536 | } |
Alec Mouri | ffb3221 | 2023-09-16 19:29:15 +0000 | [diff] [blame] | 8537 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8538 | // Screenshots leaving the device should be colorimetric |
| 8539 | if (requestedDataspace == ui::Dataspace::UNKNOWN && |
| 8540 | renderArea->getHintForSeamlessTransition()) { |
| 8541 | renderIntent = state.renderIntent; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8542 | } |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8543 | } |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8544 | |
| 8545 | captureResults.buffer = capturedBuffer->getBuffer(); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8546 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8547 | ui::LayerStack layerStack{ui::DEFAULT_LAYER_STACK}; |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8548 | if (!layerFEs.empty()) { |
| 8549 | const sp<LayerFE>& layerFE = layerFEs.back(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8550 | layerStack = layerFE->getCompositionState()->outputFilter.layerStack; |
Yichi Chen | 40773d9 | 2020-04-01 10:10:18 +0800 | [diff] [blame] | 8551 | } |
Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 8552 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8553 | auto copyLayerFEs = [&layerFEs]() { |
| 8554 | std::vector<sp<compositionengine::LayerFE>> ceLayerFEs; |
| 8555 | ceLayerFEs.reserve(layerFEs.size()); |
| 8556 | for (const auto& layerFE : layerFEs) { |
| 8557 | ceLayerFEs.push_back(layerFE); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8558 | } |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8559 | return ceLayerFEs; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8560 | }; |
| 8561 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8562 | auto present = [this, buffer = capturedBuffer, dataspace = captureResults.capturedDataspace, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8563 | sdrWhitePointNits, displayBrightnessNits, grayscale, isProtected, |
| 8564 | layerFEs = copyLayerFEs(), layerStack, regionSampling, |
Alec Mouri | a7e752e | 2024-05-24 18:21:21 +0000 | [diff] [blame] | 8565 | renderArea = std::move(renderArea), renderIntent, |
| 8566 | enableLocalTonemapping]() -> FenceResult { |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8567 | std::unique_ptr<compositionengine::CompositionEngine> compositionEngine = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8568 | mFactory.createCompositionEngine(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8569 | compositionEngine->setRenderEngine(mRenderEngine.get()); |
| 8570 | |
| 8571 | compositionengine::Output::ColorProfile colorProfile{.dataspace = dataspace, |
| 8572 | .renderIntent = renderIntent}; |
| 8573 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8574 | float targetBrightness = 1.0f; |
Alec Mouri | a7e752e | 2024-05-24 18:21:21 +0000 | [diff] [blame] | 8575 | if (enableLocalTonemapping) { |
| 8576 | // Boost the whole scene so that SDR white is at 1.0 while still communicating the hdr |
| 8577 | // sdr ratio via display brightness / sdrWhite nits. |
| 8578 | targetBrightness = sdrWhitePointNits / displayBrightnessNits; |
| 8579 | } else if (dataspace == ui::Dataspace::BT2020_HLG) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8580 | const float maxBrightnessNits = displayBrightnessNits / sdrWhitePointNits * 203; |
| 8581 | // With a low dimming ratio, don't fit the entire curve. Otherwise mixed content |
| 8582 | // will appear way too bright. |
| 8583 | if (maxBrightnessNits < 1000.f) { |
| 8584 | targetBrightness = 1000.f / maxBrightnessNits; |
| 8585 | } |
| 8586 | } |
| 8587 | |
Alec Mouri | ffb3221 | 2023-09-16 19:29:15 +0000 | [diff] [blame] | 8588 | // Screenshots leaving the device must not dim in gamma space. |
| 8589 | const bool dimInGammaSpaceForEnhancedScreenshots = mDimInGammaSpaceForEnhancedScreenshots && |
| 8590 | renderArea->getHintForSeamlessTransition(); |
| 8591 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8592 | std::shared_ptr<ScreenCaptureOutput> output = createScreenCaptureOutput( |
| 8593 | ScreenCaptureOutputArgs{.compositionEngine = *compositionEngine, |
| 8594 | .colorProfile = colorProfile, |
| 8595 | .renderArea = *renderArea, |
| 8596 | .layerStack = layerStack, |
| 8597 | .buffer = std::move(buffer), |
| 8598 | .sdrWhitePointNits = sdrWhitePointNits, |
| 8599 | .displayBrightnessNits = displayBrightnessNits, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8600 | .targetBrightness = targetBrightness, |
Alec Mouri | 7dae9c1 | 2023-07-13 19:40:53 +0000 | [diff] [blame] | 8601 | .regionSampling = regionSampling, |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 8602 | .treat170mAsSrgb = mTreat170mAsSrgb, |
| 8603 | .dimInGammaSpaceForEnhancedScreenshots = |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8604 | dimInGammaSpaceForEnhancedScreenshots, |
Alec Mouri | a7e752e | 2024-05-24 18:21:21 +0000 | [diff] [blame] | 8605 | .isProtected = isProtected, |
| 8606 | .enableLocalTonemapping = enableLocalTonemapping}); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8607 | |
| 8608 | const float colorSaturation = grayscale ? 0 : 1; |
| 8609 | compositionengine::CompositionRefreshArgs refreshArgs{ |
| 8610 | .outputs = {output}, |
| 8611 | .layers = std::move(layerFEs), |
| 8612 | .updatingOutputGeometryThisFrame = true, |
| 8613 | .updatingGeometryThisFrame = true, |
| 8614 | .colorTransformMatrix = calculateColorMatrix(colorSaturation), |
| 8615 | }; |
| 8616 | compositionEngine->present(refreshArgs); |
| 8617 | |
| 8618 | return output->getRenderSurface()->getClientTargetAcquireFence(); |
| 8619 | }; |
| 8620 | |
| 8621 | // If RenderEngine is threaded, we can safely call CompositionEngine::present off the main |
| 8622 | // thread as the RenderEngine::drawLayers call will run on RenderEngine's thread. Otherwise, |
| 8623 | // we need RenderEngine to run on the main thread so we call CompositionEngine::present |
| 8624 | // immediately. |
| 8625 | // |
| 8626 | // TODO(b/196334700) Once we use RenderEngineThreaded everywhere we can always defer the call |
| 8627 | // to CompositionEngine::present. |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8628 | ftl::SharedFuture<FenceResult> presentFuture; |
| 8629 | if (FlagManager::getInstance().single_hop_screenshot() && |
Vishnu Nair | 454f7f2 | 2024-06-29 01:17:02 +0000 | [diff] [blame] | 8630 | FlagManager::getInstance().ce_fence_promise() && mRenderEngine->isThreaded()) { |
| 8631 | presentFuture = ftl::yield(present()).share(); |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 8632 | } else { |
| 8633 | presentFuture = mRenderEngine->isThreaded() ? ftl::defer(std::move(present)).share() |
| 8634 | : ftl::yield(present()).share(); |
| 8635 | } |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8636 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 8637 | if (!FlagManager::getInstance().ce_fence_promise()) { |
| 8638 | for (auto& [layer, layerFE] : layers) { |
| 8639 | layer->onLayerDisplayed(presentFuture, ui::INVALID_LAYER_STACK, |
| 8640 | [layerFE = std::move(layerFE)](FenceResult) { |
| 8641 | if (FlagManager::getInstance() |
| 8642 | .screenshot_fence_preservation()) { |
| 8643 | const auto compositionResult = |
| 8644 | layerFE->stealCompositionResult(); |
| 8645 | const auto& fences = compositionResult.releaseFences; |
| 8646 | // CompositionEngine may choose to cull layers that |
| 8647 | // aren't visible, so pass a non-fence. |
| 8648 | return fences.empty() ? Fence::NO_FENCE |
| 8649 | : fences.back().first.get(); |
| 8650 | } else { |
| 8651 | return layerFE->stealCompositionResult() |
| 8652 | .releaseFences.back() |
| 8653 | .first.get(); |
| 8654 | } |
| 8655 | }); |
| 8656 | } |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8657 | } |
| 8658 | |
| 8659 | return presentFuture; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 8660 | } |
| 8661 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8662 | void SurfaceFlinger::traverseLegacyLayers(const LayerVector::Visitor& visitor) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8663 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8664 | for (auto& layer : mLegacyLayers) { |
| 8665 | visitor(layer.second.get()); |
| 8666 | } |
| 8667 | } else { |
| 8668 | mDrawingState.traverse(visitor); |
| 8669 | } |
| 8670 | } |
| 8671 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 8672 | // --------------------------------------------------------------------------- |
| 8673 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 8674 | void SurfaceFlinger::State::traverse(const LayerVector::Visitor& visitor) const { |
| 8675 | layersSortedByZ.traverse(visitor); |
| 8676 | } |
| 8677 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 8678 | void SurfaceFlinger::State::traverseInZOrder(const LayerVector::Visitor& visitor) const { |
| 8679 | layersSortedByZ.traverseInZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 8680 | } |
| 8681 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 8682 | void SurfaceFlinger::State::traverseInReverseZOrder(const LayerVector::Visitor& visitor) const { |
| 8683 | layersSortedByZ.traverseInReverseZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 8684 | } |
| 8685 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8686 | void SurfaceFlinger::traverseLayersInLayerStack(ui::LayerStack layerStack, const int32_t uid, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8687 | std::unordered_set<uint32_t> excludeLayerIds, |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 8688 | const LayerVector::Visitor& visitor) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8689 | // We loop through the first level of layers without traversing, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 8690 | // as we need to determine which layers belong to the requested display. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8691 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 8692 | if (layer->getLayerStack() != layerStack) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8693 | continue; |
| 8694 | } |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 8695 | // relative layers are traversed in Layer::traverseInZOrder |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8696 | layer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 8697 | if (layer->isInternalDisplayOverlay()) { |
Adrian Roos | 8acf5a0 | 2018-01-17 21:28:19 +0100 | [diff] [blame] | 8698 | return; |
| 8699 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8700 | if (!layer->isVisible()) { |
| 8701 | return; |
| 8702 | } |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8703 | if (uid != CaptureArgs::UNSET_UID && layer->getOwnerUid() != uid) { |
| 8704 | return; |
| 8705 | } |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8706 | |
| 8707 | if (!excludeLayerIds.empty()) { |
| 8708 | auto p = sp<Layer>::fromExisting(layer); |
| 8709 | while (p != nullptr) { |
| 8710 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 8711 | return; |
| 8712 | } |
| 8713 | p = p->getParent(); |
| 8714 | } |
| 8715 | } |
| 8716 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8717 | visitor(layer); |
| 8718 | }); |
| 8719 | } |
| 8720 | } |
| 8721 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8722 | ftl::Optional<scheduler::FrameRateMode> SurfaceFlinger::getPreferredDisplayMode( |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8723 | PhysicalDisplayId displayId, DisplayModeId defaultModeId) const { |
| 8724 | if (const auto schedulerMode = mScheduler->getPreferredDisplayMode(); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8725 | schedulerMode.modePtr->getPhysicalDisplayId() == displayId) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8726 | return schedulerMode; |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8727 | } |
| 8728 | |
| 8729 | return mPhysicalDisplays.get(displayId) |
| 8730 | .transform(&PhysicalDisplay::snapshotRef) |
| 8731 | .and_then([&](const display::DisplaySnapshot& snapshot) { |
| 8732 | return snapshot.displayModes().get(defaultModeId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 8733 | }) |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8734 | .transform([](const DisplayModePtr& modePtr) { |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 8735 | return scheduler::FrameRateMode{modePtr->getPeakFps(), ftl::as_non_null(modePtr)}; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8736 | }); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8737 | } |
| 8738 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8739 | status_t SurfaceFlinger::setDesiredDisplayModeSpecsInternal( |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 8740 | const sp<DisplayDevice>& display, |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8741 | const scheduler::RefreshRateSelector::PolicyVariant& policy) { |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8742 | const auto displayId = display->getPhysicalId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8743 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8744 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 8745 | Mutex::Autolock lock(mStateLock); |
| 8746 | |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 8747 | if (mDebugDisplayModeSetByBackdoor) { |
| 8748 | // ignore this request as mode is overridden by backdoor |
| 8749 | return NO_ERROR; |
| 8750 | } |
| 8751 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8752 | auto& selector = display->refreshRateSelector(); |
| 8753 | using SetPolicyResult = scheduler::RefreshRateSelector::SetPolicyResult; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8754 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8755 | switch (selector.setPolicy(policy)) { |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8756 | case SetPolicyResult::Invalid: |
| 8757 | return BAD_VALUE; |
| 8758 | case SetPolicyResult::Unchanged: |
| 8759 | return NO_ERROR; |
| 8760 | case SetPolicyResult::Changed: |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8761 | break; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8762 | } |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8763 | |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8764 | return applyRefreshRateSelectorPolicy(displayId, selector); |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8765 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8766 | |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8767 | status_t SurfaceFlinger::applyRefreshRateSelectorPolicy( |
Dominik Laskowski | 1746afd | 2024-04-10 19:21:37 -0400 | [diff] [blame] | 8768 | PhysicalDisplayId displayId, const scheduler::RefreshRateSelector& selector) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8769 | const scheduler::RefreshRateSelector::Policy currentPolicy = selector.getCurrentPolicy(); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8770 | ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str()); |
Adrian Salido | ab6ef6c | 2019-08-28 10:02:49 -0700 | [diff] [blame] | 8771 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 8772 | // TODO(b/140204874): Leave the event in until we do proper testing with all apps that might |
| 8773 | // be depending in this callback. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8774 | if (const auto activeMode = selector.getActiveMode(); displayId == mActiveDisplayId) { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8775 | mScheduler->onPrimaryDisplayModeChanged(scheduler::Cycle::Render, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8776 | toggleKernelIdleTimer(); |
| 8777 | } else { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8778 | mScheduler->onNonPrimaryDisplayModeChanged(scheduler::Cycle::Render, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8779 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 8780 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8781 | auto preferredModeOpt = getPreferredDisplayMode(displayId, currentPolicy.defaultMode); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8782 | if (!preferredModeOpt) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8783 | ALOGE("%s: Preferred mode is unknown", __func__); |
| 8784 | return NAME_NOT_FOUND; |
| 8785 | } |
| 8786 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8787 | auto preferredMode = std::move(*preferredModeOpt); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8788 | const auto preferredModeId = preferredMode.modePtr->getId(); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 8789 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8790 | const Fps preferredFps = preferredMode.fps; |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8791 | ALOGV("Switching to Scheduler preferred mode %d (%s)", ftl::to_underlying(preferredModeId), |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8792 | to_string(preferredFps).c_str()); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8793 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8794 | if (!selector.isModeAllowed(preferredMode)) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8795 | ALOGE("%s: Preferred mode %d is disallowed", __func__, ftl::to_underlying(preferredModeId)); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8796 | return INVALID_OPERATION; |
Dominik Laskowski | 4f1dd8c | 2019-04-17 15:54:30 -0700 | [diff] [blame] | 8797 | } |
| 8798 | |
Dominik Laskowski | 1746afd | 2024-04-10 19:21:37 -0400 | [diff] [blame] | 8799 | setDesiredMode({std::move(preferredMode), .emitEvent = true}); |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 8800 | |
| 8801 | // Update the frameRateOverride list as the display render rate might have changed |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8802 | if (mScheduler->updateFrameRateOverrides(scheduler::GlobalSignals{}, preferredFps)) { |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 8803 | triggerOnFrameRateOverridesChanged(); |
| 8804 | } |
| 8805 | |
Ady Abraham | d9b3ea6 | 2019-02-26 14:08:03 -0800 | [diff] [blame] | 8806 | return NO_ERROR; |
| 8807 | } |
| 8808 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8809 | namespace { |
| 8810 | FpsRange translate(const gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange& aidlRange) { |
| 8811 | return FpsRange{Fps::fromValue(aidlRange.min), Fps::fromValue(aidlRange.max)}; |
| 8812 | } |
| 8813 | |
| 8814 | FpsRanges translate(const gui::DisplayModeSpecs::RefreshRateRanges& aidlRanges) { |
| 8815 | return FpsRanges{translate(aidlRanges.physical), translate(aidlRanges.render)}; |
| 8816 | } |
| 8817 | |
| 8818 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange translate(const FpsRange& range) { |
| 8819 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange aidlRange; |
| 8820 | aidlRange.min = range.min.getValue(); |
| 8821 | aidlRange.max = range.max.getValue(); |
| 8822 | return aidlRange; |
| 8823 | } |
| 8824 | |
| 8825 | gui::DisplayModeSpecs::RefreshRateRanges translate(const FpsRanges& ranges) { |
| 8826 | gui::DisplayModeSpecs::RefreshRateRanges aidlRanges; |
| 8827 | aidlRanges.physical = translate(ranges.physical); |
| 8828 | aidlRanges.render = translate(ranges.render); |
| 8829 | return aidlRanges; |
| 8830 | } |
| 8831 | |
| 8832 | } // namespace |
| 8833 | |
dianlujitao | b38ee07 | 2020-05-25 18:23:49 +0800 | [diff] [blame^] | 8834 | #ifdef QCOM_UM_FAMILY |
Ramakant Singh | f7e8191 | 2020-04-11 16:02:43 +0530 | [diff] [blame] | 8835 | bool SurfaceFlinger::canAllocateHwcDisplayIdForVDS(uint64_t usage) { |
| 8836 | uint64_t flag_mask_pvt_wfd = ~0; |
| 8837 | uint64_t flag_mask_hw_video = ~0; |
Ramakant Singh | f7e8191 | 2020-04-11 16:02:43 +0530 | [diff] [blame] | 8838 | // Reserve hardware acceleration for WFD use-case |
| 8839 | // GRALLOC_USAGE_PRIVATE_WFD + GRALLOC_USAGE_HW_VIDEO_ENCODER = WFD using HW composer. |
| 8840 | flag_mask_pvt_wfd = GRALLOC_USAGE_PRIVATE_WFD; |
| 8841 | flag_mask_hw_video = GRALLOC_USAGE_HW_VIDEO_ENCODER; |
Rheygine Medel | 88606ff | 2022-06-30 11:21:55 -0700 | [diff] [blame] | 8842 | bool isWfd = (usage & flag_mask_pvt_wfd) && (usage & flag_mask_hw_video); |
Rheygine Medel | 9be9d5f | 2022-05-25 19:20:55 -0700 | [diff] [blame] | 8843 | // Enabling only the vendor property would allow WFD to use HWC |
| 8844 | // Enabling both the aosp and vendor properties would allow all other VDS to use HWC |
| 8845 | // Disabling both would set all virtual displays to fall back to GPU |
Rheygine Medel | 88606ff | 2022-06-30 11:21:55 -0700 | [diff] [blame] | 8846 | // In vendor frozen targets, allow WFD to use HWC without any property settings. |
| 8847 | bool canAllocate = mAllowHwcForVDS || (isWfd && mAllowHwcForWFD) || (isWfd && |
| 8848 | mFirstApiLevel < __ANDROID_API_T__); |
Rheygine Medel | 9be9d5f | 2022-05-25 19:20:55 -0700 | [diff] [blame] | 8849 | |
| 8850 | if (canAllocate) { |
| 8851 | enableHalVirtualDisplays(true); |
| 8852 | } |
| 8853 | |
| 8854 | return canAllocate; |
| 8855 | |
Ramakant Singh | f7e8191 | 2020-04-11 16:02:43 +0530 | [diff] [blame] | 8856 | } |
dianlujitao | b38ee07 | 2020-05-25 18:23:49 +0800 | [diff] [blame^] | 8857 | #else |
| 8858 | bool SurfaceFlinger::canAllocateHwcDisplayIdForVDS(uint64_t) { |
| 8859 | return true; |
| 8860 | } |
| 8861 | #endif |
Ramakant Singh | f7e8191 | 2020-04-11 16:02:43 +0530 | [diff] [blame] | 8862 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8863 | status_t SurfaceFlinger::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 8864 | const gui::DisplayModeSpecs& specs) { |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8865 | ATRACE_CALL(); |
| 8866 | |
| 8867 | if (!displayToken) { |
| 8868 | return BAD_VALUE; |
| 8869 | } |
| 8870 | |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 8871 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8872 | const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayToken)); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8873 | if (!display) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8874 | ALOGE("Attempt to set desired display modes for invalid display token %p", |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8875 | displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8876 | return NAME_NOT_FOUND; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8877 | } else if (display->isVirtual()) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8878 | ALOGW("Attempt to set desired display modes for virtual display"); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8879 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8880 | } else { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8881 | using Policy = scheduler::RefreshRateSelector::DisplayManagerPolicy; |
Ady Abraham | 6723172 | 2024-03-21 18:06:21 -0700 | [diff] [blame] | 8882 | const auto idleScreenConfigOpt = |
| 8883 | FlagManager::getInstance().idle_screen_refresh_rate_timeout() |
| 8884 | ? specs.idleScreenRefreshRateConfig |
| 8885 | : std::nullopt; |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8886 | const Policy policy{DisplayModeId(specs.defaultMode), translate(specs.primaryRanges), |
Ady Abraham | 6723172 | 2024-03-21 18:06:21 -0700 | [diff] [blame] | 8887 | translate(specs.appRequestRanges), specs.allowGroupSwitching, |
| 8888 | idleScreenConfigOpt}; |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 8889 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8890 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8891 | } |
| 8892 | }); |
| 8893 | |
| 8894 | return future.get(); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8895 | } |
| 8896 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 8897 | status_t SurfaceFlinger::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8898 | gui::DisplayModeSpecs* outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8899 | ATRACE_CALL(); |
| 8900 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8901 | if (!displayToken || !outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8902 | return BAD_VALUE; |
| 8903 | } |
| 8904 | |
| 8905 | Mutex::Autolock lock(mStateLock); |
| 8906 | const auto display = getDisplayDeviceLocked(displayToken); |
| 8907 | if (!display) { |
| 8908 | return NAME_NOT_FOUND; |
| 8909 | } |
| 8910 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8911 | if (display->isVirtual()) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 8912 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8913 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8914 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8915 | scheduler::RefreshRateSelector::Policy policy = |
| 8916 | display->refreshRateSelector().getDisplayManagerPolicy(); |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8917 | outSpecs->defaultMode = ftl::to_underlying(policy.defaultMode); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8918 | outSpecs->allowGroupSwitching = policy.allowGroupSwitching; |
| 8919 | outSpecs->primaryRanges = translate(policy.primaryRanges); |
| 8920 | outSpecs->appRequestRanges = translate(policy.appRequestRanges); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8921 | return NO_ERROR; |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8922 | } |
| 8923 | |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 8924 | void SurfaceFlinger::onLayerFirstRef(Layer* layer) { |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8925 | mNumLayers++; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8926 | if (!layer->isRemovedFromCurrentState()) { |
| 8927 | mScheduler->registerLayer(layer); |
| 8928 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8929 | } |
| 8930 | |
| 8931 | void SurfaceFlinger::onLayerDestroyed(Layer* layer) { |
| 8932 | mNumLayers--; |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8933 | removeHierarchyFromOffscreenLayers(layer); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8934 | if (!layer->isRemovedFromCurrentState()) { |
| 8935 | mScheduler->deregisterLayer(layer); |
| 8936 | } |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 8937 | if (mTransactionTracing) { |
| 8938 | mTransactionTracing->onLayerRemoved(layer->getSequence()); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 8939 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 8940 | mScheduler->onLayerDestroyed(layer); |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8941 | } |
| 8942 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8943 | void SurfaceFlinger::onLayerUpdate() { |
| 8944 | scheduleCommit(FrameHint::kActive); |
| 8945 | } |
| 8946 | |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8947 | // WARNING: ONLY CALL THIS FROM LAYER DTOR |
| 8948 | // Here we add children in the current state to offscreen layers and remove the |
| 8949 | // layer itself from the offscreen layer list. Since |
| 8950 | // this is the dtor, it is safe to access the current state. This keeps us |
| 8951 | // from dangling children layers such that they are not reachable from the |
| 8952 | // Drawing state nor the offscreen layer list |
| 8953 | // See b/141111965 |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8954 | void SurfaceFlinger::removeHierarchyFromOffscreenLayers(Layer* layer) { |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8955 | for (auto& child : layer->getCurrentChildren()) { |
| 8956 | mOffscreenLayers.emplace(child.get()); |
| 8957 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8958 | mOffscreenLayers.erase(layer); |
| 8959 | } |
| 8960 | |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8961 | void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) { |
| 8962 | mOffscreenLayers.erase(layer); |
| 8963 | } |
| 8964 | |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 8965 | status_t SurfaceFlinger::setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, |
| 8966 | float lightPosY, float lightPosZ, |
| 8967 | float lightRadius) { |
| 8968 | Mutex::Autolock _l(mStateLock); |
| 8969 | mCurrentState.globalShadowSettings.ambientColor = vec4(ambientColor); |
| 8970 | mCurrentState.globalShadowSettings.spotColor = vec4(spotColor); |
| 8971 | mCurrentState.globalShadowSettings.lightPos.y = lightPosY; |
| 8972 | mCurrentState.globalShadowSettings.lightPos.z = lightPosZ; |
| 8973 | mCurrentState.globalShadowSettings.lightRadius = lightRadius; |
| 8974 | |
| 8975 | // these values are overridden when calculating the shadow settings for a layer. |
| 8976 | mCurrentState.globalShadowSettings.lightPos.x = 0.f; |
| 8977 | mCurrentState.globalShadowSettings.length = 0.f; |
Vishnu Nair | b13bb95 | 2019-11-15 10:24:08 -0800 | [diff] [blame] | 8978 | return NO_ERROR; |
| 8979 | } |
| 8980 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8981 | const std::unordered_map<std::string, uint32_t>& SurfaceFlinger::getGenericLayerMetadataKeyMap() |
| 8982 | const { |
| 8983 | // TODO(b/149500060): Remove this fixed/static mapping. Please prefer taking |
| 8984 | // on the work to remove the table in that bug rather than adding more to |
| 8985 | // it. |
| 8986 | static const std::unordered_map<std::string, uint32_t> genericLayerMetadataKeyMap{ |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8987 | {"org.chromium.arc.V1_0.TaskId", gui::METADATA_TASK_ID}, |
| 8988 | {"org.chromium.arc.V1_0.CursorInfo", gui::METADATA_MOUSE_CURSOR}, |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8989 | }; |
| 8990 | return genericLayerMetadataKeyMap; |
| 8991 | } |
| 8992 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8993 | status_t SurfaceFlinger::setGameModeFrameRateOverride(uid_t uid, float frameRate) { |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 8994 | PhysicalDisplayId displayId = [&]() { |
| 8995 | Mutex::Autolock lock(mStateLock); |
| 8996 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 8997 | }(); |
| 8998 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8999 | mScheduler->setGameModeFrameRateForUid(FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 9000 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 9001 | return NO_ERROR; |
| 9002 | } |
| 9003 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 9004 | status_t SurfaceFlinger::setGameDefaultFrameRateOverride(uid_t uid, float frameRate) { |
| 9005 | if (FlagManager::getInstance().game_default_frame_rate()) { |
| 9006 | mScheduler->setGameDefaultFrameRateForUid( |
| 9007 | FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
| 9008 | } |
| 9009 | return NO_ERROR; |
| 9010 | } |
| 9011 | |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9012 | status_t SurfaceFlinger::updateSmallAreaDetection( |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 9013 | std::vector<std::pair<int32_t, float>>& appIdThresholdMappings) { |
| 9014 | mScheduler->updateSmallAreaDetection(appIdThresholdMappings); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9015 | return NO_ERROR; |
| 9016 | } |
| 9017 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 9018 | status_t SurfaceFlinger::setSmallAreaDetectionThreshold(int32_t appId, float threshold) { |
| 9019 | mScheduler->setSmallAreaDetectionThreshold(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9020 | return NO_ERROR; |
| 9021 | } |
| 9022 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 9023 | void SurfaceFlinger::enableRefreshRateOverlay(bool enable) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 9024 | bool setByHwc = getHwComposer().hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG); |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 9025 | for (const auto& [displayId, physical] : mPhysicalDisplays) { |
| 9026 | if (physical.snapshot().connectionType() == ui::DisplayConnectionType::Internal || |
Sally Qi | de329f2 | 2023-09-26 16:21:39 -0700 | [diff] [blame] | 9027 | FlagManager::getInstance().refresh_rate_overlay_on_external_display()) { |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 9028 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 9029 | const auto enableOverlay = [&](bool setByHwc) FTL_FAKE_GUARD(kMainThreadContext) { |
| 9030 | const auto activeMode = mDisplayModeController.getActiveMode(displayId); |
| 9031 | const Fps refreshRate = activeMode.modePtr->getVsyncRate(); |
| 9032 | const Fps renderFps = activeMode.fps; |
| 9033 | |
| 9034 | display->enableRefreshRateOverlay(enable, setByHwc, refreshRate, renderFps, |
| 9035 | mRefreshRateOverlaySpinner, |
| 9036 | mRefreshRateOverlayRenderRate, |
| 9037 | mRefreshRateOverlayShowInMiddle); |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 9038 | }; |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 9039 | |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 9040 | enableOverlay(setByHwc); |
| 9041 | if (setByHwc) { |
| 9042 | const auto status = |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 9043 | getHwComposer().setRefreshRateChangedCallbackDebugEnabled(displayId, |
| 9044 | enable); |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 9045 | if (status != NO_ERROR) { |
Ying Wei | 22d59cc | 2024-05-11 02:41:08 +0000 | [diff] [blame] | 9046 | ALOGE("Error %s refresh rate changed callback debug", |
| 9047 | enable ? "enabling" : "disabling"); |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 9048 | enableOverlay(/*setByHwc*/ false); |
| 9049 | } |
| 9050 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 9051 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 9052 | } |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 9053 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 9054 | } |
| 9055 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 9056 | void SurfaceFlinger::enableHdrSdrRatioOverlay(bool enable) { |
| 9057 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 9058 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal) { |
| 9059 | if (const auto device = getDisplayDeviceLocked(id)) { |
| 9060 | device->enableHdrSdrRatioOverlay(enable); |
| 9061 | } |
| 9062 | } |
| 9063 | } |
| 9064 | } |
| 9065 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9066 | int SurfaceFlinger::getGpuContextPriority() { |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 9067 | return getRenderEngine().getContextPriority(); |
Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 9068 | } |
| 9069 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 9070 | int SurfaceFlinger::calculateMaxAcquiredBufferCount(Fps refreshRate, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9071 | std::chrono::nanoseconds presentLatency) { |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 9072 | auto pipelineDepth = presentLatency.count() / refreshRate.getPeriodNsecs(); |
| 9073 | if (presentLatency.count() % refreshRate.getPeriodNsecs()) { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 9074 | pipelineDepth++; |
| 9075 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9076 | return std::max(minAcquiredBuffers, static_cast<int64_t>(pipelineDepth - 1)); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 9077 | } |
| 9078 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 9079 | status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 9080 | Fps maxRefreshRate = 60_Hz; |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 9081 | |
| 9082 | if (!getHwComposer().isHeadless()) { |
| 9083 | if (const auto display = getDefaultDisplayDevice()) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 9084 | maxRefreshRate = display->refreshRateSelector().getSupportedRefreshRateRange().max; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 9085 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 9086 | } |
| 9087 | |
| 9088 | *buffers = getMaxAcquiredBufferCountForRefreshRate(maxRefreshRate); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 9089 | return NO_ERROR; |
| 9090 | } |
| 9091 | |
rnlee | ed20fa4 | 2021-08-10 18:00:03 -0700 | [diff] [blame] | 9092 | uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 9093 | Fps refreshRate = 60_Hz; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 9094 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 9095 | if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) { |
| 9096 | refreshRate = *frameRateOverride; |
| 9097 | } else if (!getHwComposer().isHeadless()) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 9098 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked())) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 9099 | refreshRate = display->refreshRateSelector().getActiveMode().fps; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 9100 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 9101 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 9102 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 9103 | return getMaxAcquiredBufferCountForRefreshRate(refreshRate); |
| 9104 | } |
| 9105 | |
| 9106 | int SurfaceFlinger::getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 9107 | const auto vsyncConfig = |
| 9108 | mScheduler->getVsyncConfiguration().getConfigsForRefreshRate(refreshRate).late; |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 9109 | const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration; |
| 9110 | return calculateMaxAcquiredBufferCount(refreshRate, presentLatency); |
| 9111 | } |
| 9112 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 9113 | void SurfaceFlinger::handleLayerCreatedLocked(const LayerCreatedState& state, VsyncId vsyncId) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9114 | sp<Layer> layer = state.layer.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 9115 | if (!layer) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9116 | ALOGD("Layer was destroyed soon after creation %p", state.layer.unsafe_get()); |
| 9117 | return; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 9118 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 9119 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 9120 | |
| 9121 | sp<Layer> parent; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9122 | bool addToRoot = state.addToRoot; |
| 9123 | if (state.initialParent != nullptr) { |
| 9124 | parent = state.initialParent.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 9125 | if (parent == nullptr) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9126 | ALOGD("Parent was destroyed soon after creation %p", state.initialParent.unsafe_get()); |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 9127 | addToRoot = false; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 9128 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 9129 | } |
| 9130 | |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 9131 | if (parent == nullptr && addToRoot) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 9132 | layer->setIsAtRoot(true); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 9133 | mCurrentState.layersSortedByZ.add(layer); |
| 9134 | } else if (parent == nullptr) { |
| 9135 | layer->onRemovedFromCurrentState(); |
| 9136 | } else if (parent->isRemovedFromCurrentState()) { |
| 9137 | parent->addChild(layer); |
| 9138 | layer->onRemovedFromCurrentState(); |
| 9139 | } else { |
| 9140 | parent->addChild(layer); |
| 9141 | } |
| 9142 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 9143 | ui::LayerStack layerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 9144 | sp<const DisplayDevice> hintDisplay; |
| 9145 | // Find the display that includes the layer. |
| 9146 | for (const auto& [token, display] : mDisplays) { |
| 9147 | if (display->getLayerStack() == layerStack) { |
| 9148 | hintDisplay = display; |
| 9149 | break; |
| 9150 | } |
| 9151 | } |
| 9152 | |
| 9153 | if (hintDisplay) { |
| 9154 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
| 9155 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 9156 | } |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 9157 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 9158 | void SurfaceFlinger::sample() { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9159 | if (!mLumaSampling || !mRegionSamplingThread) { |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 9160 | return; |
| 9161 | } |
| 9162 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 9163 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 9164 | const auto scheduleFrameTimeOpt = scheduledFrameResultOpt |
| 9165 | ? std::optional{scheduledFrameResultOpt->callbackTime} |
| 9166 | : std::nullopt; |
| 9167 | mRegionSamplingThread->onCompositionComplete(scheduleFrameTimeOpt); |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 9168 | } |
| 9169 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 9170 | void SurfaceFlinger::onActiveDisplaySizeChanged(const DisplayDevice& activeDisplay) { |
| 9171 | mScheduler->onActiveDisplayAreaChanged(activeDisplay.getWidth() * activeDisplay.getHeight()); |
| 9172 | getRenderEngine().onActiveDisplaySizeChanged(activeDisplay.getSize()); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 9173 | } |
| 9174 | |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 9175 | sp<DisplayDevice> SurfaceFlinger::getActivatableDisplay() const { |
| 9176 | if (mPhysicalDisplays.size() == 1) return nullptr; |
| 9177 | |
| 9178 | // TODO(b/255635821): Choose the pacesetter display, considering both internal and external |
| 9179 | // displays. For now, pick the other internal display, assuming a dual-display foldable. |
| 9180 | return findDisplay([this](const DisplayDevice& display) REQUIRES(mStateLock) { |
| 9181 | const auto idOpt = PhysicalDisplayId::tryCast(display.getId()); |
| 9182 | return idOpt && *idOpt != mActiveDisplayId && display.isPoweredOn() && |
| 9183 | mPhysicalDisplays.get(*idOpt) |
| 9184 | .transform(&PhysicalDisplay::isInternal) |
| 9185 | .value_or(false); |
| 9186 | }); |
| 9187 | } |
| 9188 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 9189 | void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveDisplayPtr, |
| 9190 | const DisplayDevice& activeDisplay) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 9191 | ATRACE_CALL(); |
| 9192 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 9193 | if (inactiveDisplayPtr) { |
| 9194 | inactiveDisplayPtr->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false); |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 9195 | } |
| 9196 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 9197 | mActiveDisplayId = activeDisplay.getPhysicalId(); |
| 9198 | activeDisplay.getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 9199 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 9200 | mScheduler->resetPhaseConfiguration(mDisplayModeController.getActiveMode(mActiveDisplayId).fps); |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 9201 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 9202 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 9203 | mScheduler->setModeChangePending(false); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 9204 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 9205 | mScheduler->setPacesetterDisplay(mActiveDisplayId); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 9206 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 9207 | onActiveDisplaySizeChanged(activeDisplay); |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 9208 | mActiveDisplayTransformHint = activeDisplay.getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 9209 | sActiveDisplayRotationFlags = ui::Transform::toRotationFlags(activeDisplay.getOrientation()); |
Ady Abraham | 85d692d | 2021-09-28 14:08:54 -0700 | [diff] [blame] | 9210 | |
Dominik Laskowski | 1746afd | 2024-04-10 19:21:37 -0400 | [diff] [blame] | 9211 | // Whether or not the policy of the new active/pacesetter display changed while it was inactive |
| 9212 | // (in which case its preferred mode has already been propagated to HWC via setDesiredMode), the |
| 9213 | // Scheduler's cachedModeChangedParams must be initialized to the newly active mode, and the |
| 9214 | // kernel idle timer of the newly active display must be toggled. |
| 9215 | applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay.refreshRateSelector()); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 9216 | } |
| 9217 | |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 9218 | status_t SurfaceFlinger::addWindowInfosListener(const sp<IWindowInfosListener>& windowInfosListener, |
| 9219 | gui::WindowInfosListenerInfo* outInfo) { |
| 9220 | mWindowInfosListenerInvoker->addWindowInfosListener(windowInfosListener, outInfo); |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 9221 | setTransactionFlags(eInputInfoUpdateNeeded); |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 9222 | return NO_ERROR; |
| 9223 | } |
| 9224 | |
| 9225 | status_t SurfaceFlinger::removeWindowInfosListener( |
| 9226 | const sp<IWindowInfosListener>& windowInfosListener) const { |
| 9227 | mWindowInfosListenerInvoker->removeWindowInfosListener(windowInfosListener); |
| 9228 | return NO_ERROR; |
| 9229 | } |
| 9230 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 9231 | status_t SurfaceFlinger::getStalledTransactionInfo( |
| 9232 | int pid, std::optional<TransactionHandler::StalledTransactionInfo>& result) { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 9233 | // Used to add a stalled transaction which uses an internal lock. |
| 9234 | ftl::FakeGuard guard(kMainThreadContext); |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 9235 | result = mTransactionHandler.getStalledTransactionInfo(pid); |
| 9236 | return NO_ERROR; |
| 9237 | } |
| 9238 | |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 9239 | void SurfaceFlinger::updateHdcpLevels(hal::HWDisplayId hwcDisplayId, int32_t connectedLevel, |
| 9240 | int32_t maxLevel) { |
| 9241 | if (!FlagManager::getInstance().connected_display()) { |
| 9242 | return; |
| 9243 | } |
| 9244 | |
| 9245 | Mutex::Autolock lock(mStateLock); |
| 9246 | |
| 9247 | const auto idOpt = getHwComposer().toPhysicalDisplayId(hwcDisplayId); |
| 9248 | if (!idOpt) { |
| 9249 | ALOGE("No display found for HDCP level changed event: connected=%d, max=%d for " |
| 9250 | "display=%" PRIu64, |
| 9251 | connectedLevel, maxLevel, hwcDisplayId); |
| 9252 | return; |
| 9253 | } |
| 9254 | |
| 9255 | const bool isInternalDisplay = |
| 9256 | mPhysicalDisplays.get(*idOpt).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 9257 | if (isInternalDisplay) { |
| 9258 | ALOGW("Unexpected HDCP level changed for internal display: connected=%d, max=%d for " |
| 9259 | "display=%" PRIu64, |
| 9260 | connectedLevel, maxLevel, hwcDisplayId); |
| 9261 | return; |
| 9262 | } |
| 9263 | |
| 9264 | static_cast<void>(mScheduler->schedule([this, displayId = *idOpt, connectedLevel, maxLevel]() { |
| 9265 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayId))) { |
| 9266 | Mutex::Autolock lock(mStateLock); |
| 9267 | display->setSecure(connectedLevel >= 2 /* HDCP_V1 */); |
| 9268 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 9269 | mScheduler->onHdcpLevelsChanged(scheduler::Cycle::Render, displayId, connectedLevel, |
| 9270 | maxLevel); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 9271 | })); |
| 9272 | } |
| 9273 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 9274 | std::shared_ptr<renderengine::ExternalTexture> SurfaceFlinger::getExternalTextureFromBufferData( |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 9275 | BufferData& bufferData, const char* layerName, uint64_t transactionId) { |
| 9276 | if (bufferData.buffer && |
| 9277 | exceedsMaxRenderTargetSize(bufferData.buffer->getWidth(), bufferData.buffer->getHeight())) { |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 9278 | std::string errorMessage = |
| 9279 | base::StringPrintf("Attempted to create an ExternalTexture with size (%u, %u) for " |
| 9280 | "layer %s that exceeds render target size limit of %u.", |
| 9281 | bufferData.buffer->getWidth(), bufferData.buffer->getHeight(), |
| 9282 | layerName, static_cast<uint32_t>(mMaxRenderTargetSize)); |
| 9283 | ALOGD("%s", errorMessage.c_str()); |
| 9284 | if (bufferData.releaseBufferListener) { |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 9285 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
| 9286 | String8(errorMessage.c_str())); |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 9287 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 9288 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 9289 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 9290 | |
| 9291 | bool cachedBufferChanged = |
| 9292 | bufferData.flags.test(BufferData::BufferDataChange::cachedBufferChanged); |
| 9293 | if (cachedBufferChanged && bufferData.buffer) { |
| 9294 | auto result = ClientCache::getInstance().add(bufferData.cachedBuffer, bufferData.buffer); |
| 9295 | if (result.ok()) { |
| 9296 | return result.value(); |
| 9297 | } |
| 9298 | |
| 9299 | if (result.error() == ClientCache::AddError::CacheFull) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 9300 | ALOGE("Attempted to create an ExternalTexture for layer %s but CacheFull", layerName); |
| 9301 | |
| 9302 | if (bufferData.releaseBufferListener) { |
| 9303 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 9304 | String8("Buffer processing hung due to full buffer cache")); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 9305 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 9306 | } |
| 9307 | |
| 9308 | return nullptr; |
| 9309 | } |
| 9310 | |
| 9311 | if (cachedBufferChanged) { |
| 9312 | return ClientCache::getInstance().get(bufferData.cachedBuffer); |
| 9313 | } |
| 9314 | |
| 9315 | if (bufferData.buffer) { |
| 9316 | return std::make_shared< |
| 9317 | renderengine::impl::ExternalTexture>(bufferData.buffer, getRenderEngine(), |
| 9318 | renderengine::impl::ExternalTexture::Usage:: |
| 9319 | READABLE); |
| 9320 | } |
| 9321 | |
| 9322 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 9323 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9324 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 9325 | bool SurfaceFlinger::commitMirrorDisplays(VsyncId vsyncId) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9326 | std::vector<MirrorDisplayState> mirrorDisplays; |
| 9327 | { |
| 9328 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
| 9329 | mirrorDisplays = std::move(mMirrorDisplays); |
| 9330 | mMirrorDisplays.clear(); |
| 9331 | if (mirrorDisplays.size() == 0) { |
| 9332 | return false; |
| 9333 | } |
| 9334 | } |
| 9335 | |
| 9336 | sp<IBinder> unused; |
| 9337 | for (const auto& mirrorDisplay : mirrorDisplays) { |
| 9338 | // Set mirror layer's default layer stack to -1 so it doesn't end up rendered on a display |
| 9339 | // accidentally. |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 9340 | sp<Layer> rootMirrorLayer = LayerHandle::getLayer(mirrorDisplay.rootHandle); |
Qi Jing | b8e4c13 | 2023-08-25 23:01:47 +0000 | [diff] [blame] | 9341 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(rootMirrorLayer); |
| 9342 | bool ret = rootMirrorLayer->setLayerStack(ui::LayerStack::fromValue(-1)); |
| 9343 | if (idx >= 0 && ret) { |
| 9344 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 9345 | mCurrentState.layersSortedByZ.add(rootMirrorLayer); |
| 9346 | } |
| 9347 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9348 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 9349 | if (layer->getLayerStack() != mirrorDisplay.layerStack || |
| 9350 | layer->isInternalDisplayOverlay()) { |
| 9351 | continue; |
| 9352 | } |
| 9353 | |
| 9354 | LayerCreationArgs mirrorArgs(this, mirrorDisplay.client, "MirrorLayerParent", |
| 9355 | ISurfaceComposerClient::eNoColorFill, |
| 9356 | gui::LayerMetadata()); |
| 9357 | sp<Layer> childMirror; |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 9358 | { |
| 9359 | Mutex::Autolock lock(mStateLock); |
| 9360 | createEffectLayer(mirrorArgs, &unused, &childMirror); |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 9361 | MUTEX_ALIAS(mStateLock, childMirror->mFlinger->mStateLock); |
Melody Hsu | 12ecd08 | 2024-04-17 19:03:13 +0000 | [diff] [blame] | 9362 | childMirror->setClonedChild(layer->createClone()); |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 9363 | childMirror->reparent(mirrorDisplay.rootHandle); |
| 9364 | } |
| 9365 | // lock on mStateLock needs to be released before binder handle gets destroyed |
| 9366 | unused.clear(); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9367 | } |
| 9368 | } |
| 9369 | return true; |
| 9370 | } |
| 9371 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9372 | bool SurfaceFlinger::commitCreatedLayers(VsyncId vsyncId, |
| 9373 | std::vector<LayerCreatedState>& createdLayers) { |
| 9374 | if (createdLayers.size() == 0) { |
| 9375 | return false; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9376 | } |
| 9377 | |
| 9378 | Mutex::Autolock _l(mStateLock); |
| 9379 | for (const auto& createdLayer : createdLayers) { |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 9380 | handleLayerCreatedLocked(createdLayer, vsyncId); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9381 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9382 | mLayersAdded = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9383 | return mLayersAdded; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9384 | } |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9385 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 9386 | void SurfaceFlinger::updateLayerMetadataSnapshot() { |
| 9387 | LayerMetadata parentMetadata; |
| 9388 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 9389 | layer->updateMetadataSnapshot(parentMetadata); |
| 9390 | } |
| 9391 | |
| 9392 | std::unordered_set<Layer*> visited; |
| 9393 | mDrawingState.traverse([&visited](Layer* layer) { |
| 9394 | if (visited.find(layer) != visited.end()) { |
| 9395 | return; |
| 9396 | } |
| 9397 | |
| 9398 | // If the layer isRelativeOf, then either it's relative metadata will be set |
| 9399 | // recursively when updateRelativeMetadataSnapshot is called on its relative parent or |
| 9400 | // it's relative parent has been deleted. Clear the layer's relativeLayerMetadata to ensure |
| 9401 | // that layers with deleted relative parents don't hold stale relativeLayerMetadata. |
| 9402 | if (layer->getDrawingState().isRelativeOf) { |
| 9403 | layer->editLayerSnapshot()->relativeLayerMetadata = {}; |
| 9404 | return; |
| 9405 | } |
| 9406 | |
| 9407 | layer->updateRelativeMetadataSnapshot({}, visited); |
| 9408 | }); |
| 9409 | } |
| 9410 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9411 | void SurfaceFlinger::moveSnapshotsFromCompositionArgs( |
| 9412 | compositionengine::CompositionRefreshArgs& refreshArgs, |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 9413 | const std::vector<std::pair<Layer*, LayerFE*>>& layers) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9414 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9415 | std::vector<std::unique_ptr<frontend::LayerSnapshot>>& snapshots = |
| 9416 | mLayerSnapshotBuilder.getSnapshots(); |
| 9417 | for (auto [_, layerFE] : layers) { |
| 9418 | auto i = layerFE->mSnapshot->globalZ; |
| 9419 | snapshots[i] = std::move(layerFE->mSnapshot); |
| 9420 | } |
| 9421 | } |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 9422 | if (!mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9423 | for (auto [layer, layerFE] : layers) { |
| 9424 | layer->updateLayerSnapshot(std::move(layerFE->mSnapshot)); |
| 9425 | } |
| 9426 | } |
| 9427 | } |
| 9428 | |
| 9429 | std::vector<std::pair<Layer*, LayerFE*>> SurfaceFlinger::moveSnapshotsToCompositionArgs( |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 9430 | compositionengine::CompositionRefreshArgs& refreshArgs, bool cursorOnly) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9431 | std::vector<std::pair<Layer*, LayerFE*>> layers; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9432 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9433 | nsecs_t currentTime = systemTime(); |
Garfield Tan | ad34a68 | 2024-05-21 15:25:35 +0000 | [diff] [blame] | 9434 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 9435 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) FTL_FAKE_GUARD( |
| 9436 | kMainThreadContext) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9437 | if (cursorOnly && |
| 9438 | snapshot->compositionType != |
| 9439 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) { |
| 9440 | return; |
| 9441 | } |
| 9442 | |
| 9443 | if (!snapshot->hasSomethingToDraw()) { |
| 9444 | return; |
| 9445 | } |
| 9446 | |
| 9447 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 9448 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 9449 | "Couldnt find layer object for %s", |
| 9450 | snapshot->getDebugString().c_str()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9451 | auto& legacyLayer = it->second; |
| 9452 | sp<LayerFE> layerFE = legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9453 | snapshot->fps = getLayerFramerate(currentTime, snapshot->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9454 | layerFE->mSnapshot = std::move(snapshot); |
| 9455 | refreshArgs.layers.push_back(layerFE); |
| 9456 | layers.emplace_back(legacyLayer.get(), layerFE.get()); |
| 9457 | }); |
| 9458 | } |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 9459 | if (!mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 9460 | auto moveSnapshots = [&layers, &refreshArgs, cursorOnly](Layer* layer) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9461 | if (const auto& layerFE = layer->getCompositionEngineLayerFE()) { |
| 9462 | if (cursorOnly && |
| 9463 | layer->getLayerSnapshot()->compositionType != |
| 9464 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) |
| 9465 | return; |
| 9466 | layer->updateSnapshot(refreshArgs.updatingGeometryThisFrame); |
| 9467 | layerFE->mSnapshot = layer->stealLayerSnapshot(); |
| 9468 | refreshArgs.layers.push_back(layerFE); |
| 9469 | layers.emplace_back(layer, layerFE.get()); |
| 9470 | } |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 9471 | }; |
| 9472 | |
| 9473 | if (cursorOnly || !mVisibleRegionsDirty) { |
| 9474 | // for hot path avoid traversals by walking though the previous composition list |
| 9475 | for (sp<Layer> layer : mPreviouslyComposedLayers) { |
| 9476 | moveSnapshots(layer.get()); |
| 9477 | } |
| 9478 | } else { |
| 9479 | mPreviouslyComposedLayers.clear(); |
| 9480 | mDrawingState.traverseInZOrder( |
| 9481 | [&moveSnapshots](Layer* layer) { moveSnapshots(layer); }); |
| 9482 | mPreviouslyComposedLayers.reserve(layers.size()); |
| 9483 | for (auto [layer, _] : layers) { |
| 9484 | mPreviouslyComposedLayers.push_back(sp<Layer>::fromExisting(layer)); |
| 9485 | } |
| 9486 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9487 | } |
| 9488 | |
| 9489 | return layers; |
| 9490 | } |
| 9491 | |
| 9492 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9493 | SurfaceFlinger::getLayerSnapshotsForScreenshots( |
| 9494 | std::optional<ui::LayerStack> layerStack, uint32_t uid, |
| 9495 | std::function<bool(const frontend::LayerSnapshot&, bool& outStopTraversal)> |
| 9496 | snapshotFilterFn) { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 9497 | return [&, layerStack, uid]() FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9498 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers; |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9499 | bool stopTraversal = false; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9500 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 9501 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) FTL_FAKE_GUARD( |
| 9502 | kMainThreadContext) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9503 | if (stopTraversal) { |
| 9504 | return; |
| 9505 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9506 | if (layerStack && snapshot->outputFilter.layerStack != *layerStack) { |
| 9507 | return; |
| 9508 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 9509 | if (uid != CaptureArgs::UNSET_UID && snapshot->uid != gui::Uid(uid)) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9510 | return; |
| 9511 | } |
| 9512 | if (!snapshot->hasSomethingToDraw()) { |
| 9513 | return; |
| 9514 | } |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9515 | if (snapshotFilterFn && !snapshotFilterFn(*snapshot, stopTraversal)) { |
| 9516 | return; |
| 9517 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9518 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9519 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 9520 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 9521 | "Couldnt find layer object for %s", |
| 9522 | snapshot->getDebugString().c_str()); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9523 | Layer* legacyLayer = (it == mLegacyLayers.end()) ? nullptr : it->second.get(); |
Lloyd Pique | 70ddc67 | 2024-04-30 18:20:40 -0700 | [diff] [blame] | 9524 | sp<LayerFE> layerFE = getFactory().createLayerFE(snapshot->name, legacyLayer); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9525 | layerFE->mSnapshot = std::make_unique<frontend::LayerSnapshot>(*snapshot); |
| 9526 | layers.emplace_back(legacyLayer, std::move(layerFE)); |
| 9527 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9528 | |
| 9529 | return layers; |
| 9530 | }; |
| 9531 | } |
| 9532 | |
| 9533 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9534 | SurfaceFlinger::getLayerSnapshotsForScreenshots(std::optional<ui::LayerStack> layerStack, |
| 9535 | uint32_t uid, |
| 9536 | std::unordered_set<uint32_t> excludeLayerIds) { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 9537 | return [&, layerStack, uid, |
| 9538 | excludeLayerIds = std::move(excludeLayerIds)]() FTL_FAKE_GUARD(kMainThreadContext) { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9539 | if (excludeLayerIds.empty()) { |
| 9540 | auto getLayerSnapshotsFn = |
| 9541 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 9542 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9543 | return layers; |
| 9544 | } |
| 9545 | |
| 9546 | frontend::LayerSnapshotBuilder::Args |
| 9547 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 9548 | .layerLifecycleManager = mLayerLifecycleManager, |
| 9549 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
| 9550 | .displays = mFrontEndDisplayInfos, |
| 9551 | .displayChanges = true, |
| 9552 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9553 | .supportsBlur = mSupportsBlur, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9554 | .forceFullDamage = mForceFullDamage, |
| 9555 | .excludeLayerIds = std::move(excludeLayerIds), |
| 9556 | .supportedLayerGenericMetadata = |
| 9557 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 9558 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 9559 | .skipRoundCornersWhenProtected = |
| 9560 | !getRenderEngine().supportsProtectedContent()}; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9561 | mLayerSnapshotBuilder.update(args); |
| 9562 | |
| 9563 | auto getLayerSnapshotsFn = |
| 9564 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 9565 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9566 | |
| 9567 | args.excludeLayerIds.clear(); |
| 9568 | mLayerSnapshotBuilder.update(args); |
| 9569 | |
| 9570 | return layers; |
| 9571 | }; |
| 9572 | } |
| 9573 | |
| 9574 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9575 | SurfaceFlinger::getLayerSnapshotsForScreenshots(uint32_t rootLayerId, uint32_t uid, |
| 9576 | std::unordered_set<uint32_t> excludeLayerIds, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 9577 | bool childrenOnly, |
| 9578 | const std::optional<FloatRect>& parentCrop) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9579 | return [&, rootLayerId, uid, excludeLayerIds = std::move(excludeLayerIds), childrenOnly, |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 9580 | parentCrop]() FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9581 | auto root = mLayerHierarchyBuilder.getPartialHierarchy(rootLayerId, childrenOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9582 | frontend::LayerSnapshotBuilder::Args |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9583 | args{.root = root, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9584 | .layerLifecycleManager = mLayerLifecycleManager, |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9585 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9586 | .displays = mFrontEndDisplayInfos, |
| 9587 | .displayChanges = true, |
| 9588 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9589 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9590 | .forceFullDamage = mForceFullDamage, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 9591 | .parentCrop = parentCrop, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9592 | .excludeLayerIds = std::move(excludeLayerIds), |
| 9593 | .supportedLayerGenericMetadata = |
| 9594 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 9595 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 9596 | .skipRoundCornersWhenProtected = |
| 9597 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | c54fdb0 | 2023-11-21 17:19:58 -0800 | [diff] [blame] | 9598 | // The layer may not exist if it was just created and a screenshot was requested immediately |
| 9599 | // after. In this case, the hierarchy will be empty so we will not render any layers. |
| 9600 | args.rootSnapshot.isSecure = mLayerLifecycleManager.getLayerFromId(rootLayerId) && |
| 9601 | mLayerLifecycleManager.isLayerSecure(rootLayerId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9602 | mLayerSnapshotBuilder.update(args); |
| 9603 | |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9604 | auto getLayerSnapshotsFn = |
| 9605 | getLayerSnapshotsForScreenshots({}, uid, /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9606 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9607 | args.root = mLayerHierarchyBuilder.getHierarchy(); |
| 9608 | args.parentCrop.reset(); |
| 9609 | args.excludeLayerIds.clear(); |
| 9610 | mLayerSnapshotBuilder.update(args); |
| 9611 | return layers; |
| 9612 | }; |
| 9613 | } |
| 9614 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9615 | frontend::Update SurfaceFlinger::flushLifecycleUpdates() { |
| 9616 | frontend::Update update; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9617 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 9618 | // Locking: |
| 9619 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 9620 | // we must keep a copy of the transactions (specifically the composer |
| 9621 | // states) around outside the scope of the lock. |
| 9622 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 9623 | // transactions with layers still in the createdLayer queue, flush the transactions |
| 9624 | // before committing the created layers. |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 9625 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9626 | update.transactions = mTransactionHandler.flushTransactions(); |
| 9627 | { |
| 9628 | // TODO(b/238781169) lockless queue this and keep order. |
| 9629 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 9630 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 9631 | mCreatedLayers.clear(); |
| 9632 | update.newLayers = std::move(mNewLayers); |
| 9633 | mNewLayers.clear(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9634 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 9635 | mNewLayerArgs.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9636 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 9637 | mDestroyedHandles.clear(); |
| 9638 | } |
| 9639 | return update; |
| 9640 | } |
| 9641 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9642 | void SurfaceFlinger::doActiveLayersTracingIfNeeded(bool isCompositionComputed, |
| 9643 | bool visibleRegionDirty, TimePoint time, |
| 9644 | VsyncId vsyncId) { |
| 9645 | if (!mLayerTracing.isActiveTracingStarted()) { |
| 9646 | return; |
| 9647 | } |
| 9648 | if (isCompositionComputed != |
| 9649 | mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_COMPOSITION)) { |
| 9650 | return; |
| 9651 | } |
| 9652 | if (!visibleRegionDirty && |
| 9653 | !mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_BUFFERS)) { |
| 9654 | return; |
| 9655 | } |
| 9656 | auto snapshot = takeLayersSnapshotProto(mLayerTracing.getActiveTracingFlags(), time, vsyncId, |
| 9657 | visibleRegionDirty); |
| 9658 | mLayerTracing.addProtoSnapshotToOstream(std::move(snapshot), LayerTracing::Mode::MODE_ACTIVE); |
| 9659 | } |
| 9660 | |
| 9661 | perfetto::protos::LayersSnapshotProto SurfaceFlinger::takeLayersSnapshotProto( |
| 9662 | uint32_t traceFlags, TimePoint time, VsyncId vsyncId, bool visibleRegionDirty) { |
| 9663 | ATRACE_CALL(); |
| 9664 | perfetto::protos::LayersSnapshotProto snapshot; |
| 9665 | snapshot.set_elapsed_realtime_nanos(time.ns()); |
| 9666 | snapshot.set_vsync_id(ftl::to_underlying(vsyncId)); |
| 9667 | snapshot.set_where(visibleRegionDirty ? "visibleRegionsDirty" : "bufferLatched"); |
| 9668 | snapshot.set_excludes_composition_state((traceFlags & LayerTracing::Flag::TRACE_COMPOSITION) == |
| 9669 | 0); |
| 9670 | |
| 9671 | auto layers = dumpDrawingStateProto(traceFlags); |
| 9672 | if (traceFlags & LayerTracing::Flag::TRACE_EXTRA) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9673 | dumpOffscreenLayersProto(layers); |
| 9674 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9675 | *snapshot.mutable_layers() = std::move(layers); |
| 9676 | |
| 9677 | if (traceFlags & LayerTracing::Flag::TRACE_HWC) { |
| 9678 | std::string hwcDump; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9679 | dumpHwc(hwcDump); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9680 | snapshot.set_hwc_blob(std::move(hwcDump)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9681 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9682 | |
| 9683 | *snapshot.mutable_displays() = dumpDisplayProto(); |
| 9684 | |
| 9685 | return snapshot; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9686 | } |
| 9687 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 9688 | // sfdo functions |
| 9689 | |
| 9690 | void SurfaceFlinger::sfdo_enableRefreshRateOverlay(bool active) { |
| 9691 | auto future = mScheduler->schedule( |
| 9692 | [&]() FTL_FAKE_GUARD(mStateLock) |
| 9693 | FTL_FAKE_GUARD(kMainThreadContext) { enableRefreshRateOverlay(active); }); |
| 9694 | future.wait(); |
| 9695 | } |
| 9696 | |
| 9697 | void SurfaceFlinger::sfdo_setDebugFlash(int delay) { |
| 9698 | if (delay > 0) { |
| 9699 | mDebugFlashDelay = delay; |
| 9700 | } else { |
| 9701 | mDebugFlashDelay = mDebugFlashDelay ? 0 : 1; |
| 9702 | } |
| 9703 | scheduleRepaint(); |
| 9704 | } |
| 9705 | |
| 9706 | void SurfaceFlinger::sfdo_scheduleComposite() { |
| 9707 | scheduleComposite(SurfaceFlinger::FrameHint::kActive); |
| 9708 | } |
| 9709 | |
| 9710 | void SurfaceFlinger::sfdo_scheduleCommit() { |
| 9711 | Mutex::Autolock lock(mStateLock); |
| 9712 | setTransactionFlags(eTransactionNeeded | eDisplayTransactionNeeded | eTraversalNeeded); |
| 9713 | } |
| 9714 | |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 9715 | void SurfaceFlinger::sfdo_forceClientComposition(bool enabled) { |
| 9716 | mDebugDisableHWC = enabled; |
| 9717 | scheduleRepaint(); |
| 9718 | } |
| 9719 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9720 | // gui::ISurfaceComposer |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9721 | |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9722 | binder::Status SurfaceComposerAIDL::bootFinished() { |
| 9723 | status_t status = checkAccessPermission(); |
| 9724 | if (status != OK) { |
| 9725 | return binderStatusFromStatusT(status); |
| 9726 | } |
| 9727 | mFlinger->bootFinished(); |
| 9728 | return binder::Status::ok(); |
| 9729 | } |
| 9730 | |
| 9731 | binder::Status SurfaceComposerAIDL::createDisplayEventConnection( |
| 9732 | VsyncSource vsyncSource, EventRegistration eventRegistration, |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 9733 | const sp<IBinder>& layerHandle, sp<IDisplayEventConnection>* outConnection) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9734 | sp<IDisplayEventConnection> conn = |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 9735 | mFlinger->createDisplayEventConnection(vsyncSource, eventRegistration, layerHandle); |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9736 | if (conn == nullptr) { |
| 9737 | *outConnection = nullptr; |
| 9738 | return binderStatusFromStatusT(BAD_VALUE); |
| 9739 | } else { |
| 9740 | *outConnection = conn; |
| 9741 | return binder::Status::ok(); |
| 9742 | } |
| 9743 | } |
| 9744 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9745 | binder::Status SurfaceComposerAIDL::createConnection(sp<gui::ISurfaceComposerClient>* outClient) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 9746 | const sp<Client> client = sp<Client>::make(mFlinger); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9747 | if (client->initCheck() == NO_ERROR) { |
| 9748 | *outClient = client; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 9749 | if (FlagManager::getInstance().misc1()) { |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 9750 | const int policy = SCHED_FIFO; |
| 9751 | client->setMinSchedulerPolicy(policy, sched_get_priority_min(policy)); |
| 9752 | } |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9753 | return binder::Status::ok(); |
| 9754 | } else { |
| 9755 | *outClient = nullptr; |
| 9756 | return binderStatusFromStatusT(BAD_VALUE); |
| 9757 | } |
| 9758 | } |
| 9759 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 9760 | binder::Status SurfaceComposerAIDL::createVirtualDisplay(const std::string& displayName, |
| 9761 | bool isSecure, const std::string& uniqueId, |
| 9762 | float requestedRefreshRate, |
| 9763 | sp<IBinder>* outDisplay) { |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9764 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9765 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9766 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9767 | } |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 9768 | *outDisplay = |
| 9769 | mFlinger->createVirtualDisplay(displayName, isSecure, uniqueId, requestedRefreshRate); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9770 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9771 | } |
| 9772 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 9773 | binder::Status SurfaceComposerAIDL::destroyVirtualDisplay(const sp<IBinder>& displayToken) { |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9774 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9775 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9776 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9777 | } |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 9778 | return binder::Status::fromStatusT(mFlinger->destroyVirtualDisplay(displayToken)); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9779 | } |
| 9780 | |
| 9781 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) { |
| 9782 | std::vector<PhysicalDisplayId> physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); |
| 9783 | std::vector<int64_t> displayIds; |
| 9784 | displayIds.reserve(physicalDisplayIds.size()); |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 9785 | for (const auto id : physicalDisplayIds) { |
| 9786 | displayIds.push_back(static_cast<int64_t>(id.value)); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9787 | } |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 9788 | *outDisplayIds = std::move(displayIds); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9789 | return binder::Status::ok(); |
| 9790 | } |
| 9791 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9792 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, |
| 9793 | sp<IBinder>* outDisplay) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9794 | status_t status = checkAccessPermission(); |
| 9795 | if (status != OK) { |
| 9796 | return binderStatusFromStatusT(status); |
| 9797 | } |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9798 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 9799 | *outDisplay = mFlinger->getPhysicalDisplayToken(*id); |
| 9800 | return binder::Status::ok(); |
| 9801 | } |
| 9802 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9803 | binder::Status SurfaceComposerAIDL::setPowerMode(const sp<IBinder>& display, int mode) { |
| 9804 | status_t status = checkAccessPermission(); |
| 9805 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9806 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9807 | } |
| 9808 | mFlinger->setPowerMode(display, mode); |
| 9809 | return binder::Status::ok(); |
| 9810 | } |
| 9811 | |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 9812 | binder::Status SurfaceComposerAIDL::getSupportedFrameTimestamps( |
| 9813 | std::vector<FrameEvent>* outSupported) { |
| 9814 | status_t status; |
| 9815 | if (!outSupported) { |
| 9816 | status = UNEXPECTED_NULL; |
| 9817 | } else { |
| 9818 | outSupported->clear(); |
| 9819 | status = mFlinger->getSupportedFrameTimestamps(outSupported); |
| 9820 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9821 | return binderStatusFromStatusT(status); |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 9822 | } |
| 9823 | |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9824 | binder::Status SurfaceComposerAIDL::getDisplayStats(const sp<IBinder>& display, |
| 9825 | gui::DisplayStatInfo* outStatInfo) { |
| 9826 | DisplayStatInfo statInfo; |
| 9827 | status_t status = mFlinger->getDisplayStats(display, &statInfo); |
| 9828 | if (status == NO_ERROR) { |
| 9829 | outStatInfo->vsyncTime = static_cast<long>(statInfo.vsyncTime); |
| 9830 | outStatInfo->vsyncPeriod = static_cast<long>(statInfo.vsyncPeriod); |
| 9831 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9832 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9833 | } |
| 9834 | |
| 9835 | binder::Status SurfaceComposerAIDL::getDisplayState(const sp<IBinder>& display, |
| 9836 | gui::DisplayState* outState) { |
| 9837 | ui::DisplayState state; |
| 9838 | status_t status = mFlinger->getDisplayState(display, &state); |
| 9839 | if (status == NO_ERROR) { |
| 9840 | outState->layerStack = state.layerStack.id; |
| 9841 | outState->orientation = static_cast<gui::Rotation>(state.orientation); |
| 9842 | outState->layerStackSpaceRect.width = state.layerStackSpaceRect.width; |
| 9843 | outState->layerStackSpaceRect.height = state.layerStackSpaceRect.height; |
| 9844 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9845 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9846 | } |
| 9847 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9848 | binder::Status SurfaceComposerAIDL::getStaticDisplayInfo(int64_t displayId, |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9849 | gui::StaticDisplayInfo* outInfo) { |
| 9850 | using Tag = gui::DeviceProductInfo::ManufactureOrModelDate::Tag; |
| 9851 | ui::StaticDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9852 | |
| 9853 | status_t status = mFlinger->getStaticDisplayInfo(displayId, &info); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9854 | if (status == NO_ERROR) { |
| 9855 | // convert ui::StaticDisplayInfo to gui::StaticDisplayInfo |
| 9856 | outInfo->connectionType = static_cast<gui::DisplayConnectionType>(info.connectionType); |
| 9857 | outInfo->density = info.density; |
| 9858 | outInfo->secure = info.secure; |
| 9859 | outInfo->installOrientation = static_cast<gui::Rotation>(info.installOrientation); |
| 9860 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9861 | if (const std::optional<DeviceProductInfo> dpi = info.deviceProductInfo) { |
| 9862 | gui::DeviceProductInfo dinfo; |
| 9863 | dinfo.name = std::move(dpi->name); |
| 9864 | dinfo.manufacturerPnpId = std::vector<uint8_t>(dpi->manufacturerPnpId.begin(), |
| 9865 | dpi->manufacturerPnpId.end()); |
| 9866 | dinfo.productId = dpi->productId; |
| 9867 | dinfo.relativeAddress = |
| 9868 | std::vector<uint8_t>(dpi->relativeAddress.begin(), dpi->relativeAddress.end()); |
| 9869 | if (const auto* model = |
| 9870 | std::get_if<DeviceProductInfo::ModelYear>(&dpi->manufactureOrModelDate)) { |
| 9871 | gui::DeviceProductInfo::ModelYear modelYear; |
| 9872 | modelYear.year = model->year; |
| 9873 | dinfo.manufactureOrModelDate.set<Tag::modelYear>(modelYear); |
| 9874 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureYear>( |
| 9875 | &dpi->manufactureOrModelDate)) { |
| 9876 | gui::DeviceProductInfo::ManufactureYear date; |
| 9877 | date.modelYear.year = manufacture->year; |
| 9878 | dinfo.manufactureOrModelDate.set<Tag::manufactureYear>(date); |
| 9879 | } else if (const auto* manufacture = |
| 9880 | std::get_if<DeviceProductInfo::ManufactureWeekAndYear>( |
| 9881 | &dpi->manufactureOrModelDate)) { |
| 9882 | gui::DeviceProductInfo::ManufactureWeekAndYear date; |
| 9883 | date.manufactureYear.modelYear.year = manufacture->year; |
| 9884 | date.week = manufacture->week; |
| 9885 | dinfo.manufactureOrModelDate.set<Tag::manufactureWeekAndYear>(date); |
| 9886 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9887 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9888 | outInfo->deviceProductInfo = dinfo; |
| 9889 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9890 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9891 | return binderStatusFromStatusT(status); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9892 | } |
| 9893 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9894 | void SurfaceComposerAIDL::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo& info, |
| 9895 | gui::DynamicDisplayInfo*& outInfo) { |
| 9896 | // convert ui::DynamicDisplayInfo to gui::DynamicDisplayInfo |
| 9897 | outInfo->supportedDisplayModes.clear(); |
| 9898 | outInfo->supportedDisplayModes.reserve(info.supportedDisplayModes.size()); |
| 9899 | for (const auto& mode : info.supportedDisplayModes) { |
| 9900 | gui::DisplayMode outMode; |
| 9901 | outMode.id = mode.id; |
| 9902 | outMode.resolution.width = mode.resolution.width; |
| 9903 | outMode.resolution.height = mode.resolution.height; |
| 9904 | outMode.xDpi = mode.xDpi; |
| 9905 | outMode.yDpi = mode.yDpi; |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 9906 | outMode.peakRefreshRate = mode.peakRefreshRate; |
Alec Mouri | d122a1c | 2023-09-30 01:36:33 +0000 | [diff] [blame] | 9907 | outMode.vsyncRate = mode.vsyncRate; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9908 | outMode.appVsyncOffset = mode.appVsyncOffset; |
| 9909 | outMode.sfVsyncOffset = mode.sfVsyncOffset; |
| 9910 | outMode.presentationDeadline = mode.presentationDeadline; |
| 9911 | outMode.group = mode.group; |
| 9912 | std::transform(mode.supportedHdrTypes.begin(), mode.supportedHdrTypes.end(), |
| 9913 | std::back_inserter(outMode.supportedHdrTypes), |
| 9914 | [](const ui::Hdr& value) { return static_cast<int32_t>(value); }); |
| 9915 | outInfo->supportedDisplayModes.push_back(outMode); |
| 9916 | } |
| 9917 | |
| 9918 | outInfo->activeDisplayModeId = info.activeDisplayModeId; |
| 9919 | outInfo->renderFrameRate = info.renderFrameRate; |
| 9920 | |
| 9921 | outInfo->supportedColorModes.clear(); |
| 9922 | outInfo->supportedColorModes.reserve(info.supportedColorModes.size()); |
| 9923 | for (const auto& cmode : info.supportedColorModes) { |
| 9924 | outInfo->supportedColorModes.push_back(static_cast<int32_t>(cmode)); |
| 9925 | } |
| 9926 | |
| 9927 | outInfo->activeColorMode = static_cast<int32_t>(info.activeColorMode); |
| 9928 | |
| 9929 | gui::HdrCapabilities& hdrCapabilities = outInfo->hdrCapabilities; |
| 9930 | hdrCapabilities.supportedHdrTypes.clear(); |
| 9931 | hdrCapabilities.supportedHdrTypes.reserve(info.hdrCapabilities.getSupportedHdrTypes().size()); |
| 9932 | for (const auto& hdr : info.hdrCapabilities.getSupportedHdrTypes()) { |
| 9933 | hdrCapabilities.supportedHdrTypes.push_back(static_cast<int32_t>(hdr)); |
| 9934 | } |
| 9935 | hdrCapabilities.maxLuminance = info.hdrCapabilities.getDesiredMaxLuminance(); |
| 9936 | hdrCapabilities.maxAverageLuminance = info.hdrCapabilities.getDesiredMaxAverageLuminance(); |
| 9937 | hdrCapabilities.minLuminance = info.hdrCapabilities.getDesiredMinLuminance(); |
| 9938 | |
| 9939 | outInfo->autoLowLatencyModeSupported = info.autoLowLatencyModeSupported; |
| 9940 | outInfo->gameContentTypeSupported = info.gameContentTypeSupported; |
| 9941 | outInfo->preferredBootDisplayMode = info.preferredBootDisplayMode; |
| 9942 | } |
| 9943 | |
| 9944 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromToken( |
| 9945 | const sp<IBinder>& display, gui::DynamicDisplayInfo* outInfo) { |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9946 | ui::DynamicDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9947 | status_t status = mFlinger->getDynamicDisplayInfoFromToken(display, &info); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9948 | if (status == NO_ERROR) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9949 | getDynamicDisplayInfoInternal(info, outInfo); |
| 9950 | } |
| 9951 | return binderStatusFromStatusT(status); |
| 9952 | } |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 9953 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9954 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromId(int64_t displayId, |
| 9955 | gui::DynamicDisplayInfo* outInfo) { |
| 9956 | ui::DynamicDisplayInfo info; |
| 9957 | status_t status = mFlinger->getDynamicDisplayInfoFromId(displayId, &info); |
| 9958 | if (status == NO_ERROR) { |
| 9959 | getDynamicDisplayInfoInternal(info, outInfo); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9960 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9961 | return binderStatusFromStatusT(status); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9962 | } |
| 9963 | |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9964 | binder::Status SurfaceComposerAIDL::getDisplayNativePrimaries(const sp<IBinder>& display, |
| 9965 | gui::DisplayPrimaries* outPrimaries) { |
| 9966 | ui::DisplayPrimaries primaries; |
| 9967 | status_t status = mFlinger->getDisplayNativePrimaries(display, primaries); |
| 9968 | if (status == NO_ERROR) { |
| 9969 | outPrimaries->red.X = primaries.red.X; |
| 9970 | outPrimaries->red.Y = primaries.red.Y; |
| 9971 | outPrimaries->red.Z = primaries.red.Z; |
| 9972 | |
| 9973 | outPrimaries->green.X = primaries.green.X; |
| 9974 | outPrimaries->green.Y = primaries.green.Y; |
| 9975 | outPrimaries->green.Z = primaries.green.Z; |
| 9976 | |
| 9977 | outPrimaries->blue.X = primaries.blue.X; |
| 9978 | outPrimaries->blue.Y = primaries.blue.Y; |
| 9979 | outPrimaries->blue.Z = primaries.blue.Z; |
| 9980 | |
| 9981 | outPrimaries->white.X = primaries.white.X; |
| 9982 | outPrimaries->white.Y = primaries.white.Y; |
| 9983 | outPrimaries->white.Z = primaries.white.Z; |
| 9984 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9985 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9986 | } |
| 9987 | |
| 9988 | binder::Status SurfaceComposerAIDL::setActiveColorMode(const sp<IBinder>& display, int colorMode) { |
| 9989 | status_t status = checkAccessPermission(); |
| 9990 | if (status == OK) { |
| 9991 | status = mFlinger->setActiveColorMode(display, static_cast<ui::ColorMode>(colorMode)); |
| 9992 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9993 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9994 | } |
| 9995 | |
| 9996 | binder::Status SurfaceComposerAIDL::setBootDisplayMode(const sp<IBinder>& display, |
| 9997 | int displayModeId) { |
| 9998 | status_t status = checkAccessPermission(); |
| 9999 | if (status == OK) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 10000 | status = mFlinger->setBootDisplayMode(display, DisplayModeId{displayModeId}); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 10001 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10002 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 10003 | } |
| 10004 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10005 | binder::Status SurfaceComposerAIDL::clearBootDisplayMode(const sp<IBinder>& display) { |
| 10006 | status_t status = checkAccessPermission(); |
| 10007 | if (status == OK) { |
| 10008 | status = mFlinger->clearBootDisplayMode(display); |
| 10009 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10010 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10011 | } |
| 10012 | |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 10013 | binder::Status SurfaceComposerAIDL::getOverlaySupport(gui::OverlayProperties* outProperties) { |
| 10014 | status_t status = checkAccessPermission(); |
| 10015 | if (status == OK) { |
| 10016 | status = mFlinger->getOverlaySupport(outProperties); |
| 10017 | } |
| 10018 | return binderStatusFromStatusT(status); |
| 10019 | } |
| 10020 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10021 | binder::Status SurfaceComposerAIDL::getBootDisplayModeSupport(bool* outMode) { |
| 10022 | status_t status = checkAccessPermission(); |
| 10023 | if (status == OK) { |
| 10024 | status = mFlinger->getBootDisplayModeSupport(outMode); |
| 10025 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10026 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10027 | } |
| 10028 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 10029 | binder::Status SurfaceComposerAIDL::getHdrConversionCapabilities( |
| 10030 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) { |
| 10031 | status_t status = checkAccessPermission(); |
| 10032 | if (status == OK) { |
| 10033 | status = mFlinger->getHdrConversionCapabilities(hdrConversionCapabilities); |
| 10034 | } |
| 10035 | return binderStatusFromStatusT(status); |
| 10036 | } |
| 10037 | |
| 10038 | binder::Status SurfaceComposerAIDL::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 10039 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 10040 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 10041 | status_t status = checkAccessPermission(); |
| 10042 | if (status == OK) { |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 10043 | status = mFlinger->setHdrConversionStrategy(hdrConversionStrategy, |
| 10044 | outPreferredHdrOutputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 10045 | } |
| 10046 | return binderStatusFromStatusT(status); |
| 10047 | } |
| 10048 | |
| 10049 | binder::Status SurfaceComposerAIDL::getHdrOutputConversionSupport(bool* outMode) { |
| 10050 | status_t status = checkAccessPermission(); |
| 10051 | if (status == OK) { |
| 10052 | status = mFlinger->getHdrOutputConversionSupport(outMode); |
| 10053 | } |
| 10054 | return binderStatusFromStatusT(status); |
| 10055 | } |
| 10056 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10057 | binder::Status SurfaceComposerAIDL::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) { |
| 10058 | status_t status = checkAccessPermission(); |
| 10059 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10060 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10061 | } |
| 10062 | mFlinger->setAutoLowLatencyMode(display, on); |
| 10063 | return binder::Status::ok(); |
| 10064 | } |
| 10065 | |
| 10066 | binder::Status SurfaceComposerAIDL::setGameContentType(const sp<IBinder>& display, bool on) { |
| 10067 | status_t status = checkAccessPermission(); |
| 10068 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10069 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10070 | } |
| 10071 | mFlinger->setGameContentType(display, on); |
| 10072 | return binder::Status::ok(); |
| 10073 | } |
| 10074 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 10075 | binder::Status SurfaceComposerAIDL::captureDisplay( |
| 10076 | const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 10077 | mFlinger->captureDisplay(args, captureListener); |
| 10078 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 10079 | } |
| 10080 | |
| 10081 | binder::Status SurfaceComposerAIDL::captureDisplayById( |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 10082 | int64_t displayId, const CaptureArgs& args, |
| 10083 | const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 10084 | // status_t status; |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 10085 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10086 | const int uid = ipc->getCallingUid(); |
| 10087 | if (uid == AID_ROOT || uid == AID_GRAPHICS || uid == AID_SYSTEM || uid == AID_SHELL) { |
| 10088 | std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId)); |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 10089 | mFlinger->captureDisplay(*id, args, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 10090 | } else { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 10091 | ALOGD("Permission denied to captureDisplayById"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 10092 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 10093 | } |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 10094 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 10095 | } |
| 10096 | |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 10097 | binder::Status SurfaceComposerAIDL::captureLayersSync(const LayerCaptureArgs& args, |
| 10098 | ScreenCaptureResults* outResults) { |
| 10099 | *outResults = mFlinger->captureLayersSync(args); |
| 10100 | return binderStatusFromStatusT(NO_ERROR); |
| 10101 | } |
| 10102 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 10103 | binder::Status SurfaceComposerAIDL::captureLayers( |
| 10104 | const LayerCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 10105 | mFlinger->captureLayers(args, captureListener); |
| 10106 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 10107 | } |
| 10108 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 10109 | binder::Status SurfaceComposerAIDL::overrideHdrTypes(const sp<IBinder>& display, |
| 10110 | const std::vector<int32_t>& hdrTypes) { |
| 10111 | // overrideHdrTypes is used by CTS tests, which acquire the necessary |
| 10112 | // permission dynamically. Don't use the permission cache for this check. |
| 10113 | status_t status = checkAccessPermission(false); |
| 10114 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10115 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 10116 | } |
| 10117 | |
| 10118 | std::vector<ui::Hdr> hdrTypesVector; |
| 10119 | for (int32_t i : hdrTypes) { |
| 10120 | hdrTypesVector.push_back(static_cast<ui::Hdr>(i)); |
| 10121 | } |
| 10122 | status = mFlinger->overrideHdrTypes(display, hdrTypesVector); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10123 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 10124 | } |
| 10125 | |
| 10126 | binder::Status SurfaceComposerAIDL::onPullAtom(int32_t atomId, gui::PullAtomData* outPullData) { |
| 10127 | status_t status; |
| 10128 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 10129 | if (uid != AID_SYSTEM) { |
| 10130 | status = PERMISSION_DENIED; |
| 10131 | } else { |
| 10132 | status = mFlinger->onPullAtom(atomId, &outPullData->data, &outPullData->success); |
| 10133 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10134 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 10135 | } |
| 10136 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 10137 | binder::Status SurfaceComposerAIDL::getCompositionPreference(gui::CompositionPreference* outPref) { |
| 10138 | ui::Dataspace dataspace; |
| 10139 | ui::PixelFormat pixelFormat; |
| 10140 | ui::Dataspace wideColorGamutDataspace; |
| 10141 | ui::PixelFormat wideColorGamutPixelFormat; |
| 10142 | status_t status = |
| 10143 | mFlinger->getCompositionPreference(&dataspace, &pixelFormat, &wideColorGamutDataspace, |
| 10144 | &wideColorGamutPixelFormat); |
| 10145 | if (status == NO_ERROR) { |
| 10146 | outPref->defaultDataspace = static_cast<int32_t>(dataspace); |
| 10147 | outPref->defaultPixelFormat = static_cast<int32_t>(pixelFormat); |
| 10148 | outPref->wideColorGamutDataspace = static_cast<int32_t>(wideColorGamutDataspace); |
| 10149 | outPref->wideColorGamutPixelFormat = static_cast<int32_t>(wideColorGamutPixelFormat); |
| 10150 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10151 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 10152 | } |
| 10153 | |
| 10154 | binder::Status SurfaceComposerAIDL::getDisplayedContentSamplingAttributes( |
| 10155 | const sp<IBinder>& display, gui::ContentSamplingAttributes* outAttrs) { |
| 10156 | status_t status = checkAccessPermission(); |
| 10157 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10158 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 10159 | } |
| 10160 | |
| 10161 | ui::PixelFormat format; |
| 10162 | ui::Dataspace dataspace; |
| 10163 | uint8_t componentMask; |
| 10164 | status = mFlinger->getDisplayedContentSamplingAttributes(display, &format, &dataspace, |
| 10165 | &componentMask); |
| 10166 | if (status == NO_ERROR) { |
| 10167 | outAttrs->format = static_cast<int32_t>(format); |
| 10168 | outAttrs->dataspace = static_cast<int32_t>(dataspace); |
| 10169 | outAttrs->componentMask = static_cast<int8_t>(componentMask); |
| 10170 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10171 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 10172 | } |
| 10173 | |
| 10174 | binder::Status SurfaceComposerAIDL::setDisplayContentSamplingEnabled(const sp<IBinder>& display, |
| 10175 | bool enable, |
| 10176 | int8_t componentMask, |
| 10177 | int64_t maxFrames) { |
| 10178 | status_t status = checkAccessPermission(); |
| 10179 | if (status == OK) { |
| 10180 | status = mFlinger->setDisplayContentSamplingEnabled(display, enable, |
| 10181 | static_cast<uint8_t>(componentMask), |
| 10182 | static_cast<uint64_t>(maxFrames)); |
| 10183 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10184 | return binderStatusFromStatusT(status); |
| 10185 | } |
| 10186 | |
| 10187 | binder::Status SurfaceComposerAIDL::getDisplayedContentSample(const sp<IBinder>& display, |
| 10188 | int64_t maxFrames, int64_t timestamp, |
| 10189 | gui::DisplayedFrameStats* outStats) { |
| 10190 | if (!outStats) { |
| 10191 | return binderStatusFromStatusT(BAD_VALUE); |
| 10192 | } |
| 10193 | |
| 10194 | status_t status = checkAccessPermission(); |
| 10195 | if (status != OK) { |
| 10196 | return binderStatusFromStatusT(status); |
| 10197 | } |
| 10198 | |
| 10199 | DisplayedFrameStats stats; |
| 10200 | status = mFlinger->getDisplayedContentSample(display, static_cast<uint64_t>(maxFrames), |
| 10201 | static_cast<uint64_t>(timestamp), &stats); |
| 10202 | if (status == NO_ERROR) { |
| 10203 | // convert from ui::DisplayedFrameStats to gui::DisplayedFrameStats |
| 10204 | outStats->numFrames = static_cast<int64_t>(stats.numFrames); |
| 10205 | outStats->component_0_sample.reserve(stats.component_0_sample.size()); |
| 10206 | for (const auto& s : stats.component_0_sample) { |
| 10207 | outStats->component_0_sample.push_back(static_cast<int64_t>(s)); |
| 10208 | } |
| 10209 | outStats->component_1_sample.reserve(stats.component_1_sample.size()); |
| 10210 | for (const auto& s : stats.component_1_sample) { |
| 10211 | outStats->component_1_sample.push_back(static_cast<int64_t>(s)); |
| 10212 | } |
| 10213 | outStats->component_2_sample.reserve(stats.component_2_sample.size()); |
| 10214 | for (const auto& s : stats.component_2_sample) { |
| 10215 | outStats->component_2_sample.push_back(static_cast<int64_t>(s)); |
| 10216 | } |
| 10217 | outStats->component_3_sample.reserve(stats.component_3_sample.size()); |
| 10218 | for (const auto& s : stats.component_3_sample) { |
| 10219 | outStats->component_3_sample.push_back(static_cast<int64_t>(s)); |
| 10220 | } |
| 10221 | } |
| 10222 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 10223 | } |
| 10224 | |
| 10225 | binder::Status SurfaceComposerAIDL::getProtectedContentSupport(bool* outSupported) { |
| 10226 | status_t status = mFlinger->getProtectedContentSupport(outSupported); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10227 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 10228 | } |
| 10229 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10230 | binder::Status SurfaceComposerAIDL::isWideColorDisplay(const sp<IBinder>& token, |
| 10231 | bool* outIsWideColorDisplay) { |
| 10232 | status_t status = mFlinger->isWideColorDisplay(token, outIsWideColorDisplay); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10233 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10234 | } |
| 10235 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10236 | binder::Status SurfaceComposerAIDL::addRegionSamplingListener( |
| 10237 | const gui::ARect& samplingArea, const sp<IBinder>& stopLayerHandle, |
| 10238 | const sp<gui::IRegionSamplingListener>& listener) { |
| 10239 | status_t status = checkReadFrameBufferPermission(); |
| 10240 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10241 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10242 | } |
| 10243 | android::Rect rect; |
| 10244 | rect.left = samplingArea.left; |
| 10245 | rect.top = samplingArea.top; |
| 10246 | rect.right = samplingArea.right; |
| 10247 | rect.bottom = samplingArea.bottom; |
| 10248 | status = mFlinger->addRegionSamplingListener(rect, stopLayerHandle, listener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10249 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10250 | } |
| 10251 | |
| 10252 | binder::Status SurfaceComposerAIDL::removeRegionSamplingListener( |
| 10253 | const sp<gui::IRegionSamplingListener>& listener) { |
| 10254 | status_t status = checkReadFrameBufferPermission(); |
| 10255 | if (status == OK) { |
| 10256 | status = mFlinger->removeRegionSamplingListener(listener); |
| 10257 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10258 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10259 | } |
| 10260 | |
| 10261 | binder::Status SurfaceComposerAIDL::addFpsListener(int32_t taskId, |
| 10262 | const sp<gui::IFpsListener>& listener) { |
| 10263 | status_t status = checkReadFrameBufferPermission(); |
| 10264 | if (status == OK) { |
| 10265 | status = mFlinger->addFpsListener(taskId, listener); |
| 10266 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10267 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10268 | } |
| 10269 | |
| 10270 | binder::Status SurfaceComposerAIDL::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 10271 | status_t status = checkReadFrameBufferPermission(); |
| 10272 | if (status == OK) { |
| 10273 | status = mFlinger->removeFpsListener(listener); |
| 10274 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10275 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10276 | } |
| 10277 | |
| 10278 | binder::Status SurfaceComposerAIDL::addTunnelModeEnabledListener( |
| 10279 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 10280 | status_t status = checkAccessPermission(); |
| 10281 | if (status == OK) { |
| 10282 | status = mFlinger->addTunnelModeEnabledListener(listener); |
| 10283 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10284 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10285 | } |
| 10286 | |
| 10287 | binder::Status SurfaceComposerAIDL::removeTunnelModeEnabledListener( |
| 10288 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 10289 | status_t status = checkAccessPermission(); |
| 10290 | if (status == OK) { |
| 10291 | status = mFlinger->removeTunnelModeEnabledListener(listener); |
| 10292 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10293 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10294 | } |
| 10295 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 10296 | binder::Status SurfaceComposerAIDL::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 10297 | const gui::DisplayModeSpecs& specs) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10298 | status_t status = checkAccessPermission(); |
| 10299 | if (status == OK) { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 10300 | status = mFlinger->setDesiredDisplayModeSpecs(displayToken, specs); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10301 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10302 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10303 | } |
| 10304 | |
| 10305 | binder::Status SurfaceComposerAIDL::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 10306 | gui::DisplayModeSpecs* outSpecs) { |
| 10307 | if (!outSpecs) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10308 | return binderStatusFromStatusT(BAD_VALUE); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10309 | } |
| 10310 | |
| 10311 | status_t status = checkAccessPermission(); |
| 10312 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10313 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10314 | } |
| 10315 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 10316 | status = mFlinger->getDesiredDisplayModeSpecs(displayToken, outSpecs); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10317 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10318 | } |
| 10319 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10320 | binder::Status SurfaceComposerAIDL::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 10321 | bool* outSupport) { |
| 10322 | status_t status = mFlinger->getDisplayBrightnessSupport(displayToken, outSupport); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10323 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10324 | } |
| 10325 | |
| 10326 | binder::Status SurfaceComposerAIDL::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 10327 | const gui::DisplayBrightness& brightness) { |
| 10328 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10329 | if (status == OK) { |
| 10330 | status = mFlinger->setDisplayBrightness(displayToken, brightness); |
| 10331 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10332 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10333 | } |
| 10334 | |
| 10335 | binder::Status SurfaceComposerAIDL::addHdrLayerInfoListener( |
| 10336 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 10337 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10338 | if (status == OK) { |
| 10339 | status = mFlinger->addHdrLayerInfoListener(displayToken, listener); |
| 10340 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10341 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10342 | } |
| 10343 | |
| 10344 | binder::Status SurfaceComposerAIDL::removeHdrLayerInfoListener( |
| 10345 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 10346 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10347 | if (status == OK) { |
| 10348 | status = mFlinger->removeHdrLayerInfoListener(displayToken, listener); |
| 10349 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10350 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10351 | } |
| 10352 | |
| 10353 | binder::Status SurfaceComposerAIDL::notifyPowerBoost(int boostId) { |
| 10354 | status_t status = checkAccessPermission(); |
| 10355 | if (status == OK) { |
| 10356 | status = mFlinger->notifyPowerBoost(boostId); |
| 10357 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10358 | return binderStatusFromStatusT(status); |
| 10359 | } |
| 10360 | |
| 10361 | binder::Status SurfaceComposerAIDL::setGlobalShadowSettings(const gui::Color& ambientColor, |
| 10362 | const gui::Color& spotColor, |
| 10363 | float lightPosY, float lightPosZ, |
| 10364 | float lightRadius) { |
| 10365 | status_t status = checkAccessPermission(); |
| 10366 | if (status != OK) { |
| 10367 | return binderStatusFromStatusT(status); |
| 10368 | } |
| 10369 | |
| 10370 | half4 ambientColorHalf = {ambientColor.r, ambientColor.g, ambientColor.b, ambientColor.a}; |
| 10371 | half4 spotColorHalf = {spotColor.r, spotColor.g, spotColor.b, spotColor.a}; |
| 10372 | status = mFlinger->setGlobalShadowSettings(ambientColorHalf, spotColorHalf, lightPosY, |
| 10373 | lightPosZ, lightRadius); |
| 10374 | return binderStatusFromStatusT(status); |
| 10375 | } |
| 10376 | |
| 10377 | binder::Status SurfaceComposerAIDL::getDisplayDecorationSupport( |
| 10378 | const sp<IBinder>& displayToken, std::optional<gui::DisplayDecorationSupport>* outSupport) { |
| 10379 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport> support; |
| 10380 | status_t status = mFlinger->getDisplayDecorationSupport(displayToken, &support); |
| 10381 | if (status != NO_ERROR) { |
| 10382 | ALOGE("getDisplayDecorationSupport failed with error %d", status); |
| 10383 | return binderStatusFromStatusT(status); |
| 10384 | } |
| 10385 | |
| 10386 | if (!support || !support.has_value()) { |
| 10387 | outSupport->reset(); |
| 10388 | } else { |
| 10389 | outSupport->emplace(); |
| 10390 | outSupport->value().format = static_cast<int32_t>(support->format); |
| 10391 | outSupport->value().alphaInterpretation = |
| 10392 | static_cast<int32_t>(support->alphaInterpretation); |
| 10393 | } |
| 10394 | |
| 10395 | return binder::Status::ok(); |
| 10396 | } |
| 10397 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10398 | binder::Status SurfaceComposerAIDL::setGameModeFrameRateOverride(int32_t uid, float frameRate) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10399 | status_t status; |
| 10400 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10401 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10402 | status = mFlinger->setGameModeFrameRateOverride(uid, frameRate); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10403 | } else { |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10404 | ALOGE("setGameModeFrameRateOverride() permission denied for uid: %d", c_uid); |
| 10405 | status = PERMISSION_DENIED; |
| 10406 | } |
| 10407 | return binderStatusFromStatusT(status); |
| 10408 | } |
| 10409 | |
| 10410 | binder::Status SurfaceComposerAIDL::setGameDefaultFrameRateOverride(int32_t uid, float frameRate) { |
| 10411 | status_t status; |
| 10412 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10413 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 10414 | status = mFlinger->setGameDefaultFrameRateOverride(uid, frameRate); |
| 10415 | } else { |
| 10416 | ALOGE("setGameDefaultFrameRateOverride() permission denied for uid: %d", c_uid); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10417 | status = PERMISSION_DENIED; |
| 10418 | } |
| 10419 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10420 | } |
| 10421 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 10422 | binder::Status SurfaceComposerAIDL::enableRefreshRateOverlay(bool active) { |
| 10423 | mFlinger->sfdo_enableRefreshRateOverlay(active); |
| 10424 | return binder::Status::ok(); |
| 10425 | } |
| 10426 | |
| 10427 | binder::Status SurfaceComposerAIDL::setDebugFlash(int delay) { |
| 10428 | mFlinger->sfdo_setDebugFlash(delay); |
| 10429 | return binder::Status::ok(); |
| 10430 | } |
| 10431 | |
| 10432 | binder::Status SurfaceComposerAIDL::scheduleComposite() { |
| 10433 | mFlinger->sfdo_scheduleComposite(); |
| 10434 | return binder::Status::ok(); |
| 10435 | } |
| 10436 | |
| 10437 | binder::Status SurfaceComposerAIDL::scheduleCommit() { |
| 10438 | mFlinger->sfdo_scheduleCommit(); |
| 10439 | return binder::Status::ok(); |
| 10440 | } |
| 10441 | |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 10442 | binder::Status SurfaceComposerAIDL::forceClientComposition(bool enabled) { |
| 10443 | mFlinger->sfdo_forceClientComposition(enabled); |
| 10444 | return binder::Status::ok(); |
| 10445 | } |
| 10446 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10447 | binder::Status SurfaceComposerAIDL::updateSmallAreaDetection(const std::vector<int32_t>& appIds, |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10448 | const std::vector<float>& thresholds) { |
| 10449 | status_t status; |
| 10450 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10451 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10452 | if (appIds.size() != thresholds.size()) return binderStatusFromStatusT(BAD_VALUE); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10453 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10454 | std::vector<std::pair<int32_t, float>> mappings; |
| 10455 | const size_t size = appIds.size(); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10456 | mappings.reserve(size); |
| 10457 | for (int i = 0; i < size; i++) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10458 | auto row = std::make_pair(appIds[i], thresholds[i]); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10459 | mappings.push_back(row); |
| 10460 | } |
| 10461 | status = mFlinger->updateSmallAreaDetection(mappings); |
| 10462 | } else { |
| 10463 | ALOGE("updateSmallAreaDetection() permission denied for uid: %d", c_uid); |
| 10464 | status = PERMISSION_DENIED; |
| 10465 | } |
| 10466 | return binderStatusFromStatusT(status); |
| 10467 | } |
| 10468 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10469 | binder::Status SurfaceComposerAIDL::setSmallAreaDetectionThreshold(int32_t appId, float threshold) { |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10470 | status_t status; |
| 10471 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10472 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10473 | status = mFlinger->setSmallAreaDetectionThreshold(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10474 | } else { |
| 10475 | ALOGE("setSmallAreaDetectionThreshold() permission denied for uid: %d", c_uid); |
| 10476 | status = PERMISSION_DENIED; |
| 10477 | } |
| 10478 | return binderStatusFromStatusT(status); |
| 10479 | } |
| 10480 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10481 | binder::Status SurfaceComposerAIDL::getGpuContextPriority(int32_t* outPriority) { |
| 10482 | *outPriority = mFlinger->getGpuContextPriority(); |
| 10483 | return binder::Status::ok(); |
| 10484 | } |
| 10485 | |
| 10486 | binder::Status SurfaceComposerAIDL::getMaxAcquiredBufferCount(int32_t* buffers) { |
| 10487 | status_t status = mFlinger->getMaxAcquiredBufferCount(buffers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10488 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10489 | } |
| 10490 | |
| 10491 | binder::Status SurfaceComposerAIDL::addWindowInfosListener( |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 10492 | const sp<gui::IWindowInfosListener>& windowInfosListener, |
| 10493 | gui::WindowInfosListenerInfo* outInfo) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10494 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10495 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10496 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10497 | // TODO(b/270566761) update permissions check so that only system_server and shell can add |
| 10498 | // WindowInfosListeners |
| 10499 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 10500 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 10501 | status = mFlinger->addWindowInfosListener(windowInfosListener, outInfo); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10502 | } else { |
| 10503 | status = PERMISSION_DENIED; |
| 10504 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10505 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10506 | } |
| 10507 | |
| 10508 | binder::Status SurfaceComposerAIDL::removeWindowInfosListener( |
| 10509 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 10510 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10511 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10512 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10513 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 10514 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10515 | status = mFlinger->removeWindowInfosListener(windowInfosListener); |
| 10516 | } else { |
| 10517 | status = PERMISSION_DENIED; |
| 10518 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10519 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10520 | } |
| 10521 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 10522 | binder::Status SurfaceComposerAIDL::getStalledTransactionInfo( |
| 10523 | int pid, std::optional<gui::StalledTransactionInfo>* outInfo) { |
| 10524 | const int callingPid = IPCThreadState::self()->getCallingPid(); |
| 10525 | const int callingUid = IPCThreadState::self()->getCallingUid(); |
| 10526 | if (!checkPermission(sAccessSurfaceFlinger, callingPid, callingUid)) { |
| 10527 | return binderStatusFromStatusT(PERMISSION_DENIED); |
| 10528 | } |
| 10529 | |
| 10530 | std::optional<TransactionHandler::StalledTransactionInfo> stalledTransactionInfo; |
| 10531 | status_t status = mFlinger->getStalledTransactionInfo(pid, stalledTransactionInfo); |
| 10532 | if (stalledTransactionInfo) { |
| 10533 | gui::StalledTransactionInfo result; |
| 10534 | result.layerName = String16{stalledTransactionInfo->layerName.c_str()}, |
| 10535 | result.bufferId = stalledTransactionInfo->bufferId, |
| 10536 | result.frameNumber = stalledTransactionInfo->frameNumber, |
| 10537 | outInfo->emplace(std::move(result)); |
| 10538 | } else { |
| 10539 | outInfo->reset(); |
| 10540 | } |
| 10541 | return binderStatusFromStatusT(status); |
| 10542 | } |
| 10543 | |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 10544 | binder::Status SurfaceComposerAIDL::getSchedulingPolicy(gui::SchedulingPolicy* outPolicy) { |
| 10545 | return gui::getSchedulingPolicy(outPolicy); |
| 10546 | } |
| 10547 | |
Wenhui Yang | eafc18a | 2024-05-14 17:15:52 +0000 | [diff] [blame] | 10548 | binder::Status SurfaceComposerAIDL::notifyShutdown() { |
| 10549 | TransactionTraceWriter::getInstance().invoke("systemShutdown_", /* overwrite= */ false); |
| 10550 | return ::android::binder::Status::ok(); |
| 10551 | } |
| 10552 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 10553 | status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { |
| 10554 | if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
| 10555 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10556 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", ipc->getCallingPid(), |
| 10557 | ipc->getCallingUid()); |
| 10558 | return PERMISSION_DENIED; |
| 10559 | } |
| 10560 | return OK; |
| 10561 | } |
| 10562 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10563 | status_t SurfaceComposerAIDL::checkControlDisplayBrightnessPermission() { |
| 10564 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10565 | const int pid = ipc->getCallingPid(); |
| 10566 | const int uid = ipc->getCallingUid(); |
Rheygine Medel | 9e9281e | 2022-09-22 10:13:56 -0700 | [diff] [blame] | 10567 | if ((uid != AID_GRAPHICS) && (uid != AID_SYSTEM) && |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10568 | !PermissionCache::checkPermission(sControlDisplayBrightness, pid, uid)) { |
| 10569 | ALOGE("Permission Denial: can't control brightness pid=%d, uid=%d", pid, uid); |
| 10570 | return PERMISSION_DENIED; |
| 10571 | } |
| 10572 | return OK; |
| 10573 | } |
| 10574 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10575 | status_t SurfaceComposerAIDL::checkReadFrameBufferPermission() { |
| 10576 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10577 | const int pid = ipc->getCallingPid(); |
| 10578 | const int uid = ipc->getCallingUid(); |
| 10579 | if ((uid != AID_GRAPHICS) && !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 10580 | ALOGE("Permission Denial: can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 10581 | return PERMISSION_DENIED; |
| 10582 | } |
| 10583 | return OK; |
| 10584 | } |
| 10585 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 10586 | void SurfaceFlinger::forceFutureUpdate(int delayInMs) { |
| 10587 | static_cast<void>(mScheduler->scheduleDelayed([&]() { scheduleRepaint(); }, ms2ns(delayInMs))); |
| 10588 | } |
| 10589 | |
Vishnu Nair | 2f65e97 | 2023-04-04 16:36:28 +0000 | [diff] [blame] | 10590 | const DisplayDevice* SurfaceFlinger::getDisplayFromLayerStack(ui::LayerStack layerStack) { |
| 10591 | for (const auto& [_, display] : mDisplays) { |
| 10592 | if (display->getLayerStack() == layerStack) { |
| 10593 | return display.get(); |
| 10594 | } |
| 10595 | } |
| 10596 | return nullptr; |
| 10597 | } |
| 10598 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 10599 | } // namespace android |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 10600 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 10601 | #if defined(__gl_h_) |
| 10602 | #error "don't include gl/gl.h in this file" |
| 10603 | #endif |
| 10604 | |
| 10605 | #if defined(__gl2_h_) |
| 10606 | #error "don't include gl2/gl2.h in this file" |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 10607 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 10608 | |
| 10609 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 10610 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |