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> |
Jim Shargo | 6ccc5e8 | 2024-07-27 03:42:08 +0000 | [diff] [blame] | 43 | #include <com_android_graphics_libgui_flags.h> |
Nolan Scobie | 488101b | 2024-05-20 13:32:13 -0400 | [diff] [blame] | 44 | #include <com_android_graphics_surfaceflinger_flags.h> |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 45 | #include <common/FlagManager.h> |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 46 | #include <common/trace.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 47 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 48 | #include <compositionengine/CompositionRefreshArgs.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 49 | #include <compositionengine/Display.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 50 | #include <compositionengine/DisplayColorProfile.h> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 51 | #include <compositionengine/DisplayColorProfileCreationArgs.h> |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 52 | #include <compositionengine/DisplayCreationArgs.h> |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 53 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 54 | #include <compositionengine/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 55 | #include <compositionengine/RenderSurface.h> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 56 | #include <compositionengine/impl/DisplayColorProfile.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 57 | #include <compositionengine/impl/OutputCompositionState.h> |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 58 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 59 | #include <configstore/Utils.h> |
| 60 | #include <cutils/compiler.h> |
| 61 | #include <cutils/properties.h> |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 62 | #include <fmt/format.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 63 | #include <ftl/algorithm.h> |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 64 | #include <ftl/concat.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 65 | #include <ftl/fake_guard.h> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 66 | #include <ftl/future.h> |
Melody Hsu | e524dd9 | 2024-08-27 22:27:29 +0000 | [diff] [blame] | 67 | #include <ftl/small_map.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 68 | #include <ftl/unit.h> |
Alec Mouri | 924f950 | 2024-08-15 20:01:08 +0000 | [diff] [blame] | 69 | #include <gui/AidlUtil.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 70 | #include <gui/BufferQueue.h> |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 71 | #include <gui/DebugEGLImageTracker.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 72 | #include <gui/IProducerListener.h> |
Melody Hsu | e524dd9 | 2024-08-27 22:27:29 +0000 | [diff] [blame] | 73 | #include <gui/JankInfo.h> |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 74 | #include <gui/LayerMetadata.h> |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 75 | #include <gui/LayerState.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 76 | #include <gui/Surface.h> |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 77 | #include <gui/SurfaceComposerClient.h> |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 78 | #include <hidl/ServiceManagement.h> |
Vishnu Nair | 6aac09e | 2024-07-26 21:38:58 +0000 | [diff] [blame] | 79 | #include <layerproto/LayerProtoHeader.h> |
Elliott Hughes | e3ffd13 | 2023-06-28 19:45:15 +0000 | [diff] [blame] | 80 | #include <linux/sched/types.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 81 | #include <log/log.h> |
| 82 | #include <private/android_filesystem_config.h> |
| 83 | #include <private/gui/SyncFeatures.h> |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 84 | #include <processgroup/processgroup.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 85 | #include <renderengine/RenderEngine.h> |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 86 | #include <renderengine/impl/ExternalTexture.h> |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 87 | #include <scheduler/FrameTargeter.h> |
Alec Mouri | d05a745 | 2024-09-20 13:44:02 +0000 | [diff] [blame] | 88 | #include <statslog_surfaceflinger.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 89 | #include <sys/types.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 90 | #include <ui/ColorSpace.h> |
| 91 | #include <ui/DebugUtils.h> |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 92 | #include <ui/DisplayId.h> |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 93 | #include <ui/DisplayMode.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 94 | #include <ui/DisplayStatInfo.h> |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 95 | #include <ui/DisplayState.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 96 | #include <ui/DynamicDisplayInfo.h> |
ramindani | d2a0e72 | 2024-10-18 15:25:20 -0700 | [diff] [blame] | 97 | #include <ui/FrameRateCategoryRate.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 98 | #include <ui/GraphicBufferAllocator.h> |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 99 | #include <ui/HdrRenderTypeUtils.h> |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 100 | #include <ui/LayerStack.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 101 | #include <ui/PixelFormat.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 102 | #include <ui/StaticDisplayInfo.h> |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 103 | #include <unistd.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | #include <utils/StopWatch.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 105 | #include <utils/String16.h> |
| 106 | #include <utils/String8.h> |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 107 | #include <utils/Timers.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 108 | #include <utils/misc.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 109 | #include <algorithm> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 110 | #include <cerrno> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 111 | #include <cinttypes> |
| 112 | #include <cmath> |
| 113 | #include <cstdint> |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 114 | #include <filesystem> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 115 | #include <functional> |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 116 | #include <memory> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 117 | #include <mutex> |
| 118 | #include <optional> |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 119 | #include <string> |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 120 | #include <type_traits> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 121 | #include <unordered_map> |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 122 | #include <vector> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | |
Alec Mouri | 9b133ca | 2023-11-14 19:00:01 +0000 | [diff] [blame] | 124 | #include <common/FlagManager.h> |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 125 | #include <gui/LayerStatePermissions.h> |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 126 | #include <gui/SchedulingPolicy.h> |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 127 | #include <gui/SyncScreenCaptureListener.h> |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 128 | #include <ui/DisplayIdentification.h> |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 129 | #include "BackgroundExecutor.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 130 | #include "Client.h" |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 131 | #include "ClientCache.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 132 | #include "Colorizer.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 133 | #include "DisplayDevice.h" |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 134 | #include "DisplayHardware/ComposerHal.h" |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 135 | #include "DisplayHardware/FramebufferSurface.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 136 | #include "DisplayHardware/HWComposer.h" |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 137 | #include "DisplayHardware/Hal.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 138 | #include "DisplayHardware/VirtualDisplaySurface.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 139 | #include "DisplayRenderArea.h" |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 140 | #include "Effects/Daltonizer.h" |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 141 | #include "FpsReporter.h" |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 142 | #include "FrameTimeline/FrameTimeline.h" |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 143 | #include "FrameTracer/FrameTracer.h" |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 144 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 145 | #include "FrontEnd/LayerHandle.h" |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 146 | #include "FrontEnd/LayerLifecycleManager.h" |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 147 | #include "FrontEnd/LayerLog.h" |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 148 | #include "FrontEnd/LayerSnapshot.h" |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 149 | #include "HdrLayerInfoReporter.h" |
Pascal Mütschard | d56514e | 2024-05-24 17:37:13 +0200 | [diff] [blame] | 150 | #include "Jank/JankTracker.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 151 | #include "Layer.h" |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 152 | #include "LayerProtoHelper.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 153 | #include "LayerRenderArea.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 154 | #include "LayerVector.h" |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 155 | #include "MutexUtils.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 156 | #include "NativeWindowSurface.h" |
Matt Buckley | 18b9352 | 2024-08-27 05:30:18 +0000 | [diff] [blame] | 157 | #include "PowerAdvisor/PowerAdvisor.h" |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 158 | #include "RegionSamplingThread.h" |
Melody Hsu | 41ade20 | 2024-05-03 01:25:50 +0000 | [diff] [blame] | 159 | #include "RenderAreaBuilder.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 160 | #include "Scheduler/EventThread.h" |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 161 | #include "Scheduler/LayerHistory.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 162 | #include "Scheduler/Scheduler.h" |
Ady Abraham | c581d3c | 2020-08-06 17:34:27 -0700 | [diff] [blame] | 163 | #include "Scheduler/VsyncConfiguration.h" |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 164 | #include "Scheduler/VsyncModulator.h" |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 165 | #include "ScreenCaptureOutput.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 166 | #include "SurfaceFlingerProperties.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 167 | #include "TimeStats/TimeStats.h" |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 168 | #include "TunnelModeEnabledReporter.h" |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 169 | #include "Utils/Dumper.h" |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 170 | #include "WindowInfosListenerInvoker.h" |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 171 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 172 | #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 173 | #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 174 | #include <aidl/android/hardware/graphics/composer3/RenderIntent.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 175 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 176 | #undef NO_THREAD_SAFETY_ANALYSIS |
| 177 | #define NO_THREAD_SAFETY_ANALYSIS \ |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 178 | _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] | 179 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | namespace android { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 181 | using namespace std::chrono_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 182 | using namespace std::string_literals; |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 183 | using namespace std::string_view_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 184 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 185 | using namespace hardware::configstore; |
| 186 | using namespace hardware::configstore::V1_0; |
| 187 | using namespace sysprop; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 188 | using ftl::Flags; |
| 189 | using namespace ftl::flag_operators; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 190 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 191 | using aidl::android::hardware::graphics::common::DisplayDecorationSupport; |
| 192 | using aidl::android::hardware::graphics::composer3::Capability; |
| 193 | using aidl::android::hardware::graphics::composer3::DisplayCapability; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 194 | using CompositionStrategyPredictionState = android::compositionengine::impl:: |
| 195 | OutputCompositionState::CompositionStrategyPredictionState; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 196 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 197 | using base::StringAppendF; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 198 | using display::PhysicalDisplay; |
| 199 | using display::PhysicalDisplays; |
Vishnu Nair | af6d297 | 2022-11-18 06:26:38 +0000 | [diff] [blame] | 200 | using frontend::TransactionHandler; |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 201 | using gui::DisplayInfo; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 202 | using gui::GameMode; |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 203 | using gui::IDisplayEventConnection; |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 204 | using gui::IWindowInfosListener; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 205 | using gui::LayerMetadata; |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 206 | using gui::WindowInfo; |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 207 | using gui::aidl_utils::binderStatusFromStatusT; |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 208 | using scheduler::VsyncModulator; |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 209 | using ui::Dataspace; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 210 | using ui::DisplayPrimaries; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 211 | using ui::RenderIntent; |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 212 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 213 | namespace hal = android::hardware::graphics::composer::hal; |
| 214 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 215 | namespace { |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 216 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 217 | static constexpr int FOUR_K_WIDTH = 3840; |
| 218 | static constexpr int FOUR_K_HEIGHT = 2160; |
| 219 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 220 | // TODO(b/141333600): Consolidate with DisplayMode::Builder::getDefaultDensity. |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 221 | constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 222 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 223 | float getDensityFromProperty(const char* property, bool required) { |
| 224 | char value[PROPERTY_VALUE_MAX]; |
| 225 | const float density = property_get(property, value, nullptr) > 0 ? std::atof(value) : 0.f; |
| 226 | if (!density && required) { |
| 227 | ALOGE("%s must be defined as a build property", property); |
| 228 | return FALLBACK_DENSITY; |
| 229 | } |
| 230 | return density; |
| 231 | } |
| 232 | |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 233 | // Currently we only support V0_SRGB and DISPLAY_P3 as composition preference. |
| 234 | bool validateCompositionDataspace(Dataspace dataspace) { |
| 235 | return dataspace == Dataspace::V0_SRGB || dataspace == Dataspace::DISPLAY_P3; |
| 236 | } |
| 237 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 238 | std::chrono::milliseconds getIdleTimerTimeout(PhysicalDisplayId displayId) { |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 239 | if (const int32_t displayIdleTimerMs = |
| 240 | base::GetIntProperty("debug.sf.set_idle_timer_ms_"s + |
| 241 | std::to_string(displayId.value), |
| 242 | 0); |
| 243 | displayIdleTimerMs > 0) { |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 244 | return std::chrono::milliseconds(displayIdleTimerMs); |
| 245 | } |
| 246 | |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 247 | 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] | 248 | const int32_t millis = setIdleTimerMs ? setIdleTimerMs : sysprop::set_idle_timer_ms(0); |
| 249 | return std::chrono::milliseconds(millis); |
| 250 | } |
| 251 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 252 | bool getKernelIdleTimerSyspropConfig(PhysicalDisplayId displayId) { |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 253 | const bool displaySupportKernelIdleTimer = |
| 254 | base::GetBoolProperty("debug.sf.support_kernel_idle_timer_"s + |
| 255 | std::to_string(displayId.value), |
| 256 | false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 257 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 258 | return displaySupportKernelIdleTimer || sysprop::support_kernel_idle_timer(false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 261 | bool isAbove4k30(const ui::DisplayMode& outMode) { |
| 262 | using fps_approx_ops::operator>; |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 263 | Fps refreshRate = Fps::fromValue(outMode.peakRefreshRate); |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 264 | return outMode.resolution.getWidth() >= FOUR_K_WIDTH && |
| 265 | outMode.resolution.getHeight() >= FOUR_K_HEIGHT && refreshRate > 30_Hz; |
| 266 | } |
| 267 | |
| 268 | void excludeDolbyVisionIf4k30Present(const std::vector<ui::Hdr>& displayHdrTypes, |
| 269 | ui::DisplayMode& outMode) { |
| 270 | if (isAbove4k30(outMode) && |
| 271 | std::any_of(displayHdrTypes.begin(), displayHdrTypes.end(), |
| 272 | [](ui::Hdr type) { return type == ui::Hdr::DOLBY_VISION_4K30; })) { |
| 273 | for (ui::Hdr type : displayHdrTypes) { |
| 274 | if (type != ui::Hdr::DOLBY_VISION_4K30 && type != ui::Hdr::DOLBY_VISION) { |
| 275 | outMode.supportedHdrTypes.push_back(type); |
| 276 | } |
| 277 | } |
| 278 | } else { |
| 279 | for (ui::Hdr type : displayHdrTypes) { |
| 280 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 281 | outMode.supportedHdrTypes.push_back(type); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | HdrCapabilities filterOut4k30(const HdrCapabilities& displayHdrCapabilities) { |
| 288 | std::vector<ui::Hdr> hdrTypes; |
| 289 | for (ui::Hdr type : displayHdrCapabilities.getSupportedHdrTypes()) { |
| 290 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 291 | hdrTypes.push_back(type); |
| 292 | } |
| 293 | } |
| 294 | return {hdrTypes, displayHdrCapabilities.getDesiredMaxLuminance(), |
| 295 | displayHdrCapabilities.getDesiredMaxAverageLuminance(), |
| 296 | displayHdrCapabilities.getDesiredMinLuminance()}; |
| 297 | } |
| 298 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 299 | uint32_t getLayerIdFromSurfaceControl(sp<SurfaceControl> surfaceControl) { |
| 300 | if (!surfaceControl) { |
| 301 | return UNASSIGNED_LAYER_ID; |
| 302 | } |
| 303 | return LayerHandle::getLayerId(surfaceControl->getHandle()); |
| 304 | } |
| 305 | |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 306 | /** |
| 307 | * Returns true if the file at path exists and is newer than duration. |
| 308 | */ |
| 309 | bool fileNewerThan(const std::string& path, std::chrono::minutes duration) { |
| 310 | using Clock = std::filesystem::file_time_type::clock; |
| 311 | std::error_code error; |
| 312 | std::filesystem::file_time_type updateTime = std::filesystem::last_write_time(path, error); |
| 313 | if (error) { |
| 314 | return false; |
| 315 | } |
| 316 | return duration > (Clock::now() - updateTime); |
| 317 | } |
| 318 | |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 319 | bool isFrameIntervalOnCadence(TimePoint expectedPresentTime, TimePoint lastExpectedPresentTimestamp, |
| 320 | Fps lastFrameInterval, Period timeout, Duration threshold) { |
| 321 | if (lastFrameInterval.getPeriodNsecs() == 0) { |
| 322 | return false; |
| 323 | } |
| 324 | |
| 325 | const auto expectedPresentTimeDeltaNs = |
| 326 | expectedPresentTime.ns() - lastExpectedPresentTimestamp.ns(); |
| 327 | |
| 328 | if (expectedPresentTimeDeltaNs > timeout.ns()) { |
| 329 | return false; |
| 330 | } |
| 331 | |
| 332 | const auto expectedPresentPeriods = static_cast<nsecs_t>( |
| 333 | std::round(static_cast<float>(expectedPresentTimeDeltaNs) / |
| 334 | static_cast<float>(lastFrameInterval.getPeriodNsecs()))); |
| 335 | const auto calculatedPeriodsOutNs = lastFrameInterval.getPeriodNsecs() * expectedPresentPeriods; |
| 336 | const auto calculatedExpectedPresentTimeNs = |
| 337 | lastExpectedPresentTimestamp.ns() + calculatedPeriodsOutNs; |
| 338 | const auto presentTimeDelta = |
| 339 | std::abs(expectedPresentTime.ns() - calculatedExpectedPresentTimeNs); |
| 340 | return presentTimeDelta < threshold.ns(); |
| 341 | } |
| 342 | |
| 343 | bool isExpectedPresentWithinTimeout(TimePoint expectedPresentTime, |
| 344 | TimePoint lastExpectedPresentTimestamp, |
| 345 | std::optional<Period> timeoutOpt, Duration threshold) { |
| 346 | if (!timeoutOpt) { |
| 347 | // Always within timeout if timeoutOpt is absent and don't send hint |
| 348 | // for the timeout |
| 349 | return true; |
| 350 | } |
| 351 | |
| 352 | if (timeoutOpt->ns() == 0) { |
| 353 | // Always outside timeout if timeoutOpt is 0 and always send |
| 354 | // the hint for the timeout. |
| 355 | return false; |
| 356 | } |
| 357 | |
| 358 | if (expectedPresentTime.ns() < lastExpectedPresentTimestamp.ns() + timeoutOpt->ns()) { |
| 359 | return true; |
| 360 | } |
| 361 | |
| 362 | // Check if within the threshold as it can be just outside the timeout |
| 363 | return std::abs(expectedPresentTime.ns() - |
| 364 | (lastExpectedPresentTimestamp.ns() + timeoutOpt->ns())) < threshold.ns(); |
| 365 | } |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 366 | } // namespace anonymous |
| 367 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | // --------------------------------------------------------------------------- |
| 369 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 370 | const String16 sHardwareTest("android.permission.HARDWARE_TEST"); |
| 371 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 372 | const String16 sRotateSurfaceFlinger("android.permission.ROTATE_SURFACE_FLINGER"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 373 | const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER"); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 374 | const String16 sControlDisplayBrightness("android.permission.CONTROL_DISPLAY_BRIGHTNESS"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 375 | const String16 sDump("android.permission.DUMP"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 376 | const String16 sCaptureBlackoutContent("android.permission.CAPTURE_BLACKOUT_CONTENT"); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 377 | const String16 sInternalSystemWindow("android.permission.INTERNAL_SYSTEM_WINDOW"); |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 378 | const String16 sWakeupSurfaceFlinger("android.permission.WAKEUP_SURFACE_FLINGER"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 379 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 380 | // --------------------------------------------------------------------------- |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 381 | int64_t SurfaceFlinger::dispSyncPresentTimeOffset; |
| 382 | bool SurfaceFlinger::useHwcForRgbToYuv; |
| 383 | bool SurfaceFlinger::hasSyncFramework; |
| 384 | int64_t SurfaceFlinger::maxFrameBufferAcquiredBuffers; |
| 385 | int64_t SurfaceFlinger::minAcquiredBuffers = 1; |
| 386 | uint32_t SurfaceFlinger::maxGraphicsWidth; |
| 387 | uint32_t SurfaceFlinger::maxGraphicsHeight; |
| 388 | bool SurfaceFlinger::useContextPriority; |
| 389 | Dataspace SurfaceFlinger::defaultCompositionDataspace = Dataspace::V0_SRGB; |
| 390 | ui::PixelFormat SurfaceFlinger::defaultCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
| 391 | Dataspace SurfaceFlinger::wideColorGamutCompositionDataspace = Dataspace::V0_SRGB; |
| 392 | ui::PixelFormat SurfaceFlinger::wideColorGamutCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 393 | LatchUnsignaledConfig SurfaceFlinger::enableLatchUnsignaledConfig; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 394 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 395 | std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) { |
| 396 | switch(displayColorSetting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 397 | case DisplayColorSetting::kManaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 398 | return std::string("Managed"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 399 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 400 | return std::string("Unmanaged"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 401 | case DisplayColorSetting::kEnhanced: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 402 | return std::string("Enhanced"); |
| 403 | default: |
| 404 | return std::string("Unknown ") + |
| 405 | std::to_string(static_cast<int>(displayColorSetting)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 406 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 407 | } |
| 408 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 409 | bool callingThreadHasPermission(const String16& permission) { |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 410 | IPCThreadState* ipc = IPCThreadState::self(); |
| 411 | const int pid = ipc->getCallingPid(); |
| 412 | const int uid = ipc->getCallingUid(); |
| 413 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 414 | PermissionCache::checkPermission(permission, pid, uid); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 417 | ui::Transform::RotationFlags SurfaceFlinger::sActiveDisplayRotationFlags = ui::Transform::ROT_0; |
| 418 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 419 | SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag) |
| 420 | : mFactory(factory), |
| 421 | mPid(getpid()), |
Yiwei Zhang | f0229a7 | 2019-09-09 19:28:02 -0700 | [diff] [blame] | 422 | mTimeStats(std::make_shared<impl::TimeStats>()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 423 | mFrameTracer(mFactory.createFrameTracer()), |
| 424 | mFrameTimeline(mFactory.createFrameTimeline(mTimeStats, mPid)), |
| 425 | mCompositionEngine(mFactory.createCompositionEngine()), |
| 426 | mHwcServiceName(base::GetProperty("debug.sf.hwc_service_name"s, "default"s)), |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 427 | mTunnelModeEnabledReporter(sp<TunnelModeEnabledReporter>::make()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 428 | mEmulatedDisplayDensity(getDensityFromProperty("qemu.sf.lcd_density", false)), |
| 429 | mInternalDisplayDensity( |
| 430 | getDensityFromProperty("ro.sf.lcd_density", !mEmulatedDisplayDensity)), |
Matt Buckley | 18b9352 | 2024-08-27 05:30:18 +0000 | [diff] [blame] | 431 | mPowerAdvisor(std::make_unique< |
| 432 | adpf::impl::PowerAdvisor>([this] { disableExpensiveRendering(); }, |
| 433 | std::chrono::milliseconds( |
| 434 | sysprop::display_update_imminent_timeout_ms( |
| 435 | 80)))), |
Robert Horvath | dce110a | 2022-09-16 11:08:47 +0200 | [diff] [blame] | 436 | mWindowInfosListenerInvoker(sp<WindowInfosListenerInvoker>::make()), |
| 437 | mSkipPowerOnForQuiescent(base::GetBoolProperty("ro.boot.quiescent"s, false)) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 438 | ALOGI("Using HWComposer service: %s", mHwcServiceName.c_str()); |
| 439 | } |
Fabien Sanglard | 0cc1938 | 2017-03-06 11:54:40 -0800 | [diff] [blame] | 440 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 441 | SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 442 | SFTRACE_CALL(); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 443 | ALOGI("SurfaceFlinger is starting"); |
| 444 | |
| 445 | hasSyncFramework = running_without_sync_framework(true); |
| 446 | |
| 447 | dispSyncPresentTimeOffset = present_time_offset_from_vsync_ns(0); |
| 448 | |
| 449 | useHwcForRgbToYuv = force_hwc_copy_for_virtual_displays(false); |
| 450 | |
| 451 | maxFrameBufferAcquiredBuffers = max_frame_buffer_acquired_buffers(2); |
| 452 | minAcquiredBuffers = |
| 453 | SurfaceFlingerProperties::min_acquired_buffers().value_or(minAcquiredBuffers); |
| 454 | |
| 455 | maxGraphicsWidth = std::max(max_graphics_width(0), 0); |
| 456 | maxGraphicsHeight = std::max(max_graphics_height(0), 0); |
| 457 | |
| 458 | mSupportsWideColor = has_wide_color_display(false); |
| 459 | mDefaultCompositionDataspace = |
| 460 | static_cast<ui::Dataspace>(default_composition_dataspace(Dataspace::V0_SRGB)); |
| 461 | mWideColorGamutCompositionDataspace = static_cast<ui::Dataspace>(wcg_composition_dataspace( |
| 462 | mSupportsWideColor ? Dataspace::DISPLAY_P3 : Dataspace::V0_SRGB)); |
| 463 | defaultCompositionDataspace = mDefaultCompositionDataspace; |
| 464 | wideColorGamutCompositionDataspace = mWideColorGamutCompositionDataspace; |
| 465 | defaultCompositionPixelFormat = static_cast<ui::PixelFormat>( |
| 466 | default_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 467 | wideColorGamutCompositionPixelFormat = |
| 468 | static_cast<ui::PixelFormat>(wcg_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 469 | |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 470 | mLayerCachingEnabled = |
| 471 | base::GetBoolProperty("debug.sf.enable_layer_caching"s, |
| 472 | sysprop::SurfaceFlingerProperties::enable_layer_caching() |
| 473 | .value_or(false)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 474 | |
| 475 | useContextPriority = use_context_priority(true); |
| 476 | |
| 477 | mInternalDisplayPrimaries = sysprop::getDisplayNativePrimaries(); |
| 478 | |
| 479 | // debugging stuff... |
| 480 | char value[PROPERTY_VALUE_MAX]; |
| 481 | |
| 482 | property_get("ro.build.type", value, "user"); |
| 483 | mIsUserBuild = strcmp(value, "user") == 0; |
| 484 | |
| 485 | mDebugFlashDelay = base::GetUintProperty("debug.sf.showupdates"s, 0u); |
| 486 | |
| 487 | mBackpressureGpuComposition = base::GetBoolProperty("debug.sf.enable_gl_backpressure"s, true); |
| 488 | ALOGI_IF(mBackpressureGpuComposition, "Enabling backpressure for GPU composition"); |
| 489 | |
| 490 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 491 | bool supportsBlurs = atoi(value); |
| 492 | mSupportsBlur = supportsBlurs; |
| 493 | ALOGI_IF(!mSupportsBlur, "Disabling blur effects, they are not supported."); |
| 494 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 495 | property_get("debug.sf.luma_sampling", value, "1"); |
| 496 | mLumaSampling = atoi(value); |
| 497 | |
| 498 | property_get("debug.sf.disable_client_composition_cache", value, "0"); |
| 499 | mDisableClientCompositionCache = atoi(value); |
| 500 | |
| 501 | property_get("debug.sf.predict_hwc_composition_strategy", value, "1"); |
| 502 | mPredictCompositionStrategy = atoi(value); |
| 503 | |
| 504 | property_get("debug.sf.treat_170m_as_sRGB", value, "0"); |
| 505 | mTreat170mAsSrgb = atoi(value); |
| 506 | |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 507 | property_get("debug.sf.dim_in_gamma_in_enhanced_screenshots", value, 0); |
| 508 | mDimInGammaSpaceForEnhancedScreenshots = atoi(value); |
| 509 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 510 | mIgnoreHwcPhysicalDisplayOrientation = |
| 511 | base::GetBoolProperty("debug.sf.ignore_hwc_physical_display_orientation"s, false); |
| 512 | |
| 513 | // We should be reading 'persist.sys.sf.color_saturation' here |
| 514 | // but since /data may be encrypted, we need to wait until after vold |
| 515 | // comes online to attempt to read the property. The property is |
| 516 | // instead read after the boot animation |
| 517 | |
| 518 | if (base::GetBoolProperty("debug.sf.treble_testing_override"s, false)) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 519 | // Without the override SurfaceFlinger cannot connect to HIDL |
| 520 | // services that are not listed in the manifests. Considered |
| 521 | // deriving the setting from the set service name, but it |
| 522 | // would be brittle if the name that's not 'default' is used |
| 523 | // for production purposes later on. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 524 | ALOGI("Enabling Treble testing override"); |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 525 | android::hardware::details::setTrebleTestingOverride(true); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 526 | } |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 527 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 528 | // TODO (b/270966065) Update the HWC based refresh rate overlay to support spinner |
| 529 | mRefreshRateOverlaySpinner = property_get_bool("debug.sf.show_refresh_rate_overlay_spinner", 0); |
| 530 | mRefreshRateOverlayRenderRate = |
| 531 | property_get_bool("debug.sf.show_refresh_rate_overlay_render_rate", 0); |
| 532 | mRefreshRateOverlayShowInMiddle = |
| 533 | property_get_bool("debug.sf.show_refresh_rate_overlay_in_middle", 0); |
| 534 | |
| 535 | if (!mIsUserBuild && base::GetBoolProperty("debug.sf.enable_transaction_tracing"s, true)) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 536 | mTransactionTracing.emplace(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 537 | mLayerTracing.setTransactionTracing(*mTransactionTracing); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 538 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 539 | |
| 540 | mIgnoreHdrCameraLayers = ignore_hdr_camera_layers(false); |
| 541 | |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 542 | // These are set by the HWC implementation to indicate that they will use the workarounds. |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 543 | mIsHdcpViaNegVsync = base::GetBoolProperty("debug.sf.hwc_hdcp_via_neg_vsync"s, false); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | LatchUnsignaledConfig SurfaceFlinger::getLatchUnsignaledConfig() { |
Ady Abraham | d9e8d1b | 2022-02-25 00:36:10 +0000 | [diff] [blame] | 547 | if (base::GetBoolProperty("debug.sf.auto_latch_unsignaled"s, true)) { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 548 | return LatchUnsignaledConfig::AutoSingleLayer; |
| 549 | } |
| 550 | |
| 551 | return LatchUnsignaledConfig::Disabled; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | } |
| 553 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 554 | SurfaceFlinger::~SurfaceFlinger() = default; |
| 555 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 556 | void SurfaceFlinger::binderDied(const wp<IBinder>&) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 557 | // the window manager died on us. prepare its eulogy. |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 558 | mBootFinished = false; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 559 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 560 | static_cast<void>(mScheduler->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 561 | // Sever the link to inputflinger since it's gone as well. |
| 562 | mInputFlinger.clear(); |
Vishnu Nair | b9df470 | 2021-03-01 11:53:15 -0800 | [diff] [blame] | 563 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 564 | initializeDisplays(); |
| 565 | })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 566 | |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 567 | mInitBootPropsFuture.callOnce([this] { |
| 568 | return std::async(std::launch::async, &SurfaceFlinger::initBootProperties, this); |
| 569 | }); |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 570 | |
| 571 | mInitBootPropsFuture.wait(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 572 | } |
| 573 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 574 | void SurfaceFlinger::run() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 575 | mScheduler->run(); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 576 | } |
| 577 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 578 | sp<IBinder> SurfaceFlinger::createVirtualDisplay(const std::string& displayName, bool isSecure, |
| 579 | const std::string& uniqueId, |
| 580 | float requestedRefreshRate) { |
Patrick Williams | e58a92b | 2024-02-29 14:52:25 -0600 | [diff] [blame] | 581 | // SurfaceComposerAIDL checks for some permissions, but adding an additional check here. |
| 582 | // 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] | 583 | // 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] | 584 | const uid_t uid = IPCThreadState::self()->getCallingUid(); |
| 585 | if (isSecure && uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM) { |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 586 | ALOGE("Only privileged processes can create a secure display"); |
| 587 | return nullptr; |
| 588 | } |
| 589 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 590 | class DisplayToken : public BBinder { |
| 591 | sp<SurfaceFlinger> flinger; |
| 592 | virtual ~DisplayToken() { |
| 593 | // no more references, this display must be terminated |
| 594 | Mutex::Autolock _l(flinger->mStateLock); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 595 | flinger->mCurrentState.displays.removeItem(wp<IBinder>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 596 | flinger->setTransactionFlags(eDisplayTransactionNeeded); |
| 597 | } |
| 598 | public: |
Chih-Hung Hsieh | c406791 | 2016-05-03 14:03:27 -0700 | [diff] [blame] | 599 | explicit DisplayToken(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 600 | : flinger(flinger) { |
| 601 | } |
| 602 | }; |
| 603 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 604 | sp<BBinder> token = sp<DisplayToken>::make(sp<SurfaceFlinger>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 605 | |
| 606 | Mutex::Autolock _l(mStateLock); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 607 | // Display ID is assigned when virtual display is allocated by HWC. |
| 608 | DisplayDeviceState state; |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 609 | state.isSecure = isSecure; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 610 | // Set display as protected when marked as secure to ensure no behavior change |
| 611 | // TODO (b/314820005): separate as a different arg when creating the display. |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 612 | state.isProtected = isSecure; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 613 | state.displayName = displayName; |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 614 | state.uniqueId = uniqueId; |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 615 | state.requestedRefreshRate = Fps::fromValue(requestedRefreshRate); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 616 | mCurrentState.displays.add(token, state); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 617 | return token; |
| 618 | } |
| 619 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 620 | status_t SurfaceFlinger::destroyVirtualDisplay(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 621 | Mutex::Autolock lock(mStateLock); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 622 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 623 | const ssize_t index = mCurrentState.displays.indexOfKey(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 624 | if (index < 0) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 625 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 626 | return NAME_NOT_FOUND; |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 629 | const DisplayDeviceState& state = mCurrentState.displays.valueAt(index); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 630 | if (state.physical) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 631 | ALOGE("%s: Invalid operation on physical display", __func__); |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 632 | return INVALID_OPERATION; |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 633 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 634 | mCurrentState.displays.removeItemsAt(index); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 635 | setTransactionFlags(eDisplayTransactionNeeded); |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 636 | return NO_ERROR; |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 639 | void SurfaceFlinger::enableHalVirtualDisplays(bool enable) { |
| 640 | auto& generator = mVirtualDisplayIdGenerators.hal; |
| 641 | if (!generator && enable) { |
| 642 | ALOGI("Enabling HAL virtual displays"); |
| 643 | generator.emplace(getHwComposer().getMaxVirtualDisplayCount()); |
| 644 | } else if (generator && !enable) { |
| 645 | ALOGW_IF(generator->inUse(), "Disabling HAL virtual displays while in use"); |
| 646 | generator.reset(); |
| 647 | } |
| 648 | } |
| 649 | |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 650 | VirtualDisplayId SurfaceFlinger::acquireVirtualDisplay(ui::Size resolution, |
| 651 | ui::PixelFormat format) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 652 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 653 | if (const auto id = generator->generateId()) { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 654 | if (getHwComposer().allocateVirtualDisplay(*id, resolution, &format)) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 655 | return *id; |
| 656 | } |
| 657 | |
| 658 | generator->releaseId(*id); |
| 659 | } else { |
| 660 | ALOGW("%s: Exhausted HAL virtual displays", __func__); |
| 661 | } |
| 662 | |
| 663 | ALOGW("%s: Falling back to GPU virtual display", __func__); |
| 664 | } |
| 665 | |
| 666 | const auto id = mVirtualDisplayIdGenerators.gpu.generateId(); |
| 667 | LOG_ALWAYS_FATAL_IF(!id, "Failed to generate ID for GPU virtual display"); |
| 668 | return *id; |
| 669 | } |
| 670 | |
| 671 | void SurfaceFlinger::releaseVirtualDisplay(VirtualDisplayId displayId) { |
| 672 | if (const auto id = HalVirtualDisplayId::tryCast(displayId)) { |
| 673 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 674 | generator->releaseId(*id); |
| 675 | } |
| 676 | return; |
| 677 | } |
| 678 | |
| 679 | const auto id = GpuVirtualDisplayId::tryCast(displayId); |
| 680 | LOG_ALWAYS_FATAL_IF(!id); |
| 681 | mVirtualDisplayIdGenerators.gpu.releaseId(*id); |
| 682 | } |
| 683 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 684 | std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdsLocked() const { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 685 | std::vector<PhysicalDisplayId> displayIds; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 686 | displayIds.reserve(mPhysicalDisplays.size()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 687 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 688 | const auto defaultDisplayId = getDefaultDisplayDeviceLocked()->getPhysicalId(); |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 689 | displayIds.push_back(defaultDisplayId); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 690 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 691 | for (const auto& [id, display] : mPhysicalDisplays) { |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 692 | if (id != defaultDisplayId) { |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 693 | displayIds.push_back(id); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 694 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 695 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 696 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 697 | return displayIds; |
| 698 | } |
| 699 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 700 | std::optional<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdLocked( |
| 701 | const sp<display::DisplayToken>& displayToken) const { |
| 702 | return ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 703 | .transform(&ftl::to_key<PhysicalDisplays>); |
| 704 | } |
| 705 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 706 | sp<IBinder> SurfaceFlinger::getPhysicalDisplayToken(PhysicalDisplayId displayId) const { |
| 707 | Mutex::Autolock lock(mStateLock); |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 708 | return getPhysicalDisplayTokenLocked(displayId); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 709 | } |
| 710 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 711 | HWComposer& SurfaceFlinger::getHwComposer() const { |
| 712 | return mCompositionEngine->getHwComposer(); |
| 713 | } |
| 714 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 715 | renderengine::RenderEngine& SurfaceFlinger::getRenderEngine() const { |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 716 | return *mRenderEngine; |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 719 | compositionengine::CompositionEngine& SurfaceFlinger::getCompositionEngine() const { |
| 720 | return *mCompositionEngine.get(); |
| 721 | } |
| 722 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 723 | void SurfaceFlinger::bootFinished() { |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 724 | if (mBootFinished == true) { |
| 725 | ALOGE("Extra call to bootFinished"); |
| 726 | return; |
| 727 | } |
| 728 | mBootFinished = true; |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame] | 729 | FlagManager::getMutableInstance().markBootCompleted(); |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 730 | |
Vishnu Nair | 47b6e68 | 2024-07-12 18:46:07 +0000 | [diff] [blame] | 731 | ::tracing_perfetto::registerWithPerfetto(); |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 732 | mInitBootPropsFuture.wait(); |
| 733 | mRenderEnginePrimeCacheFuture.wait(); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 734 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 735 | const nsecs_t now = systemTime(); |
| 736 | const nsecs_t duration = now - mBootTime; |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 737 | ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 738 | |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 739 | mFrameTracer->initialize(); |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 740 | mFrameTimeline->onBootFinished(); |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 741 | getRenderEngine().setEnableTracing(FlagManager::getInstance().use_skia_tracing()); |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 742 | |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 743 | // wait patiently for the window manager death |
| 744 | const String16 name("window"); |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 745 | mWindowManager = defaultServiceManager()->waitForService(name); |
Steven Moreland | a904bb9 | 2019-07-02 17:37:23 -0700 | [diff] [blame] | 746 | if (mWindowManager != 0) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 747 | mWindowManager->linkToDeath(sp<IBinder::DeathRecipient>::fromExisting(this)); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | // stop boot animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 751 | // formerly we would just kill the process, but we now ask it to exit so it |
| 752 | // can choose where to stop the animation. |
| 753 | property_set("service.bootanim.exit", "1"); |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 754 | |
| 755 | const int LOGTAG_SF_STOP_BOOTANIM = 60110; |
| 756 | LOG_EVENT_LONG(LOGTAG_SF_STOP_BOOTANIM, |
| 757 | ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 758 | |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 759 | sp<IBinder> input(defaultServiceManager()->waitForService(String16("inputflinger"))); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 760 | |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 761 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 762 | if (input == nullptr) { |
| 763 | ALOGE("Failed to link to input service"); |
| 764 | } else { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 765 | mInputFlinger = interface_cast<os::IInputFlinger>(input); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 766 | } |
| 767 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 768 | readPersistentProperties(); |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 769 | const bool hintSessionEnabled = FlagManager::getInstance().use_adpf_cpu_hint(); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 770 | mPowerAdvisor->enablePowerHintSession(hintSessionEnabled); |
| 771 | const bool hintSessionUsed = mPowerAdvisor->usePowerHintSession(); |
Matt Buckley | 547cc0c | 2023-10-27 22:22:36 +0000 | [diff] [blame] | 772 | // Ordering is important here, as onBootFinished signals to PowerAdvisor that concurrency |
| 773 | // is safe because its variables are initialized. |
| 774 | mPowerAdvisor->onBootFinished(); |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 775 | ALOGD("Power hint is %s", |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 776 | hintSessionUsed ? "supported" : (hintSessionEnabled ? "unsupported" : "disabled")); |
| 777 | if (hintSessionUsed) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 778 | std::optional<pid_t> renderEngineTid = getRenderEngine().getRenderEngineTid(); |
| 779 | std::vector<int32_t> tidList; |
| 780 | tidList.emplace_back(gettid()); |
| 781 | if (renderEngineTid.has_value()) { |
| 782 | tidList.emplace_back(*renderEngineTid); |
| 783 | } |
Matt Buckley | 547cc0c | 2023-10-27 22:22:36 +0000 | [diff] [blame] | 784 | if (!mPowerAdvisor->startPowerHintSession(std::move(tidList))) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 785 | ALOGW("Cannot start power hint session"); |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 786 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 789 | mBootStage = BootStage::FINISHED; |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 790 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 791 | if (base::GetBoolProperty("sf.debug.show_refresh_rate_overlay"s, false)) { |
| 792 | ftl::FakeGuard guard(mStateLock); |
| 793 | enableRefreshRateOverlay(true); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 794 | } |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 795 | })); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | } |
| 797 | |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 798 | void chooseRenderEngineType(renderengine::RenderEngineCreationArgs::Builder& builder) { |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 799 | char prop[PROPERTY_VALUE_MAX]; |
Leon Scroggins III | f840ae5 | 2024-01-25 15:10:12 -0500 | [diff] [blame] | 800 | property_get(PROPERTY_DEBUG_RENDERENGINE_BACKEND, prop, ""); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 801 | |
Nolan Scobie | 576e77f | 2024-03-26 10:59:59 -0400 | [diff] [blame] | 802 | // TODO: b/293371537 - Once GraphiteVk is deemed relatively stable, log a warning that |
| 803 | // PROPERTY_DEBUG_RENDERENGINE_BACKEND is deprecated |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 804 | if (strcmp(prop, "skiagl") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 805 | builder.setThreaded(renderengine::RenderEngine::Threaded::NO) |
| 806 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::GL); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 807 | } else if (strcmp(prop, "skiaglthreaded") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 808 | builder.setThreaded(renderengine::RenderEngine::Threaded::YES) |
| 809 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::GL); |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 810 | } else if (strcmp(prop, "skiavk") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 811 | builder.setThreaded(renderengine::RenderEngine::Threaded::NO) |
| 812 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::VK); |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 813 | } else if (strcmp(prop, "skiavkthreaded") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 814 | builder.setThreaded(renderengine::RenderEngine::Threaded::YES) |
| 815 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::VK); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 816 | } else { |
Leon Scroggins III | f3369ed | 2024-02-16 17:52:42 -0500 | [diff] [blame] | 817 | const auto kVulkan = renderengine::RenderEngine::GraphicsApi::VK; |
Nolan Scobie | 488101b | 2024-05-20 13:32:13 -0400 | [diff] [blame] | 818 | // TODO: b/341728634 - Clean up conditional compilation. |
| 819 | // Note: this guard in particular must check e.g. |
| 820 | // COM_ANDROID_GRAPHICS_SURFACEFLINGER_FLAGS_GRAPHITE_RENDERENGINE directly (instead of calling e.g. |
| 821 | // COM_ANDROID_GRAPHICS_SURFACEFLINGER_FLAGS(GRAPHITE_RENDERENGINE)) because that macro is undefined |
| 822 | // in the libsurfaceflingerflags_test variant of com_android_graphics_surfaceflinger_flags.h, which |
| 823 | // is used by layertracegenerator (which also needs SurfaceFlinger.cpp). :) |
| 824 | #if COM_ANDROID_GRAPHICS_SURFACEFLINGER_FLAGS_GRAPHITE_RENDERENGINE || \ |
| 825 | COM_ANDROID_GRAPHICS_SURFACEFLINGER_FLAGS_FORCE_COMPILE_GRAPHITE_RENDERENGINE |
Nolan Scobie | 2526b2f | 2024-04-16 15:12:22 -0400 | [diff] [blame] | 826 | const bool useGraphite = FlagManager::getInstance().graphite_renderengine() && |
| 827 | renderengine::RenderEngine::canSupport(kVulkan); |
Nolan Scobie | 488101b | 2024-05-20 13:32:13 -0400 | [diff] [blame] | 828 | #else |
| 829 | const bool useGraphite = false; |
| 830 | if (FlagManager::getInstance().graphite_renderengine()) { |
| 831 | ALOGE("RenderEngine's Graphite Skia backend was requested with the " |
| 832 | "debug.renderengine.graphite system property, but it is not compiled in this " |
| 833 | "build! Falling back to Ganesh backend selection logic."); |
| 834 | } |
| 835 | #endif |
Nolan Scobie | 576e77f | 2024-03-26 10:59:59 -0400 | [diff] [blame] | 836 | const bool useVulkan = useGraphite || |
Nolan Scobie | 2526b2f | 2024-04-16 15:12:22 -0400 | [diff] [blame] | 837 | (FlagManager::getInstance().vulkan_renderengine() && |
| 838 | renderengine::RenderEngine::canSupport(kVulkan)); |
Nolan Scobie | 576e77f | 2024-03-26 10:59:59 -0400 | [diff] [blame] | 839 | |
| 840 | builder.setSkiaBackend(useGraphite ? renderengine::RenderEngine::SkiaBackend::GRAPHITE |
| 841 | : renderengine::RenderEngine::SkiaBackend::GANESH); |
Leon Scroggins III | f3369ed | 2024-02-16 17:52:42 -0500 | [diff] [blame] | 842 | builder.setGraphicsApi(useVulkan ? kVulkan : renderengine::RenderEngine::GraphicsApi::GL); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 843 | } |
| 844 | } |
| 845 | |
Robin Lee | 7338bd9 | 2024-04-04 14:05:07 +0000 | [diff] [blame] | 846 | /** |
| 847 | * Choose a suggested blurring algorithm if supportsBlur is true. By default Kawase will be |
| 848 | * suggested as it's faster than a full Gaussian blur and looks close enough. |
| 849 | */ |
| 850 | renderengine::RenderEngine::BlurAlgorithm chooseBlurAlgorithm(bool supportsBlur) { |
| 851 | if (!supportsBlur) { |
| 852 | return renderengine::RenderEngine::BlurAlgorithm::NONE; |
| 853 | } |
| 854 | |
| 855 | auto const algorithm = base::GetProperty(PROPERTY_DEBUG_RENDERENGINE_BLUR_ALGORITHM, ""); |
| 856 | if (algorithm == "gaussian") { |
| 857 | return renderengine::RenderEngine::BlurAlgorithm::GAUSSIAN; |
Robin Lee | 2631520 | 2021-08-10 22:54:51 +0200 | [diff] [blame] | 858 | } else if (algorithm == "kawase2") { |
| 859 | return renderengine::RenderEngine::BlurAlgorithm::KAWASE_DUAL_FILTER; |
Robin Lee | 7338bd9 | 2024-04-04 14:05:07 +0000 | [diff] [blame] | 860 | } else { |
| 861 | return renderengine::RenderEngine::BlurAlgorithm::KAWASE; |
| 862 | } |
| 863 | } |
| 864 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 865 | void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 866 | SFTRACE_CALL(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 867 | ALOGI( "SurfaceFlinger's main thread ready to run. " |
| 868 | "Initializing graphics H/W..."); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 869 | addTransactionReadyFilters(); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 870 | Mutex::Autolock lock(mStateLock); |
Kevin DuBois | 413287f | 2019-02-25 08:46:47 -0800 | [diff] [blame] | 871 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 872 | // Get a RenderEngine for the given display / config (can't fail) |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 873 | // 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] | 874 | // Sending maxFrameBufferAcquiredBuffers as the cache size is tightly tuned to single-display. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 875 | auto builder = renderengine::RenderEngineCreationArgs::Builder() |
| 876 | .setPixelFormat(static_cast<int32_t>(defaultCompositionPixelFormat)) |
| 877 | .setImageCacheSize(maxFrameBufferAcquiredBuffers) |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 878 | .setEnableProtectedContext(enable_protected_contents(false)) |
| 879 | .setPrecacheToneMapperShaderOnly(false) |
Robin Lee | 7338bd9 | 2024-04-04 14:05:07 +0000 | [diff] [blame] | 880 | .setBlurAlgorithm(chooseBlurAlgorithm(mSupportsBlur)) |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 881 | .setContextPriority( |
| 882 | useContextPriority |
| 883 | ? renderengine::RenderEngine::ContextPriority::REALTIME |
| 884 | : renderengine::RenderEngine::ContextPriority::MEDIUM); |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 885 | chooseRenderEngineType(builder); |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 886 | mRenderEngine = renderengine::RenderEngine::create(builder.build()); |
| 887 | mCompositionEngine->setRenderEngine(mRenderEngine.get()); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 888 | mMaxRenderTargetSize = |
| 889 | std::min(getRenderEngine().getMaxTextureSize(), getRenderEngine().getMaxViewportDims()); |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 890 | |
| 891 | // Set SF main policy after initializing RenderEngine which has its own policy. |
| 892 | if (!SetTaskProfiles(0, {"SFMainPolicy"})) { |
| 893 | ALOGW("Failed to set main task profile"); |
| 894 | } |
| 895 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 896 | mCompositionEngine->setTimeStats(mTimeStats); |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 897 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 898 | mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName)); |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 899 | auto& composer = mCompositionEngine->getHwComposer(); |
| 900 | composer.setCallback(*this); |
| 901 | mDisplayModeController.setHwComposer(&composer); |
| 902 | |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 903 | ClientCache::getInstance().setRenderEngine(&getRenderEngine()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 904 | |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 905 | mHasReliablePresentFences = |
| 906 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE); |
| 907 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 908 | enableLatchUnsignaledConfig = getLatchUnsignaledConfig(); |
| 909 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 910 | if (base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false)) { |
| 911 | enableHalVirtualDisplays(true); |
| 912 | } |
| 913 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 914 | // Process hotplug for displays connected at boot. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 915 | LOG_ALWAYS_FATAL_IF(!configureLocked(), |
| 916 | "Initial display configuration failed: HWC did not hotplug"); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 917 | |
Dominik Laskowski | a0858db | 2024-07-23 16:45:11 -0400 | [diff] [blame] | 918 | mActiveDisplayId = getPrimaryDisplayIdLocked(); |
| 919 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 920 | // Commit primary display. |
| 921 | sp<const DisplayDevice> display; |
Dominik Laskowski | a0858db | 2024-07-23 16:45:11 -0400 | [diff] [blame] | 922 | if (const auto indexOpt = mCurrentState.getDisplayIndex(mActiveDisplayId)) { |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 923 | const auto& displays = mCurrentState.displays; |
| 924 | |
| 925 | const auto& token = displays.keyAt(*indexOpt); |
| 926 | const auto& state = displays.valueAt(*indexOpt); |
| 927 | |
| 928 | processDisplayAdded(token, state); |
| 929 | mDrawingState.displays.add(token, state); |
| 930 | |
| 931 | display = getDefaultDisplayDeviceLocked(); |
| 932 | } |
| 933 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 934 | LOG_ALWAYS_FATAL_IF(!display, "Failed to configure the primary display"); |
| 935 | LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(display->getPhysicalId()), |
| 936 | "Primary display is disconnected"); |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 937 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 938 | // TODO(b/241285876): The Scheduler needlessly depends on creating the CompositionEngine part of |
| 939 | // the DisplayDevice, hence the above commit of the primary display. Remove that special case by |
| 940 | // initializing the Scheduler after configureLocked, once decoupled from DisplayDevice. |
| 941 | initScheduler(display); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 942 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 943 | // Start listening after creating the Scheduler, since the listener calls into it. |
| 944 | mDisplayModeController.setActiveModeListener( |
| 945 | display::DisplayModeController::ActiveModeListener::make( |
| 946 | [this](PhysicalDisplayId displayId, Fps vsyncRate, Fps renderRate) { |
| 947 | // This callback cannot lock mStateLock, as some callers already lock it. |
| 948 | // Instead, switch context to the main thread. |
| 949 | static_cast<void>(mScheduler->schedule([=, |
| 950 | this]() FTL_FAKE_GUARD(mStateLock) { |
| 951 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 952 | display->updateRefreshRateOverlayRate(vsyncRate, renderRate); |
| 953 | } |
| 954 | })); |
| 955 | })); |
| 956 | |
Kean Mariotti | fc0cd25 | 2023-12-07 09:27:40 +0000 | [diff] [blame] | 957 | mLayerTracing.setTakeLayersSnapshotProtoFunction( |
| 958 | [&](uint32_t traceFlags, |
| 959 | const LayerTracing::OnLayersSnapshotCallback& onLayersSnapshot) { |
| 960 | // Do not wait the future to avoid deadlocks |
| 961 | // between main and Perfetto threads (b/313130597) |
| 962 | static_cast<void>(mScheduler->schedule( |
Kean Mariotti | dfb122d | 2024-09-30 09:16:40 +0000 | [diff] [blame] | 963 | [&, traceFlags, onLayersSnapshot]() FTL_FAKE_GUARD(mStateLock) |
Kean Mariotti | fc0cd25 | 2023-12-07 09:27:40 +0000 | [diff] [blame] | 964 | FTL_FAKE_GUARD(kMainThreadContext) { |
| 965 | auto snapshot = |
| 966 | takeLayersSnapshotProto(traceFlags, TimePoint::now(), |
| 967 | mLastCommittedVsyncId, true); |
| 968 | onLayersSnapshot(std::move(snapshot)); |
| 969 | })); |
| 970 | }); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 971 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 972 | // Commit secondary display(s). |
| 973 | processDisplayChangesLocked(); |
| 974 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 975 | // initialize our drawing state |
| 976 | mDrawingState = mCurrentState; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 977 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 978 | onActiveDisplayChangedLocked(nullptr, *display); |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 979 | |
| 980 | static_cast<void>(mScheduler->schedule( |
| 981 | [this]() FTL_FAKE_GUARD(kMainThreadContext) { initializeDisplays(); })); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 982 | |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 983 | mPowerAdvisor->init(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 984 | |
Bruno BELANYI | fd02878 | 2023-10-13 14:39:53 +0000 | [diff] [blame] | 985 | if (base::GetBoolProperty("service.sf.prime_shader_cache"s, true)) { |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 986 | if (setSchedFifo(false) != NO_ERROR) { |
| 987 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 988 | } |
| 989 | |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 990 | mRenderEnginePrimeCacheFuture.callOnce([this] { |
Russell Myers | 3348c74 | 2024-04-29 20:22:42 +0000 | [diff] [blame] | 991 | renderengine::PrimeCacheConfig config; |
| 992 | config.cacheHolePunchLayer = |
| 993 | base::GetBoolProperty("debug.sf.prime_shader_cache.hole_punch"s, true); |
| 994 | config.cacheSolidLayers = |
| 995 | base::GetBoolProperty("debug.sf.prime_shader_cache.solid_layers"s, true); |
| 996 | config.cacheSolidDimmedLayers = |
| 997 | base::GetBoolProperty("debug.sf.prime_shader_cache.solid_dimmed_layers"s, true); |
| 998 | config.cacheImageLayers = |
| 999 | base::GetBoolProperty("debug.sf.prime_shader_cache.image_layers"s, true); |
| 1000 | config.cacheImageDimmedLayers = |
| 1001 | base::GetBoolProperty("debug.sf.prime_shader_cache.image_dimmed_layers"s, true); |
| 1002 | config.cacheClippedLayers = |
| 1003 | base::GetBoolProperty("debug.sf.prime_shader_cache.clipped_layers"s, true); |
| 1004 | config.cacheShadowLayers = |
| 1005 | base::GetBoolProperty("debug.sf.prime_shader_cache.shadow_layers"s, true); |
| 1006 | config.cachePIPImageLayers = |
| 1007 | base::GetBoolProperty("debug.sf.prime_shader_cache.pip_image_layers"s, true); |
| 1008 | config.cacheTransparentImageDimmedLayers = base:: |
| 1009 | GetBoolProperty("debug.sf.prime_shader_cache.transparent_image_dimmed_layers"s, |
| 1010 | true); |
| 1011 | config.cacheClippedDimmedImageLayers = base:: |
| 1012 | GetBoolProperty("debug.sf.prime_shader_cache.clipped_dimmed_image_layers"s, |
| 1013 | true); |
| 1014 | // ro.surface_flinger.prime_chader_cache.ultrahdr exists as a previous ro property |
| 1015 | // which we maintain for backwards compatibility. |
| 1016 | config.cacheUltraHDR = |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 1017 | base::GetBoolProperty("ro.surface_flinger.prime_shader_cache.ultrahdr"s, false); |
Marzia Favaro | 7354b39 | 2024-07-05 15:46:12 +0000 | [diff] [blame] | 1018 | config.cacheEdgeExtension = |
Marzia Favaro | c8437a5 | 2024-10-30 17:11:21 +0000 | [diff] [blame] | 1019 | base::GetBoolProperty("debug.sf.prime_shader_cache.edge_extension_shader"s, |
| 1020 | true); |
Russell Myers | 3348c74 | 2024-04-29 20:22:42 +0000 | [diff] [blame] | 1021 | return getRenderEngine().primeCache(config); |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 1022 | }); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 1023 | |
| 1024 | if (setSchedFifo(true) != NO_ERROR) { |
linkai | d696a4f | 2023-11-14 10:13:36 +0800 | [diff] [blame] | 1025 | ALOGW("Can't set SCHED_FIFO after primeCache"); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 1026 | } |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 1027 | } |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 1028 | |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 1029 | // Avoid blocking the main thread on `init` to set properties. |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 1030 | mInitBootPropsFuture.callOnce([this] { |
| 1031 | return std::async(std::launch::async, &SurfaceFlinger::initBootProperties, this); |
| 1032 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 1034 | initTransactionTraceWriter(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1035 | ALOGV("Done initializing"); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 1038 | // During boot, offload `initBootProperties` to another thread. `property_set` depends on |
| 1039 | // `property_service`, which may be delayed by slow operations like `mount_all --late` in |
| 1040 | // the `init` process. See b/34499826 and b/63844978. |
| 1041 | void SurfaceFlinger::initBootProperties() { |
| 1042 | property_set("service.sf.present_timestamp", mHasReliablePresentFences ? "1" : "0"); |
| 1043 | |
Dominik Laskowski | b0fdfe7 | 2024-02-21 10:42:23 -0500 | [diff] [blame] | 1044 | if (base::GetBoolProperty("debug.sf.boot_animation"s, true)) { |
| 1045 | // Reset and (if needed) start BootAnimation. |
| 1046 | property_set("service.bootanim.exit", "0"); |
| 1047 | property_set("service.bootanim.progress", "0"); |
| 1048 | property_set("ctl.start", "bootanim"); |
| 1049 | } |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 1050 | } |
| 1051 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 1052 | void SurfaceFlinger::initTransactionTraceWriter() { |
| 1053 | if (!mTransactionTracing) { |
| 1054 | return; |
| 1055 | } |
| 1056 | TransactionTraceWriter::getInstance().setWriterFunction( |
| 1057 | [&](const std::string& filename, bool overwrite) { |
| 1058 | auto writeFn = [&]() { |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 1059 | if (!overwrite && fileNewerThan(filename, std::chrono::minutes{10})) { |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 1060 | ALOGD("TransactionTraceWriter: file=%s already exists", filename.c_str()); |
| 1061 | return; |
| 1062 | } |
Wenhui Yang | eafc18a | 2024-05-14 17:15:52 +0000 | [diff] [blame] | 1063 | ALOGD("TransactionTraceWriter: writing file=%s", filename.c_str()); |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 1064 | mTransactionTracing->writeToFile(filename); |
Wenhui Yang | eafc18a | 2024-05-14 17:15:52 +0000 | [diff] [blame] | 1065 | mTransactionTracing->flush(); |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 1066 | }; |
| 1067 | if (std::this_thread::get_id() == mMainThreadId) { |
| 1068 | writeFn(); |
| 1069 | } else { |
| 1070 | mScheduler->schedule(writeFn).get(); |
| 1071 | } |
| 1072 | }); |
| 1073 | } |
| 1074 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 1075 | void SurfaceFlinger::readPersistentProperties() { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 1076 | Mutex::Autolock _l(mStateLock); |
| 1077 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 1078 | char value[PROPERTY_VALUE_MAX]; |
| 1079 | |
| 1080 | property_get("persist.sys.sf.color_saturation", value, "1.0"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 1081 | mGlobalSaturationFactor = atof(value); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 1082 | updateColorMatrixLocked(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 1083 | ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 1084 | |
| 1085 | property_get("persist.sys.sf.native_mode", value, "0"); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 1086 | mDisplayColorSetting = static_cast<DisplayColorSetting>(atoi(value)); |
Peiyong Lin | a3ea559 | 2019-02-10 14:45:00 -0800 | [diff] [blame] | 1087 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1088 | mForceColorMode = |
| 1089 | 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] | 1090 | } |
| 1091 | |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 1092 | status_t SurfaceFlinger::getSupportedFrameTimestamps( |
| 1093 | std::vector<FrameEvent>* outSupported) const { |
| 1094 | *outSupported = { |
| 1095 | FrameEvent::REQUESTED_PRESENT, |
| 1096 | FrameEvent::ACQUIRE, |
| 1097 | FrameEvent::LATCH, |
| 1098 | FrameEvent::FIRST_REFRESH_START, |
| 1099 | FrameEvent::LAST_REFRESH_START, |
| 1100 | FrameEvent::GPU_COMPOSITION_DONE, |
| 1101 | FrameEvent::DEQUEUE_READY, |
| 1102 | FrameEvent::RELEASE, |
| 1103 | }; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1104 | |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 1105 | if (mHasReliablePresentFences) { |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 1106 | outSupported->push_back(FrameEvent::DISPLAY_PRESENT); |
| 1107 | } |
| 1108 | return NO_ERROR; |
| 1109 | } |
| 1110 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1111 | status_t SurfaceFlinger::getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState* state) { |
| 1112 | if (!displayToken || !state) { |
| 1113 | return BAD_VALUE; |
| 1114 | } |
| 1115 | |
| 1116 | Mutex::Autolock lock(mStateLock); |
| 1117 | |
| 1118 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1119 | if (!display) { |
| 1120 | return NAME_NOT_FOUND; |
| 1121 | } |
| 1122 | |
| 1123 | state->layerStack = display->getLayerStack(); |
| 1124 | state->orientation = display->getOrientation(); |
| 1125 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 1126 | const Rect layerStackRect = display->getLayerStackSpaceRect(); |
| 1127 | state->layerStackSpaceRect = |
| 1128 | layerStackRect.isValid() ? layerStackRect.getSize() : display->getSize(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1129 | |
| 1130 | return NO_ERROR; |
| 1131 | } |
| 1132 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1133 | status_t SurfaceFlinger::getStaticDisplayInfo(int64_t displayId, ui::StaticDisplayInfo* info) { |
| 1134 | if (!info) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1135 | return BAD_VALUE; |
| 1136 | } |
| 1137 | |
| 1138 | Mutex::Autolock lock(mStateLock); |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1139 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 1140 | const auto displayOpt = mPhysicalDisplays.get(*id).and_then(getDisplayDeviceAndSnapshot()); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1141 | |
| 1142 | if (!displayOpt) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1143 | return NAME_NOT_FOUND; |
| 1144 | } |
| 1145 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1146 | const auto& [display, snapshotRef] = *displayOpt; |
| 1147 | const auto& snapshot = snapshotRef.get(); |
| 1148 | |
| 1149 | info->connectionType = snapshot.connectionType(); |
| 1150 | info->deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1151 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1152 | if (mEmulatedDisplayDensity) { |
| 1153 | info->density = mEmulatedDisplayDensity; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1154 | } else { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1155 | info->density = info->connectionType == ui::DisplayConnectionType::Internal |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1156 | ? mInternalDisplayDensity |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1157 | : FALLBACK_DENSITY; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1158 | } |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 1159 | info->density /= ACONFIGURATION_DENSITY_MEDIUM; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1160 | |
| 1161 | info->secure = display->isSecure(); |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1162 | info->installOrientation = display->getPhysicalOrientation(); |
Vishnu Nair | d0a8965 | 2022-01-13 12:05:54 -0800 | [diff] [blame] | 1163 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1164 | return NO_ERROR; |
| 1165 | } |
| 1166 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1167 | void SurfaceFlinger::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo*& info, |
| 1168 | const sp<DisplayDevice>& display, |
| 1169 | const display::DisplaySnapshot& snapshot) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1170 | const auto& displayModes = snapshot.displayModes(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1171 | info->supportedDisplayModes.clear(); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1172 | info->supportedDisplayModes.reserve(displayModes.size()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1173 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1174 | for (const auto& [id, mode] : displayModes) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1175 | ui::DisplayMode outMode; |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1176 | outMode.id = ftl::to_underlying(id); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1177 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1178 | auto [width, height] = mode->getResolution(); |
| 1179 | auto [xDpi, yDpi] = mode->getDpi(); |
Yiwei Zhang | 27de5df | 2018-08-23 17:04:51 -0700 | [diff] [blame] | 1180 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1181 | if (const auto physicalOrientation = display->getPhysicalOrientation(); |
| 1182 | physicalOrientation == ui::ROTATION_90 || physicalOrientation == ui::ROTATION_270) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1183 | std::swap(width, height); |
| 1184 | std::swap(xDpi, yDpi); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1187 | outMode.resolution = ui::Size(width, height); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1188 | |
Huan Song | f7eeb10 | 2022-03-28 11:02:38 -0700 | [diff] [blame] | 1189 | outMode.xDpi = xDpi; |
| 1190 | outMode.yDpi = yDpi; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1191 | |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1192 | const auto peakFps = mode->getPeakFps(); |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 1193 | outMode.peakRefreshRate = peakFps.getValue(); |
Alec Mouri | d122a1c | 2023-09-30 01:36:33 +0000 | [diff] [blame] | 1194 | outMode.vsyncRate = mode->getVsyncRate().getValue(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1195 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1196 | const auto vsyncConfigSet = mScheduler->getVsyncConfiguration().getConfigsForRefreshRate( |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 1197 | Fps::fromValue(outMode.peakRefreshRate)); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1198 | outMode.appVsyncOffset = vsyncConfigSet.late.appOffset; |
| 1199 | outMode.sfVsyncOffset = vsyncConfigSet.late.sfOffset; |
| 1200 | outMode.group = mode->getGroup(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1201 | |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1202 | // This is how far in advance a buffer must be queued for |
| 1203 | // presentation at a given time. If you want a buffer to appear |
| 1204 | // on the screen at time N, you must submit the buffer before |
| 1205 | // (N - presentationDeadline). |
| 1206 | // |
| 1207 | // Normally it's one full refresh period (to give SF a chance to |
| 1208 | // latch the buffer), but this can be reduced by configuring a |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 1209 | // VsyncController offset. Any additional delays introduced by the hardware |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1210 | // composer or panel must be accounted for here. |
| 1211 | // |
| 1212 | // We add an additional 1ms to allow for processing time and |
| 1213 | // differences between the ideal and actual refresh rate. |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1214 | outMode.presentationDeadline = peakFps.getPeriodNsecs() - outMode.sfVsyncOffset + 1000000; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1215 | excludeDolbyVisionIf4k30Present(display->getHdrCapabilities().getSupportedHdrTypes(), |
| 1216 | outMode); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1217 | info->supportedDisplayModes.push_back(outMode); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1220 | info->supportedColorModes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1221 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1222 | const PhysicalDisplayId displayId = snapshot.displayId(); |
| 1223 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1224 | const auto mode = display->refreshRateSelector().getActiveMode(); |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1225 | info->activeDisplayModeId = ftl::to_underlying(mode.modePtr->getId()); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1226 | info->renderFrameRate = mode.fps.getValue(); |
ramindani | 89fbb6e | 2024-09-26 11:30:24 -0700 | [diff] [blame] | 1227 | info->hasArrSupport = mode.modePtr->getVrrConfig() && FlagManager::getInstance().vrr_config(); |
ramindani | d2a0e72 | 2024-10-18 15:25:20 -0700 | [diff] [blame] | 1228 | |
| 1229 | const auto [normal, high] = display->refreshRateSelector().getFrameRateCategoryRates(); |
| 1230 | ui::FrameRateCategoryRate frameRateCategoryRate(normal.getValue(), high.getValue()); |
| 1231 | info->frameRateCategoryRate = frameRateCategoryRate; |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1232 | info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1233 | info->hdrCapabilities = filterOut4k30(display->getHdrCapabilities()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1234 | |
Marin Shalamanov | b173f75 | 2021-02-16 19:38:36 +0100 | [diff] [blame] | 1235 | info->autoLowLatencyModeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1236 | getHwComposer().hasDisplayCapability(displayId, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1237 | DisplayCapability::AUTO_LOW_LATENCY_MODE); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1238 | info->gameContentTypeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1239 | getHwComposer().supportsContentType(displayId, hal::ContentType::GAME); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1240 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1241 | info->preferredBootDisplayMode = static_cast<ui::DisplayModeId>(-1); |
Kriti Dang | ac0a74d | 2022-03-16 11:52:35 +0100 | [diff] [blame] | 1242 | |
| 1243 | if (getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG)) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1244 | if (const auto hwcId = getHwComposer().getPreferredBootDisplayMode(displayId)) { |
| 1245 | if (const auto modeId = snapshot.translateModeId(*hwcId)) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1246 | info->preferredBootDisplayMode = ftl::to_underlying(*modeId); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1247 | } |
| 1248 | } |
| 1249 | } |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1250 | } |
Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame] | 1251 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1252 | status_t SurfaceFlinger::getDynamicDisplayInfoFromId(int64_t physicalDisplayId, |
| 1253 | ui::DynamicDisplayInfo* info) { |
| 1254 | if (!info) { |
| 1255 | return BAD_VALUE; |
| 1256 | } |
| 1257 | |
| 1258 | Mutex::Autolock lock(mStateLock); |
| 1259 | |
| 1260 | const auto id_ = |
| 1261 | DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(physicalDisplayId)); |
| 1262 | const auto displayOpt = mPhysicalDisplays.get(*id_).and_then(getDisplayDeviceAndSnapshot()); |
| 1263 | |
| 1264 | if (!displayOpt) { |
| 1265 | return NAME_NOT_FOUND; |
| 1266 | } |
| 1267 | |
| 1268 | const auto& [display, snapshotRef] = *displayOpt; |
| 1269 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
| 1270 | return NO_ERROR; |
| 1271 | } |
| 1272 | |
| 1273 | status_t SurfaceFlinger::getDynamicDisplayInfoFromToken(const sp<IBinder>& displayToken, |
| 1274 | ui::DynamicDisplayInfo* info) { |
| 1275 | if (!displayToken || !info) { |
| 1276 | return BAD_VALUE; |
| 1277 | } |
| 1278 | |
| 1279 | Mutex::Autolock lock(mStateLock); |
| 1280 | |
| 1281 | const auto displayOpt = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1282 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1283 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1284 | |
| 1285 | if (!displayOpt) { |
| 1286 | return NAME_NOT_FOUND; |
| 1287 | } |
| 1288 | |
| 1289 | const auto& [display, snapshotRef] = *displayOpt; |
| 1290 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1291 | return NO_ERROR; |
| 1292 | } |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 1293 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1294 | status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>& displayToken, |
| 1295 | DisplayStatInfo* outStats) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1296 | if (!outStats) { |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1297 | return BAD_VALUE; |
| 1298 | } |
| 1299 | |
Dominik Laskowski | cfaaceb | 2024-08-04 16:02:58 -0400 | [diff] [blame] | 1300 | // TODO: b/277364366 - Require a display token from clients and remove fallback to pacesetter. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1301 | std::optional<PhysicalDisplayId> displayIdOpt; |
Dominik Laskowski | cfaaceb | 2024-08-04 16:02:58 -0400 | [diff] [blame] | 1302 | if (displayToken) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1303 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | cfaaceb | 2024-08-04 16:02:58 -0400 | [diff] [blame] | 1304 | displayIdOpt = getPhysicalDisplayIdLocked(displayToken); |
| 1305 | if (!displayIdOpt) { |
| 1306 | ALOGW("%s: Invalid physical display token %p", __func__, displayToken.get()); |
| 1307 | return NAME_NOT_FOUND; |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1308 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1309 | } |
| 1310 | |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1311 | const auto schedule = mScheduler->getVsyncSchedule(displayIdOpt); |
| 1312 | if (!schedule) { |
| 1313 | ALOGE("%s: Missing VSYNC schedule for display %s!", __func__, |
| 1314 | to_string(*displayIdOpt).c_str()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1315 | return NAME_NOT_FOUND; |
| 1316 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1317 | outStats->vsyncTime = schedule->vsyncDeadlineAfter(TimePoint::now()).ns(); |
| 1318 | outStats->vsyncPeriod = schedule->period().ns(); |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1319 | return NO_ERROR; |
| 1320 | } |
| 1321 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1322 | void SurfaceFlinger::setDesiredMode(display::DisplayModeRequest&& desiredMode) { |
| 1323 | const auto mode = desiredMode.mode; |
| 1324 | const auto displayId = mode.modePtr->getPhysicalDisplayId(); |
| 1325 | |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1326 | SFTRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1327 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1328 | const bool emitEvent = desiredMode.emitEvent; |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 1329 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1330 | using DesiredModeAction = display::DisplayModeController::DesiredModeAction; |
| 1331 | |
| 1332 | switch (mDisplayModeController.setDesiredMode(displayId, std::move(desiredMode))) { |
| 1333 | case DesiredModeAction::InitiateDisplayModeSwitch: { |
| 1334 | const auto selectorPtr = mDisplayModeController.selectorPtrFor(displayId); |
| 1335 | if (!selectorPtr) break; |
| 1336 | |
| 1337 | const Fps renderRate = selectorPtr->getActiveMode().fps; |
| 1338 | |
| 1339 | // DisplayModeController::setDesiredMode updated the render rate, so inform Scheduler. |
| 1340 | mScheduler->setRenderRate(displayId, renderRate, true /* applyImmediately */); |
Ady Abraham | 95a37e2 | 2023-01-18 22:57:28 -0800 | [diff] [blame] | 1341 | |
| 1342 | // Schedule a new frame to initiate the display mode switch. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1343 | scheduleComposite(FrameHint::kNone); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1344 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1345 | // Start receiving vsync samples now, so that we can detect a period |
| 1346 | // switch. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1347 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 1348 | mode.modePtr.get()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1349 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1350 | // As we called to set period, we will call to onRefreshRateChangeCompleted once |
| 1351 | // VsyncController model is locked. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1352 | mScheduler->modulateVsync(displayId, &VsyncModulator::onRefreshRateChangeInitiated); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1353 | |
Dominik Laskowski | e37c04e | 2024-08-04 15:48:00 -0400 | [diff] [blame] | 1354 | mScheduler->updatePhaseConfiguration(displayId, mode.fps); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1355 | mScheduler->setModeChangePending(true); |
| 1356 | break; |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1357 | } |
| 1358 | case DesiredModeAction::InitiateRenderRateSwitch: |
Ady Abraham | ee6365b | 2024-03-06 14:31:45 -0800 | [diff] [blame] | 1359 | mScheduler->setRenderRate(displayId, mode.fps, /*applyImmediately*/ false); |
Dominik Laskowski | e37c04e | 2024-08-04 15:48:00 -0400 | [diff] [blame] | 1360 | mScheduler->updatePhaseConfiguration(displayId, mode.fps); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1361 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1362 | if (emitEvent) { |
Ady Abraham | fc48edc | 2024-11-05 19:29:49 -0800 | [diff] [blame] | 1363 | mScheduler->onDisplayModeChanged(displayId, mode, |
| 1364 | /*clearContentRequirements*/ false); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1365 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1366 | break; |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1367 | case DesiredModeAction::None: |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1368 | break; |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1369 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1370 | } |
| 1371 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1372 | status_t SurfaceFlinger::setActiveModeFromBackdoor(const sp<display::DisplayToken>& displayToken, |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1373 | DisplayModeId modeId, Fps minFps, Fps maxFps) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1374 | SFTRACE_CALL(); |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1375 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 1376 | if (!displayToken) { |
| 1377 | return BAD_VALUE; |
| 1378 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1379 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1380 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1381 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1382 | const auto displayOpt = |
| 1383 | FTL_FAKE_GUARD(mStateLock, |
| 1384 | ftl::find_if(mPhysicalDisplays, |
| 1385 | PhysicalDisplay::hasToken(displayToken)) |
| 1386 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1387 | .and_then(getDisplayDeviceAndSnapshot())); |
| 1388 | if (!displayOpt) { |
| 1389 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1390 | return NAME_NOT_FOUND; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1391 | } |
| 1392 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1393 | const auto& [display, snapshotRef] = *displayOpt; |
| 1394 | const auto& snapshot = snapshotRef.get(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1395 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1396 | const auto fpsOpt = snapshot.displayModes().get(modeId).transform( |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1397 | [](const DisplayModePtr& mode) { return mode->getPeakFps(); }); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1398 | |
| 1399 | if (!fpsOpt) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1400 | 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] | 1401 | to_string(snapshot.displayId()).c_str()); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1402 | return BAD_VALUE; |
| 1403 | } |
| 1404 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1405 | const Fps fps = *fpsOpt; |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1406 | const FpsRange physical = {fps, fps}; |
| 1407 | const FpsRange render = {minFps.isValid() ? minFps : fps, maxFps.isValid() ? maxFps : fps}; |
| 1408 | const FpsRanges ranges = {physical, render}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1409 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1410 | // Keep the old switching type. |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1411 | const bool allowGroupSwitching = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1412 | display->refreshRateSelector().getCurrentPolicy().allowGroupSwitching; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1413 | |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1414 | const scheduler::RefreshRateSelector::DisplayManagerPolicy policy{modeId, ranges, ranges, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 1415 | allowGroupSwitching}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1416 | |
| 1417 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1418 | }); |
| 1419 | |
| 1420 | return future.get(); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1421 | } |
| 1422 | |
Dominik Laskowski | b2fc423 | 2024-07-15 08:24:49 -0400 | [diff] [blame] | 1423 | // TODO: b/241285876 - Restore thread safety analysis once mStateLock below is unconditional. |
| 1424 | [[clang::no_thread_safety_analysis]] |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1425 | void SurfaceFlinger::finalizeDisplayModeChange(PhysicalDisplayId displayId) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1426 | SFTRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1427 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1428 | const auto pendingModeOpt = mDisplayModeController.getPendingMode(displayId); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1429 | if (!pendingModeOpt) { |
| 1430 | // There is no pending mode change. This can happen if the active |
| 1431 | // display changed and the mode change happened on a different display. |
| 1432 | return; |
| 1433 | } |
Ady Abraham | faac6da | 2021-07-15 10:04:40 -0700 | [diff] [blame] | 1434 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1435 | const auto& activeMode = pendingModeOpt->mode; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1436 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1437 | if (const auto oldResolution = |
| 1438 | mDisplayModeController.getActiveMode(displayId).modePtr->getResolution(); |
| 1439 | oldResolution != activeMode.modePtr->getResolution()) { |
Dominik Laskowski | b2fc423 | 2024-07-15 08:24:49 -0400 | [diff] [blame] | 1440 | ConditionalLock lock(mStateLock, !FlagManager::getInstance().connected_display()); |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1441 | |
| 1442 | auto& state = mCurrentState.displays.editValueFor(getPhysicalDisplayTokenLocked(displayId)); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1443 | // We need to generate new sequenceId in order to recreate the display (and this |
| 1444 | // way the framebuffer). |
| 1445 | state.sequenceId = DisplayDeviceState{}.sequenceId; |
| 1446 | state.physical->activeMode = activeMode.modePtr.get(); |
| 1447 | processDisplayChangesLocked(); |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1448 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1449 | // processDisplayChangesLocked will update all necessary components so we're done here. |
| 1450 | return; |
| 1451 | } |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 1452 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1453 | mDisplayModeController.finalizeModeChange(displayId, activeMode.modePtr->getId(), |
| 1454 | activeMode.modePtr->getVsyncRate(), activeMode.fps); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1455 | |
Dominik Laskowski | e37c04e | 2024-08-04 15:48:00 -0400 | [diff] [blame] | 1456 | mScheduler->updatePhaseConfiguration(displayId, activeMode.fps); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1457 | |
| 1458 | if (pendingModeOpt->emitEvent) { |
Ady Abraham | fc48edc | 2024-11-05 19:29:49 -0800 | [diff] [blame] | 1459 | mScheduler->onDisplayModeChanged(displayId, activeMode, /*clearContentRequirements*/ true); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1460 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1461 | } |
| 1462 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1463 | void SurfaceFlinger::dropModeRequest(PhysicalDisplayId displayId) { |
| 1464 | mDisplayModeController.clearDesiredMode(displayId); |
| 1465 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1466 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1467 | mScheduler->setModeChangePending(false); |
| 1468 | } |
Ady Abraham | 53852a5 | 2019-05-28 18:07:44 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1471 | void SurfaceFlinger::applyActiveMode(PhysicalDisplayId displayId) { |
| 1472 | const auto activeModeOpt = mDisplayModeController.getDesiredMode(displayId); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1473 | auto activeModePtr = activeModeOpt->mode.modePtr; |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1474 | const auto renderFps = activeModeOpt->mode.fps; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1475 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1476 | dropModeRequest(displayId); |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1477 | |
| 1478 | constexpr bool kAllowToEnable = true; |
| 1479 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, std::move(activeModePtr).take()); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1480 | |
Dominik Laskowski | e37c04e | 2024-08-04 15:48:00 -0400 | [diff] [blame] | 1481 | mScheduler->setRenderRate(displayId, renderFps, /*applyImmediately*/ true); |
| 1482 | mScheduler->updatePhaseConfiguration(displayId, renderFps); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1483 | } |
| 1484 | |
Ady Abraham | 0b10360 | 2024-05-21 20:37:49 +0000 | [diff] [blame] | 1485 | void SurfaceFlinger::initiateDisplayModeChanges() { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1486 | SFTRACE_CALL(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1487 | |
Dominik Laskowski | b2fc423 | 2024-07-15 08:24:49 -0400 | [diff] [blame] | 1488 | for (const auto& [displayId, physical] : mPhysicalDisplays) { |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1489 | auto desiredModeOpt = mDisplayModeController.getDesiredMode(displayId); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1490 | if (!desiredModeOpt) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1491 | continue; |
| 1492 | } |
| 1493 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1494 | const auto desiredModeId = desiredModeOpt->mode.modePtr->getId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1495 | const auto displayModePtrOpt = physical.snapshot().displayModes().get(desiredModeId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1496 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1497 | if (!displayModePtrOpt) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1498 | ALOGW("Desired display mode is no longer supported. Mode ID = %d", |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1499 | ftl::to_underlying(desiredModeId)); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1500 | continue; |
| 1501 | } |
| 1502 | |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1503 | ALOGV("%s changing active mode to %d(%s) for display %s", __func__, |
| 1504 | ftl::to_underlying(desiredModeId), |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1505 | to_string(displayModePtrOpt->get()->getVsyncRate()).c_str(), |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1506 | to_string(displayId).c_str()); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1507 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1508 | if ((!FlagManager::getInstance().connected_display() || !desiredModeOpt->force) && |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1509 | mDisplayModeController.getActiveMode(displayId) == desiredModeOpt->mode) { |
| 1510 | applyActiveMode(displayId); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1511 | continue; |
| 1512 | } |
| 1513 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1514 | const auto selectorPtr = mDisplayModeController.selectorPtrFor(displayId); |
| 1515 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1516 | // Desired active mode was set, it is different than the mode currently in use, however |
| 1517 | // allowed modes might have changed by the time we process the refresh. |
| 1518 | // Make sure the desired mode is still allowed |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1519 | if (!selectorPtr->isModeAllowed(desiredModeOpt->mode)) { |
| 1520 | dropModeRequest(displayId); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1521 | continue; |
| 1522 | } |
| 1523 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1524 | // TODO(b/142753666) use constrains |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1525 | hal::VsyncPeriodChangeConstraints constraints; |
| 1526 | constraints.desiredTimeNanos = systemTime(); |
| 1527 | constraints.seamlessRequired = false; |
| 1528 | hal::VsyncPeriodChangeTimeline outTimeline; |
| 1529 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1530 | if (!mDisplayModeController.initiateModeChange(displayId, std::move(*desiredModeOpt), |
| 1531 | constraints, outTimeline)) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1532 | continue; |
| 1533 | } |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1534 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 1535 | selectorPtr->onModeChangeInitiated(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1536 | mScheduler->onNewVsyncPeriodChangeTimeline(outTimeline); |
| 1537 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1538 | if (outTimeline.refreshRequired) { |
Ady Abraham | 0b10360 | 2024-05-21 20:37:49 +0000 | [diff] [blame] | 1539 | scheduleComposite(FrameHint::kNone); |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1540 | } else { |
Dominik Laskowski | 92900f8 | 2024-06-25 11:50:43 -0400 | [diff] [blame] | 1541 | // HWC has requested to apply the mode change immediately rather than on the next frame. |
| 1542 | finalizeDisplayModeChange(displayId); |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1543 | |
Dominik Laskowski | 92900f8 | 2024-06-25 11:50:43 -0400 | [diff] [blame] | 1544 | const auto desiredModeOpt = mDisplayModeController.getDesiredMode(displayId); |
| 1545 | if (desiredModeOpt && |
| 1546 | mDisplayModeController.getActiveMode(displayId) == desiredModeOpt->mode) { |
| 1547 | applyActiveMode(displayId); |
| 1548 | } |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1549 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1550 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1551 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1552 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1553 | void SurfaceFlinger::disableExpensiveRendering() { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1554 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1555 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1556 | SFTRACE_NAME(whence); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1557 | if (mPowerAdvisor->isUsingExpensiveRendering()) { |
Dominik Laskowski | bc6c860 | 2022-01-11 08:53:24 -0800 | [diff] [blame] | 1558 | for (const auto& [_, display] : mDisplays) { |
| 1559 | constexpr bool kDisable = false; |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1560 | mPowerAdvisor->setExpensiveRenderingExpected(display->getId(), kDisable); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1561 | } |
| 1562 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1563 | }); |
| 1564 | |
| 1565 | future.wait(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1568 | status_t SurfaceFlinger::getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1569 | ui::DisplayPrimaries& primaries) { |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1570 | if (!displayToken) { |
| 1571 | return BAD_VALUE; |
| 1572 | } |
| 1573 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1574 | Mutex::Autolock lock(mStateLock); |
| 1575 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1576 | const auto display = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1577 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>); |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1578 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1579 | return NAME_NOT_FOUND; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1580 | } |
| 1581 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1582 | if (!display.transform(&PhysicalDisplay::isInternal).value()) { |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1583 | return INVALID_OPERATION; |
| 1584 | } |
| 1585 | |
| 1586 | // 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] | 1587 | primaries = mInternalDisplayPrimaries; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1588 | return NO_ERROR; |
| 1589 | } |
| 1590 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1591 | status_t SurfaceFlinger::setActiveColorMode(const sp<IBinder>& displayToken, ui::ColorMode mode) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1592 | if (!displayToken) { |
| 1593 | return BAD_VALUE; |
| 1594 | } |
| 1595 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1596 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1597 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1598 | const auto displayOpt = |
| 1599 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1600 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1601 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1602 | |
| 1603 | if (!displayOpt) { |
| 1604 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1605 | return NAME_NOT_FOUND; |
| 1606 | } |
| 1607 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1608 | const auto& [display, snapshotRef] = *displayOpt; |
| 1609 | const auto& snapshot = snapshotRef.get(); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1610 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1611 | const auto modes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1612 | const bool exists = std::find(modes.begin(), modes.end(), mode) != modes.end(); |
| 1613 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1614 | if (mode < ui::ColorMode::NATIVE || !exists) { |
| 1615 | ALOGE("%s: Invalid color mode %s (%d) for display %s", whence, |
| 1616 | decodeColorMode(mode).c_str(), mode, to_string(snapshot.displayId()).c_str()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1617 | return BAD_VALUE; |
| 1618 | } |
| 1619 | |
| 1620 | display->getCompositionDisplay()->setColorProfile( |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 1621 | {mode, Dataspace::UNKNOWN, RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1622 | |
| 1623 | return NO_ERROR; |
| 1624 | }); |
| 1625 | |
Dominik Laskowski | 0a5f921 | 2021-08-05 17:00:04 -0700 | [diff] [blame] | 1626 | // TODO(b/195698395): Propagate error. |
| 1627 | future.wait(); |
| 1628 | return NO_ERROR; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1629 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1630 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1631 | status_t SurfaceFlinger::getBootDisplayModeSupport(bool* outSupport) const { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1632 | auto future = mScheduler->schedule( |
| 1633 | [this] { return getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG); }); |
| 1634 | |
| 1635 | *outSupport = future.get(); |
| 1636 | return NO_ERROR; |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1637 | } |
| 1638 | |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1639 | status_t SurfaceFlinger::getOverlaySupport(gui::OverlayProperties* outProperties) const { |
| 1640 | const auto& aidlProperties = getHwComposer().getOverlaySupport(); |
| 1641 | // convert aidl OverlayProperties to gui::OverlayProperties |
| 1642 | outProperties->combinations.reserve(aidlProperties.combinations.size()); |
| 1643 | for (const auto& combination : aidlProperties.combinations) { |
| 1644 | std::vector<int32_t> pixelFormats; |
| 1645 | pixelFormats.reserve(combination.pixelFormats.size()); |
| 1646 | std::transform(combination.pixelFormats.cbegin(), combination.pixelFormats.cend(), |
| 1647 | std::back_inserter(pixelFormats), |
| 1648 | [](const auto& val) { return static_cast<int32_t>(val); }); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1649 | std::vector<int32_t> standards; |
| 1650 | standards.reserve(combination.standards.size()); |
| 1651 | std::transform(combination.standards.cbegin(), combination.standards.cend(), |
| 1652 | std::back_inserter(standards), |
| 1653 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1654 | std::vector<int32_t> transfers; |
| 1655 | transfers.reserve(combination.transfers.size()); |
| 1656 | std::transform(combination.transfers.cbegin(), combination.transfers.cend(), |
| 1657 | std::back_inserter(transfers), |
| 1658 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1659 | std::vector<int32_t> ranges; |
| 1660 | ranges.reserve(combination.ranges.size()); |
| 1661 | std::transform(combination.ranges.cbegin(), combination.ranges.cend(), |
| 1662 | std::back_inserter(ranges), |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1663 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1664 | gui::OverlayProperties::SupportedBufferCombinations outCombination; |
| 1665 | outCombination.pixelFormats = std::move(pixelFormats); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1666 | outCombination.standards = std::move(standards); |
| 1667 | outCombination.transfers = std::move(transfers); |
| 1668 | outCombination.ranges = std::move(ranges); |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1669 | outProperties->combinations.emplace_back(outCombination); |
| 1670 | } |
Sally Qi | 8b4cb55 | 2022-12-14 16:24:31 -0800 | [diff] [blame] | 1671 | outProperties->supportMixedColorSpaces = aidlProperties.supportMixedColorSpaces; |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 1672 | if (aidlProperties.lutProperties) { |
Sally Qi | 95f669a | 2024-08-27 11:31:42 -0700 | [diff] [blame] | 1673 | std::vector<gui::LutProperties> outLutProperties; |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 1674 | for (auto properties : *aidlProperties.lutProperties) { |
| 1675 | if (!properties) { |
| 1676 | gui::LutProperties currentProperties; |
| 1677 | currentProperties.dimension = |
| 1678 | static_cast<gui::LutProperties::Dimension>(properties->dimension); |
| 1679 | currentProperties.size = properties->size; |
| 1680 | currentProperties.samplingKeys.reserve(properties->samplingKeys.size()); |
| 1681 | std::transform(properties->samplingKeys.cbegin(), properties->samplingKeys.cend(), |
| 1682 | std::back_inserter(currentProperties.samplingKeys), |
| 1683 | [](const auto& val) { |
| 1684 | return static_cast<gui::LutProperties::SamplingKey>(val); |
| 1685 | }); |
| 1686 | outLutProperties.push_back(std::move(currentProperties)); |
| 1687 | } |
Sally Qi | 95f669a | 2024-08-27 11:31:42 -0700 | [diff] [blame] | 1688 | } |
| 1689 | outProperties->lutProperties.emplace(outLutProperties.begin(), outLutProperties.end()); |
| 1690 | } |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 1691 | return NO_ERROR; |
| 1692 | } |
| 1693 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1694 | status_t SurfaceFlinger::setBootDisplayMode(const sp<display::DisplayToken>& displayToken, |
| 1695 | DisplayModeId modeId) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1696 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1697 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1698 | const auto snapshotOpt = |
| 1699 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1700 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1701 | .transform(&PhysicalDisplay::snapshotRef); |
| 1702 | |
| 1703 | if (!snapshotOpt) { |
| 1704 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1705 | return NAME_NOT_FOUND; |
| 1706 | } |
Kriti Dang | f50d677 | 2022-02-18 15:09:12 +0100 | [diff] [blame] | 1707 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1708 | const auto& snapshot = snapshotOpt->get(); |
| 1709 | const auto hwcIdOpt = snapshot.displayModes().get(modeId).transform( |
| 1710 | [](const DisplayModePtr& mode) { return mode->getHwcId(); }); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1711 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1712 | if (!hwcIdOpt) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1713 | 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] | 1714 | to_string(snapshot.displayId()).c_str()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1715 | return BAD_VALUE; |
| 1716 | } |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1717 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1718 | return getHwComposer().setBootDisplayMode(snapshot.displayId(), *hwcIdOpt); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1719 | }); |
| 1720 | return future.get(); |
| 1721 | } |
| 1722 | |
| 1723 | status_t SurfaceFlinger::clearBootDisplayMode(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1724 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1725 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1726 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1727 | return getHwComposer().clearBootDisplayMode(*displayId); |
| 1728 | } else { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1729 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1730 | return BAD_VALUE; |
| 1731 | } |
| 1732 | }); |
| 1733 | return future.get(); |
| 1734 | } |
| 1735 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1736 | status_t SurfaceFlinger::getHdrConversionCapabilities( |
| 1737 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) const { |
| 1738 | bool hdrOutputConversionSupport; |
| 1739 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1740 | if (hdrOutputConversionSupport == false) { |
| 1741 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1742 | return INVALID_OPERATION; |
| 1743 | } |
| 1744 | const auto aidlConversionCapability = getHwComposer().getHdrConversionCapabilities(); |
| 1745 | for (auto capability : aidlConversionCapability) { |
| 1746 | gui::HdrConversionCapability tempCapability; |
Kriti Dang | 3c243dc | 2023-03-07 15:00:13 +0100 | [diff] [blame] | 1747 | tempCapability.sourceType = static_cast<int>(capability.sourceType); |
| 1748 | tempCapability.outputType = static_cast<int>(capability.outputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1749 | tempCapability.addsLatency = capability.addsLatency; |
| 1750 | hdrConversionCapabilities->push_back(tempCapability); |
| 1751 | } |
| 1752 | return NO_ERROR; |
| 1753 | } |
| 1754 | |
| 1755 | status_t SurfaceFlinger::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1756 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 1757 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1758 | bool hdrOutputConversionSupport; |
| 1759 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1760 | if (hdrOutputConversionSupport == false) { |
| 1761 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1762 | return INVALID_OPERATION; |
| 1763 | } |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1764 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) mutable -> status_t { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1765 | using AidlHdrConversionStrategy = |
| 1766 | aidl::android::hardware::graphics::common::HdrConversionStrategy; |
| 1767 | using GuiHdrConversionStrategyTag = gui::HdrConversionStrategy::Tag; |
| 1768 | AidlHdrConversionStrategy aidlConversionStrategy; |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1769 | status_t status; |
| 1770 | aidl::android::hardware::graphics::common::Hdr aidlPreferredHdrOutputType; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1771 | switch (hdrConversionStrategy.getTag()) { |
| 1772 | case GuiHdrConversionStrategyTag::passthrough: { |
| 1773 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::passthrough>( |
| 1774 | hdrConversionStrategy.get<GuiHdrConversionStrategyTag::passthrough>()); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1775 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1776 | &aidlPreferredHdrOutputType); |
| 1777 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1778 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1779 | } |
| 1780 | case GuiHdrConversionStrategyTag::autoAllowedHdrTypes: { |
| 1781 | auto autoHdrTypes = |
| 1782 | hdrConversionStrategy |
| 1783 | .get<GuiHdrConversionStrategyTag::autoAllowedHdrTypes>(); |
| 1784 | std::vector<aidl::android::hardware::graphics::common::Hdr> aidlAutoHdrTypes; |
| 1785 | for (auto type : autoHdrTypes) { |
| 1786 | aidlAutoHdrTypes.push_back( |
| 1787 | static_cast<aidl::android::hardware::graphics::common::Hdr>(type)); |
| 1788 | } |
| 1789 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::autoAllowedHdrTypes>( |
| 1790 | aidlAutoHdrTypes); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1791 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1792 | &aidlPreferredHdrOutputType); |
| 1793 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1794 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1795 | } |
| 1796 | case GuiHdrConversionStrategyTag::forceHdrConversion: { |
| 1797 | auto forceHdrConversion = |
| 1798 | hdrConversionStrategy |
| 1799 | .get<GuiHdrConversionStrategyTag::forceHdrConversion>(); |
| 1800 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::forceHdrConversion>( |
| 1801 | static_cast<aidl::android::hardware::graphics::common::Hdr>( |
| 1802 | forceHdrConversion)); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1803 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1804 | &aidlPreferredHdrOutputType); |
| 1805 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1806 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1807 | } |
| 1808 | } |
| 1809 | }); |
| 1810 | return future.get(); |
| 1811 | } |
| 1812 | |
| 1813 | status_t SurfaceFlinger::getHdrOutputConversionSupport(bool* outSupport) const { |
| 1814 | auto future = mScheduler->schedule([this] { |
| 1815 | return getHwComposer().hasCapability(Capability::HDR_OUTPUT_CONVERSION_CONFIG); |
| 1816 | }); |
| 1817 | |
| 1818 | *outSupport = future.get(); |
| 1819 | return NO_ERROR; |
| 1820 | } |
| 1821 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1822 | void SurfaceFlinger::setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1823 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1824 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1825 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1826 | getHwComposer().setAutoLowLatencyMode(*displayId, on); |
| 1827 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1828 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1829 | } |
| 1830 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1831 | } |
| 1832 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1833 | void SurfaceFlinger::setGameContentType(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1834 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1835 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1836 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1837 | const auto type = on ? hal::ContentType::GAME : hal::ContentType::NONE; |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1838 | getHwComposer().setContentType(*displayId, type); |
| 1839 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1840 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1841 | } |
| 1842 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1843 | } |
| 1844 | |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1845 | status_t SurfaceFlinger::overrideHdrTypes(const sp<IBinder>& displayToken, |
| 1846 | const std::vector<ui::Hdr>& hdrTypes) { |
| 1847 | Mutex::Autolock lock(mStateLock); |
| 1848 | |
| 1849 | auto display = getDisplayDeviceLocked(displayToken); |
| 1850 | if (!display) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1851 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1852 | return NAME_NOT_FOUND; |
| 1853 | } |
| 1854 | |
| 1855 | display->overrideHdrTypes(hdrTypes); |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 1856 | mScheduler->dispatchHotplug(display->getPhysicalId(), scheduler::Scheduler::Hotplug::Connected); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1857 | return NO_ERROR; |
| 1858 | } |
| 1859 | |
Huihong Luo | 30aa437 | 2022-10-03 14:54:12 -0700 | [diff] [blame] | 1860 | status_t SurfaceFlinger::onPullAtom(const int32_t atomId, std::vector<uint8_t>* pulledData, |
| 1861 | bool* success) { |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 1862 | *success = mTimeStats->onPullAtom(atomId, pulledData); |
| 1863 | return NO_ERROR; |
| 1864 | } |
| 1865 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1866 | status_t SurfaceFlinger::getDisplayedContentSamplingAttributes(const sp<IBinder>& displayToken, |
| 1867 | ui::PixelFormat* outFormat, |
| 1868 | ui::Dataspace* outDataspace, |
| 1869 | uint8_t* outComponentMask) const { |
| 1870 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 1871 | return BAD_VALUE; |
| 1872 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1873 | |
| 1874 | Mutex::Autolock lock(mStateLock); |
| 1875 | |
| 1876 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1877 | if (!displayId) { |
| 1878 | return NAME_NOT_FOUND; |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1879 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1880 | |
| 1881 | return getHwComposer().getDisplayedContentSamplingAttributes(*displayId, outFormat, |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1882 | outDataspace, outComponentMask); |
| 1883 | } |
| 1884 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1885 | status_t SurfaceFlinger::setDisplayContentSamplingEnabled(const sp<IBinder>& displayToken, |
| 1886 | bool enable, uint8_t componentMask, |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1887 | uint64_t maxFrames) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1888 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1889 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1890 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1891 | return getHwComposer().setDisplayContentSamplingEnabled(*displayId, enable, |
| 1892 | componentMask, maxFrames); |
| 1893 | } else { |
| 1894 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
| 1895 | return NAME_NOT_FOUND; |
| 1896 | } |
| 1897 | }); |
| 1898 | |
| 1899 | return future.get(); |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1900 | } |
| 1901 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1902 | status_t SurfaceFlinger::getDisplayedContentSample(const sp<IBinder>& displayToken, |
| 1903 | uint64_t maxFrames, uint64_t timestamp, |
| 1904 | DisplayedFrameStats* outStats) const { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1905 | Mutex::Autolock lock(mStateLock); |
| 1906 | |
| 1907 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1908 | if (!displayId) { |
| 1909 | return NAME_NOT_FOUND; |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1912 | return getHwComposer().getDisplayedContentSample(*displayId, maxFrames, timestamp, outStats); |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
Peiyong Lin | 3c2791e | 2019-01-14 17:05:18 -0800 | [diff] [blame] | 1915 | status_t SurfaceFlinger::getProtectedContentSupport(bool* outSupported) const { |
| 1916 | if (!outSupported) { |
| 1917 | return BAD_VALUE; |
| 1918 | } |
| 1919 | *outSupported = getRenderEngine().supportsProtectedContent(); |
| 1920 | return NO_ERROR; |
| 1921 | } |
| 1922 | |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1923 | status_t SurfaceFlinger::isWideColorDisplay(const sp<IBinder>& displayToken, |
| 1924 | bool* outIsWideColorDisplay) const { |
| 1925 | if (!displayToken || !outIsWideColorDisplay) { |
| 1926 | return BAD_VALUE; |
| 1927 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1928 | |
| 1929 | Mutex::Autolock lock(mStateLock); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1930 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1931 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1932 | return NAME_NOT_FOUND; |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1933 | } |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 1934 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1935 | *outIsWideColorDisplay = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1936 | display->isPrimary() ? mSupportsWideColor : display->hasWideColorGamut(); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1937 | return NO_ERROR; |
| 1938 | } |
| 1939 | |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1940 | status_t SurfaceFlinger::getCompositionPreference( |
| 1941 | Dataspace* outDataspace, ui::PixelFormat* outPixelFormat, |
| 1942 | Dataspace* outWideColorGamutDataspace, |
| 1943 | ui::PixelFormat* outWideColorGamutPixelFormat) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1944 | *outDataspace = mDefaultCompositionDataspace; |
| 1945 | *outPixelFormat = defaultCompositionPixelFormat; |
| 1946 | *outWideColorGamutDataspace = mWideColorGamutCompositionDataspace; |
| 1947 | *outWideColorGamutPixelFormat = wideColorGamutCompositionPixelFormat; |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 1948 | return NO_ERROR; |
| 1949 | } |
| 1950 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1951 | status_t SurfaceFlinger::addRegionSamplingListener(const Rect& samplingArea, |
| 1952 | const sp<IBinder>& stopLayerHandle, |
| 1953 | const sp<IRegionSamplingListener>& listener) { |
Leon Scroggins III | ae16b80 | 2022-01-12 11:42:05 -0500 | [diff] [blame] | 1954 | if (!listener || samplingArea == Rect::INVALID_RECT || samplingArea.isEmpty()) { |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1955 | return BAD_VALUE; |
| 1956 | } |
Alec Mouri | 9a02eda | 2020-04-21 17:39:34 -0700 | [diff] [blame] | 1957 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 1958 | // LayerHandle::getLayer promotes the layer object in a binder thread but we will not destroy |
| 1959 | // 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] | 1960 | const sp<Layer> stopLayer = LayerHandle::getLayer(stopLayerHandle); |
| 1961 | mRegionSamplingThread->addListener(samplingArea, |
| 1962 | stopLayer ? stopLayer->getSequence() : UNASSIGNED_LAYER_ID, |
| 1963 | listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1964 | return NO_ERROR; |
| 1965 | } |
| 1966 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1967 | status_t SurfaceFlinger::removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) { |
tangrobin | af45f01 | 2019-02-26 18:10:10 +0800 | [diff] [blame] | 1968 | if (!listener) { |
| 1969 | return BAD_VALUE; |
| 1970 | } |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1971 | mRegionSamplingThread->removeListener(listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1972 | return NO_ERROR; |
| 1973 | } |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1974 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1975 | status_t SurfaceFlinger::addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) { |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1976 | if (!listener) { |
| 1977 | return BAD_VALUE; |
| 1978 | } |
| 1979 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1980 | mFpsReporter->addListener(listener, taskId); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1981 | return NO_ERROR; |
| 1982 | } |
| 1983 | |
| 1984 | status_t SurfaceFlinger::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 1985 | if (!listener) { |
| 1986 | return BAD_VALUE; |
| 1987 | } |
| 1988 | mFpsReporter->removeListener(listener); |
| 1989 | return NO_ERROR; |
| 1990 | } |
| 1991 | |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 1992 | status_t SurfaceFlinger::addTunnelModeEnabledListener( |
| 1993 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1994 | if (!listener) { |
| 1995 | return BAD_VALUE; |
| 1996 | } |
| 1997 | |
| 1998 | mTunnelModeEnabledReporter->addListener(listener); |
| 1999 | return NO_ERROR; |
| 2000 | } |
| 2001 | |
| 2002 | status_t SurfaceFlinger::removeTunnelModeEnabledListener( |
| 2003 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 2004 | if (!listener) { |
| 2005 | return BAD_VALUE; |
| 2006 | } |
| 2007 | |
| 2008 | mTunnelModeEnabledReporter->removeListener(listener); |
| 2009 | return NO_ERROR; |
| 2010 | } |
| 2011 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2012 | status_t SurfaceFlinger::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 2013 | bool* outSupport) const { |
| 2014 | if (!displayToken || !outSupport) { |
| 2015 | return BAD_VALUE; |
| 2016 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 2017 | |
| 2018 | Mutex::Autolock lock(mStateLock); |
| 2019 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2020 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 2021 | if (!displayId) { |
| 2022 | return NAME_NOT_FOUND; |
| 2023 | } |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 2024 | *outSupport = getHwComposer().hasDisplayCapability(*displayId, DisplayCapability::BRIGHTNESS); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2025 | return NO_ERROR; |
| 2026 | } |
| 2027 | |
John Reck | 22be696 | 2021-03-10 12:59:54 -0500 | [diff] [blame] | 2028 | status_t SurfaceFlinger::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 2029 | const gui::DisplayBrightness& brightness) { |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2030 | if (!displayToken) { |
| 2031 | return BAD_VALUE; |
| 2032 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 2033 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2034 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 2035 | return ftl::Future(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 2036 | // 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] | 2037 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2038 | const bool supportsDisplayBrightnessCommand = |
| 2039 | getHwComposer().getComposer()->isSupported( |
| 2040 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 2041 | // If we support applying display brightness as a command, then we also support |
| 2042 | // dimming SDR layers. |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 2043 | if (supportsDisplayBrightnessCommand) { |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 2044 | auto compositionDisplay = display->getCompositionDisplay(); |
| 2045 | float currentDimmingRatio = |
| 2046 | compositionDisplay->editState().sdrWhitePointNits / |
| 2047 | compositionDisplay->editState().displayBrightnessNits; |
Sally Qi | 0ea47b5 | 2023-06-22 13:27:20 -0700 | [diff] [blame] | 2048 | static constexpr float kDimmingThreshold = 0.02f; |
| 2049 | if (brightness.sdrWhitePointNits == 0.f || |
| 2050 | abs(brightness.sdrWhitePointNits - brightness.displayBrightnessNits) / |
| 2051 | brightness.sdrWhitePointNits >= |
| 2052 | kDimmingThreshold) { |
| 2053 | // to optimize, skip brightness setter if the brightness difference ratio |
| 2054 | // is lower than threshold |
| 2055 | compositionDisplay |
| 2056 | ->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 2057 | brightness.displayBrightnessNits); |
| 2058 | } else { |
| 2059 | compositionDisplay->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 2060 | brightness.sdrWhitePointNits); |
| 2061 | } |
| 2062 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2063 | FTL_FAKE_GUARD(kMainThreadContext, |
| 2064 | display->stageBrightness(brightness.displayBrightness)); |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2065 | float currentHdrSdrRatio = |
| 2066 | compositionDisplay->editState().displayBrightnessNits / |
| 2067 | compositionDisplay->editState().sdrWhitePointNits; |
| 2068 | FTL_FAKE_GUARD(kMainThreadContext, |
| 2069 | display->updateHdrSdrRatioOverlayRatio(currentHdrSdrRatio)); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2070 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 2071 | if (brightness.sdrWhitePointNits / brightness.displayBrightnessNits != |
| 2072 | currentDimmingRatio) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2073 | scheduleComposite(FrameHint::kNone); |
| 2074 | } else { |
| 2075 | scheduleCommit(FrameHint::kNone); |
| 2076 | } |
| 2077 | return ftl::yield<status_t>(OK); |
| 2078 | } else { |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 2079 | return getHwComposer() |
| 2080 | .setDisplayBrightness(display->getPhysicalId(), |
| 2081 | brightness.displayBrightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 2082 | brightness.displayBrightnessNits, |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 2083 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 2084 | .applyImmediately = true}); |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 2085 | } |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2086 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2087 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 2088 | return ftl::yield<status_t>(NAME_NOT_FOUND); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2089 | } |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 2090 | })) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 2091 | .then([](ftl::Future<status_t> task) { return task; }) |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2092 | .get(); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2093 | } |
| 2094 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2095 | status_t SurfaceFlinger::addHdrLayerInfoListener(const sp<IBinder>& displayToken, |
| 2096 | const sp<gui::IHdrLayerInfoListener>& listener) { |
| 2097 | if (!displayToken) { |
| 2098 | return BAD_VALUE; |
| 2099 | } |
| 2100 | |
| 2101 | Mutex::Autolock lock(mStateLock); |
| 2102 | |
| 2103 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2104 | if (!display) { |
| 2105 | return NAME_NOT_FOUND; |
| 2106 | } |
| 2107 | const auto displayId = display->getId(); |
| 2108 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2109 | if (!hdrInfoReporter) { |
| 2110 | hdrInfoReporter = sp<HdrLayerInfoReporter>::make(); |
| 2111 | } |
| 2112 | hdrInfoReporter->addListener(listener); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2113 | |
| 2114 | |
| 2115 | mAddingHDRLayerInfoListener = true; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2116 | return OK; |
| 2117 | } |
| 2118 | |
| 2119 | status_t SurfaceFlinger::removeHdrLayerInfoListener( |
| 2120 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 2121 | if (!displayToken) { |
| 2122 | return BAD_VALUE; |
| 2123 | } |
| 2124 | |
| 2125 | Mutex::Autolock lock(mStateLock); |
| 2126 | |
| 2127 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2128 | if (!display) { |
| 2129 | return NAME_NOT_FOUND; |
| 2130 | } |
| 2131 | const auto displayId = display->getId(); |
| 2132 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2133 | if (hdrInfoReporter) { |
| 2134 | hdrInfoReporter->removeListener(listener); |
| 2135 | } |
| 2136 | return OK; |
| 2137 | } |
| 2138 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2139 | status_t SurfaceFlinger::notifyPowerBoost(int32_t boostId) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 2140 | using aidl::android::hardware::power::Boost; |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2141 | Boost powerBoost = static_cast<Boost>(boostId); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2142 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2143 | if (powerBoost == Boost::INTERACTION) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2144 | mScheduler->onTouchHint(); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | return NO_ERROR; |
| 2148 | } |
| 2149 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2150 | status_t SurfaceFlinger::getDisplayDecorationSupport( |
| 2151 | const sp<IBinder>& displayToken, |
| 2152 | std::optional<DisplayDecorationSupport>* outSupport) const { |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2153 | if (!displayToken || !outSupport) { |
| 2154 | return BAD_VALUE; |
| 2155 | } |
| 2156 | |
| 2157 | Mutex::Autolock lock(mStateLock); |
| 2158 | |
| 2159 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 2160 | if (!displayId) { |
| 2161 | return NAME_NOT_FOUND; |
| 2162 | } |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2163 | getHwComposer().getDisplayDecorationSupport(*displayId, outSupport); |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2164 | return NO_ERROR; |
| 2165 | } |
| 2166 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 2167 | // ---------------------------------------------------------------------------- |
| 2168 | |
Jorim Jaggi | b1e2f8d | 2017-06-08 15:43:59 -0700 | [diff] [blame] | 2169 | sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection( |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 2170 | gui::ISurfaceComposer::VsyncSource vsyncSource, EventRegistrationFlags eventRegistration, |
| 2171 | const sp<IBinder>& layerHandle) { |
Ady Abraham | b334758 | 2024-04-03 01:01:51 +0000 | [diff] [blame] | 2172 | const auto cycle = [&] { |
| 2173 | if (FlagManager::getInstance().deprecate_vsync_sf()) { |
| 2174 | ALOGW_IF(vsyncSource == gui::ISurfaceComposer::VsyncSource::eVsyncSourceSurfaceFlinger, |
| 2175 | "requested unsupported config eVsyncSourceSurfaceFlinger"); |
| 2176 | return scheduler::Cycle::Render; |
| 2177 | } |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 2178 | |
Ady Abraham | b334758 | 2024-04-03 01:01:51 +0000 | [diff] [blame] | 2179 | return vsyncSource == gui::ISurfaceComposer::VsyncSource::eVsyncSourceSurfaceFlinger |
| 2180 | ? scheduler::Cycle::LastComposite |
| 2181 | : scheduler::Cycle::Render; |
| 2182 | }(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 2183 | return mScheduler->createDisplayEventConnection(cycle, eventRegistration, layerHandle); |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 2184 | } |
| 2185 | |
Ady Abraham | 9953e06 | 2024-07-24 22:56:22 -0700 | [diff] [blame] | 2186 | void SurfaceFlinger::scheduleCommit(FrameHint hint, Duration workDurationSlack) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2187 | if (hint == FrameHint::kActive) { |
| 2188 | mScheduler->resetIdleTimer(); |
| 2189 | } |
Matt Buckley | 15ecd1c | 2022-11-01 21:57:16 +0000 | [diff] [blame] | 2190 | mPowerAdvisor->notifyDisplayUpdateImminentAndCpuReset(); |
Ady Abraham | 9953e06 | 2024-07-24 22:56:22 -0700 | [diff] [blame] | 2191 | mScheduler->scheduleFrame(workDurationSlack); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2192 | } |
| 2193 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2194 | void SurfaceFlinger::scheduleComposite(FrameHint hint) { |
| 2195 | mMustComposite = true; |
| 2196 | scheduleCommit(hint); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | void SurfaceFlinger::scheduleRepaint() { |
| 2200 | mGeometryDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2201 | scheduleComposite(FrameHint::kActive); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2202 | } |
| 2203 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2204 | void SurfaceFlinger::scheduleSample() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2205 | static_cast<void>(mScheduler->schedule([this] { sample(); })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2206 | } |
| 2207 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2208 | void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp, |
| 2209 | std::optional<hal::VsyncPeriodNanos> vsyncPeriod) { |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2210 | if (FlagManager::getInstance().connected_display() && timestamp < 0 && |
| 2211 | vsyncPeriod.has_value()) { |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2212 | if (mIsHdcpViaNegVsync && vsyncPeriod.value() == ~1) { |
| 2213 | const int32_t value = static_cast<int32_t>(-timestamp); |
| 2214 | // one byte is good enough to encode android.hardware.drm.HdcpLevel |
| 2215 | const int32_t maxLevel = (value >> 8) & 0xFF; |
| 2216 | const int32_t connectedLevel = value & 0xFF; |
Huihong Luo | 817ebb8 | 2023-12-13 12:54:24 -0800 | [diff] [blame] | 2217 | ALOGD("%s: HDCP levels changed (connected=%d, max=%d) for hwcDisplayId %" PRIu64, |
| 2218 | __func__, connectedLevel, maxLevel, hwcDisplayId); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2219 | updateHdcpLevels(hwcDisplayId, connectedLevel, maxLevel); |
| 2220 | return; |
| 2221 | } |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2222 | } |
| 2223 | |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 2224 | SFTRACE_NAME(vsyncPeriod |
| 2225 | ? ftl::Concat(__func__, ' ', hwcDisplayId, ' ', *vsyncPeriod, "ns").c_str() |
| 2226 | : ftl::Concat(__func__, ' ', hwcDisplayId).c_str()); |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 2227 | |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2228 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2229 | if (const auto displayIdOpt = getHwComposer().onVsync(hwcDisplayId, timestamp)) { |
| 2230 | if (mScheduler->addResyncSample(*displayIdOpt, timestamp, vsyncPeriod)) { |
| 2231 | // period flushed |
| 2232 | mScheduler->modulateVsync(displayIdOpt, &VsyncModulator::onRefreshRateChangeCompleted); |
| 2233 | } |
Alec Mouri | 754c98a | 2019-03-18 18:53:42 -0700 | [diff] [blame] | 2234 | } |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 2235 | } |
| 2236 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2237 | void SurfaceFlinger::onComposerHalHotplugEvent(hal::HWDisplayId hwcDisplayId, |
| 2238 | DisplayHotplugEvent event) { |
| 2239 | if (event == DisplayHotplugEvent::CONNECTED || event == DisplayHotplugEvent::DISCONNECTED) { |
| 2240 | hal::Connection connection = (event == DisplayHotplugEvent::CONNECTED) |
| 2241 | ? hal::Connection::CONNECTED |
| 2242 | : hal::Connection::DISCONNECTED; |
| 2243 | { |
| 2244 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 2245 | mPendingHotplugEvents.push_back(HotplugEvent{hwcDisplayId, connection}); |
| 2246 | } |
| 2247 | |
| 2248 | if (mScheduler) { |
| 2249 | mScheduler->scheduleConfigure(); |
| 2250 | } |
| 2251 | |
| 2252 | return; |
Jiwen 'Steve' Cai | ccfd682 | 2018-02-21 16:15:58 -0800 | [diff] [blame] | 2253 | } |
| 2254 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2255 | if (FlagManager::getInstance().hotplug2()) { |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2256 | // TODO(b/311403559): use enum type instead of int |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2257 | const auto errorCode = static_cast<int32_t>(event); |
Huihong Luo | 817ebb8 | 2023-12-13 12:54:24 -0800 | [diff] [blame] | 2258 | ALOGD("%s: Hotplug error %d for hwcDisplayId %" PRIu64, __func__, errorCode, hwcDisplayId); |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2259 | mScheduler->dispatchHotplugError(errorCode); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2260 | } |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2263 | void SurfaceFlinger::onComposerHalVsyncPeriodTimingChanged( |
| 2264 | hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline& timeline) { |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2265 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2266 | mScheduler->onNewVsyncPeriodChangeTimeline(timeline); |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2267 | |
| 2268 | if (timeline.refreshRequired) { |
| 2269 | scheduleComposite(FrameHint::kNone); |
| 2270 | } |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 2271 | } |
| 2272 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2273 | void SurfaceFlinger::onComposerHalSeamlessPossible(hal::HWDisplayId) { |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 2274 | // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and |
Ady Abraham | b0433bc | 2020-01-08 17:31:06 -0800 | [diff] [blame] | 2275 | // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE. |
| 2276 | } |
| 2277 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2278 | void SurfaceFlinger::onComposerHalRefresh(hal::HWDisplayId) { |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2279 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2280 | scheduleComposite(FrameHint::kNone); |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2281 | } |
| 2282 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2283 | void SurfaceFlinger::onComposerHalVsyncIdle(hal::HWDisplayId) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 2284 | SFTRACE_CALL(); |
Ady Abraham | e9befd7 | 2022-02-24 17:24:44 -0800 | [diff] [blame] | 2285 | mScheduler->forceNextResync(); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2286 | } |
| 2287 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 2288 | void SurfaceFlinger::onRefreshRateChangedDebug(const RefreshRateChangedDebugData& data) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 2289 | SFTRACE_CALL(); |
Dominik Laskowski | 7372a60 | 2024-04-29 16:40:42 -0400 | [diff] [blame] | 2290 | const char* const whence = __func__; |
| 2291 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
| 2292 | kMainThreadContext) { |
| 2293 | if (const auto displayIdOpt = getHwComposer().toPhysicalDisplayId(data.display)) { |
| 2294 | if (const auto display = getDisplayDeviceLocked(*displayIdOpt)) { |
Ying Wei | 22d59cc | 2024-05-11 02:41:08 +0000 | [diff] [blame] | 2295 | const Fps refreshRate = Fps::fromPeriodNsecs( |
| 2296 | getHwComposer().getComposer()->isVrrSupported() ? data.refreshPeriodNanos |
| 2297 | : data.vsyncPeriodNanos); |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 2298 | SFTRACE_FORMAT("%s refresh rate = %d", whence, refreshRate.getIntValue()); |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 2299 | |
| 2300 | const auto renderRate = mDisplayModeController.getActiveMode(*displayIdOpt).fps; |
| 2301 | constexpr bool kSetByHwc = true; |
| 2302 | display->updateRefreshRateOverlayRate(refreshRate, renderRate, kSetByHwc); |
Dominik Laskowski | 7372a60 | 2024-04-29 16:40:42 -0400 | [diff] [blame] | 2303 | } |
| 2304 | } |
| 2305 | })); |
ramindani | 12bfe6b | 2023-02-03 13:29:19 -0800 | [diff] [blame] | 2306 | } |
| 2307 | |
Huihong Luo | 817ebb8 | 2023-12-13 12:54:24 -0800 | [diff] [blame] | 2308 | void SurfaceFlinger::onComposerHalHdcpLevelsChanged(hal::HWDisplayId hwcDisplayId, |
| 2309 | const HdcpLevels& levels) { |
| 2310 | if (FlagManager::getInstance().hdcp_level_hal()) { |
| 2311 | // TODO(b/362270040): propagate enum constants |
| 2312 | const int32_t maxLevel = static_cast<int32_t>(levels.maxLevel); |
| 2313 | const int32_t connectedLevel = static_cast<int32_t>(levels.connectedLevel); |
| 2314 | ALOGD("%s: HDCP levels changed (connected=%d, max=%d) for hwcDisplayId %" PRIu64, __func__, |
| 2315 | connectedLevel, maxLevel, hwcDisplayId); |
| 2316 | updateHdcpLevels(hwcDisplayId, connectedLevel, maxLevel); |
| 2317 | } |
| 2318 | } |
| 2319 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2320 | void SurfaceFlinger::configure() { |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2321 | Mutex::Autolock lock(mStateLock); |
| 2322 | if (configureLocked()) { |
| 2323 | setTransactionFlags(eDisplayTransactionNeeded); |
| 2324 | } |
| 2325 | } |
| 2326 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2327 | void SurfaceFlinger::updateLayerHistory(nsecs_t now) { |
| 2328 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 2329 | using Changes = frontend::RequestedLayerState::Changes; |
| 2330 | if (snapshot->path.isClone()) { |
| 2331 | continue; |
| 2332 | } |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 2333 | |
Jerry Chang | 3667800 | 2023-11-29 16:56:17 +0000 | [diff] [blame] | 2334 | const bool updateSmallDirty = FlagManager::getInstance().enable_small_area_detection() && |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2335 | ((snapshot->clientChanges & layer_state_t::eSurfaceDamageRegionChanged) || |
| 2336 | snapshot->changes.any(Changes::Geometry)); |
| 2337 | |
| 2338 | const bool hasChanges = |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 2339 | snapshot->changes.any(Changes::FrameRate | Changes::Buffer | Changes::Animation | |
| 2340 | Changes::Geometry | Changes::Visibility) || |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2341 | (snapshot->clientChanges & layer_state_t::eDefaultFrameRateCompatibilityChanged) != |
| 2342 | 0; |
| 2343 | |
| 2344 | if (!updateSmallDirty && !hasChanges) { |
| 2345 | continue; |
| 2346 | } |
| 2347 | |
| 2348 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 2349 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 2350 | "Couldn't find layer object for %s", |
| 2351 | snapshot->getDebugString().c_str()); |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2352 | |
| 2353 | if (updateSmallDirty) { |
| 2354 | // Update small dirty flag while surface damage region or geometry changed |
| 2355 | it->second->setIsSmallDirty(snapshot.get()); |
| 2356 | } |
| 2357 | |
| 2358 | if (!hasChanges) { |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2359 | continue; |
| 2360 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2361 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2362 | const auto layerProps = scheduler::LayerProps{ |
| 2363 | .visible = snapshot->isVisible, |
| 2364 | .bounds = snapshot->geomLayerBounds, |
| 2365 | .transform = snapshot->geomLayerTransform, |
| 2366 | .setFrameRateVote = snapshot->frameRate, |
| 2367 | .frameRateSelectionPriority = snapshot->frameRateSelectionPriority, |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2368 | .isSmallDirty = snapshot->isSmallDirty, |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 2369 | .isFrontBuffered = snapshot->isFrontBuffered(), |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2370 | }; |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2371 | |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 2372 | if (snapshot->changes.any(Changes::Geometry | Changes::Visibility)) { |
| 2373 | mScheduler->setLayerProperties(snapshot->sequence, layerProps); |
| 2374 | } |
| 2375 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2376 | if (snapshot->clientChanges & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 2377 | mScheduler->setDefaultFrameRateCompatibility(snapshot->sequence, |
| 2378 | snapshot->defaultFrameRateCompatibility); |
| 2379 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2380 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2381 | if (snapshot->changes.test(Changes::Animation)) { |
| 2382 | it->second->recordLayerHistoryAnimationTx(layerProps, now); |
| 2383 | } |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 2384 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2385 | if (snapshot->changes.test(Changes::FrameRate)) { |
| 2386 | it->second->setFrameRateForLayerTree(snapshot->frameRate, layerProps, now); |
| 2387 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2388 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2389 | if (snapshot->changes.test(Changes::Buffer)) { |
| 2390 | it->second->recordLayerHistoryBufferUpdate(layerProps, now); |
| 2391 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2392 | } |
| 2393 | } |
| 2394 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2395 | bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2396 | bool flushTransactions, bool& outTransactionsAreEmpty) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2397 | using Changes = frontend::RequestedLayerState::Changes; |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 2398 | SFTRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2399 | frontend::Update update; |
| 2400 | if (flushTransactions) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 2401 | SFTRACE_NAME("TransactionHandler:flushTransactions"); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2402 | // Locking: |
| 2403 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 2404 | // we must keep a copy of the transactions (specifically the composer |
| 2405 | // states) around outside the scope of the lock. |
| 2406 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 2407 | // transactions with layers still in the createdLayer queue, collect the transactions |
| 2408 | // before committing the created layers. |
| 2409 | // 3. Transactions can only be flushed after adding layers, since the layer can be a newly |
| 2410 | // created one |
| 2411 | mTransactionHandler.collectTransactions(); |
| 2412 | { |
| 2413 | // TODO(b/238781169) lockless queue this and keep order. |
| 2414 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | a12c5c7 | 2024-08-28 15:42:17 -0700 | [diff] [blame] | 2415 | update.legacyLayers = std::move(mCreatedLayers); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2416 | mCreatedLayers.clear(); |
| 2417 | update.newLayers = std::move(mNewLayers); |
| 2418 | mNewLayers.clear(); |
| 2419 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 2420 | mNewLayerArgs.clear(); |
| 2421 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 2422 | mDestroyedHandles.clear(); |
| 2423 | } |
| 2424 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2425 | mLayerLifecycleManager.addLayers(std::move(update.newLayers)); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2426 | update.transactions = mTransactionHandler.flushTransactions(); |
| 2427 | if (mTransactionTracing) { |
| 2428 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2429 | update, mFrontEndDisplayInfos, |
| 2430 | mFrontEndDisplayInfosChanged); |
| 2431 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2432 | mLayerLifecycleManager.applyTransactions(update.transactions); |
| 2433 | mLayerLifecycleManager.onHandlesDestroyed(update.destroyedHandles); |
Vishnu Nair | a12c5c7 | 2024-08-28 15:42:17 -0700 | [diff] [blame] | 2434 | for (auto& legacyLayer : update.legacyLayers) { |
| 2435 | mLegacyLayers[legacyLayer->sequence] = legacyLayer; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2436 | } |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 2437 | mLayerHierarchyBuilder.update(mLayerLifecycleManager); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2438 | } |
| 2439 | |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 2440 | // Keep a copy of the drawing state (that is going to be overwritten |
| 2441 | // by commitTransactionsLocked) outside of mStateLock so that the side |
| 2442 | // effects of the State assignment don't happen with mStateLock held, |
| 2443 | // which can cause deadlocks. |
| 2444 | State drawingState(mDrawingState); |
| 2445 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2446 | bool mustComposite = false; |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 2447 | mustComposite |= applyAndCommitDisplayTransactionStatesLocked(update.transactions); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2448 | |
| 2449 | { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 2450 | SFTRACE_NAME("LayerSnapshotBuilder:update"); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2451 | frontend::LayerSnapshotBuilder::Args |
| 2452 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 2453 | .layerLifecycleManager = mLayerLifecycleManager, |
Melody Hsu | 63e3dcc | 2024-04-03 23:22:20 +0000 | [diff] [blame] | 2454 | .includeMetadata = mCompositionEngine->getFeatureFlags().test( |
| 2455 | compositionengine::Feature::kSnapshotLayerMetadata), |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2456 | .displays = mFrontEndDisplayInfos, |
| 2457 | .displayChanges = mFrontEndDisplayInfosChanged, |
| 2458 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2459 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2460 | .forceFullDamage = mForceFullDamage, |
| 2461 | .supportedLayerGenericMetadata = |
| 2462 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 2463 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 2464 | .skipRoundCornersWhenProtected = |
| 2465 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2466 | mLayerSnapshotBuilder.update(args); |
| 2467 | } |
| 2468 | |
| 2469 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Geometry | Changes::Input | |
Vishnu Nair | 40d0228 | 2023-02-28 21:11:40 +0000 | [diff] [blame] | 2470 | Changes::Hierarchy | Changes::Visibility)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2471 | mUpdateInputInfo = true; |
| 2472 | } |
| 2473 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::VisibleRegion | Changes::Hierarchy | |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2474 | Changes::Visibility | Changes::Geometry)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2475 | mVisibleRegionsDirty = true; |
| 2476 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2477 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Hierarchy | Changes::FrameRate)) { |
| 2478 | // The frame rate of attached choreographers can only change as a result of a |
| 2479 | // FrameRate change (including when Hierarchy changes). |
| 2480 | mUpdateAttachedChoreographer = true; |
| 2481 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2482 | outTransactionsAreEmpty = mLayerLifecycleManager.getGlobalChanges().get() == 0; |
Vishnu Nair | df59f47 | 2024-05-17 16:51:33 +0000 | [diff] [blame] | 2483 | if (FlagManager::getInstance().vrr_bugfix_24q4()) { |
Ady Abraham | 6846ade | 2024-05-20 21:58:27 +0000 | [diff] [blame] | 2484 | mustComposite |= mLayerLifecycleManager.getGlobalChanges().any( |
| 2485 | frontend::RequestedLayerState::kMustComposite); |
Vishnu Nair | df59f47 | 2024-05-17 16:51:33 +0000 | [diff] [blame] | 2486 | } else { |
| 2487 | mustComposite |= mLayerLifecycleManager.getGlobalChanges().get() != 0; |
| 2488 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2489 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2490 | bool newDataLatched = false; |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 2491 | SFTRACE_NAME("DisplayCallbackAndStatsUpdates"); |
Shuangxi Xiang | a97d59d | 2024-08-27 07:28:20 +0000 | [diff] [blame] | 2492 | mustComposite |= applyTransactionsLocked(update.transactions); |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2493 | traverseLegacyLayers([&](Layer* layer) { layer->commitTransaction(); }); |
| 2494 | const nsecs_t latchTime = systemTime(); |
| 2495 | bool unused = false; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2496 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2497 | for (auto& layer : mLayerLifecycleManager.getLayers()) { |
| 2498 | if (layer->changes.test(frontend::RequestedLayerState::Changes::Created) && |
| 2499 | layer->bgColorLayer) { |
| 2500 | sp<Layer> bgColorLayer = getFactory().createEffectLayer( |
| 2501 | LayerCreationArgs(this, nullptr, layer->name, |
| 2502 | ISurfaceComposerClient::eFXSurfaceEffect, LayerMetadata(), |
| 2503 | std::make_optional(layer->id), true)); |
| 2504 | mLegacyLayers[bgColorLayer->sequence] = bgColorLayer; |
| 2505 | } |
| 2506 | const bool willReleaseBufferOnLatch = layer->willReleaseBufferOnLatch(); |
Matthew DeVore | ce6bde8 | 2024-04-28 16:58:06 +0000 | [diff] [blame] | 2507 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2508 | auto it = mLegacyLayers.find(layer->id); |
| 2509 | if (it == mLegacyLayers.end() && |
| 2510 | layer->changes.test(frontend::RequestedLayerState::Changes::Destroyed)) { |
| 2511 | // Layer handle was created and immediately destroyed. It was destroyed before it |
| 2512 | // was added to the map. |
| 2513 | continue; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2514 | } |
| 2515 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2516 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 2517 | "Couldnt find layer object for %s", |
| 2518 | layer->getDebugString().c_str()); |
| 2519 | if (!layer->hasReadyFrame() && !willReleaseBufferOnLatch) { |
| 2520 | if (!it->second->hasBuffer()) { |
| 2521 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 2522 | // instead of a missed frame. This is used to identify scenarios where we |
| 2523 | // could not latch a buffer or apply a transaction due to backpressure. |
| 2524 | // We only update the latch time for buffer less layers here, the latch time |
| 2525 | // is updated for buffer layers when the buffer is latched. |
| 2526 | it->second->updateLastLatchTime(latchTime); |
| 2527 | } |
| 2528 | continue; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2529 | } |
| 2530 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2531 | const bool bgColorOnly = |
| 2532 | !layer->externalTexture && (layer->bgColorLayerId != UNASSIGNED_LAYER_ID); |
| 2533 | if (willReleaseBufferOnLatch) { |
| 2534 | mLayersWithBuffersRemoved.emplace(it->second); |
Matthew DeVore | ce6bde8 | 2024-04-28 16:58:06 +0000 | [diff] [blame] | 2535 | } |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2536 | it->second->latchBufferImpl(unused, latchTime, bgColorOnly); |
| 2537 | newDataLatched = true; |
Matthew DeVore | ce6bde8 | 2024-04-28 16:58:06 +0000 | [diff] [blame] | 2538 | |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 2539 | frontend::LayerSnapshot* snapshot = mLayerSnapshotBuilder.getSnapshot(it->second->sequence); |
| 2540 | gui::GameMode gameMode = (snapshot) ? snapshot->gameMode : gui::GameMode::Unsupported; |
| 2541 | mLayersWithQueuedFrames.emplace(it->second, gameMode); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2542 | } |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2543 | |
| 2544 | updateLayerHistory(latchTime); |
Vishnu Nair | 438a0ac | 2024-08-15 08:09:32 +0000 | [diff] [blame] | 2545 | mLayerSnapshotBuilder.forEachSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
Vishnu Nair | a4b3a10 | 2024-11-05 05:26:38 +0000 | [diff] [blame] | 2546 | // update output's dirty region if a snapshot is visible and its |
| 2547 | // content is dirty or if a snapshot recently became invisible |
| 2548 | if ((snapshot.isVisible && snapshot.contentDirty) || |
Vishnu Nair | 438a0ac | 2024-08-15 08:09:32 +0000 | [diff] [blame] | 2549 | (!snapshot.isVisible && snapshot.changes.test(Changes::Visibility))) { |
| 2550 | Region visibleReg; |
| 2551 | visibleReg.set(snapshot.transformedBoundsWithoutTransparentRegion); |
| 2552 | invalidateLayerStack(snapshot.outputFilter, visibleReg); |
| 2553 | } |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2554 | }); |
| 2555 | |
| 2556 | for (auto& destroyedLayer : mLayerLifecycleManager.getDestroyedLayers()) { |
| 2557 | mLegacyLayers.erase(destroyedLayer->id); |
| 2558 | } |
| 2559 | |
| 2560 | { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 2561 | SFTRACE_NAME("LLM:commitChanges"); |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2562 | mLayerLifecycleManager.commitChanges(); |
| 2563 | } |
| 2564 | |
| 2565 | // enter boot animation on first buffer latch |
| 2566 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 2567 | ALOGI("Enter boot animation"); |
| 2568 | mBootStage = BootStage::BOOTANIMATION; |
| 2569 | } |
| 2570 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2571 | mustComposite |= (getTransactionFlags() & ~eTransactionFlushNeeded) || newDataLatched; |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2572 | if (mustComposite) { |
Vishnu Nair | 8134c1a | 2023-10-17 22:55:49 -0700 | [diff] [blame] | 2573 | commitTransactions(); |
| 2574 | } |
| 2575 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2576 | return mustComposite; |
| 2577 | } |
| 2578 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2579 | bool SurfaceFlinger::commit(PhysicalDisplayId pacesetterId, |
| 2580 | const scheduler::FrameTargets& frameTargets) { |
| 2581 | const scheduler::FrameTarget& pacesetterFrameTarget = *frameTargets.get(pacesetterId)->get(); |
| 2582 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2583 | const VsyncId vsyncId = pacesetterFrameTarget.vsyncId(); |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 2584 | SFTRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2585 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2586 | if (pacesetterFrameTarget.didMissFrame()) { |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2587 | mTimeStats->incrementMissedFrames(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2590 | // If a mode set is pending and the fence hasn't fired yet, wait for the next commit. |
| 2591 | if (std::any_of(frameTargets.begin(), frameTargets.end(), |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 2592 | [this](const auto& pair) FTL_FAKE_GUARD(kMainThreadContext) { |
| 2593 | const auto [displayId, target] = pair; |
| 2594 | return target->isFramePending() && |
| 2595 | mDisplayModeController.isModeSetPending(displayId); |
| 2596 | })) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2597 | mScheduler->scheduleFrame(); |
| 2598 | return false; |
| 2599 | } |
| 2600 | |
Dominik Laskowski | b2fc423 | 2024-07-15 08:24:49 -0400 | [diff] [blame] | 2601 | { |
| 2602 | ConditionalLock lock(mStateLock, FlagManager::getInstance().connected_display()); |
| 2603 | |
| 2604 | for (const auto [displayId, _] : frameTargets) { |
| 2605 | if (mDisplayModeController.isModeSetPending(displayId)) { |
| 2606 | finalizeDisplayModeChange(displayId); |
| 2607 | } |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2608 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
Ady Abraham | ed1283a | 2024-07-24 15:49:16 -0700 | [diff] [blame] | 2611 | if (pacesetterFrameTarget.wouldBackpressureHwc()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2612 | if (mBackpressureGpuComposition || pacesetterFrameTarget.didMissHwcFrame()) { |
Ady Abraham | e988303 | 2023-11-20 17:54:54 -0800 | [diff] [blame] | 2613 | if (FlagManager::getInstance().vrr_config()) { |
| 2614 | mScheduler->getVsyncSchedule()->getTracker().onFrameMissed( |
| 2615 | pacesetterFrameTarget.expectedPresentTime()); |
| 2616 | } |
Ady Abraham | 9953e06 | 2024-07-24 22:56:22 -0700 | [diff] [blame] | 2617 | const Duration slack = FlagManager::getInstance().allow_n_vsyncs_in_targeter() |
| 2618 | ? TimePoint::now() - pacesetterFrameTarget.frameBeginTime() |
| 2619 | : Duration::fromNs(0); |
| 2620 | scheduleCommit(FrameHint::kNone, slack); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2621 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2622 | } |
| 2623 | } |
| 2624 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2625 | const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); |
| 2626 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2627 | // Save this once per commit + composite to ensure consistency |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2628 | // TODO (b/240619471): consider removing active display check once AOD is fixed |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 2629 | const auto activeDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(mActiveDisplayId)); |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2630 | mPowerHintSessionEnabled = mPowerAdvisor->usePowerHintSession() && activeDisplay && |
| 2631 | activeDisplay->getPowerMode() == hal::PowerMode::ON; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2632 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2633 | mPowerAdvisor->setCommitStart(pacesetterFrameTarget.frameBeginTime()); |
| 2634 | mPowerAdvisor->setExpectedPresentTime(pacesetterFrameTarget.expectedPresentTime()); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2635 | |
| 2636 | // 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] | 2637 | const Duration idealSfWorkDuration = |
| 2638 | mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2639 | const Duration frameDelay = |
| 2640 | idealSfWorkDuration - pacesetterFrameTarget.expectedFrameDuration(); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2641 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2642 | mPowerAdvisor->setFrameDelay(frameDelay); |
| 2643 | mPowerAdvisor->setTotalFrameTargetWorkDuration(idealSfWorkDuration); |
Matt Buckley | 676e439 | 2023-05-25 22:09:26 +0000 | [diff] [blame] | 2644 | |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 2645 | const Period idealVsyncPeriod = |
| 2646 | mDisplayModeController.getActiveMode(pacesetterId).fps.getPeriod(); |
Matt Buckley | 676e439 | 2023-05-25 22:09:26 +0000 | [diff] [blame] | 2647 | mPowerAdvisor->updateTargetWorkDuration(idealVsyncPeriod); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2648 | } |
| 2649 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2650 | if (mRefreshRateOverlaySpinner || mHdrSdrRatioOverlay) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 2651 | Mutex::Autolock lock(mStateLock); |
| 2652 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2653 | display->animateOverlay(); |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2654 | } |
| 2655 | } |
| 2656 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2657 | // Composite if transactions were committed, or if requested by HWC. |
| 2658 | bool mustComposite = mMustComposite.exchange(false); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2659 | { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2660 | mFrameTimeline->setSfWakeUp(ftl::to_underlying(vsyncId), |
| 2661 | pacesetterFrameTarget.frameBeginTime().ns(), |
Pascal Muetschard | ac7bcd9 | 2023-10-03 15:05:36 +0200 | [diff] [blame] | 2662 | Fps::fromPeriodNsecs(vsyncPeriod.ns()), |
| 2663 | mScheduler->getPacesetterRefreshRate()); |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 2664 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2665 | const bool flushTransactions = clearTransactionFlags(eTransactionFlushNeeded); |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2666 | bool transactionsAreEmpty = false; |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 2667 | mustComposite |= updateLayerSnapshots(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2668 | flushTransactions, transactionsAreEmpty); |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2669 | |
Ady Abraham | aa7ebd6 | 2024-03-26 02:27:57 +0000 | [diff] [blame] | 2670 | // Tell VsyncTracker that we are going to present this frame before scheduling |
| 2671 | // setTransactionFlags which will schedule another SF frame. This was if the tracker |
| 2672 | // needs to adjust the vsync timeline, it will be done before the next frame. |
| 2673 | if (FlagManager::getInstance().vrr_config() && mustComposite) { |
| 2674 | mScheduler->getVsyncSchedule()->getTracker().onFrameBegin( |
| 2675 | pacesetterFrameTarget.expectedPresentTime(), |
| 2676 | pacesetterFrameTarget.lastSignaledFrameTime()); |
| 2677 | } |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2678 | if (transactionFlushNeeded()) { |
| 2679 | setTransactionFlags(eTransactionFlushNeeded); |
| 2680 | } |
| 2681 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2682 | // This has to be called after latchBuffers because we want to include the layers that have |
| 2683 | // been latched in the commit callback |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2684 | if (transactionsAreEmpty) { |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2685 | // Invoke empty transaction callbacks early. |
| 2686 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 2687 | } else { |
| 2688 | // Invoke OnCommit callbacks. |
| 2689 | mTransactionCallbackInvoker.sendCallbacks(true /* onCommitOnly */); |
| 2690 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | // Layers need to get updated (in the previous line) before we can use them for |
| 2694 | // choosing the refresh rate. |
| 2695 | // Hold mStateLock as chooseRefreshRateForContent promotes wp<Layer> to sp<Layer> |
| 2696 | // and may eventually call to ~Layer() if it holds the last reference |
| 2697 | { |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2698 | bool updateAttachedChoreographer = mUpdateAttachedChoreographer; |
| 2699 | mUpdateAttachedChoreographer = false; |
| 2700 | |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 2701 | Mutex::Autolock lock(mStateLock); |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 2702 | mScheduler->chooseRefreshRateForContent(&mLayerHierarchyBuilder.getHierarchy(), |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2703 | updateAttachedChoreographer); |
Dominik Laskowski | b2fc423 | 2024-07-15 08:24:49 -0400 | [diff] [blame] | 2704 | |
| 2705 | if (FlagManager::getInstance().connected_display()) { |
| 2706 | initiateDisplayModeChanges(); |
| 2707 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2708 | } |
| 2709 | |
Dominik Laskowski | b2fc423 | 2024-07-15 08:24:49 -0400 | [diff] [blame] | 2710 | if (!FlagManager::getInstance().connected_display()) { |
| 2711 | ftl::FakeGuard guard(mStateLock); |
| 2712 | initiateDisplayModeChanges(); |
| 2713 | } |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 2714 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2715 | updateCursorAsync(); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2716 | if (!mustComposite) { |
| 2717 | updateInputFlinger(vsyncId, pacesetterFrameTarget.frameBeginTime()); |
| 2718 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2719 | doActiveLayersTracingIfNeeded(false, mVisibleRegionsDirty, |
| 2720 | pacesetterFrameTarget.frameBeginTime(), vsyncId); |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 2721 | |
Pablo Gamito | 6be8244 | 2022-06-13 11:04:34 +0000 | [diff] [blame] | 2722 | mLastCommittedVsyncId = vsyncId; |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2723 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2724 | persistDisplayBrightness(mustComposite); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2725 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2726 | return mustComposite && CC_LIKELY(mBootStage != BootStage::BOOTLOADER); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2727 | } |
| 2728 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2729 | CompositeResultsPerDisplay SurfaceFlinger::composite( |
| 2730 | PhysicalDisplayId pacesetterId, const scheduler::FrameTargeters& frameTargeters) { |
| 2731 | const scheduler::FrameTarget& pacesetterTarget = |
| 2732 | frameTargeters.get(pacesetterId)->get()->target(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2733 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2734 | const VsyncId vsyncId = pacesetterTarget.vsyncId(); |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 2735 | SFTRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2736 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2737 | compositionengine::CompositionRefreshArgs refreshArgs; |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 2738 | refreshArgs.powerCallback = this; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2739 | const auto& displays = FTL_FAKE_GUARD(mStateLock, mDisplays); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2740 | refreshArgs.outputs.reserve(displays.size()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2741 | |
| 2742 | // Add outputs for physical displays. |
| 2743 | for (const auto& [id, targeter] : frameTargeters) { |
| 2744 | ftl::FakeGuard guard(mStateLock); |
| 2745 | |
| 2746 | if (const auto display = getCompositionDisplayLocked(id)) { |
| 2747 | refreshArgs.outputs.push_back(display); |
| 2748 | } |
Leon Scroggins III | 370b8b5 | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 2749 | |
| 2750 | refreshArgs.frameTargets.try_emplace(id, &targeter->target()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2751 | } |
| 2752 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2753 | std::vector<DisplayId> displayIds; |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2754 | for (const auto& [_, display] : displays) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2755 | displayIds.push_back(display->getId()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2756 | display->tracePowerMode(); |
| 2757 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2758 | // Add outputs for virtual displays. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2759 | if (display->isVirtual()) { |
| 2760 | const Fps refreshRate = display->getAdjustedRefreshRate(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2761 | |
| 2762 | if (!refreshRate.isValid() || |
| 2763 | mScheduler->isVsyncInPhase(pacesetterTarget.frameBeginTime(), refreshRate)) { |
| 2764 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2765 | } |
| 2766 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2767 | } |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2768 | mPowerAdvisor->setDisplays(displayIds); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2769 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 2770 | const bool updateTaskMetadata = mCompositionEngine->getFeatureFlags().test( |
| 2771 | compositionengine::Feature::kSnapshotLayerMetadata); |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 2772 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 2773 | refreshArgs.bufferIdsToUncache = std::move(mBufferIdsToUncache); |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 2774 | refreshArgs.outputColorSetting = mDisplayColorSetting; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 2775 | refreshArgs.forceOutputColorMode = mForceColorMode; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2776 | |
| 2777 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
Vishnu Nair | 995f4cf | 2024-03-07 19:40:03 -0800 | [diff] [blame] | 2778 | refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || |
| 2779 | mVisibleRegionsDirty || mDrawingState.colorMatrixChanged; |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 2780 | refreshArgs.internalDisplayRotationFlags = getActiveDisplayRotationFlags(); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2781 | |
| 2782 | if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) { |
| 2783 | refreshArgs.colorTransformMatrix = mDrawingState.colorMatrix; |
| 2784 | mDrawingState.colorMatrixChanged = false; |
| 2785 | } |
| 2786 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2787 | refreshArgs.devOptForceClientComposition = mDebugDisableHWC; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2788 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2789 | if (mDebugFlashDelay != 0) { |
| 2790 | refreshArgs.devOptForceClientComposition = true; |
| 2791 | refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay); |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 2792 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2793 | |
ramindani | 0491e64 | 2023-11-16 17:42:14 -0800 | [diff] [blame] | 2794 | // TODO(b/255601557) Update frameInterval per display |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 2795 | refreshArgs.frameInterval = |
| 2796 | mScheduler->getNextFrameInterval(pacesetterId, pacesetterTarget.expectedPresentTime()); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 2797 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 2798 | const auto scheduledFrameTimeOpt = scheduledFrameResultOpt |
| 2799 | ? std::optional{scheduledFrameResultOpt->callbackTime} |
| 2800 | : std::nullopt; |
| 2801 | refreshArgs.scheduledFrameTime = scheduledFrameTimeOpt; |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 2802 | refreshArgs.hasTrustedPresentationListener = mNumTrustedPresentationListeners > 0; |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2803 | // Store the present time just before calling to the composition engine so we could notify |
| 2804 | // the scheduler. |
| 2805 | const auto presentTime = systemTime(); |
| 2806 | |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2807 | constexpr bool kCursorOnly = false; |
| 2808 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
| 2809 | |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 2810 | if (!mVisibleRegionsDirty) { |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2811 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 2812 | auto compositionDisplay = display->getCompositionDisplay(); |
| 2813 | if (!compositionDisplay->getState().isEnabled) continue; |
| 2814 | for (auto outputLayer : compositionDisplay->getOutputLayersOrderedByZ()) { |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2815 | if (outputLayer->getLayerFE().getCompositionState() == nullptr) { |
| 2816 | // This is unexpected but instead of crashing, capture traces to disk |
| 2817 | // and recover gracefully by forcing CE to rebuild layer stack. |
| 2818 | ALOGE("Output layer %s for display %s %" PRIu64 " has a null " |
| 2819 | "snapshot. Forcing mVisibleRegionsDirty", |
| 2820 | outputLayer->getLayerFE().getDebugName(), |
| 2821 | compositionDisplay->getName().c_str(), compositionDisplay->getId().value); |
| 2822 | |
| 2823 | TransactionTraceWriter::getInstance().invoke(__func__, /* overwrite= */ false); |
| 2824 | mVisibleRegionsDirty = true; |
| 2825 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
| 2826 | refreshArgs.updatingGeometryThisFrame = mVisibleRegionsDirty; |
| 2827 | } |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2828 | } |
| 2829 | } |
| 2830 | } |
| 2831 | |
Melody Hsu | c949cde | 2024-03-12 01:43:34 +0000 | [diff] [blame] | 2832 | refreshArgs.refreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 2833 | for (auto& [layer, layerFE] : layers) { |
Melody Hsu | c949cde | 2024-03-12 01:43:34 +0000 | [diff] [blame] | 2834 | layer->onPreComposition(refreshArgs.refreshStartTime); |
| 2835 | } |
| 2836 | |
Melody Hsu | 0077fde | 2024-10-17 21:42:50 +0000 | [diff] [blame] | 2837 | for (auto& [layer, layerFE] : layers) { |
| 2838 | attachReleaseFenceFutureToLayer(layer, layerFE, |
| 2839 | layerFE->mSnapshot->outputFilter.layerStack); |
| 2840 | } |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 2841 | |
Melody Hsu | 0077fde | 2024-10-17 21:42:50 +0000 | [diff] [blame] | 2842 | refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); |
| 2843 | for (auto& [layer, _] : mLayersWithQueuedFrames) { |
| 2844 | if (const auto& layerFE = |
| 2845 | layer->getCompositionEngineLayerFE({static_cast<uint32_t>(layer->sequence)})) { |
| 2846 | refreshArgs.layersWithQueuedFrames.push_back(layerFE); |
| 2847 | // Some layers are not displayed and do not yet have a future release fence |
| 2848 | if (layerFE->getReleaseFencePromiseStatus() == |
| 2849 | LayerFE::ReleaseFencePromiseStatus::UNINITIALIZED || |
| 2850 | layerFE->getReleaseFencePromiseStatus() == |
| 2851 | LayerFE::ReleaseFencePromiseStatus::FULFILLED) { |
| 2852 | // layerStack is invalid because layer is not on a display |
| 2853 | attachReleaseFenceFutureToLayer(layer.get(), layerFE.get(), |
| 2854 | ui::INVALID_LAYER_STACK); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 2855 | } |
| 2856 | } |
Melody Hsu | 0077fde | 2024-10-17 21:42:50 +0000 | [diff] [blame] | 2857 | } |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 2858 | |
Melody Hsu | 0077fde | 2024-10-17 21:42:50 +0000 | [diff] [blame] | 2859 | mCompositionEngine->present(refreshArgs); |
| 2860 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 2861 | |
Melody Hsu | 0077fde | 2024-10-17 21:42:50 +0000 | [diff] [blame] | 2862 | for (auto& [layer, layerFE] : layers) { |
| 2863 | CompositionResult compositionResult{layerFE->stealCompositionResult()}; |
| 2864 | if (compositionResult.lastClientCompositionFence) { |
| 2865 | layer->setWasClientComposed(compositionResult.lastClientCompositionFence); |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2866 | } |
| 2867 | } |
| 2868 | |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 2869 | SFTRACE_NAME("postComposition"); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2870 | mTimeStats->recordFrameDuration(pacesetterTarget.frameBeginTime().ns(), systemTime()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2871 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2872 | // Send a power hint after presentation is finished. |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2873 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2874 | // Now that the current frame has been presented above, PowerAdvisor needs the present time |
| 2875 | // of the previous frame (whose fence is signaled by now) to determine how long the HWC had |
| 2876 | // waited on that fence to retire before presenting. |
Ady Abraham | ed1283a | 2024-07-24 15:49:16 -0700 | [diff] [blame] | 2877 | // TODO(b/355238809) `presentFenceForPreviousFrame` might not always be signaled (e.g. on |
| 2878 | // devices |
| 2879 | // where HWC does not block on the previous present fence). Revise this assumtion. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2880 | const auto& previousPresentFence = pacesetterTarget.presentFenceForPreviousFrame(); |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2881 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2882 | mPowerAdvisor->setSfPresentTiming(TimePoint::fromNs(previousPresentFence->getSignalTime()), |
| 2883 | TimePoint::now()); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 2884 | mPowerAdvisor->reportActualWorkDuration(); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2885 | } |
| 2886 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2887 | if (mScheduler->onCompositionPresented(presentTime)) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2888 | scheduleComposite(FrameHint::kNone); |
| 2889 | } |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2890 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 2891 | mNotifyExpectedPresentMap[pacesetterId].hintStatus = NotifyExpectedPresentHintStatus::Start; |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2892 | onCompositionPresented(pacesetterId, frameTargeters, presentTime); |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 2893 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2894 | const bool hadGpuComposited = |
| 2895 | multiDisplayUnion(mCompositionCoverage).test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2896 | mCompositionCoverage.clear(); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2897 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2898 | TimeStats::ClientCompositionRecord clientCompositionRecord; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2899 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2900 | for (const auto& [_, display] : displays) { |
| 2901 | const auto& state = display->getCompositionDisplay()->getState(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2902 | CompositionCoverageFlags& flags = |
| 2903 | mCompositionCoverage.try_emplace(display->getId()).first->second; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2904 | |
| 2905 | if (state.usesDeviceComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2906 | flags |= CompositionCoverage::Hwc; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | if (state.reusedClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2910 | flags |= CompositionCoverage::GpuReuse; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2911 | } else if (state.usesClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2912 | flags |= CompositionCoverage::Gpu; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2913 | } |
| 2914 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2915 | clientCompositionRecord.predicted |= |
| 2916 | (state.strategyPrediction != CompositionStrategyPredictionState::DISABLED); |
| 2917 | clientCompositionRecord.predictionSucceeded |= |
| 2918 | (state.strategyPrediction == CompositionStrategyPredictionState::SUCCESS); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2919 | } |
| 2920 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2921 | const auto coverage = multiDisplayUnion(mCompositionCoverage); |
| 2922 | const bool hasGpuComposited = coverage.test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2923 | |
| 2924 | clientCompositionRecord.hadClientComposition = hasGpuComposited; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2925 | clientCompositionRecord.reused = coverage.test(CompositionCoverage::GpuReuse); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2926 | clientCompositionRecord.changed = hadGpuComposited != hasGpuComposited; |
| 2927 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2928 | mTimeStats->pushCompositionStrategyState(clientCompositionRecord); |
| 2929 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2930 | using namespace ftl::flag_operators; |
| 2931 | |
| 2932 | // TODO(b/160583065): Enable skip validation when SF caches all client composition layers. |
| 2933 | const bool hasGpuUseOrReuse = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2934 | coverage.any(CompositionCoverage::Gpu | CompositionCoverage::GpuReuse); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2935 | mScheduler->modulateVsync({}, &VsyncModulator::onDisplayRefresh, hasGpuUseOrReuse); |
Dan Stoza | 14cd37c | 2015-07-09 12:43:33 -0700 | [diff] [blame] | 2936 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 2937 | mLayersWithQueuedFrames.clear(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2938 | doActiveLayersTracingIfNeeded(true, mVisibleRegionsDirty, pacesetterTarget.frameBeginTime(), |
| 2939 | vsyncId); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2940 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2941 | updateInputFlinger(vsyncId, pacesetterTarget.frameBeginTime()); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2942 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2943 | if (mVisibleRegionsDirty) mHdrLayerInfoChanged = true; |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 2944 | mVisibleRegionsDirty = false; |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2945 | |
| 2946 | if (mCompositionEngine->needsAnotherUpdate()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2947 | scheduleCommit(FrameHint::kNone); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2948 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2949 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2950 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2951 | mPowerAdvisor->setCompositeEnd(TimePoint::now()); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2952 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2953 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2954 | CompositeResultsPerDisplay resultsPerDisplay; |
| 2955 | |
| 2956 | // Filter out virtual displays. |
| 2957 | for (const auto& [id, coverage] : mCompositionCoverage) { |
| 2958 | if (const auto idOpt = PhysicalDisplayId::tryCast(id)) { |
| 2959 | resultsPerDisplay.try_emplace(*idOpt, CompositeResult{coverage}); |
| 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | return resultsPerDisplay; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2964 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2965 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2966 | bool SurfaceFlinger::isHdrLayer(const frontend::LayerSnapshot& snapshot) const { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2967 | // Even though the camera layer may be using an HDR transfer function or otherwise be "HDR" |
| 2968 | // the device may need to avoid boosting the brightness as a result of these layers to |
| 2969 | // reduce power consumption during camera recording |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2970 | if (mIgnoreHdrCameraLayers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2971 | if (snapshot.externalTexture && |
| 2972 | (snapshot.externalTexture->getUsage() & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) { |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2973 | return false; |
| 2974 | } |
| 2975 | } |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 2976 | // RANGE_EXTENDED layer may identify themselves as being "HDR" |
| 2977 | // via a desired hdr/sdr ratio |
| 2978 | auto pixelFormat = snapshot.buffer |
| 2979 | ? std::make_optional(static_cast<ui::PixelFormat>(snapshot.buffer->getPixelFormat())) |
| 2980 | : std::nullopt; |
| 2981 | |
| 2982 | if (getHdrRenderType(snapshot.dataspace, pixelFormat, snapshot.desiredHdrSdrRatio) != |
| 2983 | HdrRenderType::SDR) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2984 | return true; |
| 2985 | } |
| 2986 | // If the layer is not allowed to be dimmed, treat it as HDR. WindowManager may disable |
| 2987 | // dimming in order to keep animations invoking SDR screenshots of HDR layers seamless. |
| 2988 | // Treat such tagged layers as HDR so that DisplayManagerService does not try to change |
| 2989 | // the screen brightness |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2990 | if (!snapshot.dimmingEnabled) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2991 | return true; |
| 2992 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2993 | return false; |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2994 | } |
| 2995 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2996 | ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId, |
| 2997 | bool isPrimary) const { |
| 2998 | const auto id = PhysicalDisplayId::tryCast(displayId); |
| 2999 | if (!id) { |
| 3000 | return ui::ROTATION_0; |
| 3001 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3002 | if (!mIgnoreHwcPhysicalDisplayOrientation && |
Neha Jain | 7b31cca | 2023-01-09 23:10:42 +0000 | [diff] [blame] | 3003 | getHwComposer().getComposer()->isSupported( |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3004 | Hwc2::Composer::OptionalFeature::PhysicalDisplayOrientation)) { |
| 3005 | switch (getHwComposer().getPhysicalDisplayOrientation(*id)) { |
| 3006 | case Hwc2::AidlTransform::ROT_90: |
| 3007 | return ui::ROTATION_90; |
| 3008 | case Hwc2::AidlTransform::ROT_180: |
| 3009 | return ui::ROTATION_180; |
| 3010 | case Hwc2::AidlTransform::ROT_270: |
| 3011 | return ui::ROTATION_270; |
| 3012 | default: |
| 3013 | return ui::ROTATION_0; |
| 3014 | } |
| 3015 | } |
| 3016 | |
| 3017 | if (isPrimary) { |
| 3018 | using Values = SurfaceFlingerProperties::primary_display_orientation_values; |
| 3019 | switch (primary_display_orientation(Values::ORIENTATION_0)) { |
| 3020 | case Values::ORIENTATION_90: |
| 3021 | return ui::ROTATION_90; |
| 3022 | case Values::ORIENTATION_180: |
| 3023 | return ui::ROTATION_180; |
| 3024 | case Values::ORIENTATION_270: |
| 3025 | return ui::ROTATION_270; |
| 3026 | default: |
| 3027 | break; |
| 3028 | } |
| 3029 | } |
| 3030 | return ui::ROTATION_0; |
| 3031 | } |
| 3032 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 3033 | void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId, |
| 3034 | const scheduler::FrameTargeters& frameTargeters, |
| 3035 | nsecs_t presentStartTime) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 3036 | SFTRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 3037 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3038 | ui::PhysicalDisplayMap<PhysicalDisplayId, std::shared_ptr<FenceTime>> presentFences; |
| 3039 | ui::PhysicalDisplayMap<PhysicalDisplayId, const sp<Fence>> gpuCompositionDoneFences; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3040 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3041 | for (const auto& [id, targeter] : frameTargeters) { |
| 3042 | auto presentFence = getHwComposer().getPresentFence(id); |
| 3043 | |
| 3044 | if (id == pacesetterId) { |
| 3045 | mTransactionCallbackInvoker.addPresentFence(presentFence); |
| 3046 | } |
| 3047 | |
| 3048 | if (auto fenceTime = targeter->setPresentFence(std::move(presentFence)); |
| 3049 | fenceTime->isValid()) { |
| 3050 | presentFences.try_emplace(id, std::move(fenceTime)); |
| 3051 | } |
| 3052 | |
| 3053 | ftl::FakeGuard guard(mStateLock); |
| 3054 | if (const auto display = getCompositionDisplayLocked(id); |
| 3055 | display && display->getState().usesClientComposition) { |
| 3056 | gpuCompositionDoneFences |
| 3057 | .try_emplace(id, display->getRenderSurface()->getClientTargetAcquireFence()); |
| 3058 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3059 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3060 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3061 | const auto pacesetterDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(pacesetterId)); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3062 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3063 | std::shared_ptr<FenceTime> pacesetterPresentFenceTime = |
| 3064 | presentFences.get(pacesetterId) |
| 3065 | .transform([](const FenceTimePtr& ptr) { return ptr; }) |
| 3066 | .value_or(FenceTime::NO_FENCE); |
| 3067 | |
| 3068 | std::shared_ptr<FenceTime> pacesetterGpuCompositionDoneFenceTime = |
| 3069 | gpuCompositionDoneFences.get(pacesetterId) |
| 3070 | .transform([](sp<Fence> fence) { |
| 3071 | return std::make_shared<FenceTime>(std::move(fence)); |
| 3072 | }) |
| 3073 | .value_or(FenceTime::NO_FENCE); |
| 3074 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 3075 | const TimePoint presentTime = TimePoint::now(); |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 3076 | |
Melody Hsu | e524dd9 | 2024-08-27 22:27:29 +0000 | [diff] [blame] | 3077 | // The Uids of layer owners that are in buffer stuffing mode, and their elevated |
| 3078 | // buffer counts. Messages to start recovery are sent exclusively to these Uids. |
| 3079 | BufferStuffingMap bufferStuffedUids; |
| 3080 | |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 3081 | // Set presentation information before calling Layer::releasePendingBuffer, such that jank |
| 3082 | // information from previous' frame classification is already available when sending jank info |
| 3083 | // to clients, so they get jank classification as early as possible. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3084 | mFrameTimeline->setSfPresent(presentTime.ns(), pacesetterPresentFenceTime, |
| 3085 | pacesetterGpuCompositionDoneFenceTime); |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 3086 | |
Melody Hsu | e524dd9 | 2024-08-27 22:27:29 +0000 | [diff] [blame] | 3087 | // Find and register any layers that are in buffer stuffing mode |
| 3088 | const auto& presentFrames = mFrameTimeline->getPresentFrames(); |
| 3089 | |
| 3090 | for (const auto& frame : presentFrames) { |
| 3091 | const auto& layer = mLayerLifecycleManager.getLayerFromId(frame->getLayerId()); |
| 3092 | if (!layer) continue; |
| 3093 | uint32_t numberQueuedBuffers = layer->pendingBuffers ? layer->pendingBuffers->load() : 0; |
| 3094 | int32_t jankType = frame->getJankType().value_or(JankType::None); |
| 3095 | if (jankType & JankType::BufferStuffing && |
| 3096 | layer->flags & layer_state_t::eRecoverableFromBufferStuffing) { |
| 3097 | auto [it, wasEmplaced] = |
| 3098 | bufferStuffedUids.try_emplace(layer->ownerUid.val(), numberQueuedBuffers); |
| 3099 | // Update with maximum number of queued buffers, allows clients drawing |
| 3100 | // multiple windows to account for the most severely stuffed window |
| 3101 | if (!wasEmplaced && it->second < numberQueuedBuffers) { |
| 3102 | it->second = numberQueuedBuffers; |
| 3103 | } |
| 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | if (!bufferStuffedUids.empty()) { |
| 3108 | mScheduler->addBufferStuffedUids(std::move(bufferStuffedUids)); |
| 3109 | } |
| 3110 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 3111 | // We use the CompositionEngine::getLastFrameRefreshTimestamp() which might |
| 3112 | // 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] | 3113 | // but that should be okay since CompositorTiming has snapping logic. |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 3114 | const TimePoint compositeTime = |
| 3115 | TimePoint::fromNs(mCompositionEngine->getLastFrameRefreshTimestamp()); |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 3116 | const Duration presentLatency = mHasReliablePresentFences |
| 3117 | ? mPresentLatencyTracker.trackPendingFrame(compositeTime, pacesetterPresentFenceTime) |
| 3118 | : Duration::zero(); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3119 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3120 | const auto schedule = mScheduler->getVsyncSchedule(); |
| 3121 | const TimePoint vsyncDeadline = schedule->vsyncDeadlineAfter(presentTime); |
| 3122 | const Period vsyncPeriod = schedule->period(); |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 3123 | const nsecs_t vsyncPhase = |
| 3124 | mScheduler->getVsyncConfiguration().getCurrentConfigs().late.sfOffset; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3125 | |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 3126 | const CompositorTiming compositorTiming(vsyncDeadline.ns(), vsyncPeriod.ns(), vsyncPhase, |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 3127 | presentLatency.ns()); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 3128 | |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 3129 | ui::DisplayMap<ui::LayerStack, const DisplayDevice*> layerStackToDisplay; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3130 | { |
| 3131 | if (!mLayersWithBuffersRemoved.empty() || mNumTrustedPresentationListeners > 0) { |
| 3132 | Mutex::Autolock lock(mStateLock); |
| 3133 | for (const auto& [token, display] : mDisplays) { |
| 3134 | layerStackToDisplay.emplace_or_replace(display->getLayerStack(), display.get()); |
| 3135 | } |
| 3136 | } |
| 3137 | } |
| 3138 | |
| 3139 | for (auto layer : mLayersWithBuffersRemoved) { |
Vishnu Nair | f10a87b | 2023-05-01 14:02:51 -0700 | [diff] [blame] | 3140 | std::vector<ui::LayerStack> previouslyPresentedLayerStacks = |
| 3141 | std::move(layer->mPreviouslyPresentedLayerStacks); |
| 3142 | layer->mPreviouslyPresentedLayerStacks.clear(); |
| 3143 | for (auto layerStack : previouslyPresentedLayerStacks) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3144 | auto optDisplay = layerStackToDisplay.get(layerStack); |
| 3145 | if (optDisplay && !optDisplay->get()->isVirtual()) { |
| 3146 | auto fence = getHwComposer().getPresentFence(optDisplay->get()->getPhysicalId()); |
Melody Hsu | 0077fde | 2024-10-17 21:42:50 +0000 | [diff] [blame] | 3147 | layer->prepareReleaseCallbacks(ftl::yield<FenceResult>(fence), |
| 3148 | ui::INVALID_LAYER_STACK); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3149 | } |
| 3150 | } |
| 3151 | layer->releasePendingBuffer(presentTime.ns()); |
| 3152 | } |
| 3153 | mLayersWithBuffersRemoved.clear(); |
| 3154 | |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 3155 | for (const auto& [layer, gameMode] : mLayersWithQueuedFrames) { |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 3156 | layer->onCompositionPresented(pacesetterDisplay.get(), |
| 3157 | pacesetterGpuCompositionDoneFenceTime, |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 3158 | pacesetterPresentFenceTime, compositorTiming, gameMode); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3159 | layer->releasePendingBuffer(presentTime.ns()); |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 3160 | } |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 3161 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3162 | std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>> |
| 3163 | hdrInfoListeners; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3164 | bool haveNewListeners = false; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3165 | { |
| 3166 | Mutex::Autolock lock(mStateLock); |
| 3167 | if (mFpsReporter) { |
Andy Yu | aef688b | 2024-01-23 17:14:23 -0800 | [diff] [blame] | 3168 | mFpsReporter->dispatchLayerFps(mLayerHierarchyBuilder.getHierarchy()); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3169 | } |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 3170 | |
| 3171 | if (mTunnelModeEnabledReporter) { |
| 3172 | mTunnelModeEnabledReporter->updateTunnelModeStatus(); |
| 3173 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3174 | hdrInfoListeners.reserve(mHdrLayerInfoListeners.size()); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 3175 | for (const auto& [displayId, reporter] : mHdrLayerInfoListeners) { |
| 3176 | if (reporter && reporter->hasListeners()) { |
| 3177 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 3178 | hdrInfoListeners.emplace_back(display->getCompositionDisplay(), reporter); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3179 | } |
| 3180 | } |
| 3181 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3182 | haveNewListeners = mAddingHDRLayerInfoListener; // grab this with state lock |
| 3183 | mAddingHDRLayerInfoListener = false; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3184 | } |
| 3185 | |
Alec Mouri | d05a745 | 2024-09-20 13:44:02 +0000 | [diff] [blame] | 3186 | for (const auto& layerEvent : mLayerEvents) { |
| 3187 | auto result = |
| 3188 | stats::stats_write(stats::SURFACE_CONTROL_EVENT, |
| 3189 | static_cast<int32_t>(layerEvent.uid), |
| 3190 | static_cast<int64_t>(layerEvent.timeSinceLastEvent.count()), |
| 3191 | static_cast<int32_t>(layerEvent.dataspace)); |
| 3192 | if (result < 0) { |
| 3193 | ALOGW("Failed to report layer event with error: %d", result); |
| 3194 | } |
| 3195 | } |
| 3196 | |
| 3197 | mLayerEvents.clear(); |
| 3198 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3199 | if (haveNewListeners || mHdrLayerInfoChanged) { |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3200 | for (auto& [compositionDisplay, listener] : hdrInfoListeners) { |
| 3201 | HdrLayerInfoReporter::HdrLayerInfo info; |
| 3202 | int32_t maxArea = 0; |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 3203 | |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3204 | auto updateInfoFn = |
| 3205 | [&](const std::shared_ptr<compositionengine::Display>& compositionDisplay, |
| 3206 | const frontend::LayerSnapshot& snapshot, const sp<LayerFE>& layerFe) { |
| 3207 | if (snapshot.isVisible && |
| 3208 | compositionDisplay->includesLayer(snapshot.outputFilter)) { |
| 3209 | if (isHdrLayer(snapshot)) { |
| 3210 | const auto* outputLayer = |
| 3211 | compositionDisplay->getOutputLayerForLayer(layerFe); |
| 3212 | if (outputLayer) { |
| 3213 | const float desiredHdrSdrRatio = |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 3214 | snapshot.desiredHdrSdrRatio < 1.f |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3215 | ? std::numeric_limits<float>::infinity() |
| 3216 | : snapshot.desiredHdrSdrRatio; |
| 3217 | info.mergeDesiredRatio(desiredHdrSdrRatio); |
| 3218 | info.numberOfHdrLayers++; |
| 3219 | const auto displayFrame = outputLayer->getState().displayFrame; |
| 3220 | const int32_t area = |
| 3221 | displayFrame.width() * displayFrame.height(); |
| 3222 | if (area > maxArea) { |
| 3223 | maxArea = area; |
| 3224 | info.maxW = displayFrame.width(); |
| 3225 | info.maxH = displayFrame.height(); |
| 3226 | } |
| 3227 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3228 | } |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 3229 | } |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3230 | }; |
| 3231 | |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 3232 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 3233 | [&, compositionDisplay = compositionDisplay]( |
| 3234 | std::unique_ptr<frontend::LayerSnapshot>& snapshot) |
| 3235 | FTL_FAKE_GUARD(kMainThreadContext) { |
| 3236 | auto it = mLegacyLayers.find(snapshot->sequence); |
| 3237 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 3238 | "Couldnt find layer object for %s", |
| 3239 | snapshot->getDebugString().c_str()); |
| 3240 | auto& legacyLayer = it->second; |
| 3241 | sp<LayerFE> layerFe = |
| 3242 | legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3243 | |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 3244 | updateInfoFn(compositionDisplay, *snapshot, layerFe); |
| 3245 | }); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3246 | listener->dispatchHdrLayerInfo(info); |
| 3247 | } |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3248 | } |
| 3249 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3250 | mHdrLayerInfoChanged = false; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3251 | |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 3252 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 3253 | mTransactionCallbackInvoker.clearCompletedTransactions(); |
| 3254 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3255 | mTimeStats->incrementTotalFrames(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3256 | mTimeStats->setPresentFenceGlobal(pacesetterPresentFenceTime); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3257 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3258 | for (auto&& [id, presentFence] : presentFences) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3259 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3260 | const bool isInternalDisplay = |
| 3261 | mPhysicalDisplays.get(id).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 3262 | |
| 3263 | if (isInternalDisplay) { |
| 3264 | mScheduler->addPresentFence(id, std::move(presentFence)); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3265 | } |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3266 | } |
| 3267 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3268 | const bool hasPacesetterDisplay = |
| 3269 | pacesetterDisplay && getHwComposer().isConnected(pacesetterId); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3270 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3271 | if (!hasSyncFramework) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3272 | if (hasPacesetterDisplay && pacesetterDisplay->isPoweredOn()) { |
| 3273 | mScheduler->enableHardwareVsync(pacesetterId); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3274 | } |
| 3275 | } |
| 3276 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3277 | if (hasPacesetterDisplay && !pacesetterDisplay->isPoweredOn()) { |
Lars Svensson | d9e5469 | 2021-12-21 07:41:57 +0100 | [diff] [blame] | 3278 | getRenderEngine().cleanupPostRender(); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 3279 | return; |
| 3280 | } |
| 3281 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 3282 | // Cleanup any outstanding resources due to rendering a prior frame. |
| 3283 | getRenderEngine().cleanupPostRender(); |
| 3284 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3285 | if (mNumTrustedPresentationListeners > 0) { |
| 3286 | // 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] | 3287 | traverseLegacyLayers([&](Layer* layer) FTL_FAKE_GUARD(kMainThreadContext) { |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3288 | if (!layer->hasTrustedPresentationListener()) { |
| 3289 | return; |
| 3290 | } |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 3291 | const frontend::LayerSnapshot* snapshot = |
| 3292 | mLayerSnapshotBuilder.getSnapshot(layer->sequence); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3293 | std::optional<const DisplayDevice*> displayOpt = std::nullopt; |
| 3294 | if (snapshot) { |
| 3295 | displayOpt = layerStackToDisplay.get(snapshot->outputFilter.layerStack); |
| 3296 | } |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 3297 | const DisplayDevice* display = displayOpt.value_or(nullptr); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3298 | layer->updateTrustedPresentationState(display, snapshot, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 3299 | nanoseconds_to_milliseconds(presentStartTime), |
| 3300 | false); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3301 | }); |
| 3302 | } |
| 3303 | |
Vishnu Nair | 2665ca9 | 2024-07-09 22:08:15 +0000 | [diff] [blame] | 3304 | // Even though SFTRACE_INT64 already checks if tracing is enabled, it doesn't prevent the |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3305 | // side-effect of getTotalSize(), so we check that again here |
Vishnu Nair | 2665ca9 | 2024-07-09 22:08:15 +0000 | [diff] [blame] | 3306 | if (SFTRACE_ENABLED()) { |
Marissa Wall | 22b2de1 | 2019-12-02 18:11:43 -0800 | [diff] [blame] | 3307 | // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 3308 | SFTRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize()); |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3309 | } |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3312 | void SurfaceFlinger::commitTransactions() { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 3313 | SFTRACE_CALL(); |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 3314 | mDebugInTransaction = systemTime(); |
| 3315 | |
| 3316 | // Here we're guaranteed that some transaction flags are set |
| 3317 | // so we can call commitTransactionsLocked unconditionally. |
| 3318 | // We clear the flags with mStateLock held to guarantee that |
| 3319 | // mCurrentState won't change until the transaction is committed. |
| 3320 | mScheduler->modulateVsync({}, &VsyncModulator::onTransactionCommit); |
| 3321 | commitTransactionsLocked(clearTransactionFlags(eTransactionMask)); |
| 3322 | mDebugInTransaction = 0; |
| 3323 | } |
| 3324 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3325 | std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes( |
| 3326 | PhysicalDisplayId displayId) const { |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3327 | std::vector<HWComposer::HWCDisplayMode> hwcModes; |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3328 | std::optional<hal::HWConfigId> activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3329 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3330 | const bool isExternalDisplay = FlagManager::getInstance().connected_display() && |
| 3331 | getHwComposer().getDisplayConnectionType(displayId) == |
| 3332 | ui::DisplayConnectionType::External; |
| 3333 | |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3334 | int attempt = 0; |
| 3335 | constexpr int kMaxAttempts = 3; |
| 3336 | do { |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 3337 | hwcModes = getHwComposer().getModes(displayId, |
| 3338 | scheduler::RefreshRateSelector::kMinSupportedFrameRate |
| 3339 | .getPeriodNsecs()); |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3340 | const auto activeModeHwcIdExp = getHwComposer().getActiveMode(displayId); |
| 3341 | activeModeHwcIdOpt = activeModeHwcIdExp.value_opt(); |
| 3342 | |
| 3343 | if (isExternalDisplay && |
| 3344 | activeModeHwcIdExp.has_error([](status_t error) { return error == NO_INIT; })) { |
| 3345 | constexpr nsecs_t k59HzVsyncPeriod = 16949153; |
| 3346 | constexpr nsecs_t k60HzVsyncPeriod = 16666667; |
| 3347 | |
| 3348 | // DM sets the initial mode for an external display to 1080p@60, but |
| 3349 | // this comes after SF creates its own state (including the |
| 3350 | // DisplayDevice). For now, pick the same mode in order to avoid |
| 3351 | // inconsistent state and unnecessary mode switching. |
| 3352 | // TODO (b/318534874): Let DM decide the initial mode. |
| 3353 | // |
| 3354 | // Try to find 1920x1080 @ 60 Hz |
| 3355 | if (const auto iter = std::find_if(hwcModes.begin(), hwcModes.end(), |
| 3356 | [](const auto& mode) { |
| 3357 | return mode.width == 1920 && |
| 3358 | mode.height == 1080 && |
| 3359 | mode.vsyncPeriod == k60HzVsyncPeriod; |
| 3360 | }); |
| 3361 | iter != hwcModes.end()) { |
| 3362 | activeModeHwcIdOpt = iter->hwcId; |
| 3363 | break; |
| 3364 | } |
| 3365 | |
| 3366 | // Try to find 1920x1080 @ 59-60 Hz |
| 3367 | if (const auto iter = std::find_if(hwcModes.begin(), hwcModes.end(), |
| 3368 | [](const auto& mode) { |
| 3369 | return mode.width == 1920 && |
| 3370 | mode.height == 1080 && |
| 3371 | mode.vsyncPeriod >= k60HzVsyncPeriod && |
| 3372 | mode.vsyncPeriod <= k59HzVsyncPeriod; |
| 3373 | }); |
| 3374 | iter != hwcModes.end()) { |
| 3375 | activeModeHwcIdOpt = iter->hwcId; |
| 3376 | break; |
| 3377 | } |
| 3378 | |
| 3379 | // The display does not support 1080p@60, and this is the last attempt to pick a display |
| 3380 | // mode. Prefer 60 Hz if available, with the closest resolution to 1080p. |
| 3381 | if (attempt + 1 == kMaxAttempts) { |
| 3382 | std::vector<HWComposer::HWCDisplayMode> hwcModeOpts; |
| 3383 | |
| 3384 | for (const auto& mode : hwcModes) { |
| 3385 | if (mode.width <= 1920 && mode.height <= 1080 && |
| 3386 | mode.vsyncPeriod >= k60HzVsyncPeriod && |
| 3387 | mode.vsyncPeriod <= k59HzVsyncPeriod) { |
| 3388 | hwcModeOpts.push_back(mode); |
| 3389 | } |
| 3390 | } |
| 3391 | |
| 3392 | if (const auto iter = std::max_element(hwcModeOpts.begin(), hwcModeOpts.end(), |
| 3393 | [](const auto& a, const auto& b) { |
| 3394 | const auto aSize = a.width * a.height; |
| 3395 | const auto bSize = b.width * b.height; |
| 3396 | if (aSize < bSize) |
| 3397 | return true; |
| 3398 | else if (aSize == bSize) |
| 3399 | return a.vsyncPeriod > b.vsyncPeriod; |
| 3400 | else |
| 3401 | return false; |
| 3402 | }); |
| 3403 | iter != hwcModeOpts.end()) { |
| 3404 | activeModeHwcIdOpt = iter->hwcId; |
| 3405 | break; |
| 3406 | } |
| 3407 | |
| 3408 | // hwcModeOpts was empty, use hwcModes[0] as the last resort |
| 3409 | activeModeHwcIdOpt = hwcModes[0].hwcId; |
| 3410 | } |
| 3411 | } |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3412 | |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3413 | const auto isActiveMode = [activeModeHwcIdOpt](const HWComposer::HWCDisplayMode& mode) { |
| 3414 | return mode.hwcId == activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3415 | }; |
| 3416 | |
| 3417 | if (std::any_of(hwcModes.begin(), hwcModes.end(), isActiveMode)) { |
| 3418 | break; |
| 3419 | } |
| 3420 | } while (++attempt < kMaxAttempts); |
| 3421 | |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3422 | if (attempt == kMaxAttempts) { |
| 3423 | const std::string activeMode = |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3424 | activeModeHwcIdOpt ? std::to_string(*activeModeHwcIdOpt) : "unknown"s; |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3425 | ALOGE("HWC failed to report an active mode that is supported: activeModeHwcId=%s, " |
| 3426 | "hwcModes={%s}", |
| 3427 | activeMode.c_str(), base::Join(hwcModes, ", ").c_str()); |
| 3428 | return {}; |
| 3429 | } |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3430 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3431 | const DisplayModes oldModes = mPhysicalDisplays.get(displayId) |
| 3432 | .transform([](const PhysicalDisplay& display) { |
| 3433 | return display.snapshot().displayModes(); |
| 3434 | }) |
| 3435 | .value_or(DisplayModes{}); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3436 | |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 3437 | DisplayModeId nextModeId = std::accumulate(oldModes.begin(), oldModes.end(), DisplayModeId(-1), |
| 3438 | [](DisplayModeId max, const auto& pair) { |
| 3439 | return std::max(max, pair.first); |
| 3440 | }); |
| 3441 | ++nextModeId; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3442 | |
| 3443 | DisplayModes newModes; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3444 | for (const auto& hwcMode : hwcModes) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 3445 | const auto id = nextModeId++; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3446 | newModes.try_emplace(id, |
| 3447 | DisplayMode::Builder(hwcMode.hwcId) |
| 3448 | .setId(id) |
| 3449 | .setPhysicalDisplayId(displayId) |
| 3450 | .setResolution({hwcMode.width, hwcMode.height}) |
| 3451 | .setVsyncPeriod(hwcMode.vsyncPeriod) |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 3452 | .setVrrConfig(hwcMode.vrrConfig) |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3453 | .setDpiX(hwcMode.dpiX) |
| 3454 | .setDpiY(hwcMode.dpiY) |
| 3455 | .setGroup(hwcMode.configGroup) |
| 3456 | .build()); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3457 | } |
| 3458 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3459 | const bool sameModes = |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3460 | std::equal(newModes.begin(), newModes.end(), oldModes.begin(), oldModes.end(), |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3461 | [](const auto& lhs, const auto& rhs) { |
| 3462 | return equalsExceptDisplayModeId(*lhs.second, *rhs.second); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3463 | }); |
| 3464 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3465 | // Keep IDs if modes have not changed. |
| 3466 | const auto& modes = sameModes ? oldModes : newModes; |
| 3467 | const DisplayModePtr activeMode = |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3468 | std::find_if(modes.begin(), modes.end(), [activeModeHwcIdOpt](const auto& pair) { |
| 3469 | return pair.second->getHwcId() == activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3470 | })->second; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3471 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3472 | if (isExternalDisplay) { |
| 3473 | ALOGI("External display %s initial mode: {%s}", to_string(displayId).c_str(), |
| 3474 | to_string(*activeMode).c_str()); |
| 3475 | } |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3476 | return {modes, activeMode}; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3477 | } |
| 3478 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3479 | bool SurfaceFlinger::configureLocked() { |
| 3480 | std::vector<HotplugEvent> events; |
| 3481 | { |
| 3482 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 3483 | events = std::move(mPendingHotplugEvents); |
| 3484 | } |
| 3485 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3486 | for (const auto [hwcDisplayId, connection] : events) { |
| 3487 | if (auto info = getHwComposer().onHotplug(hwcDisplayId, connection)) { |
| 3488 | const auto displayId = info->id; |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3489 | const ftl::Concat displayString("display ", displayId.value, "(HAL ID ", hwcDisplayId, |
| 3490 | ')'); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3491 | |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3492 | if (connection == hal::Connection::CONNECTED) { |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3493 | const auto activeModeIdOpt = |
| 3494 | processHotplugConnect(displayId, hwcDisplayId, std::move(*info), |
| 3495 | displayString.c_str()); |
| 3496 | if (!activeModeIdOpt) { |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3497 | if (FlagManager::getInstance().hotplug2()) { |
| 3498 | mScheduler->dispatchHotplugError( |
| 3499 | static_cast<int32_t>(DisplayHotplugEvent::ERROR_UNKNOWN)); |
| 3500 | } |
| 3501 | getHwComposer().disconnectDisplay(displayId); |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3502 | continue; |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3503 | } |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3504 | |
| 3505 | const auto [kernelIdleTimerController, idleTimerTimeoutMs] = |
| 3506 | getKernelIdleTimerProperties(displayId); |
| 3507 | |
| 3508 | using Config = scheduler::RefreshRateSelector::Config; |
| 3509 | const Config config = |
| 3510 | {.enableFrameRateOverride = sysprop::enable_frame_rate_override(true) |
| 3511 | ? Config::FrameRateOverride::Enabled |
| 3512 | : Config::FrameRateOverride::Disabled, |
| 3513 | .frameRateMultipleThreshold = |
| 3514 | base::GetIntProperty("debug.sf.frame_rate_multiple_threshold"s, 0), |
| 3515 | .legacyIdleTimerTimeout = idleTimerTimeoutMs, |
| 3516 | .kernelIdleTimerController = kernelIdleTimerController}; |
| 3517 | |
| 3518 | const auto snapshotOpt = |
| 3519 | mPhysicalDisplays.get(displayId).transform(&PhysicalDisplay::snapshotRef); |
| 3520 | LOG_ALWAYS_FATAL_IF(!snapshotOpt); |
| 3521 | |
| 3522 | mDisplayModeController.registerDisplay(*snapshotOpt, *activeModeIdOpt, config); |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3523 | } else { |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3524 | // Unregister before destroying the DisplaySnapshot below. |
| 3525 | mDisplayModeController.unregisterDisplay(displayId); |
| 3526 | |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3527 | processHotplugDisconnect(displayId, displayString.c_str()); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3528 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3529 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3530 | } |
| 3531 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3532 | return !events.empty(); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3533 | } |
| 3534 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3535 | std::optional<DisplayModeId> SurfaceFlinger::processHotplugConnect(PhysicalDisplayId displayId, |
| 3536 | hal::HWDisplayId hwcDisplayId, |
| 3537 | DisplayIdentificationInfo&& info, |
| 3538 | const char* displayString) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3539 | auto [displayModes, activeMode] = loadDisplayModes(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3540 | if (!activeMode) { |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3541 | ALOGE("Failed to hotplug %s", displayString); |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3542 | return std::nullopt; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3543 | } |
| 3544 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3545 | const DisplayModeId activeModeId = activeMode->getId(); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3546 | ui::ColorModes colorModes = getHwComposer().getColorModes(displayId); |
| 3547 | |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3548 | if (const auto displayOpt = mPhysicalDisplays.get(displayId)) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3549 | const auto& display = displayOpt->get(); |
| 3550 | const auto& snapshot = display.snapshot(); |
| 3551 | |
| 3552 | std::optional<DeviceProductInfo> deviceProductInfo; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3553 | if (getHwComposer().updatesDeviceProductInfoOnHotplugReconnect()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3554 | deviceProductInfo = std::move(info.deviceProductInfo); |
| 3555 | } else { |
| 3556 | deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3557 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3558 | |
| 3559 | const auto it = |
| 3560 | mPhysicalDisplays.try_replace(displayId, display.token(), displayId, |
| 3561 | snapshot.connectionType(), std::move(displayModes), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3562 | std::move(colorModes), std::move(deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3563 | |
| 3564 | auto& state = mCurrentState.displays.editValueFor(it->second.token()); |
| 3565 | state.sequenceId = DisplayDeviceState{}.sequenceId; // Generate new sequenceId. |
| 3566 | state.physical->activeMode = std::move(activeMode); |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3567 | ALOGI("Reconnecting %s", displayString); |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3568 | return activeModeId; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3569 | } |
| 3570 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3571 | const sp<IBinder> token = sp<BBinder>::make(); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3572 | const ui::DisplayConnectionType connectionType = |
| 3573 | getHwComposer().getDisplayConnectionType(displayId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3574 | |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3575 | mPhysicalDisplays.try_emplace(displayId, token, displayId, connectionType, |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3576 | std::move(displayModes), std::move(colorModes), |
| 3577 | std::move(info.deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3578 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3579 | DisplayDeviceState state; |
| 3580 | state.physical = {.id = displayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3581 | .hwcDisplayId = hwcDisplayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3582 | .activeMode = std::move(activeMode)}; |
Huihong Luo | 82e1563 | 2024-06-27 02:37:08 +0000 | [diff] [blame] | 3583 | if (mIsHdcpViaNegVsync) { |
| 3584 | state.isSecure = connectionType == ui::DisplayConnectionType::Internal; |
| 3585 | } else { |
| 3586 | // TODO(b/349703362): Remove this when HDCP aidl API becomes ready |
| 3587 | state.isSecure = true; // All physical displays are currently considered secure. |
| 3588 | } |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3589 | state.isProtected = true; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3590 | state.displayName = std::move(info.name); |
Brian Lindahl | 07dcd49 | 2024-10-30 11:43:23 -0600 | [diff] [blame] | 3591 | state.maxLayerPictureProfiles = getHwComposer().getMaxLayerPictureProfiles(displayId); |
| 3592 | state.hasPictureProcessing = |
| 3593 | getHwComposer().hasDisplayCapability(displayId, DisplayCapability::PICTURE_PROCESSING); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3594 | mCurrentState.displays.add(token, state); |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3595 | ALOGI("Connecting %s", displayString); |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3596 | return activeModeId; |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3597 | } |
| 3598 | |
| 3599 | void SurfaceFlinger::processHotplugDisconnect(PhysicalDisplayId displayId, |
| 3600 | const char* displayString) { |
| 3601 | ALOGI("Disconnecting %s", displayString); |
| 3602 | |
| 3603 | const auto displayOpt = mPhysicalDisplays.get(displayId); |
| 3604 | LOG_ALWAYS_FATAL_IF(!displayOpt); |
| 3605 | const auto& display = displayOpt->get(); |
| 3606 | |
| 3607 | if (const ssize_t index = mCurrentState.displays.indexOfKey(display.token()); index >= 0) { |
| 3608 | mCurrentState.displays.removeItemsAt(index); |
| 3609 | } |
| 3610 | |
| 3611 | mPhysicalDisplays.erase(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3614 | sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3615 | const wp<IBinder>& displayToken, |
| 3616 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3617 | const DisplayDeviceState& state, |
| 3618 | const sp<compositionengine::DisplaySurface>& displaySurface, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3619 | const sp<IGraphicBufferProducer>& producer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3620 | DisplayDeviceCreationArgs creationArgs(sp<SurfaceFlinger>::fromExisting(this), getHwComposer(), |
| 3621 | displayToken, compositionDisplay); |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 3622 | creationArgs.sequenceId = state.sequenceId; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3623 | creationArgs.isSecure = state.isSecure; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3624 | creationArgs.isProtected = state.isProtected; |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3625 | creationArgs.displaySurface = displaySurface; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3626 | creationArgs.hasWideColorGamut = false; |
| 3627 | creationArgs.supportedPerFrameMetadata = 0; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 3628 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3629 | if (const auto physicalIdOpt = PhysicalDisplayId::tryCast(compositionDisplay->getId())) { |
| 3630 | const auto physicalId = *physicalIdOpt; |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3631 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3632 | creationArgs.isPrimary = physicalId == getPrimaryDisplayIdLocked(); |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3633 | creationArgs.refreshRateSelector = |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3634 | FTL_FAKE_GUARD(kMainThreadContext, |
| 3635 | mDisplayModeController.selectorPtrFor(physicalId)); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3636 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3637 | mPhysicalDisplays.get(physicalId) |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 3638 | .transform(&PhysicalDisplay::snapshotRef) |
| 3639 | .transform(ftl::unit_fn([&](const display::DisplaySnapshot& snapshot) { |
| 3640 | for (const auto mode : snapshot.colorModes()) { |
| 3641 | creationArgs.hasWideColorGamut |= ui::isWideColorMode(mode); |
| 3642 | creationArgs.hwcColorModes |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3643 | .emplace(mode, getHwComposer().getRenderIntents(physicalId, mode)); |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 3644 | } |
| 3645 | })); |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 3646 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3647 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3648 | if (const auto id = HalDisplayId::tryCast(compositionDisplay->getId())) { |
| 3649 | getHwComposer().getHdrCapabilities(*id, &creationArgs.hdrCapabilities); |
| 3650 | creationArgs.supportedPerFrameMetadata = getHwComposer().getSupportedPerFrameMetadata(*id); |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 3651 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3652 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 3653 | auto nativeWindowSurface = getFactory().createNativeWindowSurface(producer); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3654 | auto nativeWindow = nativeWindowSurface->getNativeWindow(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3655 | creationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3656 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3657 | // Make sure that composition can never be stalled by a virtual display |
| 3658 | // 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] | 3659 | // here, in case the display is composed entirely by HWC. |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 3660 | if (state.isVirtual()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3661 | nativeWindow->setSwapInterval(nativeWindow.get(), 0); |
| 3662 | } |
| 3663 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 3664 | creationArgs.physicalOrientation = |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3665 | getPhysicalDisplayOrientation(compositionDisplay->getId(), creationArgs.isPrimary); |
| 3666 | ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 3667 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 3668 | creationArgs.initialPowerMode = state.isVirtual() ? hal::PowerMode::ON : hal::PowerMode::OFF; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3669 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3670 | creationArgs.requestedRefreshRate = state.requestedRefreshRate; |
| 3671 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3672 | sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3673 | |
Ady Abraham | 8565ad2 | 2021-06-22 17:45:44 -0700 | [diff] [blame] | 3674 | nativeWindowSurface->preallocateBuffers(); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3675 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3676 | ui::ColorMode defaultColorMode = ui::ColorMode::NATIVE; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 3677 | Dataspace defaultDataSpace = Dataspace::UNKNOWN; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3678 | if (display->hasWideColorGamut()) { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3679 | defaultColorMode = ui::ColorMode::SRGB; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 3680 | defaultDataSpace = Dataspace::V0_SRGB; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3681 | } |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 3682 | display->getCompositionDisplay()->setColorProfile( |
| 3683 | compositionengine::Output::ColorProfile{defaultColorMode, defaultDataSpace, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 3684 | RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3685 | |
| 3686 | if (const auto& physical = state.physical) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3687 | const auto& mode = *physical->activeMode; |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 3688 | mDisplayModeController.setActiveMode(physical->id, mode.getId(), mode.getVsyncRate(), |
ramindani | 914d106 | 2024-07-15 13:16:52 -0700 | [diff] [blame] | 3689 | mode.getPeakFps()); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 3690 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3691 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3692 | display->setLayerFilter(makeLayerFilterForDisplay(display->getId(), state.layerStack)); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3693 | display->setProjection(state.orientation, state.layerStackSpaceRect, |
| 3694 | state.orientedDisplaySpaceRect); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3695 | display->setDisplayName(state.displayName); |
Vishnu Nair | a119aaa | 2021-09-24 07:19:35 -0700 | [diff] [blame] | 3696 | display->setFlags(state.flags); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3697 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3698 | return display; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3699 | } |
| 3700 | |
Ady Abraham | 8e3e2ea | 2024-10-31 15:52:31 -0700 | [diff] [blame] | 3701 | void SurfaceFlinger::incRefreshableDisplays() { |
| 3702 | if (FlagManager::getInstance().no_vsyncs_on_screen_off()) { |
| 3703 | mRefreshableDisplays++; |
| 3704 | if (mRefreshableDisplays == 1) { |
| 3705 | ftl::FakeGuard guard(kMainThreadContext); |
| 3706 | mScheduler->omitVsyncDispatching(false); |
| 3707 | } |
| 3708 | } |
| 3709 | } |
| 3710 | |
| 3711 | void SurfaceFlinger::decRefreshableDisplays() { |
| 3712 | if (FlagManager::getInstance().no_vsyncs_on_screen_off()) { |
| 3713 | mRefreshableDisplays--; |
| 3714 | if (mRefreshableDisplays == 0) { |
| 3715 | ftl::FakeGuard guard(kMainThreadContext); |
| 3716 | mScheduler->omitVsyncDispatching(true); |
| 3717 | } |
| 3718 | } |
| 3719 | } |
| 3720 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3721 | void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, |
| 3722 | const DisplayDeviceState& state) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3723 | ui::Size resolution(0, 0); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3724 | ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN); |
| 3725 | if (state.physical) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3726 | resolution = state.physical->activeMode->getResolution(); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3727 | pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888); |
| 3728 | } else if (state.surface != nullptr) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3729 | int status = state.surface->query(NATIVE_WINDOW_WIDTH, &resolution.width); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3730 | ALOGE_IF(status != NO_ERROR, "Unable to query width (%d)", status); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3731 | status = state.surface->query(NATIVE_WINDOW_HEIGHT, &resolution.height); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3732 | ALOGE_IF(status != NO_ERROR, "Unable to query height (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3733 | int format; |
| 3734 | status = state.surface->query(NATIVE_WINDOW_FORMAT, &format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3735 | ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3736 | pixelFormat = static_cast<ui::PixelFormat>(format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3737 | } else { |
| 3738 | // Virtual displays without a surface are dormant: |
| 3739 | // they have external state (layer stack, projection, |
| 3740 | // etc.) but no internal state (i.e. a DisplayDevice). |
| 3741 | return; |
| 3742 | } |
| 3743 | |
| 3744 | compositionengine::DisplayCreationArgsBuilder builder; |
| 3745 | if (const auto& physical = state.physical) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3746 | builder.setId(physical->id); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3747 | } else { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 3748 | builder.setId(acquireVirtualDisplay(resolution, pixelFormat)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3749 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3750 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3751 | builder.setPixels(resolution); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3752 | builder.setIsSecure(state.isSecure); |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3753 | builder.setIsProtected(state.isProtected); |
Brian Lindahl | 07dcd49 | 2024-10-30 11:43:23 -0600 | [diff] [blame] | 3754 | builder.setHasPictureProcessing(state.hasPictureProcessing); |
| 3755 | builder.setMaxLayerPictureProfiles(state.maxLayerPictureProfiles); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 3756 | builder.setPowerAdvisor(mPowerAdvisor.get()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3757 | builder.setName(state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3758 | auto compositionDisplay = getCompositionEngine().createDisplay(builder.build()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3759 | compositionDisplay->setLayerCachingEnabled(mLayerCachingEnabled); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3760 | |
| 3761 | sp<compositionengine::DisplaySurface> displaySurface; |
| 3762 | sp<IGraphicBufferProducer> producer; |
| 3763 | sp<IGraphicBufferProducer> bqProducer; |
| 3764 | sp<IGraphicBufferConsumer> bqConsumer; |
| 3765 | getFactory().createBufferQueue(&bqProducer, &bqConsumer, /*consumerIsSurfaceFlinger =*/false); |
| 3766 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3767 | if (state.isVirtual()) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3768 | const auto displayId = VirtualDisplayId::tryCast(compositionDisplay->getId()); |
| 3769 | LOG_FATAL_IF(!displayId); |
| 3770 | auto surface = sp<VirtualDisplaySurface>::make(getHwComposer(), *displayId, state.surface, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3771 | bqProducer, bqConsumer, state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3772 | displaySurface = surface; |
| 3773 | producer = std::move(surface); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3774 | } else { |
| 3775 | ALOGE_IF(state.surface != nullptr, |
| 3776 | "adding a supported display, but rendering " |
| 3777 | "surface is provided (%p), ignoring it", |
| 3778 | state.surface.get()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3779 | const auto displayId = PhysicalDisplayId::tryCast(compositionDisplay->getId()); |
| 3780 | LOG_FATAL_IF(!displayId); |
Jim Shargo | 6ccc5e8 | 2024-07-27 03:42:08 +0000 | [diff] [blame] | 3781 | #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ) |
| 3782 | const auto frameBufferSurface = |
| 3783 | sp<FramebufferSurface>::make(getHwComposer(), *displayId, bqProducer, bqConsumer, |
| 3784 | state.physical->activeMode->getResolution(), |
| 3785 | ui::Size(maxGraphicsWidth, maxGraphicsHeight)); |
| 3786 | displaySurface = frameBufferSurface; |
| 3787 | producer = frameBufferSurface->getSurface()->getIGraphicBufferProducer(); |
| 3788 | #else |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3789 | displaySurface = |
| 3790 | sp<FramebufferSurface>::make(getHwComposer(), *displayId, bqConsumer, |
| 3791 | state.physical->activeMode->getResolution(), |
| 3792 | ui::Size(maxGraphicsWidth, maxGraphicsHeight)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3793 | producer = bqProducer; |
Jim Shargo | 6ccc5e8 | 2024-07-27 03:42:08 +0000 | [diff] [blame] | 3794 | #endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3795 | } |
| 3796 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3797 | LOG_FATAL_IF(!displaySurface); |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3798 | auto display = setupNewDisplayDeviceInternal(displayToken, std::move(compositionDisplay), state, |
| 3799 | displaySurface, producer); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3800 | |
| 3801 | if (mScheduler && !display->isVirtual()) { |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3802 | // TODO(b/241285876): Annotate `processDisplayAdded` instead. |
| 3803 | ftl::FakeGuard guard(kMainThreadContext); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3804 | |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3805 | // For hotplug reconnect, renew the registration since display modes have been reloaded. |
Dominik Laskowski | 3ff44c7 | 2024-06-17 11:03:30 -0400 | [diff] [blame] | 3806 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector(), |
| 3807 | mActiveDisplayId); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3808 | } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3809 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3810 | if (display->isVirtual()) { |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 3811 | display->adjustRefreshRate(mScheduler->getPacesetterRefreshRate()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3812 | } |
| 3813 | |
Ady Abraham | 8e3e2ea | 2024-10-31 15:52:31 -0700 | [diff] [blame] | 3814 | if (display->isRefreshable()) { |
| 3815 | incRefreshableDisplays(); |
| 3816 | } |
| 3817 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3818 | mDisplays.try_emplace(displayToken, std::move(display)); |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3819 | |
| 3820 | // For an external display, loadDisplayModes already attempted to select the same mode |
| 3821 | // as DM, but SF still needs to be updated to match. |
| 3822 | // TODO (b/318534874): Let DM decide the initial mode. |
| 3823 | if (const auto& physical = state.physical; |
| 3824 | mScheduler && physical && FlagManager::getInstance().connected_display()) { |
| 3825 | const bool isInternalDisplay = mPhysicalDisplays.get(physical->id) |
| 3826 | .transform(&PhysicalDisplay::isInternal) |
| 3827 | .value_or(false); |
| 3828 | |
| 3829 | if (!isInternalDisplay) { |
| 3830 | auto activeModePtr = physical->activeMode; |
| 3831 | const auto fps = activeModePtr->getPeakFps(); |
| 3832 | |
| 3833 | setDesiredMode( |
| 3834 | {.mode = scheduler::FrameRateMode{fps, |
| 3835 | ftl::as_non_null(std::move(activeModePtr))}, |
| 3836 | .emitEvent = false, |
| 3837 | .force = true}); |
| 3838 | } |
| 3839 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3843 | auto display = getDisplayDeviceLocked(displayToken); |
| 3844 | if (display) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3845 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3846 | |
| 3847 | if (display->isVirtual()) { |
| 3848 | releaseVirtualDisplay(display->getVirtualId()); |
| 3849 | } else { |
Dominik Laskowski | 3ff44c7 | 2024-06-17 11:03:30 -0400 | [diff] [blame] | 3850 | mScheduler->unregisterDisplay(display->getPhysicalId(), mActiveDisplayId); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3851 | } |
Ady Abraham | 8e3e2ea | 2024-10-31 15:52:31 -0700 | [diff] [blame] | 3852 | |
| 3853 | if (display->isRefreshable()) { |
| 3854 | decRefreshableDisplays(); |
| 3855 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3856 | } |
| 3857 | |
| 3858 | mDisplays.erase(displayToken); |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3859 | |
| 3860 | if (display && display->isVirtual()) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 3861 | static_cast<void>(mScheduler->schedule([display = std::move(display)] { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3862 | // Destroy the display without holding the mStateLock. |
| 3863 | // This is a temporary solution until we can manage transaction queues without |
| 3864 | // holding the mStateLock. |
| 3865 | // With blast, the IGBP that is passed to the VirtualDisplaySurface is owned by the |
| 3866 | // client. When the IGBP is disconnected, its buffer cache in SF will be cleared |
| 3867 | // via SurfaceComposerClient::doUncacheBufferTransaction. This call from the client |
| 3868 | // ends up running on the main thread causing a deadlock since setTransactionstate |
| 3869 | // will try to acquire the mStateLock. Instead we extend the lifetime of |
| 3870 | // DisplayDevice and destroy it in the main thread without holding the mStateLock. |
| 3871 | // The display will be disconnected and removed from the mDisplays list so it will |
| 3872 | // not be accessible. |
| 3873 | })); |
| 3874 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3875 | } |
| 3876 | |
| 3877 | void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, |
| 3878 | const DisplayDeviceState& currentState, |
| 3879 | const DisplayDeviceState& drawingState) { |
| 3880 | const sp<IBinder> currentBinder = IInterface::asBinder(currentState.surface); |
| 3881 | const sp<IBinder> drawingBinder = IInterface::asBinder(drawingState.surface); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3882 | |
| 3883 | // Recreate the DisplayDevice if the surface or sequence ID changed. |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3884 | if (currentBinder != drawingBinder || currentState.sequenceId != drawingState.sequenceId) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3885 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3886 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3887 | if (display->isVirtual()) { |
| 3888 | releaseVirtualDisplay(display->getVirtualId()); |
| 3889 | } |
Ady Abraham | 8e3e2ea | 2024-10-31 15:52:31 -0700 | [diff] [blame] | 3890 | |
| 3891 | if (display->isRefreshable()) { |
| 3892 | decRefreshableDisplays(); |
| 3893 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3894 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3895 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3896 | mDisplays.erase(displayToken); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3897 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3898 | if (const auto& physical = currentState.physical) { |
Lucas Berthou | 8d0a0c4 | 2024-08-27 14:32:31 +0000 | [diff] [blame] | 3899 | getHwComposer().allocatePhysicalDisplay(physical->hwcDisplayId, physical->id, |
| 3900 | /*physicalSize=*/std::nullopt); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3901 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3902 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3903 | processDisplayAdded(displayToken, currentState); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3904 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3905 | if (currentState.physical) { |
Marin Shalamanov | 4c5e301 | 2020-06-04 21:41:42 +0200 | [diff] [blame] | 3906 | const auto display = getDisplayDeviceLocked(displayToken); |
Robert Horvath | dce110a | 2022-09-16 11:08:47 +0200 | [diff] [blame] | 3907 | if (!mSkipPowerOnForQuiescent) { |
| 3908 | setPowerModeInternal(display, hal::PowerMode::ON); |
| 3909 | } |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3910 | |
Dominik Laskowski | f504875 | 2024-08-04 15:08:00 -0400 | [diff] [blame] | 3911 | if (display->getPhysicalId() == mActiveDisplayId) { |
| 3912 | onActiveDisplayChangedLocked(nullptr, *display); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3913 | } |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3914 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3915 | return; |
| 3916 | } |
| 3917 | |
| 3918 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3919 | if (currentState.layerStack != drawingState.layerStack) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3920 | display->setLayerFilter( |
| 3921 | makeLayerFilterForDisplay(display->getId(), currentState.layerStack)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3922 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 3923 | if (currentState.flags != drawingState.flags) { |
| 3924 | display->setFlags(currentState.flags); |
| 3925 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3926 | if ((currentState.orientation != drawingState.orientation) || |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3927 | (currentState.layerStackSpaceRect != drawingState.layerStackSpaceRect) || |
| 3928 | (currentState.orientedDisplaySpaceRect != drawingState.orientedDisplaySpaceRect)) { |
| 3929 | display->setProjection(currentState.orientation, currentState.layerStackSpaceRect, |
| 3930 | currentState.orientedDisplaySpaceRect); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3931 | if (display->getId() == mActiveDisplayId) { |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 3932 | mActiveDisplayTransformHint = display->getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 3933 | sActiveDisplayRotationFlags = |
| 3934 | ui::Transform::toRotationFlags(display->getOrientation()); |
Arthur Hung | b6aa9a0 | 2021-06-09 14:23:01 +0800 | [diff] [blame] | 3935 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3936 | } |
| 3937 | if (currentState.width != drawingState.width || |
| 3938 | currentState.height != drawingState.height) { |
| 3939 | display->setDisplaySize(currentState.width, currentState.height); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 3940 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3941 | if (display->getId() == mActiveDisplayId) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 3942 | onActiveDisplaySizeChanged(*display); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3943 | } |
| 3944 | } |
| 3945 | } |
| 3946 | } |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 3947 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3948 | void SurfaceFlinger::processDisplayChangesLocked() { |
| 3949 | // here we take advantage of Vector's copy-on-write semantics to |
| 3950 | // improve performance by skipping the transaction entirely when |
| 3951 | // know that the lists are identical |
| 3952 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays); |
| 3953 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays); |
| 3954 | if (!curr.isIdenticalTo(draw)) { |
| 3955 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3956 | mUpdateInputInfo = true; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3957 | |
Dominik Laskowski | 01f191c | 2024-01-29 11:51:23 -0500 | [diff] [blame] | 3958 | // Apply the current color matrix to any added or changed display. |
| 3959 | mCurrentState.colorMatrixChanged = true; |
| 3960 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3961 | // find the displays that were removed |
| 3962 | // (ie: in drawing state but not in current state) |
| 3963 | // also handle displays that changed |
| 3964 | // (ie: displays that are in both lists) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3965 | for (size_t i = 0; i < draw.size(); i++) { |
| 3966 | const wp<IBinder>& displayToken = draw.keyAt(i); |
| 3967 | const ssize_t j = curr.indexOfKey(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3968 | if (j < 0) { |
| 3969 | // in drawing state but not in current state |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3970 | processDisplayRemoved(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3971 | } else { |
| 3972 | // this display is in both lists. see if something changed. |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3973 | const DisplayDeviceState& currentState = curr[j]; |
| 3974 | const DisplayDeviceState& drawingState = draw[i]; |
| 3975 | processDisplayChanged(displayToken, currentState, drawingState); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3976 | } |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | // find displays that were added |
| 3980 | // (ie: in current state but not in drawing state) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3981 | for (size_t i = 0; i < curr.size(); i++) { |
| 3982 | const wp<IBinder>& displayToken = curr.keyAt(i); |
| 3983 | if (draw.indexOfKey(displayToken) < 0) { |
| 3984 | processDisplayAdded(displayToken, curr[i]); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3985 | } |
| 3986 | } |
| 3987 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3988 | |
| 3989 | mDrawingState.displays = mCurrentState.displays; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3990 | } |
| 3991 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3992 | void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { |
| 3993 | // Commit display transactions. |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3994 | const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3995 | mFrontEndDisplayInfosChanged = displayTransactionNeeded; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3996 | |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3997 | if (mSomeChildrenChanged) { |
| 3998 | mVisibleRegionsDirty = true; |
| 3999 | mSomeChildrenChanged = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4000 | mUpdateInputInfo = true; |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 4001 | } |
| 4002 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4003 | if (mLayersAdded) { |
| 4004 | mLayersAdded = false; |
| 4005 | // Layers have been added. |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 4006 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4007 | mUpdateInputInfo = true; |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | // some layers might have been removed, so |
| 4011 | // we need to update the regions they're exposing. |
| 4012 | if (mLayersRemoved) { |
| 4013 | mLayersRemoved = false; |
| 4014 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4015 | mUpdateInputInfo = true; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4016 | } |
| 4017 | |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 4018 | if (transactionFlags & eInputInfoUpdateNeeded) { |
| 4019 | mUpdateInputInfo = true; |
| 4020 | } |
| 4021 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4022 | doCommitTransactions(); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 4023 | } |
| 4024 | |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4025 | void SurfaceFlinger::updateInputFlinger(VsyncId vsyncId, TimePoint frameTime) { |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4026 | if (!mInputFlinger || (!mUpdateInputInfo && mInputWindowCommands.empty())) { |
Vishnu Nair | 42a27b5 | 2021-11-18 15:35:22 -0800 | [diff] [blame] | 4027 | return; |
| 4028 | } |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4029 | SFTRACE_CALL(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4030 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4031 | std::vector<WindowInfo> windowInfos; |
| 4032 | std::vector<DisplayInfo> displayInfos; |
| 4033 | bool updateWindowInfo = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4034 | if (mUpdateInputInfo) { |
| 4035 | mUpdateInputInfo = false; |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4036 | updateWindowInfo = true; |
| 4037 | buildWindowInfos(windowInfos, displayInfos); |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4038 | } |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4039 | |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4040 | std::unordered_set<int32_t> visibleWindowIds; |
| 4041 | for (WindowInfo& windowInfo : windowInfos) { |
| 4042 | if (!windowInfo.inputConfig.test(WindowInfo::InputConfig::NOT_VISIBLE)) { |
| 4043 | visibleWindowIds.insert(windowInfo.id); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4044 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4045 | } |
| 4046 | bool visibleWindowsChanged = false; |
| 4047 | if (visibleWindowIds != mVisibleWindowIds) { |
| 4048 | visibleWindowsChanged = true; |
| 4049 | mVisibleWindowIds = std::move(visibleWindowIds); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4050 | } |
| 4051 | |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 4052 | BackgroundExecutor::getInstance().sendCallbacks({[updateWindowInfo, |
| 4053 | windowInfos = std::move(windowInfos), |
| 4054 | displayInfos = std::move(displayInfos), |
| 4055 | inputWindowCommands = |
| 4056 | std::move(mInputWindowCommands), |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4057 | inputFlinger = mInputFlinger, this, |
Patrick Williams | a4eb946 | 2024-11-07 12:57:27 -0600 | [diff] [blame] | 4058 | visibleWindowsChanged, vsyncId, |
| 4059 | frameTime]() mutable { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4060 | SFTRACE_NAME("BackgroundExecutor::updateInputFlinger"); |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4061 | if (updateWindowInfo) { |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 4062 | mWindowInfosListenerInvoker |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4063 | ->windowInfosChanged(gui::WindowInfosUpdate{std::move(windowInfos), |
| 4064 | std::move(displayInfos), |
| 4065 | ftl::to_underlying(vsyncId), |
| 4066 | frameTime.ns()}, |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4067 | std::move( |
| 4068 | inputWindowCommands.windowInfosReportedListeners), |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4069 | /* forceImmediateCall= */ visibleWindowsChanged || |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4070 | !inputWindowCommands.focusRequests.empty()); |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 4071 | } else { |
| 4072 | // If there are listeners but no changes to input windows, call the listeners |
| 4073 | // immediately. |
| 4074 | for (const auto& listener : inputWindowCommands.windowInfosReportedListeners) { |
| 4075 | if (IInterface::asBinder(listener)->isBinderAlive()) { |
| 4076 | listener->onWindowInfosReported(); |
| 4077 | } |
| 4078 | } |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4079 | } |
| 4080 | for (const auto& focusRequest : inputWindowCommands.focusRequests) { |
| 4081 | inputFlinger->setFocusedWindow(focusRequest); |
| 4082 | } |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 4083 | }}); |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 4084 | |
Arthur Hung | 6cbb975 | 2019-09-05 16:38:18 +0800 | [diff] [blame] | 4085 | mInputWindowCommands.clear(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4086 | } |
| 4087 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4088 | void SurfaceFlinger::persistDisplayBrightness(bool needsComposite) { |
| 4089 | const bool supportsDisplayBrightnessCommand = getHwComposer().getComposer()->isSupported( |
| 4090 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 4091 | if (!supportsDisplayBrightnessCommand) { |
| 4092 | return; |
| 4093 | } |
| 4094 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4095 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4096 | if (const auto brightness = display->getStagedBrightness(); brightness) { |
| 4097 | if (!needsComposite) { |
| 4098 | const status_t error = |
| 4099 | getHwComposer() |
| 4100 | .setDisplayBrightness(display->getPhysicalId(), *brightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 4101 | display->getCompositionDisplay() |
| 4102 | ->getState() |
| 4103 | .displayBrightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4104 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 4105 | .applyImmediately = true}) |
| 4106 | .get(); |
| 4107 | |
| 4108 | ALOGE_IF(error != NO_ERROR, |
| 4109 | "Error setting display brightness for display %s: %d (%s)", |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 4110 | to_string(display->getId()).c_str(), error, strerror(error)); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4111 | } |
| 4112 | display->persistBrightness(needsComposite); |
| 4113 | } |
| 4114 | } |
| 4115 | } |
| 4116 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4117 | void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, |
| 4118 | std::vector<DisplayInfo>& outDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4119 | static size_t sNumWindowInfos = 0; |
| 4120 | outWindowInfos.reserve(sNumWindowInfos); |
| 4121 | sNumWindowInfos = 0; |
| 4122 | |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 4123 | mLayerSnapshotBuilder.forEachInputSnapshot( |
| 4124 | [&outWindowInfos](const frontend::LayerSnapshot& snapshot) { |
| 4125 | outWindowInfos.push_back(snapshot.inputInfo); |
| 4126 | }); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 4127 | |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4128 | sNumWindowInfos = outWindowInfos.size(); |
| 4129 | |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 4130 | outDisplayInfos.reserve(mFrontEndDisplayInfos.size()); |
| 4131 | for (const auto& [_, info] : mFrontEndDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4132 | outDisplayInfos.push_back(info.info); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 4133 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 4134 | } |
| 4135 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 4136 | void SurfaceFlinger::updateCursorAsync() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4137 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4138 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 4139 | if (HalDisplayId::tryCast(display->getId())) { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4140 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 4141 | } |
| 4142 | } |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 4143 | |
| 4144 | constexpr bool kCursorOnly = true; |
| 4145 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4146 | mCompositionEngine->updateCursorAsync(refreshArgs); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4147 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4148 | } |
| 4149 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 4150 | void SurfaceFlinger::requestHardwareVsync(PhysicalDisplayId displayId, bool enable) { |
| 4151 | getHwComposer().setVsyncEnabled(displayId, enable ? hal::Vsync::ENABLE : hal::Vsync::DISABLE); |
| 4152 | } |
| 4153 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4154 | void SurfaceFlinger::requestDisplayModes(std::vector<display::DisplayModeRequest> modeRequests) { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 4155 | if (mBootStage != BootStage::FINISHED) { |
| 4156 | ALOGV("Currently in the boot stage, skipping display mode changes"); |
| 4157 | return; |
| 4158 | } |
| 4159 | |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4160 | SFTRACE_CALL(); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4161 | |
Bart Sears | 2d7e7f8 | 2024-07-13 19:42:29 +0000 | [diff] [blame] | 4162 | // If this is called from the main thread mStateLock must be locked before |
| 4163 | // Currently the only way to call this function from the main thread is from |
| 4164 | // Scheduler::chooseRefreshRateForContent |
| 4165 | |
| 4166 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 4167 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4168 | for (auto& request : modeRequests) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4169 | const auto& modePtr = request.mode.modePtr; |
Bart Sears | 2d7e7f8 | 2024-07-13 19:42:29 +0000 | [diff] [blame] | 4170 | |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 4171 | const auto displayId = modePtr->getPhysicalDisplayId(); |
Bart Sears | 2d7e7f8 | 2024-07-13 19:42:29 +0000 | [diff] [blame] | 4172 | const auto display = getDisplayDeviceLocked(displayId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4173 | |
Bart Sears | 2d7e7f8 | 2024-07-13 19:42:29 +0000 | [diff] [blame] | 4174 | if (!display) continue; |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4175 | |
Bart Sears | 2d7e7f8 | 2024-07-13 19:42:29 +0000 | [diff] [blame] | 4176 | if (display->refreshRateSelector().isModeAllowed(request.mode)) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 4177 | setDesiredMode(std::move(request)); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4178 | } else { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 4179 | ALOGV("%s: Mode %d is disallowed for display %s", __func__, |
| 4180 | ftl::to_underlying(modePtr->getId()), to_string(displayId).c_str()); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4181 | } |
| 4182 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 4183 | } |
| 4184 | |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 4185 | void SurfaceFlinger::notifyCpuLoadUp() { |
| 4186 | mPowerAdvisor->notifyCpuLoadUp(); |
| 4187 | } |
| 4188 | |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 4189 | void SurfaceFlinger::onChoreographerAttached() { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4190 | SFTRACE_CALL(); |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 4191 | mUpdateAttachedChoreographer = true; |
| 4192 | scheduleCommit(FrameHint::kNone); |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 4193 | } |
| 4194 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4195 | void SurfaceFlinger::onExpectedPresentTimePosted(TimePoint expectedPresentTime, |
| 4196 | ftl::NonNull<DisplayModePtr> modePtr, |
| 4197 | Fps renderRate) { |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4198 | const auto vsyncPeriod = modePtr->getVsyncRate().getPeriod(); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4199 | const auto timeoutOpt = [&]() -> std::optional<Period> { |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4200 | const auto vrrConfig = modePtr->getVrrConfig(); |
| 4201 | if (!vrrConfig) return std::nullopt; |
| 4202 | |
| 4203 | const auto notifyExpectedPresentConfig = |
| 4204 | modePtr->getVrrConfig()->notifyExpectedPresentConfig; |
| 4205 | if (!notifyExpectedPresentConfig) return std::nullopt; |
ramindani | cbd7a6d | 2023-12-19 16:00:30 -0800 | [diff] [blame] | 4206 | return Period::fromNs(notifyExpectedPresentConfig->timeoutNs); |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4207 | }(); |
| 4208 | |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4209 | notifyExpectedPresentIfRequired(modePtr->getPhysicalDisplayId(), vsyncPeriod, |
| 4210 | expectedPresentTime, renderRate, timeoutOpt); |
| 4211 | } |
| 4212 | |
| 4213 | void SurfaceFlinger::notifyExpectedPresentIfRequired(PhysicalDisplayId displayId, |
| 4214 | Period vsyncPeriod, |
| 4215 | TimePoint expectedPresentTime, |
| 4216 | Fps frameInterval, |
| 4217 | std::optional<Period> timeoutOpt) { |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4218 | auto& data = mNotifyExpectedPresentMap[displayId]; |
| 4219 | const auto lastExpectedPresentTimestamp = data.lastExpectedPresentTimestamp; |
| 4220 | const auto lastFrameInterval = data.lastFrameInterval; |
| 4221 | data.lastFrameInterval = frameInterval; |
| 4222 | data.lastExpectedPresentTimestamp = expectedPresentTime; |
| 4223 | const auto threshold = Duration::fromNs(vsyncPeriod.ns() / 2); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4224 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4225 | const constexpr nsecs_t kOneSecondNs = |
| 4226 | std::chrono::duration_cast<std::chrono::nanoseconds>(1s).count(); |
| 4227 | const auto timeout = |
| 4228 | Period::fromNs(timeoutOpt && timeoutOpt->ns() > 0 ? timeoutOpt->ns() : kOneSecondNs); |
| 4229 | const bool frameIntervalIsOnCadence = |
| 4230 | isFrameIntervalOnCadence(expectedPresentTime, lastExpectedPresentTimestamp, |
| 4231 | lastFrameInterval, timeout, threshold); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4232 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4233 | const bool expectedPresentWithinTimeout = |
| 4234 | isExpectedPresentWithinTimeout(expectedPresentTime, lastExpectedPresentTimestamp, |
| 4235 | timeoutOpt, threshold); |
| 4236 | if (expectedPresentWithinTimeout && frameIntervalIsOnCadence) { |
| 4237 | return; |
| 4238 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4239 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4240 | auto hintStatus = data.hintStatus.load(); |
| 4241 | if (!expectedPresentWithinTimeout) { |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4242 | if ((hintStatus != NotifyExpectedPresentHintStatus::Sent && |
| 4243 | hintStatus != NotifyExpectedPresentHintStatus::ScheduleOnTx) || |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4244 | (timeoutOpt && timeoutOpt->ns() == 0)) { |
| 4245 | // Send the hint immediately if timeout, as the hint gets |
| 4246 | // delayed otherwise, as the frame is scheduled close |
| 4247 | // to the actual present. |
| 4248 | if (data.hintStatus |
| 4249 | .compare_exchange_strong(hintStatus, |
| 4250 | NotifyExpectedPresentHintStatus::ScheduleOnTx)) { |
| 4251 | scheduleNotifyExpectedPresentHint(displayId); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4252 | return; |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4253 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4254 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4255 | } |
| 4256 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4257 | if (hintStatus == NotifyExpectedPresentHintStatus::Sent && |
| 4258 | data.hintStatus.compare_exchange_strong(hintStatus, |
| 4259 | NotifyExpectedPresentHintStatus::ScheduleOnTx)) { |
| 4260 | return; |
| 4261 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4262 | if (hintStatus != NotifyExpectedPresentHintStatus::Start) { |
| 4263 | return; |
| 4264 | } |
| 4265 | data.hintStatus.store(NotifyExpectedPresentHintStatus::ScheduleOnPresent); |
| 4266 | mScheduler->scheduleFrame(); |
| 4267 | } |
| 4268 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4269 | void SurfaceFlinger::scheduleNotifyExpectedPresentHint(PhysicalDisplayId displayId, |
| 4270 | VsyncId vsyncId) { |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4271 | auto itr = mNotifyExpectedPresentMap.find(displayId); |
| 4272 | if (itr == mNotifyExpectedPresentMap.end()) { |
| 4273 | return; |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4274 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4275 | |
| 4276 | const char* const whence = __func__; |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4277 | const auto sendHint = [=, this]() { |
| 4278 | auto& data = mNotifyExpectedPresentMap.at(displayId); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4279 | TimePoint expectedPresentTime = data.lastExpectedPresentTimestamp; |
| 4280 | if (ftl::to_underlying(vsyncId) != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 4281 | const auto predictionOpt = mFrameTimeline->getTokenManager()->getPredictionsForToken( |
| 4282 | ftl::to_underlying(vsyncId)); |
| 4283 | const auto expectedPresentTimeOnPredictor = TimePoint::fromNs( |
| 4284 | predictionOpt ? predictionOpt->presentTime : expectedPresentTime.ns()); |
| 4285 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 4286 | const auto expectedPresentTimeOnScheduler = scheduledFrameResultOpt.has_value() |
| 4287 | ? scheduledFrameResultOpt->vsyncTime |
| 4288 | : TimePoint::fromNs(0); |
| 4289 | expectedPresentTime = |
| 4290 | std::max(expectedPresentTimeOnPredictor, expectedPresentTimeOnScheduler); |
| 4291 | } |
| 4292 | |
| 4293 | if (expectedPresentTime < TimePoint::now()) { |
| 4294 | expectedPresentTime = |
| 4295 | mScheduler->getVsyncSchedule()->vsyncDeadlineAfter(TimePoint::now()); |
| 4296 | if (mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration > |
| 4297 | mScheduler->getVsyncSchedule(displayId)->period()) { |
| 4298 | expectedPresentTime += mScheduler->getVsyncSchedule(displayId)->period(); |
| 4299 | } |
| 4300 | } |
| 4301 | const auto status = getHwComposer().notifyExpectedPresent(displayId, expectedPresentTime, |
| 4302 | data.lastFrameInterval); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4303 | if (status != NO_ERROR) { |
| 4304 | ALOGE("%s failed to notifyExpectedPresentHint for display %" PRId64, whence, |
| 4305 | displayId.value); |
| 4306 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4307 | }; |
| 4308 | |
| 4309 | if (itr->second.hintStatus == NotifyExpectedPresentHintStatus::ScheduleOnTx) { |
| 4310 | return static_cast<void>(mScheduler->schedule([=, |
| 4311 | this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 4312 | auto& data = mNotifyExpectedPresentMap.at(displayId); |
| 4313 | auto scheduleHintOnTx = NotifyExpectedPresentHintStatus::ScheduleOnTx; |
| 4314 | if (data.hintStatus.compare_exchange_strong(scheduleHintOnTx, |
| 4315 | NotifyExpectedPresentHintStatus::Sent)) { |
| 4316 | sendHint(); |
ramindani | 2ff3cd4 | 2024-08-27 10:46:26 -0700 | [diff] [blame] | 4317 | constexpr bool kAllowToEnable = true; |
| 4318 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable); |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4319 | } |
| 4320 | })); |
| 4321 | } |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4322 | auto scheduleHintOnPresent = NotifyExpectedPresentHintStatus::ScheduleOnPresent; |
| 4323 | if (itr->second.hintStatus.compare_exchange_strong(scheduleHintOnPresent, |
| 4324 | NotifyExpectedPresentHintStatus::Sent)) { |
| 4325 | sendHint(); |
| 4326 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4327 | } |
| 4328 | |
| 4329 | void SurfaceFlinger::sendNotifyExpectedPresentHint(PhysicalDisplayId displayId) { |
| 4330 | if (auto itr = mNotifyExpectedPresentMap.find(displayId); |
| 4331 | itr == mNotifyExpectedPresentMap.end() || |
| 4332 | itr->second.hintStatus != NotifyExpectedPresentHintStatus::ScheduleOnPresent) { |
| 4333 | return; |
| 4334 | } |
| 4335 | scheduleNotifyExpectedPresentHint(displayId); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4336 | } |
| 4337 | |
Ady Abraham | 14beed7 | 2024-05-15 17:16:45 -0700 | [diff] [blame] | 4338 | void SurfaceFlinger::onCommitNotComposited(PhysicalDisplayId pacesetterDisplayId) { |
| 4339 | if (FlagManager::getInstance().commit_not_composited()) { |
| 4340 | mFrameTimeline->onCommitNotComposited(); |
| 4341 | } |
| 4342 | } |
| 4343 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 4344 | void SurfaceFlinger::initScheduler(const sp<const DisplayDevice>& display) { |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4345 | using namespace scheduler; |
| 4346 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 4347 | LOG_ALWAYS_FATAL_IF(mScheduler); |
| 4348 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4349 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 4350 | const Fps activeRefreshRate = activeMode.fps; |
Ady Abraham | 9e16a48 | 2019-12-03 17:19:41 -0800 | [diff] [blame] | 4351 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4352 | FeatureFlags features; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4353 | |
Ady Abraham | 3f84c50 | 2023-11-30 18:18:06 -0800 | [diff] [blame] | 4354 | const auto defaultContentDetectionValue = |
| 4355 | FlagManager::getInstance().enable_fro_dependent_features() && |
| 4356 | sysprop::enable_frame_rate_override(true); |
| 4357 | if (sysprop::use_content_detection_for_refresh_rate(defaultContentDetectionValue)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4358 | features |= Feature::kContentDetection; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 4359 | if (FlagManager::getInstance().enable_small_area_detection()) { |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 4360 | features |= Feature::kSmallDirtyContentDetection; |
| 4361 | } |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4362 | } |
| 4363 | if (base::GetBoolProperty("debug.sf.show_predicted_vsync"s, false)) { |
| 4364 | features |= Feature::kTracePredictedVsync; |
| 4365 | } |
| 4366 | if (!base::GetBoolProperty("debug.sf.vsync_reactor_ignore_present_fences"s, false) && |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 4367 | mHasReliablePresentFences) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4368 | features |= Feature::kPresentFences; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4369 | } |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4370 | if (display->refreshRateSelector().kernelIdleTimerController()) { |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4371 | features |= Feature::kKernelIdleTimer; |
| 4372 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4373 | if (mBackpressureGpuComposition) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4374 | features |= Feature::kBackpressureGpuComposition; |
| 4375 | } |
Leon Scroggins III | 0bd0d4c | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 4376 | if (getHwComposer().getComposer()->isSupported( |
| 4377 | Hwc2::Composer::OptionalFeature::ExpectedPresentTime)) { |
| 4378 | features |= Feature::kExpectedPresentTime; |
| 4379 | } |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4380 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4381 | mScheduler = std::make_unique<Scheduler>(static_cast<ICompositor&>(*this), |
| 4382 | static_cast<ISchedulerCallback&>(*this), features, |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4383 | getFactory(), activeRefreshRate, *mTimeStats); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4384 | |
| 4385 | // The pacesetter must be registered before EventThread creation below. |
Dominik Laskowski | 3ff44c7 | 2024-06-17 11:03:30 -0400 | [diff] [blame] | 4386 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector(), |
| 4387 | mActiveDisplayId); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4388 | if (FlagManager::getInstance().vrr_config()) { |
Ady Abraham | ee6365b | 2024-03-06 14:31:45 -0800 | [diff] [blame] | 4389 | mScheduler->setRenderRate(display->getPhysicalId(), activeMode.fps, |
| 4390 | /*applyImmediately*/ true); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4391 | } |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4392 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 4393 | const auto configs = mScheduler->getVsyncConfiguration().getCurrentConfigs(); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4394 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4395 | mScheduler->createEventThread(scheduler::Cycle::Render, mFrameTimeline->getTokenManager(), |
| 4396 | /* workDuration */ configs.late.appWorkDuration, |
| 4397 | /* readyDuration */ configs.late.sfWorkDuration); |
| 4398 | mScheduler->createEventThread(scheduler::Cycle::LastComposite, |
| 4399 | mFrameTimeline->getTokenManager(), |
| 4400 | /* workDuration */ activeRefreshRate.getPeriod(), |
| 4401 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4402 | |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 4403 | // Dispatch after EventThread creation, since registerDisplay above skipped dispatch. |
| 4404 | mScheduler->dispatchHotplug(display->getPhysicalId(), scheduler::Scheduler::Hotplug::Connected); |
| 4405 | |
Leon Scroggins III | a7be94e | 2024-01-23 12:24:30 -0500 | [diff] [blame] | 4406 | mScheduler->initVsync(*mFrameTimeline->getTokenManager(), configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4407 | |
| 4408 | mRegionSamplingThread = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4409 | sp<RegionSamplingThread>::make(*this, |
| 4410 | RegionSamplingThread::EnvironmentTimingTunables()); |
Andy Yu | aef688b | 2024-01-23 17:14:23 -0800 | [diff] [blame] | 4411 | mFpsReporter = sp<FpsReporter>::make(*mFrameTimeline); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4412 | |
| 4413 | // Timer callbacks may fire, so do this last. |
| 4414 | mScheduler->startTimers(); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4415 | } |
| 4416 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4417 | void SurfaceFlinger::doCommitTransactions() { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4418 | SFTRACE_CALL(); |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4419 | mDrawingState = mCurrentState; |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4420 | mCurrentState.colorMatrixChanged = false; |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4421 | } |
| 4422 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4423 | void SurfaceFlinger::invalidateLayerStack(const ui::LayerFilter& layerFilter, const Region& dirty) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4424 | for (const auto& [token, displayDevice] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4425 | auto display = displayDevice->getCompositionDisplay(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4426 | if (display->includesLayer(layerFilter)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4427 | display->editState().dirtyRegion.orSelf(dirty); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 4428 | } |
| 4429 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 4430 | } |
| 4431 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4432 | status_t SurfaceFlinger::addClientLayer(LayerCreationArgs& args, const sp<IBinder>& handle, |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4433 | const sp<Layer>& layer, const wp<Layer>& parent, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4434 | uint32_t* outTransformHint) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4435 | if (mNumLayers >= MAX_LAYERS) { |
qinyige1 | 0e011d0 | 2024-05-23 15:59:08 +0800 | [diff] [blame] | 4436 | static std::atomic<nsecs_t> lasttime{0}; |
| 4437 | nsecs_t now = systemTime(); |
| 4438 | if (lasttime != 0 && ns2s(now - lasttime.load()) < 10) { |
| 4439 | ALOGE("AddClientLayer already dumped 10s before"); |
| 4440 | return NO_MEMORY; |
| 4441 | } else { |
| 4442 | lasttime = now; |
| 4443 | } |
| 4444 | |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4445 | ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(), |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4446 | MAX_LAYERS); |
qinyige1 | 0e011d0 | 2024-05-23 15:59:08 +0800 | [diff] [blame] | 4447 | static_cast<void>(mScheduler->schedule([&]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 4448 | ALOGE("Dumping on-screen layers."); |
| 4449 | mLayerHierarchyBuilder.dumpLayerSample(mLayerHierarchyBuilder.getHierarchy()); |
| 4450 | ALOGE("Dumping off-screen layers."); |
| 4451 | mLayerHierarchyBuilder.dumpLayerSample(mLayerHierarchyBuilder.getOffscreenHierarchy()); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4452 | })); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4453 | return NO_MEMORY; |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4454 | } |
| 4455 | |
Vishnu Nair | 86e1190 | 2022-09-06 16:03:27 +0000 | [diff] [blame] | 4456 | if (outTransformHint) { |
| 4457 | *outTransformHint = mActiveDisplayTransformHint; |
| 4458 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4459 | args.parentId = LayerHandle::getLayerId(args.parentHandle.promote()); |
| 4460 | args.layerIdToMirror = LayerHandle::getLayerId(args.mirrorLayerHandle.promote()); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4461 | { |
| 4462 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | a12c5c7 | 2024-08-28 15:42:17 -0700 | [diff] [blame] | 4463 | mCreatedLayers.emplace_back(layer); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4464 | mNewLayers.emplace_back(std::make_unique<frontend::RequestedLayerState>(args)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 4465 | args.mirrorLayerHandle.clear(); |
| 4466 | args.parentHandle.clear(); |
| 4467 | mNewLayerArgs.emplace_back(std::move(args)); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4468 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4469 | |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4470 | setTransactionFlags(eTransactionNeeded); |
| 4471 | return NO_ERROR; |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 4472 | } |
| 4473 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4474 | uint32_t SurfaceFlinger::getTransactionFlags() const { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 4475 | return mTransactionFlags; |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 4476 | } |
| 4477 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4478 | uint32_t SurfaceFlinger::clearTransactionFlags(uint32_t mask) { |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4479 | uint32_t transactionFlags = mTransactionFlags.fetch_and(~mask); |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4480 | SFTRACE_INT("mTransactionFlags", transactionFlags); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4481 | return transactionFlags & mask; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4482 | } |
| 4483 | |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4484 | void SurfaceFlinger::setTransactionFlags(uint32_t mask, TransactionSchedule schedule, |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4485 | const sp<IBinder>& applyToken, FrameHint frameHint) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4486 | mScheduler->modulateVsync({}, &VsyncModulator::setTransactionSchedule, schedule, applyToken); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4487 | uint32_t transactionFlags = mTransactionFlags.fetch_or(mask); |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4488 | SFTRACE_INT("mTransactionFlags", transactionFlags); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4489 | |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4490 | if (const bool scheduled = transactionFlags & mask; !scheduled) { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4491 | scheduleCommit(frameHint); |
Ady Abraham | 27bcb55 | 2023-01-21 04:34:22 +0000 | [diff] [blame] | 4492 | } else if (frameHint == FrameHint::kActive) { |
| 4493 | // Even if the next frame is already scheduled, we should reset the idle timer |
| 4494 | // as a new activity just happened. |
| 4495 | mScheduler->resetIdleTimer(); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4496 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4497 | } |
| 4498 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4499 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyTimelineCheck( |
| 4500 | const TransactionHandler::TransactionFlushState& flushState) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 4501 | const auto& transaction = *flushState.transaction; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4502 | |
| 4503 | const TimePoint desiredPresentTime = TimePoint::fromNs(transaction.desiredPresentTime); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 4504 | const TimePoint expectedPresentTime = mScheduler->expectedPresentTimeForPacesetter(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4505 | |
| 4506 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4507 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4508 | // Do not present if the desiredPresentTime has not passed unless it is more than |
| 4509 | // one second in the future. We ignore timestamps more than 1 second in the future |
| 4510 | // for stability reasons. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4511 | if (!transaction.isAutoTimestamp && desiredPresentTime >= expectedPresentTime && |
| 4512 | desiredPresentTime < expectedPresentTime + 1s) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4513 | SFTRACE_FORMAT("not current desiredPresentTime: %" PRId64 " expectedPresentTime: %" PRId64, |
| 4514 | desiredPresentTime, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4515 | return TransactionReadiness::NotReady; |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4516 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4517 | |
Ady Abraham | 20024aa | 2024-03-05 01:32:49 +0000 | [diff] [blame] | 4518 | const auto vsyncId = VsyncId{transaction.frameTimelineInfo.vsyncId}; |
| 4519 | |
| 4520 | // Transactions with VsyncId are already throttled by the vsyncId (i.e. Choreographer issued |
| 4521 | // the vsyncId according to the frame rate override cadence) so we shouldn't throttle again |
| 4522 | // when applying the transaction. Otherwise we might throttle older transactions |
| 4523 | // incorrectly as the frame rate of SF changed before it drained the older transactions. |
| 4524 | if (ftl::to_underlying(vsyncId) == FrameTimelineInfo::INVALID_VSYNC_ID && |
| 4525 | !mScheduler->isVsyncValid(expectedPresentTime, transaction.originUid)) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4526 | SFTRACE_FORMAT("!isVsyncValid expectedPresentTime: %" PRId64 " uid: %d", |
| 4527 | expectedPresentTime, transaction.originUid); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4528 | return TransactionReadiness::NotReady; |
| 4529 | } |
| 4530 | |
| 4531 | // If the client didn't specify desiredPresentTime, use the vsyncId to determine the |
| 4532 | // expected present time of this transaction. |
Ady Abraham | 20024aa | 2024-03-05 01:32:49 +0000 | [diff] [blame] | 4533 | if (transaction.isAutoTimestamp && frameIsEarly(expectedPresentTime, vsyncId)) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4534 | SFTRACE_FORMAT("frameIsEarly vsyncId: %" PRId64 " expectedPresentTime: %" PRId64, |
| 4535 | transaction.frameTimelineInfo.vsyncId, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4536 | return TransactionReadiness::NotReady; |
| 4537 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4538 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4539 | return TransactionReadiness::Ready; |
| 4540 | } |
| 4541 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4542 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheck( |
| 4543 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4544 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4545 | auto ready = TransactionReadiness::Ready; |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4546 | flushState.transaction->traverseStatesWithBuffersWhileTrue( |
| 4547 | [&](const ResolvedComposerState& resolvedState) FTL_FAKE_GUARD( |
| 4548 | kMainThreadContext) -> bool { |
| 4549 | const frontend::RequestedLayerState* layer = |
| 4550 | mLayerLifecycleManager.getLayerFromId(resolvedState.layerId); |
| 4551 | const auto& transaction = *flushState.transaction; |
| 4552 | const auto& s = resolvedState.state; |
| 4553 | // check for barrier frames |
| 4554 | if (s.bufferData->hasBarrier) { |
| 4555 | // The current producerId is already a newer producer than the buffer that has a |
| 4556 | // barrier. This means the incoming buffer is older and we can release it here. |
| 4557 | // We don't wait on the barrier since we know that's stale information. |
| 4558 | if (layer->barrierProducerId > s.bufferData->producerId) { |
| 4559 | if (s.bufferData->releaseBufferListener) { |
| 4560 | uint32_t currentMaxAcquiredBufferCount = |
| 4561 | getMaxAcquiredBufferCountForCurrentRefreshRate( |
| 4562 | layer->ownerUid.val()); |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4563 | SFTRACE_FORMAT_INSTANT("callReleaseBufferCallback %s - %" PRIu64, |
| 4564 | layer->name.c_str(), s.bufferData->frameNumber); |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4565 | s.bufferData->releaseBufferListener |
| 4566 | ->onReleaseBuffer({resolvedState.externalTexture->getBuffer() |
| 4567 | ->getId(), |
| 4568 | s.bufferData->frameNumber}, |
| 4569 | s.bufferData->acquireFence |
| 4570 | ? s.bufferData->acquireFence |
| 4571 | : Fence::NO_FENCE, |
| 4572 | currentMaxAcquiredBufferCount); |
| 4573 | } |
| 4574 | |
| 4575 | // Delete the entire state at this point and not just release the buffer |
| 4576 | // because everything associated with the Layer in this Transaction is now |
| 4577 | // out of date. |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4578 | SFTRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", |
| 4579 | layer->name.c_str(), layer->barrierProducerId, |
| 4580 | s.bufferData->producerId); |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4581 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4582 | } |
| 4583 | |
| 4584 | if (layer->barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
| 4585 | const bool willApplyBarrierFrame = |
| 4586 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4587 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4588 | s.bufferData->barrierFrameNumber)); |
| 4589 | if (!willApplyBarrierFrame) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4590 | SFTRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 |
| 4591 | " > %" PRId64, |
| 4592 | layer->name.c_str(), layer->barrierFrameNumber, |
| 4593 | s.bufferData->barrierFrameNumber); |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4594 | ready = TransactionReadiness::NotReadyBarrier; |
| 4595 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4596 | } |
| 4597 | } |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4598 | } |
| 4599 | |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4600 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4601 | // the transaction in the queue. |
| 4602 | const bool hasPendingBuffer = |
| 4603 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4604 | if (layer->backpressureEnabled() && hasPendingBuffer && |
| 4605 | transaction.isAutoTimestamp) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4606 | SFTRACE_FORMAT("hasPendingBuffer %s", layer->name.c_str()); |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4607 | ready = TransactionReadiness::NotReady; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4608 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4609 | } |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4610 | |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4611 | const bool acquireFenceAvailable = s.bufferData && |
| 4612 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4613 | s.bufferData->acquireFence; |
| 4614 | const bool fenceSignaled = !acquireFenceAvailable || |
| 4615 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
| 4616 | if (!fenceSignaled) { |
| 4617 | // check fence status |
| 4618 | const bool allowLatchUnsignaled = |
| 4619 | shouldLatchUnsignaled(s, transaction.states.size(), |
| 4620 | flushState.firstTransaction) && |
| 4621 | layer->isSimpleBufferUpdate(s); |
| 4622 | if (allowLatchUnsignaled) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4623 | SFTRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", |
| 4624 | layer->name.c_str()); |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4625 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4626 | } else { |
| 4627 | ready = TransactionReadiness::NotReady; |
| 4628 | auto& listener = s.bufferData->releaseBufferListener; |
| 4629 | if (listener && |
| 4630 | (flushState.queueProcessTime - transaction.postTime) > |
| 4631 | std::chrono::nanoseconds(4s).count()) { |
| 4632 | mTransactionHandler |
| 4633 | .onTransactionQueueStalled(transaction.id, |
| 4634 | {.pid = layer->ownerPid.val(), |
| 4635 | .layerId = layer->id, |
| 4636 | .layerName = layer->name, |
| 4637 | .bufferId = s.bufferData->getId(), |
| 4638 | .frameNumber = |
| 4639 | s.bufferData->frameNumber}); |
| 4640 | } |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4641 | SFTRACE_FORMAT("fence unsignaled %s", layer->name.c_str()); |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4642 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4643 | } |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4644 | } |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4645 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
| 4646 | }); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4647 | return ready; |
| 4648 | } |
| 4649 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4650 | void SurfaceFlinger::addTransactionReadyFilters() { |
| 4651 | mTransactionHandler.addTransactionReadyFilter( |
| 4652 | std::bind(&SurfaceFlinger::transactionReadyTimelineCheck, this, std::placeholders::_1)); |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 4653 | mTransactionHandler.addTransactionReadyFilter( |
| 4654 | std::bind(&SurfaceFlinger::transactionReadyBufferCheck, this, std::placeholders::_1)); |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4655 | } |
| 4656 | |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4657 | // For tests only |
Shuangxi Xiang | a97d59d | 2024-08-27 07:28:20 +0000 | [diff] [blame] | 4658 | bool SurfaceFlinger::flushTransactionQueues() { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4659 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4660 | std::vector<TransactionState> transactions = mTransactionHandler.flushTransactions(); |
Shuangxi Xiang | a97d59d | 2024-08-27 07:28:20 +0000 | [diff] [blame] | 4661 | return applyTransactions(transactions); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4662 | } |
| 4663 | |
Shuangxi Xiang | a97d59d | 2024-08-27 07:28:20 +0000 | [diff] [blame] | 4664 | bool SurfaceFlinger::applyTransactions(std::vector<TransactionState>& transactions) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 4665 | Mutex::Autolock lock(mStateLock); |
Shuangxi Xiang | a97d59d | 2024-08-27 07:28:20 +0000 | [diff] [blame] | 4666 | return applyTransactionsLocked(transactions); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4667 | } |
| 4668 | |
Shuangxi Xiang | a97d59d | 2024-08-27 07:28:20 +0000 | [diff] [blame] | 4669 | bool SurfaceFlinger::applyTransactionsLocked(std::vector<TransactionState>& transactions) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4670 | bool needsTraversal = false; |
| 4671 | // Now apply all transactions. |
Robert Carr | ff7663b | 2022-02-08 12:46:49 -0800 | [diff] [blame] | 4672 | for (auto& transaction : transactions) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4673 | needsTraversal |= |
| 4674 | applyTransactionState(transaction.frameTimelineInfo, transaction.states, |
| 4675 | transaction.displays, transaction.flags, |
| 4676 | transaction.inputWindowCommands, |
| 4677 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4678 | std::move(transaction.uncacheBufferIds), transaction.postTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4679 | transaction.hasListenerCallbacks, |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4680 | transaction.listenerCallbacks, transaction.originPid, |
| 4681 | transaction.originUid, transaction.id); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4682 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4683 | return needsTraversal; |
Marissa Wall | e6e3c0d | 2019-03-29 10:28:30 -0700 | [diff] [blame] | 4684 | } |
| 4685 | |
| 4686 | bool SurfaceFlinger::transactionFlushNeeded() { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4687 | return mTransactionHandler.hasPendingTransactions(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4688 | } |
| 4689 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4690 | bool SurfaceFlinger::frameIsEarly(TimePoint expectedPresentTime, VsyncId vsyncId) const { |
| 4691 | const auto prediction = |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 4692 | mFrameTimeline->getTokenManager()->getPredictionsForToken(ftl::to_underlying(vsyncId)); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4693 | if (!prediction) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4694 | return false; |
| 4695 | } |
| 4696 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4697 | const auto predictedPresentTime = TimePoint::fromNs(prediction->presentTime); |
| 4698 | |
Rachel Lee | 0655a91 | 2023-04-20 19:54:18 -0700 | [diff] [blame] | 4699 | if (std::chrono::abs(predictedPresentTime - expectedPresentTime) >= |
| 4700 | scheduler::VsyncConfig::kEarlyLatchMaxThreshold) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4701 | return false; |
| 4702 | } |
| 4703 | |
Ady Abraham | 3db8a3c | 2023-11-20 17:53:47 -0800 | [diff] [blame] | 4704 | const Duration earlyLatchVsyncThreshold = mScheduler->getVsyncSchedule()->minFramePeriod() / 2; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4705 | |
| 4706 | return predictedPresentTime >= expectedPresentTime && |
| 4707 | predictedPresentTime - expectedPresentTime >= earlyLatchVsyncThreshold; |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4708 | } |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4709 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4710 | bool SurfaceFlinger::shouldLatchUnsignaled(const layer_state_t& state, size_t numStates, |
| 4711 | bool firstTransaction) const { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4712 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Disabled) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4713 | SFTRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::Disabled)", __func__); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4714 | return false; |
| 4715 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4716 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4717 | // We only want to latch unsignaled when a single layer is updated in this |
| 4718 | // transaction (i.e. not a blast sync transaction). |
| 4719 | if (numStates != 1) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4720 | SFTRACE_FORMAT_INSTANT("%s: false (numStates=%zu)", __func__, numStates); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4721 | return false; |
| 4722 | } |
| 4723 | |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4724 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::AutoSingleLayer) { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4725 | if (!firstTransaction) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4726 | SFTRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; not first " |
| 4727 | "transaction)", |
| 4728 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4729 | return false; |
| 4730 | } |
| 4731 | |
| 4732 | // We don't want to latch unsignaled if are in early / client composition |
| 4733 | // as it leads to jank due to RenderEngine waiting for unsignaled buffer |
| 4734 | // or window animations being slow. |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 4735 | if (mScheduler->vsyncModulator().isVsyncConfigEarly()) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4736 | SFTRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; " |
| 4737 | "isVsyncConfigEarly)", |
| 4738 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4739 | return false; |
| 4740 | } |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4741 | } |
| 4742 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4743 | return true; |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4744 | } |
| 4745 | |
chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 4746 | status_t SurfaceFlinger::setTransactionState( |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4747 | const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& states, |
Patrick Williams | f65da8a | 2024-07-24 17:11:19 +0000 | [diff] [blame] | 4748 | Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4749 | InputWindowCommands inputWindowCommands, int64_t desiredPresentTime, bool isAutoTimestamp, |
| 4750 | const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 4751 | const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId, |
| 4752 | const std::vector<uint64_t>& mergedTransactionIds) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 4753 | SFTRACE_CALL(); |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 4754 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4755 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4756 | const int originPid = ipc->getCallingPid(); |
| 4757 | const int originUid = ipc->getCallingUid(); |
| 4758 | uint32_t permissions = LayerStatePermissions::getTransactionPermissions(originPid, originUid); |
Patrick Williams | 04e4176 | 2024-04-23 19:05:38 -0500 | [diff] [blame] | 4759 | for (auto& composerState : states) { |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4760 | composerState.state.sanitize(permissions); |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4761 | } |
| 4762 | |
Patrick Williams | f65da8a | 2024-07-24 17:11:19 +0000 | [diff] [blame] | 4763 | for (DisplayState& display : displays) { |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4764 | display.sanitize(permissions); |
| 4765 | } |
| 4766 | |
| 4767 | if (!inputWindowCommands.empty() && |
| 4768 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) == 0) { |
| 4769 | ALOGE("Only privileged callers are allowed to send input commands."); |
| 4770 | inputWindowCommands.clear(); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 4771 | } |
| 4772 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 4773 | if (flags & (eEarlyWakeupStart | eEarlyWakeupEnd)) { |
| 4774 | const bool hasPermission = |
| 4775 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) || |
| 4776 | callingThreadHasPermission(sWakeupSurfaceFlinger); |
| 4777 | if (!hasPermission) { |
| 4778 | ALOGE("Caller needs permission android.permission.WAKEUP_SURFACE_FLINGER to use " |
| 4779 | "eEarlyWakeup[Start|End] flags"); |
| 4780 | flags &= ~(eEarlyWakeupStart | eEarlyWakeupEnd); |
| 4781 | } |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 4782 | } |
| 4783 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4784 | const int64_t postTime = systemTime(); |
| 4785 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4786 | std::vector<uint64_t> uncacheBufferIds; |
| 4787 | uncacheBufferIds.reserve(uncacheBuffers.size()); |
| 4788 | for (const auto& uncacheBuffer : uncacheBuffers) { |
| 4789 | sp<GraphicBuffer> buffer = ClientCache::getInstance().erase(uncacheBuffer); |
| 4790 | if (buffer != nullptr) { |
| 4791 | uncacheBufferIds.push_back(buffer->getId()); |
| 4792 | } |
| 4793 | } |
| 4794 | |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4795 | std::vector<ResolvedComposerState> resolvedStates; |
| 4796 | resolvedStates.reserve(states.size()); |
| 4797 | for (auto& state : states) { |
| 4798 | resolvedStates.emplace_back(std::move(state)); |
| 4799 | auto& resolvedState = resolvedStates.back(); |
Melody Hsu | cd391bc | 2024-09-24 23:46:53 +0000 | [diff] [blame] | 4800 | resolvedState.layerId = LayerHandle::getLayerId(resolvedState.state.surface); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4801 | if (resolvedState.state.hasBufferChanges() && resolvedState.state.hasValidBuffer() && |
| 4802 | resolvedState.state.surface) { |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 4803 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 4804 | std::string layerName = (layer) ? |
| 4805 | layer->getDebugName() : std::to_string(resolvedState.state.layerId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4806 | resolvedState.externalTexture = |
| 4807 | getExternalTextureFromBufferData(*resolvedState.state.bufferData, |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 4808 | layerName.c_str(), transactionId); |
Patrick Williams | 38d920e | 2023-08-31 17:31:18 -0500 | [diff] [blame] | 4809 | if (resolvedState.externalTexture) { |
| 4810 | resolvedState.state.bufferData->buffer = resolvedState.externalTexture->getBuffer(); |
| 4811 | } |
Melody Hsu | cd391bc | 2024-09-24 23:46:53 +0000 | [diff] [blame] | 4812 | mBufferCountTracker.increment(resolvedState.layerId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4813 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4814 | if (resolvedState.state.what & layer_state_t::eReparent) { |
| 4815 | resolvedState.parentId = |
| 4816 | getLayerIdFromSurfaceControl(resolvedState.state.parentSurfaceControlForChild); |
| 4817 | } |
| 4818 | if (resolvedState.state.what & layer_state_t::eRelativeLayerChanged) { |
| 4819 | resolvedState.relativeParentId = |
| 4820 | getLayerIdFromSurfaceControl(resolvedState.state.relativeLayerSurfaceControl); |
| 4821 | } |
| 4822 | if (resolvedState.state.what & layer_state_t::eInputInfoChanged) { |
| 4823 | wp<IBinder>& touchableRegionCropHandle = |
| 4824 | resolvedState.state.windowInfoHandle->editInfo()->touchableRegionCropHandle; |
| 4825 | resolvedState.touchCropId = |
| 4826 | LayerHandle::getLayerId(touchableRegionCropHandle.promote()); |
| 4827 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4828 | } |
| 4829 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4830 | TransactionState state{frameTimelineInfo, |
| 4831 | resolvedStates, |
| 4832 | displays, |
| 4833 | flags, |
| 4834 | applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4835 | std::move(inputWindowCommands), |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4836 | desiredPresentTime, |
| 4837 | isAutoTimestamp, |
| 4838 | std::move(uncacheBufferIds), |
| 4839 | postTime, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4840 | hasListenerCallbacks, |
| 4841 | listenerCallbacks, |
| 4842 | originPid, |
| 4843 | originUid, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 4844 | transactionId, |
| 4845 | mergedTransactionIds}; |
Vishnu Nair | 83df034 | 2021-03-30 11:50:44 -0700 | [diff] [blame] | 4846 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 4847 | if (mTransactionTracing) { |
| 4848 | mTransactionTracing->addQueuedTransaction(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4849 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4850 | |
| 4851 | const auto schedule = [](uint32_t flags) { |
| 4852 | if (flags & eEarlyWakeupEnd) return TransactionSchedule::EarlyEnd; |
| 4853 | if (flags & eEarlyWakeupStart) return TransactionSchedule::EarlyStart; |
| 4854 | return TransactionSchedule::Late; |
| 4855 | }(state.flags); |
| 4856 | |
| 4857 | const auto frameHint = state.isFrameActive() ? FrameHint::kActive : FrameHint::kNone; |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4858 | { |
| 4859 | // Transactions are added via a lockless queue and does not need to be added from the main |
| 4860 | // thread. |
| 4861 | ftl::FakeGuard guard(kMainThreadContext); |
| 4862 | mTransactionHandler.queueTransaction(std::move(state)); |
| 4863 | } |
| 4864 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4865 | for (const auto& [displayId, data] : mNotifyExpectedPresentMap) { |
| 4866 | if (data.hintStatus.load() == NotifyExpectedPresentHintStatus::ScheduleOnTx) { |
| 4867 | scheduleNotifyExpectedPresentHint(displayId, VsyncId{frameTimelineInfo.vsyncId}); |
| 4868 | } |
| 4869 | } |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4870 | setTransactionFlags(eTransactionFlushNeeded, schedule, applyToken, frameHint); |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 4871 | return NO_ERROR; |
| 4872 | } |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4873 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4874 | bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4875 | std::vector<ResolvedComposerState>& states, |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 4876 | Vector<DisplayState>& displays, uint32_t flags, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4877 | const InputWindowCommands& inputWindowCommands, |
| 4878 | const int64_t desiredPresentTime, bool isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4879 | const std::vector<uint64_t>& uncacheBufferIds, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4880 | const int64_t postTime, bool hasListenerCallbacks, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4881 | const std::vector<ListenerCallbacks>& listenerCallbacks, |
| 4882 | int originPid, int originUid, uint64_t transactionId) { |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 4883 | uint32_t transactionFlags = 0; |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 4884 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4885 | // start and end registration for listeners w/ no surface so they can get their callback. Note |
| 4886 | // that listeners with SurfaceControls will start registration during setClientStateLocked |
| 4887 | // below. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4888 | for (const auto& listener : listenerCallbacks) { |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4889 | mTransactionCallbackInvoker.addEmptyTransaction(listener); |
Marissa Wall | d600d57 | 2019-03-26 15:38:50 -0700 | [diff] [blame] | 4890 | } |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 4891 | uint32_t clientStateFlags = 0; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4892 | for (auto& resolvedState : states) { |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 4893 | clientStateFlags |= |
| 4894 | updateLayerCallbacksAndStats(frameTimelineInfo, resolvedState, desiredPresentTime, |
| 4895 | isAutoTimestamp, postTime, transactionId); |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 4896 | } |
| 4897 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 4898 | transactionFlags |= clientStateFlags; |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4899 | transactionFlags |= addInputWindowCommands(inputWindowCommands); |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 4900 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4901 | for (uint64_t uncacheBufferId : uncacheBufferIds) { |
| 4902 | mBufferIdsToUncache.push_back(uncacheBufferId); |
Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 4903 | } |
| 4904 | |
Jorim Jaggi | bdcf09c | 2017-08-08 15:22:08 +0200 | [diff] [blame] | 4905 | // If a synchronous transaction is explicitly requested without any changes, force a transaction |
| 4906 | // anyway. This can be used as a flush mechanism for previous async transactions. |
| 4907 | // Empty animation transaction can be used to simulate back-pressure, so also force a |
| 4908 | // transaction for empty animation transactions. |
Vishnu Nair | 1523dad | 2022-09-29 16:05:18 -0700 | [diff] [blame] | 4909 | if (transactionFlags == 0 && (flags & eAnimation)) { |
Robert Carr | 2a7dbb4 | 2016-05-24 11:41:28 -0700 | [diff] [blame] | 4910 | transactionFlags = eTransactionNeeded; |
| 4911 | } |
| 4912 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4913 | bool needsTraversal = false; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 4914 | if (transactionFlags) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4915 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 4916 | // 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] | 4917 | if (transactionFlags & eTraversalNeeded) { |
| 4918 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4919 | needsTraversal = true; |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 4920 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4921 | if (transactionFlags) { |
| 4922 | setTransactionFlags(transactionFlags); |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 4923 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4924 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4925 | |
| 4926 | return needsTraversal; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4927 | } |
| 4928 | |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 4929 | bool SurfaceFlinger::applyAndCommitDisplayTransactionStatesLocked( |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4930 | std::vector<TransactionState>& transactions) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4931 | bool needsTraversal = false; |
| 4932 | uint32_t transactionFlags = 0; |
| 4933 | for (auto& transaction : transactions) { |
| 4934 | for (DisplayState& display : transaction.displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4935 | transactionFlags |= setDisplayStateLocked(display); |
| 4936 | } |
| 4937 | } |
| 4938 | |
| 4939 | if (transactionFlags) { |
| 4940 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 4941 | // so we don't have to wake up again next frame to perform an unnecessary traversal. |
| 4942 | if (transactionFlags & eTraversalNeeded) { |
| 4943 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
| 4944 | needsTraversal = true; |
| 4945 | } |
| 4946 | if (transactionFlags) { |
| 4947 | setTransactionFlags(transactionFlags); |
| 4948 | } |
| 4949 | } |
| 4950 | |
| 4951 | mFrontEndDisplayInfosChanged = mTransactionFlags & eDisplayTransactionNeeded; |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 4952 | if (mFrontEndDisplayInfosChanged) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4953 | processDisplayChangesLocked(); |
| 4954 | mFrontEndDisplayInfos.clear(); |
| 4955 | for (const auto& [_, display] : mDisplays) { |
| 4956 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 4957 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 4958 | needsTraversal = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | return needsTraversal; |
| 4962 | } |
| 4963 | |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4964 | uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s) { |
| 4965 | const ssize_t index = mCurrentState.displays.indexOfKey(s.token); |
| 4966 | if (index < 0) return 0; |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 4967 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4968 | uint32_t flags = 0; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4969 | DisplayDeviceState& state = mCurrentState.displays.editValueAt(index); |
| 4970 | |
| 4971 | const uint32_t what = s.what; |
| 4972 | if (what & DisplayState::eSurfaceChanged) { |
| 4973 | if (IInterface::asBinder(state.surface) != IInterface::asBinder(s.surface)) { |
| 4974 | state.surface = s.surface; |
| 4975 | flags |= eDisplayTransactionNeeded; |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 4976 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4977 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4978 | if (what & DisplayState::eLayerStackChanged) { |
| 4979 | if (state.layerStack != s.layerStack) { |
| 4980 | state.layerStack = s.layerStack; |
| 4981 | flags |= eDisplayTransactionNeeded; |
| 4982 | } |
| 4983 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 4984 | if (what & DisplayState::eFlagsChanged) { |
| 4985 | if (state.flags != s.flags) { |
| 4986 | state.flags = s.flags; |
| 4987 | flags |= eDisplayTransactionNeeded; |
| 4988 | } |
| 4989 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4990 | if (what & DisplayState::eDisplayProjectionChanged) { |
| 4991 | if (state.orientation != s.orientation) { |
| 4992 | state.orientation = s.orientation; |
| 4993 | flags |= eDisplayTransactionNeeded; |
| 4994 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 4995 | if (state.orientedDisplaySpaceRect != s.orientedDisplaySpaceRect) { |
| 4996 | state.orientedDisplaySpaceRect = s.orientedDisplaySpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4997 | flags |= eDisplayTransactionNeeded; |
| 4998 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 4999 | if (state.layerStackSpaceRect != s.layerStackSpaceRect) { |
| 5000 | state.layerStackSpaceRect = s.layerStackSpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5001 | flags |= eDisplayTransactionNeeded; |
| 5002 | } |
| 5003 | } |
| 5004 | if (what & DisplayState::eDisplaySizeChanged) { |
| 5005 | if (state.width != s.width) { |
| 5006 | state.width = s.width; |
| 5007 | flags |= eDisplayTransactionNeeded; |
| 5008 | } |
| 5009 | if (state.height != s.height) { |
| 5010 | state.height = s.height; |
| 5011 | flags |= eDisplayTransactionNeeded; |
| 5012 | } |
| 5013 | } |
| 5014 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5015 | return flags; |
| 5016 | } |
| 5017 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5018 | bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5019 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5020 | const int pid = ipc->getCallingPid(); |
| 5021 | const int uid = ipc->getCallingUid(); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5022 | if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) && |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5023 | (usePermissionCache ? !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid) |
| 5024 | : !checkPermission(sAccessSurfaceFlinger, pid, uid))) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5025 | return false; |
| 5026 | } |
| 5027 | return true; |
| 5028 | } |
| 5029 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5030 | uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& frameTimelineInfo, |
| 5031 | ResolvedComposerState& composerState, |
| 5032 | int64_t desiredPresentTime, |
| 5033 | bool isAutoTimestamp, int64_t postTime, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5034 | uint64_t transactionId) { |
| 5035 | layer_state_t& s = composerState.state; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5036 | |
| 5037 | std::vector<ListenerCallbacks> filteredListeners; |
| 5038 | for (auto& listener : s.listeners) { |
| 5039 | // Starts a registration but separates the callback ids according to callback type. This |
| 5040 | // allows the callback invoker to send on latch callbacks earlier. |
| 5041 | // note that startRegistration will not re-register if the listener has |
| 5042 | // already be registered for a prior surface control |
| 5043 | |
| 5044 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5045 | if (!onCommitCallbacks.callbackIds.empty()) { |
| 5046 | filteredListeners.push_back(onCommitCallbacks); |
| 5047 | } |
| 5048 | |
| 5049 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5050 | if (!onCompleteCallbacks.callbackIds.empty()) { |
| 5051 | filteredListeners.push_back(onCompleteCallbacks); |
| 5052 | } |
| 5053 | } |
| 5054 | |
| 5055 | const uint64_t what = s.what; |
| 5056 | uint32_t flags = 0; |
| 5057 | sp<Layer> layer = nullptr; |
| 5058 | if (s.surface) { |
| 5059 | layer = LayerHandle::getLayer(s.surface); |
| 5060 | } else { |
| 5061 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5062 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5063 | } |
| 5064 | if (layer == nullptr) { |
| 5065 | for (auto& [listener, callbackIds] : s.listeners) { |
Pascal Mütschard | d56514e | 2024-05-24 17:37:13 +0200 | [diff] [blame] | 5066 | mTransactionCallbackInvoker.addCallbackHandle( |
| 5067 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5068 | } |
| 5069 | return 0; |
| 5070 | } |
| 5071 | if (what & layer_state_t::eProducerDisconnect) { |
| 5072 | layer->onDisconnect(); |
| 5073 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5074 | |
| 5075 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5076 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5077 | for (auto& [listener, callbackIds] : filteredListeners) { |
| 5078 | callbackHandles.emplace_back( |
| 5079 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
| 5080 | } |
| 5081 | } |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 5082 | |
| 5083 | frontend::LayerSnapshot* snapshot = nullptr; |
| 5084 | gui::GameMode gameMode = gui::GameMode::Unsupported; |
| 5085 | if (what & (layer_state_t::eSidebandStreamChanged | layer_state_t::eBufferChanged) || |
| 5086 | frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5087 | snapshot = mLayerSnapshotBuilder.getSnapshot(layer->sequence); |
| 5088 | if (snapshot) { |
| 5089 | gameMode = snapshot->gameMode; |
| 5090 | } |
| 5091 | } |
| 5092 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5093 | // TODO(b/238781169) remove after screenshot refactor, currently screenshots |
| 5094 | // requires to read drawing state from binder thread. So we need to fix that |
| 5095 | // before removing this. |
Vishnu Nair | aeaf9d7 | 2023-09-12 15:47:41 -0700 | [diff] [blame] | 5096 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5097 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
| 5098 | } |
| 5099 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5100 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5101 | flags |= eTraversalNeeded; |
| 5102 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5103 | if (what & layer_state_t::eCropChanged) { |
| 5104 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5105 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5106 | if (what & layer_state_t::eSidebandStreamChanged) { |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 5107 | if (layer->setSidebandStream(s.sidebandStream, frameTimelineInfo, postTime, gameMode)) |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 5108 | flags |= eTraversalNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5109 | } |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 5110 | if (what & layer_state_t::eDataspaceChanged) { |
| 5111 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5112 | } |
Vishnu Nair | c5e3416 | 2023-08-22 13:21:20 -0700 | [diff] [blame] | 5113 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
| 5114 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
| 5115 | flags |= eTraversalNeeded; |
| 5116 | } |
| 5117 | } |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 5118 | if (what & layer_state_t::eDesiredHdrHeadroomChanged) { |
| 5119 | if (layer->setDesiredHdrHeadroom(s.desiredHdrSdrRatio)) { |
| 5120 | flags |= eTraversalNeeded; |
| 5121 | } |
| 5122 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5123 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 5124 | std::optional<ui::Transform::RotationFlags> transformHint = std::nullopt; |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 5125 | if (snapshot) { |
| 5126 | transformHint = snapshot->transformHint; |
| 5127 | } |
| 5128 | layer->setTransformHint(transformHint); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5129 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 5130 | desiredPresentTime, isAutoTimestamp, frameTimelineInfo, gameMode)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5131 | flags |= eTraversalNeeded; |
| 5132 | } |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 5133 | mLayersWithQueuedFrames.emplace(layer, gameMode); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5134 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 5135 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime, gameMode); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5136 | } |
| 5137 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5138 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5139 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5140 | } |
| 5141 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5142 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5143 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5144 | s.trustedPresentationListener)) { |
| 5145 | flags |= eTraversalNeeded; |
| 5146 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5147 | } |
| 5148 | |
Patrick Williams | 7c9fa27 | 2024-08-30 12:38:43 +0000 | [diff] [blame] | 5149 | if (what & layer_state_t::eBufferReleaseChannelChanged) { |
| 5150 | layer->setBufferReleaseChannel(s.bufferReleaseChannel); |
| 5151 | } |
| 5152 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5153 | const auto& requestedLayerState = mLayerLifecycleManager.getLayerFromId(layer->getSequence()); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5154 | bool willPresentCurrentTransaction = requestedLayerState && |
| 5155 | (requestedLayerState->hasReadyFrame() || |
| 5156 | requestedLayerState->willReleaseBufferOnLatch()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5157 | if (layer->setTransactionCompletedListeners(callbackHandles, willPresentCurrentTransaction)) |
| 5158 | flags |= eTraversalNeeded; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5159 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5160 | return flags; |
| 5161 | } |
| 5162 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5163 | uint32_t SurfaceFlinger::addInputWindowCommands(const InputWindowCommands& inputWindowCommands) { |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5164 | bool hasChanges = mInputWindowCommands.merge(inputWindowCommands); |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 5165 | return hasChanges ? eTraversalNeeded : 0; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5166 | } |
| 5167 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5168 | status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5169 | const sp<IBinder>& mirrorFromHandle, |
| 5170 | gui::CreateSurfaceResult& outResult) { |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5171 | if (!mirrorFromHandle) { |
| 5172 | return NAME_NOT_FOUND; |
| 5173 | } |
| 5174 | |
| 5175 | sp<Layer> mirrorLayer; |
| 5176 | sp<Layer> mirrorFrom; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5177 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5178 | { |
| 5179 | Mutex::Autolock _l(mStateLock); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5180 | mirrorFrom = LayerHandle::getLayer(mirrorFromHandle); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5181 | if (!mirrorFrom) { |
| 5182 | return NAME_NOT_FOUND; |
| 5183 | } |
Vishnu Nair | b21272e | 2022-07-01 22:47:33 +0000 | [diff] [blame] | 5184 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5185 | mirrorArgs.mirrorLayerHandle = mirrorFromHandle; |
| 5186 | mirrorArgs.addToRoot = false; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5187 | status_t result = createEffectLayer(mirrorArgs, &outResult.handle, &mirrorLayer); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5188 | if (result != NO_ERROR) { |
| 5189 | return result; |
| 5190 | } |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5191 | } |
| 5192 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5193 | outResult.layerId = mirrorLayer->sequence; |
| 5194 | outResult.layerName = String16(mirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5195 | return addClientLayer(mirrorArgs, outResult.handle, mirrorLayer /* layer */, |
| 5196 | nullptr /* parent */, nullptr /* outTransformHint */); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5197 | } |
| 5198 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5199 | status_t SurfaceFlinger::mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5200 | gui::CreateSurfaceResult& outResult) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5201 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5202 | const int uid = ipc->getCallingUid(); |
| 5203 | if (uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM && uid != AID_SHELL) { |
| 5204 | ALOGE("Permission denied when trying to mirror display"); |
| 5205 | return PERMISSION_DENIED; |
| 5206 | } |
| 5207 | |
| 5208 | ui::LayerStack layerStack; |
| 5209 | sp<Layer> rootMirrorLayer; |
| 5210 | status_t result = 0; |
| 5211 | |
| 5212 | { |
| 5213 | Mutex::Autolock lock(mStateLock); |
| 5214 | |
| 5215 | const auto display = getDisplayDeviceLocked(displayId); |
| 5216 | if (!display) { |
| 5217 | return NAME_NOT_FOUND; |
| 5218 | } |
| 5219 | |
| 5220 | layerStack = display->getLayerStack(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5221 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5222 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5223 | mirrorArgs.addToRoot = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5224 | mirrorArgs.layerStackToMirror = layerStack; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5225 | result = createEffectLayer(mirrorArgs, &outResult.handle, &rootMirrorLayer); |
| 5226 | outResult.layerId = rootMirrorLayer->sequence; |
| 5227 | outResult.layerName = String16(rootMirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5228 | result |= addClientLayer(mirrorArgs, outResult.handle, rootMirrorLayer /* layer */, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5229 | nullptr /* parent */, nullptr /* outTransformHint */); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | if (result != NO_ERROR) { |
| 5233 | return result; |
| 5234 | } |
| 5235 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5236 | setTransactionFlags(eTransactionFlushNeeded); |
| 5237 | return NO_ERROR; |
| 5238 | } |
| 5239 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5240 | status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, gui::CreateSurfaceResult& outResult) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5241 | status_t result = NO_ERROR; |
| 5242 | |
| 5243 | sp<Layer> layer; |
| 5244 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5245 | switch (args.flags & ISurfaceComposerClient::eFXSurfaceMask) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5246 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 5247 | case ISurfaceComposerClient::eFXSurfaceContainer: |
| 5248 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 5249 | args.flags |= ISurfaceComposerClient::eNoColorFill; |
Siarhei Vishniakou | 8d66013 | 2024-01-11 16:48:44 -0800 | [diff] [blame] | 5250 | [[fallthrough]]; |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 5251 | case ISurfaceComposerClient::eFXSurfaceEffect: { |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5252 | result = createBufferStateLayer(args, &outResult.handle, &layer); |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5253 | std::atomic<int32_t>* pendingBufferCounter = layer->getPendingBufferCounter(); |
| 5254 | if (pendingBufferCounter) { |
| 5255 | std::string counterName = layer->getPendingBufferCounterName(); |
Melody Hsu | cd391bc | 2024-09-24 23:46:53 +0000 | [diff] [blame] | 5256 | mBufferCountTracker.add(LayerHandle::getLayerId(outResult.handle), counterName, |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5257 | pendingBufferCounter); |
Melody Hsu | 1635578 | 2024-10-09 08:56:28 +0000 | [diff] [blame] | 5258 | args.pendingBuffers = pendingBufferCounter; |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5259 | } |
| 5260 | } break; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5261 | default: |
| 5262 | result = BAD_VALUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5263 | break; |
| 5264 | } |
| 5265 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5266 | if (result != NO_ERROR) { |
| 5267 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5268 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5269 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5270 | args.addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess(); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5271 | // We can safely promote the parent layer in binder thread because we have a strong reference |
| 5272 | // to the layer's handle inside this scope. |
| 5273 | sp<Layer> parent = LayerHandle::getLayer(args.parentHandle.promote()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5274 | if (args.parentHandle != nullptr && parent == nullptr) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5275 | ALOGE("Invalid parent handle %p", args.parentHandle.promote().get()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5276 | args.addToRoot = false; |
Garfield Tan | dbc93d7 | 2021-10-26 18:28:57 -0700 | [diff] [blame] | 5277 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5278 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5279 | uint32_t outTransformHint; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5280 | result = addClientLayer(args, outResult.handle, layer, parent, &outTransformHint); |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 5281 | if (result != NO_ERROR) { |
| 5282 | return result; |
| 5283 | } |
| 5284 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5285 | outResult.transformHint = static_cast<int32_t>(outTransformHint); |
| 5286 | outResult.layerId = layer->sequence; |
| 5287 | outResult.layerName = String16(layer->getDebugName()); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5288 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5289 | } |
| 5290 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5291 | status_t SurfaceFlinger::createBufferStateLayer(LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5292 | sp<Layer>* outLayer) { |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5293 | *outLayer = getFactory().createBufferStateLayer(args); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5294 | *handle = (*outLayer)->getHandle(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5295 | return NO_ERROR; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 5296 | } |
| 5297 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5298 | status_t SurfaceFlinger::createEffectLayer(const LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5299 | sp<Layer>* outLayer) { |
| 5300 | *outLayer = getFactory().createEffectLayer(args); |
| 5301 | *handle = (*outLayer)->getHandle(); |
| 5302 | return NO_ERROR; |
| 5303 | } |
| 5304 | |
Melody Hsu | cd391bc | 2024-09-24 23:46:53 +0000 | [diff] [blame] | 5305 | void SurfaceFlinger::onHandleDestroyed(sp<Layer>& layer, uint32_t layerId) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5306 | { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 5307 | // Used to remove stalled transactions which uses an internal lock. |
| 5308 | ftl::FakeGuard guard(kMainThreadContext); |
| 5309 | mTransactionHandler.onLayerDestroyed(layerId); |
| 5310 | } |
Pascal Mütschard | d56514e | 2024-05-24 17:37:13 +0200 | [diff] [blame] | 5311 | JankTracker::flushJankData(layerId); |
| 5312 | |
Vishnu Nair | a12c5c7 | 2024-08-28 15:42:17 -0700 | [diff] [blame] | 5313 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 5314 | mDestroyedHandles.emplace_back(layerId, layer->getDebugName()); |
| 5315 | |
| 5316 | Mutex::Autolock stateLock(mStateLock); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 5317 | layer->onHandleDestroyed(); |
Melody Hsu | cd391bc | 2024-09-24 23:46:53 +0000 | [diff] [blame] | 5318 | mBufferCountTracker.remove(layerId); |
Robert Carr | 695d528 | 2018-12-18 15:27:58 -0800 | [diff] [blame] | 5319 | layer.clear(); |
Vishnu Nair | a12c5c7 | 2024-08-28 15:42:17 -0700 | [diff] [blame] | 5320 | setTransactionFlags(eTransactionFlushNeeded | eTransactionNeeded); |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 5321 | } |
| 5322 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 5323 | void SurfaceFlinger::initializeDisplays() { |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5324 | TransactionState state; |
| 5325 | state.inputWindowCommands = mInputWindowCommands; |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5326 | const nsecs_t now = systemTime(); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5327 | state.desiredPresentTime = now; |
| 5328 | state.postTime = now; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5329 | state.originPid = mPid; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5330 | state.originUid = static_cast<int>(getuid()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5331 | const uint64_t transactionId = (static_cast<uint64_t>(mPid) << 32) | mUniqueTransactionId++; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5332 | state.id = transactionId; |
| 5333 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 5334 | auto layerStack = ui::DEFAULT_LAYER_STACK.id; |
| 5335 | for (const auto& [id, display] : FTL_FAKE_GUARD(mStateLock, mPhysicalDisplays)) { |
| 5336 | state.displays.push(DisplayState(display.token(), ui::LayerStack::fromValue(layerStack++))); |
| 5337 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5338 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5339 | std::vector<TransactionState> transactions; |
| 5340 | transactions.emplace_back(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5341 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 5342 | { |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 5343 | Mutex::Autolock lock(mStateLock); |
| 5344 | applyAndCommitDisplayTransactionStatesLocked(transactions); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5345 | } |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 5346 | |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5347 | { |
| 5348 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 5349 | |
| 5350 | // In case of a restart, ensure all displays are off. |
| 5351 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 5352 | setPowerModeInternal(getDisplayDeviceLocked(id), hal::PowerMode::OFF); |
| 5353 | } |
| 5354 | |
| 5355 | // Power on all displays. The primary display is first, so becomes the active display. Also, |
| 5356 | // the DisplayCapability set of a display is populated on its first powering on. Do this now |
| 5357 | // before responding to any Binder query from DisplayManager about display capabilities. |
Robert Horvath | dce110a | 2022-09-16 11:08:47 +0200 | [diff] [blame] | 5358 | // Additionally, do not turn on displays if the boot should be quiescent. |
| 5359 | if (!mSkipPowerOnForQuiescent) { |
| 5360 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 5361 | setPowerModeInternal(getDisplayDeviceLocked(id), hal::PowerMode::ON); |
| 5362 | } |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 5363 | } |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5364 | } |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 5365 | } |
| 5366 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5367 | void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 5368 | if (display->isVirtual()) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 5369 | // TODO(b/241285876): This code path should not be reachable, so enforce this at compile |
| 5370 | // time. |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 5371 | ALOGE("%s: Invalid operation on virtual display", __func__); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5372 | return; |
| 5373 | } |
| 5374 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5375 | const auto displayId = display->getPhysicalId(); |
| 5376 | 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] | 5377 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 5378 | const auto currentMode = display->getPowerMode(); |
| 5379 | if (currentMode == mode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5380 | return; |
| 5381 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5382 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5383 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 5384 | .transform(&PhysicalDisplay::isInternal) |
| 5385 | .value_or(false); |
| 5386 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 5387 | const auto activeDisplay = getDisplayDeviceLocked(mActiveDisplayId); |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 5388 | |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5389 | ALOGW_IF(display != activeDisplay && isInternalDisplay && activeDisplay && |
| 5390 | activeDisplay->isPoweredOn(), |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 5391 | "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] | 5392 | |
Ady Abraham | 8e3e2ea | 2024-10-31 15:52:31 -0700 | [diff] [blame] | 5393 | const bool couldRefresh = display->isRefreshable(); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5394 | display->setPowerMode(mode); |
Ady Abraham | 8e3e2ea | 2024-10-31 15:52:31 -0700 | [diff] [blame] | 5395 | const bool canRefresh = display->isRefreshable(); |
| 5396 | |
| 5397 | if (couldRefresh && !canRefresh) { |
| 5398 | decRefreshableDisplays(); |
| 5399 | } else if (!couldRefresh && canRefresh) { |
| 5400 | incRefreshableDisplays(); |
| 5401 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5402 | |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 5403 | const auto activeMode = display->refreshRateSelector().getActiveMode().modePtr; |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 5404 | if (currentMode == hal::PowerMode::OFF) { |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 5405 | // Turn on the display |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5406 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 5407 | // Activate the display (which involves a modeset to the active mode) when the inner or |
| 5408 | // outer display of a foldable is powered on. This condition relies on the above |
| 5409 | // DisplayDevice::setPowerMode. If `display` and `activeDisplay` are the same display, |
| 5410 | // then the `activeDisplay->isPoweredOn()` below is true, such that the display is not |
| 5411 | // activated every time it is powered on. |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5412 | // |
| 5413 | // TODO(b/255635821): Remove the concept of active display. |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 5414 | if (isInternalDisplay && (!activeDisplay || !activeDisplay->isPoweredOn())) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 5415 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 5416 | } |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5417 | |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5418 | if (displayId == mActiveDisplayId) { |
| 5419 | // TODO(b/281692563): Merge the syscalls. For now, keep uclamp in a separate syscall and |
| 5420 | // set it before SCHED_FIFO due to b/190237315. |
| 5421 | if (setSchedAttr(true) != NO_ERROR) { |
| 5422 | ALOGW("Failed to set uclamp.min after powering on active display: %s", |
| 5423 | strerror(errno)); |
| 5424 | } |
| 5425 | if (setSchedFifo(true) != NO_ERROR) { |
| 5426 | ALOGW("Failed to set SCHED_FIFO after powering on active display: %s", |
| 5427 | strerror(errno)); |
| 5428 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 5429 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5430 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5431 | getHwComposer().setPowerMode(displayId, mode); |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 5432 | if (mode != hal::PowerMode::DOZE_SUSPEND && |
| 5433 | (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present())) { |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5434 | const bool enable = |
| 5435 | mScheduler->getVsyncSchedule(displayId)->getPendingHardwareVsyncState(); |
| 5436 | requestHardwareVsync(displayId, enable); |
| 5437 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 5438 | if (displayId == mActiveDisplayId) { |
| 5439 | mScheduler->enableSyntheticVsync(false); |
| 5440 | } |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5441 | |
| 5442 | constexpr bool kAllowToEnable = true; |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 5443 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, activeMode.get()); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5444 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5445 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5446 | mVisibleRegionsDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 5447 | scheduleComposite(FrameHint::kActive); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5448 | } else if (mode == hal::PowerMode::OFF) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 5449 | const bool currentModeNotDozeSuspend = (currentMode != hal::PowerMode::DOZE_SUSPEND); |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 5450 | // Turn off the display |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5451 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 5452 | if (const auto display = getActivatableDisplay()) { |
| 5453 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
| 5454 | } else { |
| 5455 | if (setSchedFifo(false) != NO_ERROR) { |
| 5456 | ALOGW("Failed to set SCHED_OTHER after powering off active display: %s", |
| 5457 | strerror(errno)); |
| 5458 | } |
| 5459 | if (setSchedAttr(false) != NO_ERROR) { |
| 5460 | ALOGW("Failed set uclamp.min after powering off active display: %s", |
| 5461 | strerror(errno)); |
| 5462 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5463 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 5464 | if (currentModeNotDozeSuspend) { |
| 5465 | if (!FlagManager::getInstance().multithreaded_present()) { |
| 5466 | mScheduler->disableHardwareVsync(displayId, true); |
| 5467 | } |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 5468 | mScheduler->enableSyntheticVsync(); |
| 5469 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5470 | } |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 5471 | } |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 5472 | if (currentModeNotDozeSuspend && FlagManager::getInstance().multithreaded_present()) { |
| 5473 | constexpr bool kDisallow = true; |
| 5474 | mScheduler->disableHardwareVsync(displayId, kDisallow); |
| 5475 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5476 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 5477 | // We must disable VSYNC *before* turning off the display. The call to |
| 5478 | // disableHardwareVsync, above, schedules a task to turn it off after |
| 5479 | // this method returns. But by that point, the display is OFF, so the |
| 5480 | // call just updates the pending state, without actually disabling |
| 5481 | // VSYNC. |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5482 | requestHardwareVsync(displayId, false); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5483 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5484 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5485 | mVisibleRegionsDirty = true; |
| 5486 | // from this point on, SF will stop drawing on this display |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5487 | } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5488 | // Update display while dozing |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5489 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 5490 | if (currentMode == hal::PowerMode::DOZE_SUSPEND && |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 5491 | (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present())) { |
| 5492 | if (displayId == mActiveDisplayId) { |
| 5493 | ALOGI("Force repainting for DOZE_SUSPEND -> DOZE or ON."); |
| 5494 | mVisibleRegionsDirty = true; |
| 5495 | scheduleRepaint(); |
| 5496 | mScheduler->enableSyntheticVsync(false); |
| 5497 | } |
| 5498 | constexpr bool kAllowToEnable = true; |
| 5499 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, activeMode.get()); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5500 | } |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5501 | } else if (mode == hal::PowerMode::DOZE_SUSPEND) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5502 | // Leave display going to doze |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 5503 | if (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present()) { |
| 5504 | constexpr bool kDisallow = true; |
| 5505 | mScheduler->disableHardwareVsync(displayId, kDisallow); |
| 5506 | } |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5507 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5508 | mScheduler->enableSyntheticVsync(); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5509 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5510 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5511 | } else { |
Matthew Bouyack | 38d4961 | 2017-05-12 12:49:32 -0700 | [diff] [blame] | 5512 | ALOGE("Attempting to set unknown power mode: %d\n", mode); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5513 | getHwComposer().setPowerMode(displayId, mode); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5514 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5515 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5516 | if (displayId == mActiveDisplayId) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 5517 | mTimeStats->setPowerMode(mode); |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 5518 | mScheduler->setActiveDisplayPowerModeForRefreshRateStats(mode); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 5519 | } |
| 5520 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5521 | mScheduler->setDisplayPowerMode(displayId, mode); |
| 5522 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5523 | 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] | 5524 | } |
| 5525 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5526 | void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) { |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 5527 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 5528 | kMainThreadContext) { |
Robert Horvath | dce110a | 2022-09-16 11:08:47 +0200 | [diff] [blame] | 5529 | mSkipPowerOnForQuiescent = false; |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 5530 | const auto display = getDisplayDeviceLocked(displayToken); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5531 | if (!display) { |
| 5532 | ALOGE("Attempt to set power mode %d for invalid display token %p", mode, |
| 5533 | displayToken.get()); |
| 5534 | } else if (display->isVirtual()) { |
| 5535 | ALOGW("Attempt to set power mode %d for virtual display", mode); |
| 5536 | } else { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5537 | setPowerModeInternal(display, static_cast<hal::PowerMode>(mode)); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5538 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5539 | }); |
| 5540 | |
| 5541 | future.wait(); |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 5542 | } |
| 5543 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5544 | status_t SurfaceFlinger::doDump(int fd, const DumpArgs& args, bool asProto) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5545 | std::string result; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 5546 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 5547 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5548 | const int pid = ipc->getCallingPid(); |
| 5549 | const int uid = ipc->getCallingUid(); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 5550 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 5551 | if ((uid != AID_SHELL) && |
| 5552 | !PermissionCache::checkPermission(sDump, pid, uid)) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5553 | StringAppendF(&result, "Permission Denial: can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 5554 | pid, uid); |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 5555 | write(fd, result.c_str(), result.size()); |
| 5556 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5557 | } |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 5558 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 5559 | if (asProto && args.empty()) { |
| 5560 | perfetto::protos::LayersTraceFileProto traceFileProto = |
| 5561 | mLayerTracing.createTraceFileProto(); |
| 5562 | perfetto::protos::LayersSnapshotProto* layersTrace = traceFileProto.add_entry(); |
| 5563 | perfetto::protos::LayersProto layersProto = dumpProtoFromMainThread(); |
| 5564 | layersTrace->mutable_layers()->Swap(&layersProto); |
| 5565 | auto displayProtos = dumpDisplayProto(); |
| 5566 | layersTrace->mutable_displays()->Swap(&displayProtos); |
| 5567 | result.append(traceFileProto.SerializeAsString()); |
| 5568 | write(fd, result.c_str(), result.size()); |
| 5569 | return NO_ERROR; |
| 5570 | } |
| 5571 | |
| 5572 | static const std::unordered_map<std::string, Dumper> dumpers = { |
| 5573 | {"--comp-displays"s, dumper(&SurfaceFlinger::dumpCompositionDisplays)}, |
| 5574 | {"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)}, |
| 5575 | {"--displays"s, dumper(&SurfaceFlinger::dumpDisplays)}, |
| 5576 | {"--edid"s, argsDumper(&SurfaceFlinger::dumpRawDisplayIdentificationData)}, |
| 5577 | {"--events"s, dumper(&SurfaceFlinger::dumpEvents)}, |
| 5578 | {"--frametimeline"s, argsDumper(&SurfaceFlinger::dumpFrameTimeline)}, |
| 5579 | {"--frontend"s, mainThreadDumper(&SurfaceFlinger::dumpFrontEnd)}, |
| 5580 | {"--hdrinfo"s, dumper(&SurfaceFlinger::dumpHdrInfo)}, |
| 5581 | {"--hwclayers"s, mainThreadDumper(&SurfaceFlinger::dumpHwcLayersMinidump)}, |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 5582 | {"--latency"s, argsMainThreadDumper(&SurfaceFlinger::dumpStats)}, |
| 5583 | {"--latency-clear"s, argsMainThreadDumper(&SurfaceFlinger::clearStats)}, |
| 5584 | {"--list"s, mainThreadDumper(&SurfaceFlinger::listLayers)}, |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 5585 | {"--planner"s, argsDumper(&SurfaceFlinger::dumpPlannerInfo)}, |
| 5586 | {"--scheduler"s, dumper(&SurfaceFlinger::dumpScheduler)}, |
| 5587 | {"--timestats"s, protoDumper(&SurfaceFlinger::dumpTimeStats)}, |
| 5588 | {"--vsync"s, dumper(&SurfaceFlinger::dumpVsync)}, |
| 5589 | {"--wide-color"s, dumper(&SurfaceFlinger::dumpWideColorInfo)}, |
| 5590 | }; |
| 5591 | |
| 5592 | const auto flag = args.empty() ? ""s : std::string(String8(args[0])); |
| 5593 | if (const auto it = dumpers.find(flag); it != dumpers.end()) { |
| 5594 | (it->second)(args, asProto, result); |
| 5595 | write(fd, result.c_str(), result.size()); |
| 5596 | return NO_ERROR; |
| 5597 | } |
| 5598 | |
Vishnu Nair | 11db986 | 2024-06-21 22:06:14 +0000 | [diff] [blame] | 5599 | // Collect debug data from main thread |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 5600 | std::string compositionLayers; |
| 5601 | mScheduler |
| 5602 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 5603 | dumpVisibleFrontEnd(compositionLayers); |
| 5604 | }) |
| 5605 | .get(); |
Vishnu Nair | 11db986 | 2024-06-21 22:06:14 +0000 | [diff] [blame] | 5606 | // get window info listener data without the state lock |
| 5607 | auto windowInfosDebug = mWindowInfosListenerInvoker->getDebugInfo(); |
| 5608 | compositionLayers.append("Window Infos:\n"); |
| 5609 | StringAppendF(&compositionLayers, " max send vsync id: %" PRId64 "\n", |
| 5610 | ftl::to_underlying(windowInfosDebug.maxSendDelayVsyncId)); |
| 5611 | StringAppendF(&compositionLayers, " max send delay (ns): %" PRId64 " ns\n", |
| 5612 | windowInfosDebug.maxSendDelayDuration); |
| 5613 | StringAppendF(&compositionLayers, " unsent messages: %zu\n", |
| 5614 | windowInfosDebug.pendingMessageCount); |
| 5615 | compositionLayers.append("\n"); |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 5616 | dumpAll(args, compositionLayers, result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5617 | write(fd, result.c_str(), result.size()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5618 | return NO_ERROR; |
| 5619 | } |
| 5620 | |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 5621 | status_t SurfaceFlinger::dumpCritical(int fd, const DumpArgs&, bool asProto) { |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 5622 | return doDump(fd, DumpArgs(), asProto); |
| 5623 | } |
| 5624 | |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 5625 | void SurfaceFlinger::listLayers(std::string& result) const { |
| 5626 | for (const auto& layer : mLayerLifecycleManager.getLayers()) { |
| 5627 | StringAppendF(&result, "%s\n", layer->getDebugString().c_str()); |
| 5628 | } |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5629 | } |
| 5630 | |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 5631 | void SurfaceFlinger::dumpStats(const DumpArgs& args, std::string& result) const { |
Dominik Laskowski | fe749dc | 2024-07-26 10:09:31 -0400 | [diff] [blame] | 5632 | StringAppendF(&result, "%" PRId64 "\n", mScheduler->getPacesetterVsyncPeriod().ns()); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5633 | if (args.size() < 2) return; |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 5634 | |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5635 | const auto name = String8(args[1]); |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 5636 | traverseLegacyLayers([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 5637 | if (layer->getName() == name.c_str()) { |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5638 | layer->dumpFrameStats(result); |
| 5639 | } |
| 5640 | }); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5641 | } |
| 5642 | |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 5643 | void SurfaceFlinger::clearStats(const DumpArgs& args, std::string&) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5644 | const bool clearAll = args.size() < 2; |
| 5645 | const auto name = clearAll ? String8() : String8(args[1]); |
| 5646 | |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 5647 | traverseLegacyLayers([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 5648 | if (clearAll || layer->getName() == name.c_str()) { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 5649 | layer->clearFrameStats(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5650 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 5651 | }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5652 | } |
| 5653 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5654 | void SurfaceFlinger::dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const { |
| 5655 | mTimeStats->parseArgs(asProto, args, result); |
| 5656 | } |
| 5657 | |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 5658 | void SurfaceFlinger::dumpFrameTimeline(const DumpArgs& args, std::string& result) const { |
| 5659 | mFrameTimeline->parseArgs(args, result); |
| 5660 | } |
| 5661 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 5662 | void SurfaceFlinger::logFrameStats(TimePoint now) { |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 5663 | static TimePoint sTimestamp = now; |
| 5664 | if (now - sTimestamp < 30min) return; |
| 5665 | sTimestamp = now; |
| 5666 | |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 5667 | SFTRACE_CALL(); |
Vishnu Nair | ad4c67a | 2024-08-15 09:25:55 +0000 | [diff] [blame] | 5668 | traverseLegacyLayers([&](Layer* layer) { layer->logFrameStats(); }); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 5669 | } |
| 5670 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5671 | void SurfaceFlinger::appendSfConfigString(std::string& result) const { |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 5672 | result.append(" [sf"); |
Fabien Sanglard | c93afd5 | 2017-03-13 13:02:42 -0700 | [diff] [blame] | 5673 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5674 | StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); |
| 5675 | StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 5676 | StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%zu", |
| 5677 | getHwComposer().getMaxVirtualDisplayDimension()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5678 | StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5679 | StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5680 | maxFrameBufferAcquiredBuffers); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 5681 | result.append("]"); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5682 | } |
| 5683 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5684 | void SurfaceFlinger::dumpScheduler(std::string& result) const { |
| 5685 | utils::Dumper dumper{result}; |
| 5686 | |
| 5687 | mScheduler->dump(dumper); |
| 5688 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5689 | // TODO(b/241285876): Move to DisplayModeController. |
| 5690 | dumper.dump("debugDisplayModeSetByBackdoor"sv, mDebugDisplayModeSetByBackdoor); |
| 5691 | dumper.eol(); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5692 | } |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5693 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5694 | void SurfaceFlinger::dumpEvents(std::string& result) const { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 5695 | mScheduler->dump(scheduler::Cycle::Render, result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | void SurfaceFlinger::dumpVsync(std::string& result) const { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 5699 | mScheduler->dumpVsync(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5700 | } |
| 5701 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 5702 | void SurfaceFlinger::dumpPlannerInfo(const DumpArgs& args, std::string& result) const { |
| 5703 | for (const auto& [token, display] : mDisplays) { |
| 5704 | const auto compositionDisplay = display->getCompositionDisplay(); |
| 5705 | compositionDisplay->dumpPlannerInfo(args, result); |
| 5706 | } |
| 5707 | } |
| 5708 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5709 | void SurfaceFlinger::dumpCompositionDisplays(std::string& result) const { |
| 5710 | for (const auto& [token, display] : mDisplays) { |
| 5711 | display->getCompositionDisplay()->dump(result); |
| 5712 | result += '\n'; |
| 5713 | } |
| 5714 | } |
| 5715 | |
| 5716 | void SurfaceFlinger::dumpDisplays(std::string& result) const { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 5717 | utils::Dumper dumper{result}; |
| 5718 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5719 | for (const auto& [id, display] : mPhysicalDisplays) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 5720 | utils::Dumper::Section section(dumper, ftl::Concat("Display ", id.value).str()); |
| 5721 | |
| 5722 | display.snapshot().dump(dumper); |
| 5723 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5724 | if (const auto device = getDisplayDeviceLocked(id)) { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 5725 | device->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5726 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5727 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5728 | |
| 5729 | for (const auto& [token, display] : mDisplays) { |
| 5730 | if (display->isVirtual()) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 5731 | const auto displayId = display->getId(); |
| 5732 | utils::Dumper::Section section(dumper, |
| 5733 | ftl::Concat("Virtual Display ", displayId.value).str()); |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 5734 | display->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5735 | } |
| 5736 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5737 | } |
| 5738 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5739 | void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 5740 | for (const auto& [token, display] : mDisplays) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5741 | const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 5742 | if (!displayId) { |
| 5743 | continue; |
| 5744 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5745 | const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId); |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 5746 | if (!hwcDisplayId) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5747 | continue; |
| 5748 | } |
| 5749 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5750 | StringAppendF(&result, |
| 5751 | "Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), |
| 5752 | *hwcDisplayId); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5753 | uint8_t port; |
| 5754 | DisplayIdentificationData data; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 5755 | if (!getHwComposer().getDisplayIdentificationData(*hwcDisplayId, &port, &data)) { |
Brian Lindahl | 8a96ef9 | 2024-05-24 14:46:29 +0000 | [diff] [blame] | 5756 | result.append("no display identification data\n"); |
| 5757 | continue; |
| 5758 | } |
| 5759 | |
| 5760 | if (data.empty()) { |
| 5761 | result.append("empty display identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5762 | continue; |
| 5763 | } |
| 5764 | |
| 5765 | if (!isEdid(data)) { |
Brian Lindahl | 8a96ef9 | 2024-05-24 14:46:29 +0000 | [diff] [blame] | 5766 | result.append("unknown format for display identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5767 | continue; |
| 5768 | } |
| 5769 | |
| 5770 | const auto edid = parseEdid(data); |
| 5771 | if (!edid) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5772 | result.append("invalid EDID\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5773 | continue; |
| 5774 | } |
| 5775 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5776 | StringAppendF(&result, "port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5777 | result.append(edid->displayName.data(), edid->displayName.length()); |
| 5778 | result.append("\"\n"); |
| 5779 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5780 | } |
| 5781 | |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5782 | void SurfaceFlinger::dumpRawDisplayIdentificationData(const DumpArgs& args, |
| 5783 | std::string& result) const { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 5784 | hal::HWDisplayId hwcDisplayId; |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5785 | uint8_t port; |
| 5786 | DisplayIdentificationData data; |
| 5787 | |
| 5788 | if (args.size() > 1 && base::ParseUint(String8(args[1]), &hwcDisplayId) && |
| 5789 | getHwComposer().getDisplayIdentificationData(hwcDisplayId, &port, &data)) { |
| 5790 | result.append(reinterpret_cast<const char*>(data.data()), data.size()); |
| 5791 | } |
| 5792 | } |
| 5793 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5794 | void SurfaceFlinger::dumpWideColorInfo(std::string& result) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5795 | StringAppendF(&result, "Device supports wide color: %d\n", mSupportsWideColor); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5796 | StringAppendF(&result, "DisplayColorSetting: %s\n", |
| 5797 | decodeDisplayColorSetting(mDisplayColorSetting).c_str()); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5798 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 5799 | // TODO: print out if wide-color mode is active or not. |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5800 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 5801 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 5802 | StringAppendF(&result, "Display %s color modes:\n", to_string(id).c_str()); |
| 5803 | for (const auto mode : display.snapshot().colorModes()) { |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 5804 | StringAppendF(&result, " %s (%d)\n", decodeColorMode(mode).c_str(), |
| 5805 | fmt::underlying(mode)); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5806 | } |
| 5807 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 5808 | if (const auto display = getDisplayDeviceLocked(id)) { |
| 5809 | ui::ColorMode currentMode = display->getCompositionDisplay()->getState().colorMode; |
| 5810 | StringAppendF(&result, " Current color mode: %s (%d)\n", |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 5811 | decodeColorMode(currentMode).c_str(), fmt::underlying(currentMode)); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 5812 | } |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5813 | } |
| 5814 | result.append("\n"); |
| 5815 | } |
| 5816 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 5817 | void SurfaceFlinger::dumpHdrInfo(std::string& result) const { |
| 5818 | for (const auto& [displayId, listener] : mHdrLayerInfoListeners) { |
| 5819 | StringAppendF(&result, "HDR events for display %" PRIu64 "\n", displayId.value); |
| 5820 | listener->dump(result); |
| 5821 | result.append("\n"); |
| 5822 | } |
| 5823 | } |
| 5824 | |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 5825 | void SurfaceFlinger::dumpFrontEnd(std::string& result) { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 5826 | std::ostringstream out; |
Wenhui Yang | 111e26e | 2024-10-03 05:22:11 +0000 | [diff] [blame] | 5827 | out << "\nComposition list (bottom to top)\n"; |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 5828 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 5829 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 5830 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 5831 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 5832 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 5833 | } |
| 5834 | out << " " << *snapshot << "\n"; |
| 5835 | } |
| 5836 | |
| 5837 | out << "\nInput list\n"; |
| 5838 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 5839 | mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 5840 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 5841 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 5842 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 5843 | } |
| 5844 | out << " " << snapshot << "\n"; |
| 5845 | }); |
| 5846 | |
| 5847 | out << "\nLayer Hierarchy\n" |
| 5848 | << mLayerHierarchyBuilder.getHierarchy().dump() << "\nOffscreen Hierarchy\n" |
| 5849 | << mLayerHierarchyBuilder.getOffscreenHierarchy().dump() << "\n\n"; |
| 5850 | result.append(out.str()); |
| 5851 | } |
| 5852 | |
| 5853 | void SurfaceFlinger::dumpVisibleFrontEnd(std::string& result) { |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 5854 | std::ostringstream out; |
Wenhui Yang | 111e26e | 2024-10-03 05:22:11 +0000 | [diff] [blame] | 5855 | out << "\nComposition list (bottom to top)\n"; |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 5856 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 5857 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 5858 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 5859 | if (snapshot->hasSomethingToDraw()) { |
| 5860 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 5861 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 5862 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 5863 | } |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 5864 | out << " " << *snapshot << "\n"; |
| 5865 | } |
| 5866 | }); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 5867 | |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 5868 | out << "\nInput list\n"; |
| 5869 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 5870 | mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 5871 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 5872 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 5873 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 5874 | } |
| 5875 | out << " " << snapshot << "\n"; |
| 5876 | }); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 5877 | |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 5878 | out << "\nLayer Hierarchy\n" |
| 5879 | << mLayerHierarchyBuilder.getHierarchy() << "\nOffscreen Hierarchy\n" |
| 5880 | << mLayerHierarchyBuilder.getOffscreenHierarchy() << "\n\n"; |
| 5881 | result = out.str(); |
| 5882 | dumpHwcLayersMinidump(result); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 5883 | } |
| 5884 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 5885 | perfetto::protos::LayersProto SurfaceFlinger::dumpDrawingStateProto(uint32_t traceFlags) const { |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 5886 | std::unordered_set<uint64_t> stackIdsToSkip; |
| 5887 | |
| 5888 | // Determine if virtual layers display should be skipped |
| 5889 | if ((traceFlags & LayerTracing::TRACE_VIRTUAL_DISPLAYS) == 0) { |
| 5890 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 5891 | if (display->isVirtual()) { |
| 5892 | stackIdsToSkip.insert(display->getLayerStack().id); |
| 5893 | } |
| 5894 | } |
| 5895 | } |
| 5896 | |
Vishnu Nair | b46e37c | 2024-08-16 14:30:28 +0000 | [diff] [blame] | 5897 | auto traceGenerator = |
| 5898 | LayerProtoFromSnapshotGenerator(mLayerSnapshotBuilder, mFrontEndDisplayInfos, |
| 5899 | mLegacyLayers, traceFlags) |
| 5900 | .with(mLayerHierarchyBuilder.getHierarchy()); |
| 5901 | |
| 5902 | if (traceFlags & LayerTracing::Flag::TRACE_EXTRA) { |
| 5903 | traceGenerator.withOffscreenLayers(mLayerHierarchyBuilder.getOffscreenHierarchy()); |
| 5904 | } |
| 5905 | |
| 5906 | return traceGenerator.generate(); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 5907 | } |
| 5908 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 5909 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> |
| 5910 | SurfaceFlinger::dumpDisplayProto() const { |
| 5911 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> displays; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 5912 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 5913 | perfetto::protos::DisplayProto* displayProto = displays.Add(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5914 | displayProto->set_id(display->getId().value); |
| 5915 | displayProto->set_name(display->getDisplayName()); |
| 5916 | displayProto->set_layer_stack(display->getLayerStack().id); |
DoÄŸancan Emek | fc4b6ed | 2023-07-26 15:24:04 +0000 | [diff] [blame] | 5917 | |
| 5918 | if (!display->isVirtual()) { |
| 5919 | const auto dpi = display->refreshRateSelector().getActiveMode().modePtr->getDpi(); |
| 5920 | displayProto->set_dpi_x(dpi.x); |
| 5921 | displayProto->set_dpi_y(dpi.y); |
| 5922 | } |
| 5923 | |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5924 | LayerProtoHelper::writeSizeToProto(display->getWidth(), display->getHeight(), |
| 5925 | [&]() { return displayProto->mutable_size(); }); |
| 5926 | LayerProtoHelper::writeToProto(display->getLayerStackSpaceRect(), [&]() { |
| 5927 | return displayProto->mutable_layer_stack_space_rect(); |
| 5928 | }); |
| 5929 | LayerProtoHelper::writeTransformToProto(display->getTransform(), |
| 5930 | displayProto->mutable_transform()); |
Vishnu Nair | 791d48a | 2021-12-02 16:55:13 -0800 | [diff] [blame] | 5931 | displayProto->set_is_virtual(display->isVirtual()); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5932 | } |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5933 | return displays; |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5934 | } |
| 5935 | |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 5936 | void SurfaceFlinger::dumpHwc(std::string& result) const { |
| 5937 | getHwComposer().dump(result); |
| 5938 | } |
| 5939 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 5940 | perfetto::protos::LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 5941 | return mScheduler |
| 5942 | ->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 5943 | return dumpDrawingStateProto(traceFlags); |
| 5944 | }) |
| 5945 | .get(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 5946 | } |
| 5947 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 5948 | void SurfaceFlinger::dumpHwcLayersMinidump(std::string& result) const { |
Dominik Laskowski | 48bc171 | 2024-07-23 13:16:04 -0400 | [diff] [blame] | 5949 | for (const auto& [token, display] : mDisplays) { |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 5950 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 5951 | if (!displayId) { |
| 5952 | continue; |
| 5953 | } |
| 5954 | |
| 5955 | StringAppendF(&result, "Display %s (%s) HWC layers:\n", to_string(*displayId).c_str(), |
| 5956 | displayId == mActiveDisplayId ? "active" : "inactive"); |
| 5957 | Layer::miniDumpHeader(result); |
| 5958 | |
| 5959 | const DisplayDevice& ref = *display; |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 5960 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 5961 | [&](const frontend::LayerSnapshot& snapshot) FTL_FAKE_GUARD(kMainThreadContext) { |
| 5962 | if (!snapshot.hasSomethingToDraw() || |
| 5963 | ref.getLayerStack() != snapshot.outputFilter.layerStack) { |
| 5964 | return; |
| 5965 | } |
| 5966 | auto it = mLegacyLayers.find(snapshot.sequence); |
| 5967 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 5968 | "Couldnt find layer object for %s", |
| 5969 | snapshot.getDebugString().c_str()); |
| 5970 | it->second->miniDump(result, snapshot, ref); |
| 5971 | }); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 5972 | result.append("\n"); |
| 5973 | } |
| 5974 | } |
| 5975 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 5976 | void SurfaceFlinger::dumpAll(const DumpArgs& args, const std::string& compositionLayers, |
| 5977 | std::string& result) const { |
| 5978 | TimedLock lock(mStateLock, s2ns(1), __func__); |
| 5979 | if (!lock.locked()) { |
| 5980 | StringAppendF(&result, "Dumping without lock after timeout: %s (%d)\n", |
| 5981 | strerror(-lock.status), lock.status); |
| 5982 | } |
| 5983 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5984 | const bool colorize = !args.empty() && args[0] == String16("--color"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5985 | Colorizer colorizer(colorize); |
| 5986 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5987 | // figure out if we're stuck somewhere |
| 5988 | const nsecs_t now = systemTime(); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5989 | const nsecs_t inTransaction(mDebugInTransaction); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5990 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 5991 | |
| 5992 | /* |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5993 | * Dump library configuration. |
| 5994 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5995 | |
| 5996 | colorizer.bold(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5997 | result.append("Build configuration:"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5998 | colorizer.reset(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5999 | appendSfConfigString(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6000 | result.append("\n"); |
| 6001 | |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6002 | result.append("\nDisplay identification data:\n"); |
| 6003 | dumpDisplayIdentificationData(result); |
| 6004 | |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6005 | result.append("\nWide-Color information:\n"); |
| 6006 | dumpWideColorInfo(result); |
| 6007 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6008 | dumpHdrInfo(result); |
| 6009 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6010 | colorizer.bold(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6011 | result.append("Sync configuration: "); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6012 | colorizer.reset(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6013 | result.append(SyncFeatures::getInstance().toString()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6014 | result.append("\n\n"); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6015 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6016 | colorizer.bold(result); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6017 | result.append("Scheduler:\n"); |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6018 | colorizer.reset(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6019 | dumpScheduler(result); |
| 6020 | dumpEvents(result); |
| 6021 | dumpVsync(result); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 6022 | result.append("\n"); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6023 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6024 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6025 | * Dump the visible layer list |
| 6026 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6027 | colorizer.bold(result); |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 6028 | StringAppendF(&result, "SurfaceFlinger New Frontend Enabled:%s\n", "true"); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6029 | StringAppendF(&result, "Active Layers - layers with client handles (count = %zu)\n", |
| 6030 | mNumLayers.load()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6031 | colorizer.reset(result); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6032 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 6033 | result.append(compositionLayers); |
Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 6034 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6035 | colorizer.bold(result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6036 | StringAppendF(&result, "Displays (%zu entries)\n", mDisplays.size()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6037 | colorizer.reset(result); |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6038 | dumpDisplays(result); |
| 6039 | dumpCompositionDisplays(result); |
| 6040 | result.push_back('\n'); |
Lloyd Pique | c3cb729 | 2019-05-17 15:25:14 -0700 | [diff] [blame] | 6041 | |
| 6042 | mCompositionEngine->dump(result); |
| 6043 | |
| 6044 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6045 | * Dump SurfaceFlinger global state |
| 6046 | */ |
| 6047 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6048 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6049 | result.append("SurfaceFlinger global state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6050 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6051 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 6052 | getRenderEngine().dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6053 | |
Robert Carr | beba6f0 | 2021-02-10 21:06:27 -0800 | [diff] [blame] | 6054 | result.append("ClientCache state:\n"); |
| 6055 | ClientCache::getInstance().dump(result); |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 6056 | DebugEGLImageTracker::getInstance()->dump(result); |
| 6057 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6058 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 6059 | display->getCompositionDisplay()->getState().undefinedRegion.dump(result, |
| 6060 | "undefinedRegion"); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 6061 | StringAppendF(&result, " orientation=%s, isPoweredOn=%d\n", |
| 6062 | toCString(display->getOrientation()), display->isPoweredOn()); |
Lloyd Pique | 2ae2b3b | 2017-12-14 17:18:17 -0800 | [diff] [blame] | 6063 | } |
Carlos Martinez Romero | 779dc1f | 2022-10-27 23:23:30 +0000 | [diff] [blame] | 6064 | StringAppendF(&result, " transaction-flags : %08x\n", mTransactionFlags.load()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6065 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 6066 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Ying Wei | 784a8e7 | 2024-04-20 08:46:42 +0000 | [diff] [blame] | 6067 | std::string peakFps, xDpi, yDpi; |
| 6068 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 6069 | if (const auto activeModePtr = activeMode.modePtr.get()) { |
| 6070 | peakFps = to_string(activeMode.modePtr->getPeakFps()); |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6071 | const auto dpi = activeModePtr->getDpi(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6072 | xDpi = base::StringPrintf("%.2f", dpi.x); |
| 6073 | yDpi = base::StringPrintf("%.2f", dpi.y); |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6074 | } else { |
Ying Wei | 784a8e7 | 2024-04-20 08:46:42 +0000 | [diff] [blame] | 6075 | peakFps = "unknown"; |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6076 | xDpi = "unknown"; |
| 6077 | yDpi = "unknown"; |
| 6078 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6079 | StringAppendF(&result, |
Ying Wei | 784a8e7 | 2024-04-20 08:46:42 +0000 | [diff] [blame] | 6080 | " peak-refresh-rate : %s\n" |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6081 | " x-dpi : %s\n" |
| 6082 | " y-dpi : %s\n", |
Ying Wei | 784a8e7 | 2024-04-20 08:46:42 +0000 | [diff] [blame] | 6083 | peakFps.c_str(), xDpi.c_str(), yDpi.c_str()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6084 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6085 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6086 | StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6087 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6088 | result.append("\nTransaction tracing: "); |
| 6089 | if (mTransactionTracing) { |
| 6090 | result.append("enabled\n"); |
| 6091 | mTransactionTracing->dump(result); |
| 6092 | } else { |
| 6093 | result.append("disabled\n"); |
| 6094 | } |
| 6095 | result.push_back('\n'); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6096 | |
Ady Abraham | 2790e9f | 2021-04-28 13:14:20 -0700 | [diff] [blame] | 6097 | { |
| 6098 | DumpArgs plannerArgs; |
| 6099 | plannerArgs.add(); // first argument is ignored |
| 6100 | plannerArgs.add(String16("--layers")); |
| 6101 | dumpPlannerInfo(plannerArgs, result); |
| 6102 | } |
| 6103 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6104 | /* |
| 6105 | * Dump HWComposer state |
| 6106 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6107 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6108 | result.append("h/w composer state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6109 | colorizer.reset(result); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6110 | const bool hwcDisabled = mDebugDisableHWC || mDebugFlashDelay; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6111 | StringAppendF(&result, " h/w composer %s\n", hwcDisabled ? "disabled" : "enabled"); |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 6112 | dumpHwc(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6113 | |
| 6114 | /* |
| 6115 | * Dump gralloc state |
| 6116 | */ |
| 6117 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 6118 | alloc.dump(result); |
Karthik Ravi Shankar | 171155a | 2017-06-28 15:40:24 -0700 | [diff] [blame] | 6119 | |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6120 | /* |
| 6121 | * Dump flag/property manager state |
| 6122 | */ |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 6123 | FlagManager::getInstance().dump(result); |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6124 | |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 6125 | result.append(mTimeStats->miniDump()); |
| 6126 | result.append("\n"); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6127 | } |
| 6128 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6129 | mat4 SurfaceFlinger::calculateColorMatrix(float saturation) { |
| 6130 | if (saturation == 1) { |
| 6131 | return mat4(); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6132 | } |
| 6133 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6134 | float3 luminance{0.213f, 0.715f, 0.072f}; |
| 6135 | luminance *= 1.0f - saturation; |
| 6136 | mat4 saturationMatrix = mat4(vec4{luminance.r + saturation, luminance.r, luminance.r, 0.0f}, |
| 6137 | vec4{luminance.g, luminance.g + saturation, luminance.g, 0.0f}, |
| 6138 | vec4{luminance.b, luminance.b, luminance.b + saturation, 0.0f}, |
| 6139 | vec4{0.0f, 0.0f, 0.0f, 1.0f}); |
| 6140 | return saturationMatrix; |
| 6141 | } |
| 6142 | |
| 6143 | void SurfaceFlinger::updateColorMatrixLocked() { |
| 6144 | mat4 colorMatrix = |
| 6145 | mClientColorMatrix * calculateColorMatrix(mGlobalSaturationFactor) * mDaltonizer(); |
| 6146 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6147 | if (mCurrentState.colorMatrix != colorMatrix) { |
| 6148 | mCurrentState.colorMatrix = colorMatrix; |
| 6149 | mCurrentState.colorMatrixChanged = true; |
| 6150 | setTransactionFlags(eTransactionNeeded); |
| 6151 | } |
| 6152 | } |
| 6153 | |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6154 | status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6155 | #pragma clang diagnostic push |
| 6156 | #pragma clang diagnostic error "-Wswitch-enum" |
| 6157 | switch (static_cast<ISurfaceComposerTag>(code)) { |
| 6158 | // These methods should at minimum make sure that the client requested |
| 6159 | // access to SF. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6160 | case GET_HDR_CAPABILITIES: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6161 | case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6162 | case GET_GAME_CONTENT_TYPE_SUPPORT: |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6163 | case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6164 | // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary |
| 6165 | // permission dynamically. Don't use the permission cache for this check. |
| 6166 | bool usePermissionCache = code != OVERRIDE_HDR_TYPES; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6167 | if (!callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 6168 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6169 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", |
| 6170 | ipc->getCallingPid(), ipc->getCallingUid()); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6171 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6172 | } |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 6173 | return OK; |
| 6174 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6175 | // The following calls are currently used by clients that do not |
| 6176 | // request necessary permissions. However, they do not expose any secret |
| 6177 | // information, so it is OK to pass them. |
Peiyong Lin | d1fedb4 | 2019-03-11 17:48:41 -0700 | [diff] [blame] | 6178 | case GET_ACTIVE_COLOR_MODE: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6179 | case GET_ACTIVE_DISPLAY_MODE: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6180 | case GET_DISPLAY_COLOR_MODES: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6181 | case GET_DISPLAY_MODES: |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 6182 | case GET_SCHEDULING_POLICY: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6183 | // Calling setTransactionState is safe, because you need to have been |
| 6184 | // granted a reference to Client* and Handle* to do anything with it. |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6185 | case SET_TRANSACTION_STATE: { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 6186 | // This is not sensitive information, so should not require permission control. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6187 | return OK; |
| 6188 | } |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 6189 | case BOOT_FINISHED: |
| 6190 | // Used by apps to hook Choreographer to SurfaceFlinger. |
| 6191 | case CREATE_DISPLAY_EVENT_CONNECTION: |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6192 | case CREATE_CONNECTION: |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 6193 | case CREATE_VIRTUAL_DISPLAY: |
| 6194 | case DESTROY_VIRTUAL_DISPLAY: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6195 | case GET_PRIMARY_PHYSICAL_DISPLAY_ID: |
| 6196 | case GET_PHYSICAL_DISPLAY_IDS: |
| 6197 | case GET_PHYSICAL_DISPLAY_TOKEN: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6198 | case AUTHENTICATE_SURFACE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6199 | case SET_POWER_MODE: |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 6200 | case GET_SUPPORTED_FRAME_TIMESTAMPS: |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6201 | case GET_DISPLAY_STATE: |
| 6202 | case GET_DISPLAY_STATS: |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 6203 | case GET_STATIC_DISPLAY_INFO: |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 6204 | case GET_DYNAMIC_DISPLAY_INFO: |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 6205 | case GET_DISPLAY_NATIVE_PRIMARIES: |
| 6206 | case SET_ACTIVE_COLOR_MODE: |
| 6207 | case SET_BOOT_DISPLAY_MODE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6208 | case CLEAR_BOOT_DISPLAY_MODE: |
| 6209 | case GET_BOOT_DISPLAY_MODE_SUPPORT: |
| 6210 | case SET_AUTO_LOW_LATENCY_MODE: |
| 6211 | case SET_GAME_CONTENT_TYPE: |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6212 | case CAPTURE_LAYERS: |
| 6213 | case CAPTURE_DISPLAY: |
| 6214 | case CAPTURE_DISPLAY_BY_ID: |
Huihong Luo | 4ed1c91 | 2022-02-22 14:30:01 -0800 | [diff] [blame] | 6215 | case CLEAR_ANIMATION_FRAME_STATS: |
| 6216 | case GET_ANIMATION_FRAME_STATS: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6217 | case OVERRIDE_HDR_TYPES: |
| 6218 | case ON_PULL_ATOM: |
| 6219 | case ENABLE_VSYNC_INJECTIONS: |
| 6220 | case INJECT_VSYNC: |
| 6221 | case GET_LAYER_DEBUG_INFO: |
| 6222 | case GET_COLOR_MANAGEMENT: |
| 6223 | case GET_COMPOSITION_PREFERENCE: |
| 6224 | case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: |
| 6225 | case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6226 | case GET_DISPLAYED_CONTENT_SAMPLE: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6227 | case GET_PROTECTED_CONTENT_SUPPORT: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6228 | case IS_WIDE_COLOR_DISPLAY: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6229 | case ADD_REGION_SAMPLING_LISTENER: |
| 6230 | case REMOVE_REGION_SAMPLING_LISTENER: |
| 6231 | case ADD_FPS_LISTENER: |
| 6232 | case REMOVE_FPS_LISTENER: |
| 6233 | case ADD_TUNNEL_MODE_ENABLED_LISTENER: |
| 6234 | case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: |
| 6235 | case ADD_WINDOW_INFOS_LISTENER: |
| 6236 | case REMOVE_WINDOW_INFOS_LISTENER: |
| 6237 | case SET_DESIRED_DISPLAY_MODE_SPECS: |
| 6238 | case GET_DESIRED_DISPLAY_MODE_SPECS: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6239 | case GET_DISPLAY_BRIGHTNESS_SUPPORT: |
| 6240 | case SET_DISPLAY_BRIGHTNESS: |
| 6241 | case ADD_HDR_LAYER_INFO_LISTENER: |
| 6242 | case REMOVE_HDR_LAYER_INFO_LISTENER: |
| 6243 | case NOTIFY_POWER_BOOST: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6244 | case SET_GLOBAL_SHADOW_SETTINGS: |
| 6245 | case GET_DISPLAY_DECORATION_SUPPORT: |
| 6246 | case SET_FRAME_RATE: |
| 6247 | case SET_OVERRIDE_FRAME_RATE: |
| 6248 | case SET_FRAME_TIMELINE_INFO: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6249 | case ADD_TRANSACTION_TRACE_LISTENER: |
| 6250 | case GET_GPU_CONTEXT_PRIORITY: |
| 6251 | case GET_MAX_ACQUIRED_BUFFER_COUNT: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6252 | LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6253 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6254 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6255 | |
| 6256 | // These codes are used for the IBinder protocol to either interrogate the recipient |
| 6257 | // side of the transaction for its canonical interface descriptor or to dump its state. |
| 6258 | // We let them pass by default. |
| 6259 | if (code == IBinder::INTERFACE_TRANSACTION || code == IBinder::DUMP_TRANSACTION || |
| 6260 | code == IBinder::PING_TRANSACTION || code == IBinder::SHELL_COMMAND_TRANSACTION || |
| 6261 | code == IBinder::SYSPROPS_TRANSACTION) { |
| 6262 | return OK; |
| 6263 | } |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 6264 | // Numbers from 1000 to 1045 are currently used for backdoors. The code |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6265 | // in onTransact verifies that the user is root, and has access to use SF. |
Ady Abraham | 708ebfb | 2024-11-14 14:42:49 -0800 | [diff] [blame^] | 6266 | if (code >= 1000 && code <= 1046) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6267 | ALOGV("Accessing SurfaceFlinger through backdoor code: %u", code); |
| 6268 | return OK; |
| 6269 | } |
| 6270 | ALOGE("Permission Denial: SurfaceFlinger did not recognize request code: %u", code); |
| 6271 | return PERMISSION_DENIED; |
| 6272 | #pragma clang diagnostic pop |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6273 | } |
| 6274 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6275 | status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 6276 | uint32_t flags) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6277 | if (const status_t error = CheckTransactCodeCredentials(code); error != OK) { |
| 6278 | return error; |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6279 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 6280 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6281 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 6282 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 6283 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Romain Guy | 8c6bbd6 | 2017-06-05 13:51:43 -0700 | [diff] [blame] | 6284 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6285 | const int uid = ipc->getCallingUid(); |
| 6286 | if (CC_UNLIKELY(uid != AID_SYSTEM |
| 6287 | && !PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6288 | const int pid = ipc->getCallingPid(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 6289 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6290 | "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] | 6291 | return PERMISSION_DENIED; |
| 6292 | } |
| 6293 | int n; |
| 6294 | switch (code) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6295 | case 1000: // Unused. |
| 6296 | case 1001: |
| 6297 | return NAME_NOT_FOUND; |
| 6298 | case 1002: // Toggle flashing on surface damage. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6299 | sfdo_setDebugFlash(data.readInt32()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6300 | return NO_ERROR; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6301 | case 1004: // Force composite ahead of next VSYNC. |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 6302 | case 1006: |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6303 | sfdo_scheduleComposite(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6304 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6305 | case 1005: { // Force commit ahead of next VSYNC. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6306 | sfdo_scheduleCommit(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 6307 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6308 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6309 | case 1007: // Unused. |
| 6310 | return NAME_NOT_FOUND; |
| 6311 | case 1008: // Toggle forced GPU composition. |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 6312 | sfdo_forceClientComposition(data.readInt32() != 0); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 6313 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6314 | case 1009: // Toggle use of transform hint. |
| 6315 | mDebugDisableTransformHint = data.readInt32() != 0; |
| 6316 | scheduleRepaint(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 6317 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6318 | case 1010: // Interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 6319 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6320 | reply->writeInt32(0); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6321 | reply->writeInt32(mDebugFlashDelay); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 6322 | reply->writeInt32(0); |
Dianne Hackborn | 12839be | 2012-02-06 21:21:05 -0800 | [diff] [blame] | 6323 | reply->writeInt32(mDebugDisableHWC); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6324 | return NO_ERROR; |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6325 | case 1013: // Unused. |
| 6326 | return NAME_NOT_FOUND; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6327 | case 1014: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6328 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6329 | // daltonize |
| 6330 | n = data.readInt32(); |
Isaac Chai | 1ec2d9a | 2024-04-11 20:10:34 +0000 | [diff] [blame] | 6331 | mDaltonizer.setLevel(data.readInt32()); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6332 | switch (n % 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6333 | case 1: |
| 6334 | mDaltonizer.setType(ColorBlindnessType::Protanomaly); |
| 6335 | break; |
| 6336 | case 2: |
| 6337 | mDaltonizer.setType(ColorBlindnessType::Deuteranomaly); |
| 6338 | break; |
| 6339 | case 3: |
| 6340 | mDaltonizer.setType(ColorBlindnessType::Tritanomaly); |
| 6341 | break; |
| 6342 | default: |
| 6343 | mDaltonizer.setType(ColorBlindnessType::None); |
| 6344 | break; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6345 | } |
| 6346 | if (n >= 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6347 | mDaltonizer.setMode(ColorBlindnessMode::Correction); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6348 | } else { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6349 | mDaltonizer.setMode(ColorBlindnessMode::Simulation); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6350 | } |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6351 | |
| 6352 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6353 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6354 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6355 | case 1015: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6356 | Mutex::Autolock _l(mStateLock); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6357 | // apply a color matrix |
| 6358 | n = data.readInt32(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6359 | if (n) { |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6360 | // color matrix is sent as a column-major mat4 matrix |
Alan Viverette | 794c5ba | 2013-10-03 16:40:52 -0700 | [diff] [blame] | 6361 | for (size_t i = 0 ; i < 4; i++) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6362 | for (size_t j = 0; j < 4; j++) { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6363 | mClientColorMatrix[i][j] = data.readFloat(); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6364 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6365 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6366 | } else { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6367 | mClientColorMatrix = mat4(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6368 | } |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 6369 | |
| 6370 | // Check that supplied matrix's last row is {0,0,0,1} so we can avoid |
| 6371 | // the division by w in the fragment shader |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6372 | float4 lastRow(transpose(mClientColorMatrix)[3]); |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 6373 | if (any(greaterThan(abs(lastRow - float4{0, 0, 0, 1}), float4{1e-4f}))) { |
| 6374 | ALOGE("The color transform's last row must be (0, 0, 0, 1)"); |
| 6375 | } |
| 6376 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6377 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6378 | return NO_ERROR; |
| 6379 | } |
Dominik Laskowski | 8d32ddc | 2019-08-07 11:25:35 -0700 | [diff] [blame] | 6380 | case 1016: { // Unused. |
| 6381 | return NAME_NOT_FOUND; |
Ruchi Kandoi | f52b3c8 | 2014-04-24 16:42:35 -0700 | [diff] [blame] | 6382 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 6383 | case 1017: { |
| 6384 | n = data.readInt32(); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 6385 | mForceFullDamage = n != 0; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 6386 | return NO_ERROR; |
| 6387 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 6388 | case 1018: { // Set the render deadline as a duration until VSYNC. |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6389 | n = data.readInt32(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 6390 | mScheduler->setDuration(scheduler::Cycle::Render, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6391 | return NO_ERROR; |
| 6392 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 6393 | 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] | 6394 | n = data.readInt32(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 6395 | mScheduler->setDuration(scheduler::Cycle::LastComposite, |
| 6396 | std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6397 | return NO_ERROR; |
| 6398 | } |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 6399 | case 1020: { // Unused |
| 6400 | return NAME_NOT_FOUND; |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 6401 | } |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 6402 | case 1021: { // Disable HWC virtual displays |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 6403 | const bool enable = data.readInt32() != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6404 | static_cast<void>( |
| 6405 | mScheduler->schedule([this, enable] { enableHalVirtualDisplays(enable); })); |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 6406 | return NO_ERROR; |
| 6407 | } |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6408 | case 1022: { // Set saturation boost |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6409 | Mutex::Autolock _l(mStateLock); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6410 | mGlobalSaturationFactor = std::max(0.0f, std::min(data.readFloat(), 2.0f)); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6411 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6412 | updateColorMatrixLocked(); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6413 | return NO_ERROR; |
| 6414 | } |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6415 | case 1023: { // Set color mode. |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6416 | mDisplayColorSetting = static_cast<DisplayColorSetting>(data.readInt32()); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6417 | |
| 6418 | if (int32_t colorMode; data.readInt32(&colorMode) == NO_ERROR) { |
| 6419 | mForceColorMode = static_cast<ui::ColorMode>(colorMode); |
Daniel Solomon | 7c7ede2 | 2019-07-11 16:35:40 -0700 | [diff] [blame] | 6420 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6421 | scheduleRepaint(); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 6422 | return NO_ERROR; |
| 6423 | } |
Peiyong Lin | 4bac91c | 2018-10-25 09:48:33 -0700 | [diff] [blame] | 6424 | // Deprecate, use 1030 to check whether the device is color managed. |
| 6425 | case 1024: { |
| 6426 | return NAME_NOT_FOUND; |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 6427 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 6428 | // Deprecated, use perfetto to start/stop the layer tracing |
| 6429 | case 1025: { |
| 6430 | return NAME_NOT_FOUND; |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 6431 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 6432 | // Deprecated, execute "adb shell perfetto --query" to see the ongoing tracing sessions |
| 6433 | case 1026: { |
| 6434 | return NAME_NOT_FOUND; |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 6435 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6436 | // Is a DisplayColorSetting supported? |
| 6437 | case 1027: { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6438 | const auto display = getDefaultDisplayDevice(); |
| 6439 | if (!display) { |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6440 | return NAME_NOT_FOUND; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6441 | } |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6442 | |
| 6443 | DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32()); |
| 6444 | switch (setting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6445 | case DisplayColorSetting::kManaged: |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6446 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6447 | reply->writeBool(true); |
| 6448 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6449 | case DisplayColorSetting::kEnhanced: |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6450 | reply->writeBool(display->hasRenderIntent(RenderIntent::ENHANCE)); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6451 | break; |
| 6452 | default: // vendor display color setting |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6453 | reply->writeBool( |
| 6454 | display->hasRenderIntent(static_cast<RenderIntent>(setting))); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6455 | break; |
| 6456 | } |
| 6457 | return NO_ERROR; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6458 | } |
Alec Mouri | 9c58bcd | 2020-09-09 18:57:07 -0700 | [diff] [blame] | 6459 | case 1028: { // Unused. |
| 6460 | return NAME_NOT_FOUND; |
Steven Thomas | 97f1f4c | 2018-06-01 12:04:16 -0700 | [diff] [blame] | 6461 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 6462 | // Deprecated, use perfetto to set the active layer tracing buffer size |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 6463 | case 1029: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 6464 | return NAME_NOT_FOUND; |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 6465 | } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 6466 | // Is device color managed? |
| 6467 | case 1030: { |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 6468 | // ColorDisplayManager stil calls this |
| 6469 | reply->writeBool(true); |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 6470 | return NO_ERROR; |
| 6471 | } |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 6472 | // Override default composition data space |
| 6473 | // adb shell service call SurfaceFlinger 1031 i32 1 DATASPACE_NUMBER DATASPACE_NUMBER \ |
| 6474 | // && adb shell stop zygote && adb shell start zygote |
| 6475 | // to restore: adb shell service call SurfaceFlinger 1031 i32 0 && \ |
| 6476 | // adb shell stop zygote && adb shell start zygote |
| 6477 | case 1031: { |
| 6478 | Mutex::Autolock _l(mStateLock); |
| 6479 | n = data.readInt32(); |
| 6480 | if (n) { |
| 6481 | n = data.readInt32(); |
| 6482 | if (n) { |
| 6483 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 6484 | if (!validateCompositionDataspace(dataspace)) { |
| 6485 | return BAD_VALUE; |
| 6486 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6487 | mDefaultCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 6488 | } |
| 6489 | n = data.readInt32(); |
| 6490 | if (n) { |
| 6491 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 6492 | if (!validateCompositionDataspace(dataspace)) { |
| 6493 | return BAD_VALUE; |
| 6494 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6495 | mWideColorGamutCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 6496 | } |
| 6497 | } else { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6498 | // restore composition data space. |
| 6499 | mDefaultCompositionDataspace = defaultCompositionDataspace; |
| 6500 | mWideColorGamutCompositionDataspace = wideColorGamutCompositionDataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 6501 | } |
| 6502 | return NO_ERROR; |
| 6503 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 6504 | // Deprecated, use perfetto to set layer trace flags |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 6505 | case 1033: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 6506 | return NAME_NOT_FOUND; |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 6507 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 6508 | case 1034: { |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6509 | n = data.readInt32(); |
| 6510 | if (n == 0 || n == 1) { |
| 6511 | sfdo_enableRefreshRateOverlay(static_cast<bool>(n)); |
| 6512 | } else { |
| 6513 | Mutex::Autolock lock(mStateLock); |
| 6514 | reply->writeBool(isRefreshRateOverlayEnabled()); |
| 6515 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 6516 | return NO_ERROR; |
| 6517 | } |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 6518 | case 1035: { |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 6519 | // Parameters: |
| 6520 | // - (required) i32 mode id. |
| 6521 | // - (optional) i64 display id. Using default display if not provided. |
| 6522 | // - (optional) f min render rate. Using mode's fps is not provided. |
| 6523 | // - (optional) f max render rate. Using mode's fps is not provided. |
| 6524 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 6525 | const int modeId = data.readInt32(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 6526 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6527 | const auto display = [&]() -> sp<IBinder> { |
| 6528 | uint64_t value; |
| 6529 | if (data.readUint64(&value) != NO_ERROR) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 6530 | return getDefaultDisplayDevice()->getDisplayToken().promote(); |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 6531 | } |
| 6532 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6533 | if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(value)) { |
| 6534 | return getPhysicalDisplayToken(*id); |
| 6535 | } |
| 6536 | |
| 6537 | ALOGE("Invalid physical display ID"); |
| 6538 | return nullptr; |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 6539 | }(); |
| 6540 | |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 6541 | const auto getFps = [&] { |
| 6542 | float value; |
| 6543 | if (data.readFloat(&value) == NO_ERROR) { |
| 6544 | return Fps::fromValue(value); |
| 6545 | } |
| 6546 | |
| 6547 | return Fps(); |
| 6548 | }; |
| 6549 | |
| 6550 | const auto minFps = getFps(); |
| 6551 | const auto maxFps = getFps(); |
| 6552 | |
Shiyong Li | 2bcece9 | 2021-08-30 20:38:50 +0000 | [diff] [blame] | 6553 | mDebugDisplayModeSetByBackdoor = false; |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 6554 | const status_t result = |
| 6555 | setActiveModeFromBackdoor(display, DisplayModeId{modeId}, minFps, maxFps); |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6556 | mDebugDisplayModeSetByBackdoor = result == NO_ERROR; |
| 6557 | return result; |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 6558 | } |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6559 | // Turn on/off frame rate flexibility mode. When turned on it overrides the display |
| 6560 | // manager frame rate policy a new policy which allows switching between all refresh |
| 6561 | // rates. |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6562 | case 1036: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6563 | if (data.readInt32() > 0) { // turn on |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6564 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6565 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6566 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6567 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6568 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6569 | // This is a little racy, but not in a way that hurts anything. As |
| 6570 | // we grab the defaultMode from the display manager policy, we could |
| 6571 | // be setting a new display manager policy, leaving us using a stale |
| 6572 | // defaultMode. The defaultMode doesn't matter for the override |
| 6573 | // policy though, since we set allowGroupSwitching to true, so it's |
| 6574 | // not a problem. |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6575 | scheduler::RefreshRateSelector::OverridePolicy overridePolicy; |
| 6576 | overridePolicy.defaultMode = display->refreshRateSelector() |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6577 | .getDisplayManagerPolicy() |
| 6578 | .defaultMode; |
| 6579 | overridePolicy.allowGroupSwitching = true; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6580 | return setDesiredDisplayModeSpecsInternal(display, overridePolicy); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6581 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6582 | .get(); |
| 6583 | } else { // turn off |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6584 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6585 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6586 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6587 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6588 | return setDesiredDisplayModeSpecsInternal( |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6589 | display, |
| 6590 | scheduler::RefreshRateSelector::NoOverridePolicy{}); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6591 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6592 | .get(); |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6593 | } |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6594 | } |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 6595 | // Inject a hotplug connected event for the primary display. This will deallocate and |
| 6596 | // reallocate the display state including framebuffers. |
| 6597 | case 1037: { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 6598 | const hal::HWDisplayId hwcId = |
| 6599 | (Mutex::Autolock(mStateLock), getHwComposer().getPrimaryHwcDisplayId()); |
| 6600 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 6601 | onComposerHalHotplugEvent(hwcId, DisplayHotplugEvent::CONNECTED); |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 6602 | return NO_ERROR; |
| 6603 | } |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 6604 | // Modify the max number of display frames stored within FrameTimeline |
| 6605 | case 1038: { |
| 6606 | n = data.readInt32(); |
| 6607 | if (n < 0 || n > MAX_ALLOWED_DISPLAY_FRAMES) { |
| 6608 | ALOGW("Invalid max size. Maximum allowed is %d", MAX_ALLOWED_DISPLAY_FRAMES); |
| 6609 | return BAD_VALUE; |
| 6610 | } |
| 6611 | if (n == 0) { |
| 6612 | // restore to default |
| 6613 | mFrameTimeline->reset(); |
| 6614 | return NO_ERROR; |
| 6615 | } |
| 6616 | mFrameTimeline->setMaxDisplayFrames(n); |
| 6617 | return NO_ERROR; |
| 6618 | } |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 6619 | case 1039: { |
Dominik Laskowski | 1d7be06 | 2024-07-24 13:59:07 -0400 | [diff] [blame] | 6620 | const auto uid = static_cast<uid_t>(data.readInt32()); |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 6621 | const auto refreshRate = data.readFloat(); |
Dominik Laskowski | 1d7be06 | 2024-07-24 13:59:07 -0400 | [diff] [blame] | 6622 | mScheduler->setPreferredRefreshRateForUid(FrameRateOverride{uid, refreshRate}); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 6623 | return NO_ERROR; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 6624 | } |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6625 | // Toggle caching feature |
| 6626 | // First argument is an int32 - nonzero enables caching and zero disables caching |
| 6627 | // Second argument is an optional uint64 - if present, then limits enabling/disabling |
| 6628 | // caching to a particular physical display |
| 6629 | case 1040: { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6630 | auto future = mScheduler->schedule([&] { |
| 6631 | n = data.readInt32(); |
| 6632 | std::optional<PhysicalDisplayId> inputId = std::nullopt; |
| 6633 | if (uint64_t inputDisplayId; data.readUint64(&inputDisplayId) == NO_ERROR) { |
| 6634 | inputId = DisplayId::fromValue<PhysicalDisplayId>(inputDisplayId); |
| 6635 | if (!inputId || getPhysicalDisplayToken(*inputId)) { |
| 6636 | ALOGE("No display with id: %" PRIu64, inputDisplayId); |
| 6637 | return NAME_NOT_FOUND; |
| 6638 | } |
| 6639 | } |
| 6640 | { |
| 6641 | Mutex::Autolock lock(mStateLock); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6642 | mLayerCachingEnabled = n != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6643 | for (const auto& [_, display] : mDisplays) { |
| 6644 | if (!inputId || *inputId == display->getPhysicalId()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6645 | display->enableLayerCaching(mLayerCachingEnabled); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6646 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6647 | } |
| 6648 | } |
| 6649 | return OK; |
| 6650 | }); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6651 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6652 | if (const status_t error = future.get(); error != OK) { |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6653 | return error; |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6654 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6655 | scheduleRepaint(); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6656 | return NO_ERROR; |
| 6657 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 6658 | case 1041: { // Transaction tracing |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6659 | if (mTransactionTracing) { |
Vishnu Nair | 640261c | 2023-09-21 21:22:51 -0700 | [diff] [blame] | 6660 | int arg = data.readInt32(); |
| 6661 | if (arg == -1) { |
Vishnu Nair | 50858e6 | 2023-10-13 23:28:24 +0000 | [diff] [blame] | 6662 | mScheduler->schedule([&]() { mTransactionTracing.reset(); }).get(); |
Vishnu Nair | 640261c | 2023-09-21 21:22:51 -0700 | [diff] [blame] | 6663 | } else if (arg > 0) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6664 | // Transaction tracing is always running but allow the user to temporarily |
| 6665 | // increase the buffer when actively debugging. |
| 6666 | mTransactionTracing->setBufferSize( |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 6667 | TransactionTracing::LEGACY_ACTIVE_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6668 | } else { |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 6669 | TransactionTraceWriter::getInstance().invoke("", /* overwrite= */ true); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6670 | mTransactionTracing->setBufferSize( |
| 6671 | TransactionTracing::CONTINUOUS_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6672 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 6673 | } |
| 6674 | reply->writeInt32(NO_ERROR); |
| 6675 | return NO_ERROR; |
| 6676 | } |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 6677 | case 1042: { // Write transaction trace to file |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 6678 | if (mTransactionTracing) { |
| 6679 | mTransactionTracing->writeToFile(); |
| 6680 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 6681 | reply->writeInt32(NO_ERROR); |
| 6682 | return NO_ERROR; |
| 6683 | } |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 6684 | // hdr sdr ratio overlay |
| 6685 | case 1043: { |
| 6686 | auto future = mScheduler->schedule( |
| 6687 | [&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 6688 | n = data.readInt32(); |
Sally Qi | 0cd9e86 | 2024-05-15 18:37:02 -0700 | [diff] [blame] | 6689 | if (n == 0 || n == 1) { |
| 6690 | mHdrSdrRatioOverlay = n != 0; |
| 6691 | enableHdrSdrRatioOverlay(mHdrSdrRatioOverlay); |
| 6692 | } else { |
| 6693 | reply->writeBool(isHdrSdrRatioOverlayEnabled()); |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 6694 | } |
| 6695 | }); |
| 6696 | future.wait(); |
| 6697 | return NO_ERROR; |
| 6698 | } |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 6699 | |
| 6700 | case 1044: { // Enable/Disable mirroring from one display to another |
| 6701 | /* |
| 6702 | * Mirror one display onto another. |
| 6703 | * Ensure the source and destination displays are on. |
| 6704 | * Commands: |
| 6705 | * 0: Mirror one display to another |
| 6706 | * 1: Disable mirroring to a previously mirrored display |
| 6707 | * 2: Disable mirroring on previously mirrored displays |
| 6708 | * |
| 6709 | * Ex: |
| 6710 | * Get the display ids: |
| 6711 | * adb shell dumpsys SurfaceFlinger --display-id |
| 6712 | * Mirror first display to the second: |
| 6713 | * adb shell service call SurfaceFlinger 1044 i64 0 i64 4619827677550801152 i64 |
| 6714 | * 4619827677550801153 |
| 6715 | * Stop mirroring: |
| 6716 | * adb shell service call SurfaceFlinger 1044 i64 1 |
| 6717 | */ |
| 6718 | |
| 6719 | int64_t arg0 = data.readInt64(); |
| 6720 | |
| 6721 | switch (arg0) { |
| 6722 | case 0: { |
| 6723 | // Mirror arg1 to arg2 |
| 6724 | int64_t arg1 = data.readInt64(); |
| 6725 | int64_t arg2 = data.readInt64(); |
| 6726 | // Enable mirroring for one display |
| 6727 | const auto display1id = DisplayId::fromValue(arg1); |
| 6728 | auto mirrorRoot = SurfaceComposerClient::getDefault()->mirrorDisplay( |
| 6729 | display1id.value()); |
| 6730 | auto id2 = DisplayId::fromValue<PhysicalDisplayId>(arg2); |
| 6731 | const auto token2 = getPhysicalDisplayToken(*id2); |
| 6732 | ui::LayerStack layerStack; |
| 6733 | { |
| 6734 | Mutex::Autolock lock(mStateLock); |
| 6735 | sp<DisplayDevice> display = getDisplayDeviceLocked(token2); |
| 6736 | layerStack = display->getLayerStack(); |
| 6737 | } |
| 6738 | SurfaceComposerClient::Transaction t; |
| 6739 | t.setDisplayLayerStack(token2, layerStack); |
| 6740 | t.setLayer(mirrorRoot, INT_MAX); // Top-most layer |
| 6741 | t.setLayerStack(mirrorRoot, layerStack); |
| 6742 | t.apply(); |
| 6743 | |
| 6744 | mMirrorMapForDebug.emplace_or_replace(arg2, mirrorRoot); |
| 6745 | break; |
| 6746 | } |
| 6747 | |
| 6748 | case 1: { |
| 6749 | // Disable mirroring for arg1 |
| 6750 | int64_t arg1 = data.readInt64(); |
| 6751 | mMirrorMapForDebug.erase(arg1); |
| 6752 | break; |
| 6753 | } |
| 6754 | |
| 6755 | case 2: { |
| 6756 | // Disable mirroring for all displays |
| 6757 | mMirrorMapForDebug.clear(); |
| 6758 | break; |
| 6759 | } |
| 6760 | |
| 6761 | default: |
| 6762 | return BAD_VALUE; |
| 6763 | } |
| 6764 | return NO_ERROR; |
| 6765 | } |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 6766 | // Inject jank |
| 6767 | // First argument is a float that describes the fraction of frame duration to jank by. |
| 6768 | // Second argument is a delay in ms for triggering the jank. This is useful for working |
| 6769 | // with tools that steal the adb connection. This argument is optional. |
| 6770 | case 1045: { |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 6771 | if (FlagManager::getInstance().vrr_config()) { |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 6772 | float jankAmount = data.readFloat(); |
| 6773 | int32_t jankDelayMs = 0; |
| 6774 | if (data.readInt32(&jankDelayMs) != NO_ERROR) { |
| 6775 | jankDelayMs = 0; |
| 6776 | } |
| 6777 | |
| 6778 | const auto jankDelayDuration = Duration(std::chrono::milliseconds(jankDelayMs)); |
| 6779 | |
| 6780 | const bool jankAmountValid = jankAmount > 0.0 && jankAmount < 100.0; |
| 6781 | |
| 6782 | if (!jankAmountValid) { |
| 6783 | ALOGD("Ignoring invalid jank amount: %f", jankAmount); |
| 6784 | reply->writeInt32(BAD_VALUE); |
| 6785 | return BAD_VALUE; |
| 6786 | } |
| 6787 | |
| 6788 | (void)mScheduler->scheduleDelayed( |
| 6789 | [&, jankAmount]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 6790 | mScheduler->injectPacesetterDelay(jankAmount); |
| 6791 | scheduleComposite(FrameHint::kActive); |
| 6792 | }, |
| 6793 | jankDelayDuration.ns()); |
| 6794 | reply->writeInt32(NO_ERROR); |
| 6795 | return NO_ERROR; |
| 6796 | } |
| 6797 | return err; |
| 6798 | } |
Ady Abraham | 708ebfb | 2024-11-14 14:42:49 -0800 | [diff] [blame^] | 6799 | // Introduce jank to HWC |
| 6800 | case 1046: { |
| 6801 | int32_t jankDelayMs = 0; |
| 6802 | if (data.readInt32(&jankDelayMs) != NO_ERROR) { |
| 6803 | return BAD_VALUE; |
| 6804 | } |
| 6805 | mScheduler->setDebugPresentDelay(TimePoint::fromNs(ms2ns(jankDelayMs))); |
| 6806 | return NO_ERROR; |
| 6807 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6808 | } |
| 6809 | } |
| 6810 | return err; |
| 6811 | } |
| 6812 | |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 6813 | void SurfaceFlinger::kernelTimerChanged(bool expired) { |
| 6814 | static bool updateOverlay = |
| 6815 | property_get_bool("debug.sf.kernel_idle_timer_update_overlay", true); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 6816 | if (!updateOverlay) return; |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 6817 | |
| 6818 | // Update the overlay on the main thread to avoid race conditions with |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 6819 | // RefreshRateSelector::getActiveMode |
Dominik Laskowski | 4383967 | 2024-08-04 02:01:48 -0400 | [diff] [blame] | 6820 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6821 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6822 | if (!display) { |
| 6823 | ALOGW("%s: default display is null", __func__); |
| 6824 | return; |
| 6825 | } |
Adrian Salido | a942af8 | 2022-02-17 19:22:31 -0800 | [diff] [blame] | 6826 | if (!display->isRefreshRateOverlayEnabled()) return; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 6827 | |
Dominik Laskowski | 4383967 | 2024-08-04 02:01:48 -0400 | [diff] [blame] | 6828 | const auto state = mDisplayModeController.getKernelIdleTimerState(display->getPhysicalId()); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 6829 | |
Dominik Laskowski | 4383967 | 2024-08-04 02:01:48 -0400 | [diff] [blame] | 6830 | if (display->onKernelTimerChanged(state.desiredModeIdOpt, state.isEnabled && expired)) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 6831 | mScheduler->scheduleFrame(); |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 6832 | } |
| 6833 | })); |
| 6834 | } |
| 6835 | |
Ady Abraham | eba039c | 2024-07-10 17:45:29 -0700 | [diff] [blame] | 6836 | void SurfaceFlinger::vrrDisplayIdle(bool idle) { |
| 6837 | // Update the overlay on the main thread to avoid race conditions with |
| 6838 | // RefreshRateSelector::getActiveMode |
| 6839 | static_cast<void>(mScheduler->schedule([=, this] { |
| 6840 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
| 6841 | if (!display) { |
| 6842 | ALOGW("%s: default display is null", __func__); |
| 6843 | return; |
| 6844 | } |
| 6845 | if (!display->isRefreshRateOverlayEnabled()) return; |
| 6846 | |
| 6847 | display->onVrrIdle(idle); |
| 6848 | mScheduler->scheduleFrame(); |
| 6849 | })); |
| 6850 | } |
| 6851 | |
Dominik Laskowski | 4383967 | 2024-08-04 02:01:48 -0400 | [diff] [blame] | 6852 | auto SurfaceFlinger::getKernelIdleTimerProperties(PhysicalDisplayId displayId) |
| 6853 | -> std::pair<std::optional<KernelIdleTimerController>, std::chrono::milliseconds> { |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6854 | const bool isKernelIdleTimerHwcSupported = getHwComposer().getComposer()->isSupported( |
| 6855 | android::Hwc2::Composer::OptionalFeature::KernelIdleTimer); |
| 6856 | const auto timeout = getIdleTimerTimeout(displayId); |
| 6857 | if (isKernelIdleTimerHwcSupported) { |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 6858 | if (getHwComposer().hasDisplayIdleTimerCapability(displayId)) { |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6859 | // In order to decide if we can use the HWC api for idle timer |
| 6860 | // we query DisplayCapability::DISPLAY_IDLE_TIMER directly on the composer |
| 6861 | // without relying on hasDisplayCapability. |
| 6862 | // hasDisplayCapability relies on DisplayCapabilities |
| 6863 | // which are updated after we set the PowerMode::ON. |
| 6864 | // DISPLAY_IDLE_TIMER is a display driver property |
| 6865 | // and is available before the PowerMode::ON |
| 6866 | return {KernelIdleTimerController::HwcApi, timeout}; |
| 6867 | } |
| 6868 | return {std::nullopt, timeout}; |
| 6869 | } |
| 6870 | if (getKernelIdleTimerSyspropConfig(displayId)) { |
| 6871 | return {KernelIdleTimerController::Sysprop, timeout}; |
| 6872 | } |
| 6873 | |
| 6874 | return {std::nullopt, timeout}; |
| 6875 | } |
| 6876 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 6877 | // A simple RAII class to disconnect from an ANativeWindow* when it goes out of scope |
| 6878 | class WindowDisconnector { |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 6879 | public: |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 6880 | WindowDisconnector(ANativeWindow* window, int api) : mWindow(window), mApi(api) {} |
| 6881 | ~WindowDisconnector() { |
| 6882 | native_window_api_disconnect(mWindow, mApi); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 6883 | } |
| 6884 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 6885 | private: |
| 6886 | ANativeWindow* mWindow; |
| 6887 | const int mApi; |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 6888 | }; |
| 6889 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 6890 | static bool hasCaptureBlackoutContentPermission() { |
| 6891 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6892 | const int pid = ipc->getCallingPid(); |
| 6893 | const int uid = ipc->getCallingUid(); |
| 6894 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 6895 | PermissionCache::checkPermission(sCaptureBlackoutContent, pid, uid); |
| 6896 | } |
| 6897 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6898 | static status_t validateScreenshotPermissions(const CaptureArgs& captureArgs) { |
| 6899 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6900 | const int pid = ipc->getCallingPid(); |
| 6901 | const int uid = ipc->getCallingUid(); |
Huihong Luo | fcadcff | 2024-08-26 17:22:57 +0000 | [diff] [blame] | 6902 | if (uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 6903 | PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6904 | return OK; |
| 6905 | } |
| 6906 | |
| 6907 | // If the caller doesn't have the correct permissions but is only attempting to screenshot |
| 6908 | // itself, we allow it to continue. |
| 6909 | if (captureArgs.uid == uid) { |
| 6910 | return OK; |
| 6911 | } |
| 6912 | |
| 6913 | ALOGE("Permission Denial: can't take screenshot pid=%d, uid=%d", pid, uid); |
| 6914 | return PERMISSION_DENIED; |
| 6915 | } |
| 6916 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6917 | status_t SurfaceFlinger::setSchedFifo(bool enabled) { |
| 6918 | static constexpr int kFifoPriority = 2; |
| 6919 | static constexpr int kOtherPriority = 0; |
| 6920 | |
| 6921 | struct sched_param param = {0}; |
| 6922 | int sched_policy; |
| 6923 | if (enabled) { |
| 6924 | sched_policy = SCHED_FIFO; |
| 6925 | param.sched_priority = kFifoPriority; |
| 6926 | } else { |
| 6927 | sched_policy = SCHED_OTHER; |
| 6928 | param.sched_priority = kOtherPriority; |
| 6929 | } |
| 6930 | |
| 6931 | if (sched_setscheduler(0, sched_policy, ¶m) != 0) { |
| 6932 | return -errno; |
| 6933 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 6934 | |
| 6935 | return NO_ERROR; |
| 6936 | } |
| 6937 | |
| 6938 | status_t SurfaceFlinger::setSchedAttr(bool enabled) { |
| 6939 | static const unsigned int kUclampMin = |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 6940 | base::GetUintProperty<unsigned int>("ro.surface_flinger.uclamp.min"s, 0U); |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 6941 | |
| 6942 | if (!kUclampMin) { |
| 6943 | // uclamp.min set to 0 (default), skip setting |
| 6944 | return NO_ERROR; |
| 6945 | } |
| 6946 | |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 6947 | sched_attr attr = {}; |
| 6948 | attr.size = sizeof(attr); |
| 6949 | |
| 6950 | attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP); |
| 6951 | attr.sched_util_min = enabled ? kUclampMin : 0; |
| 6952 | attr.sched_util_max = 1024; |
| 6953 | |
| 6954 | if (syscall(__NR_sched_setattr, 0, &attr, 0)) { |
| 6955 | return -errno; |
| 6956 | } |
| 6957 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6958 | return NO_ERROR; |
| 6959 | } |
| 6960 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 6961 | namespace { |
| 6962 | |
Melody Hsu | 683fe04 | 2024-06-04 17:22:04 +0000 | [diff] [blame] | 6963 | ui::Dataspace pickBestDataspace(ui::Dataspace requestedDataspace, |
| 6964 | const compositionengine::impl::OutputCompositionState& state, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 6965 | bool capturingHdrLayers, bool hintForSeamlessTransition) { |
Melody Hsu | 683fe04 | 2024-06-04 17:22:04 +0000 | [diff] [blame] | 6966 | if (requestedDataspace != ui::Dataspace::UNKNOWN) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 6967 | return requestedDataspace; |
| 6968 | } |
| 6969 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 6970 | const auto dataspaceForColorMode = ui::pickDataspaceFor(state.colorMode); |
| 6971 | |
Alec Mouri | 2964072 | 2023-05-16 23:22:41 +0000 | [diff] [blame] | 6972 | // TODO: Enable once HDR screenshots are ready. |
| 6973 | if constexpr (/* DISABLES CODE */ (false)) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 6974 | // For now since we only support 8-bit screenshots, just use HLG and |
| 6975 | // assume that 1.0 >= display max luminance. This isn't quite as future |
| 6976 | // proof as PQ is, but is good enough. |
| 6977 | // Consider using PQ once we support 16-bit screenshots and we're able |
| 6978 | // to consistently supply metadata to image encoders. |
| 6979 | return ui::Dataspace::BT2020_HLG; |
| 6980 | } |
| 6981 | |
| 6982 | return dataspaceForColorMode; |
| 6983 | } |
| 6984 | |
| 6985 | } // namespace |
| 6986 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 6987 | static void invokeScreenCaptureError(const status_t status, |
| 6988 | const sp<IScreenCaptureListener>& captureListener) { |
| 6989 | ScreenCaptureResults captureResults; |
| 6990 | captureResults.fenceResult = base::unexpected(status); |
| 6991 | captureListener->onScreenCaptureCompleted(captureResults); |
| 6992 | } |
| 6993 | |
| 6994 | void SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, |
| 6995 | const sp<IScreenCaptureListener>& captureListener) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 6996 | SFTRACE_CALL(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6997 | |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 6998 | const auto& captureArgs = args.captureArgs; |
| 6999 | status_t validate = validateScreenshotPermissions(captureArgs); |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7000 | if (validate != OK) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7001 | ALOGD("Permission denied to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7002 | invokeScreenCaptureError(validate, captureListener); |
| 7003 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7004 | } |
| 7005 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7006 | if (!args.displayToken) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7007 | ALOGD("Invalid display token to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7008 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7009 | return; |
| 7010 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7011 | |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7012 | if (captureArgs.captureSecureLayers && !hasCaptureBlackoutContentPermission()) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7013 | ALOGD("Attempting to capture secure layers without CAPTURE_BLACKOUT_CONTENT"); |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 7014 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 7015 | return; |
| 7016 | } |
| 7017 | |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7018 | wp<const DisplayDevice> displayWeak; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7019 | ui::LayerStack layerStack; |
| 7020 | ui::Size reqSize(args.width, args.height); |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7021 | std::unordered_set<uint32_t> excludeLayerIds; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7022 | { |
| 7023 | Mutex::Autolock lock(mStateLock); |
| 7024 | sp<DisplayDevice> display = getDisplayDeviceLocked(args.displayToken); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7025 | if (!display) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7026 | ALOGD("Unable to find display device for captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7027 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7028 | return; |
| 7029 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7030 | displayWeak = display; |
| 7031 | layerStack = display->getLayerStack(); |
| 7032 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7033 | // 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] | 7034 | if (args.width == 0 || args.height == 0) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7035 | reqSize = display->getLayerStackSpaceRect().getSize(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7036 | } |
| 7037 | |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7038 | for (const auto& handle : captureArgs.excludeHandles) { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7039 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7040 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7041 | excludeLayerIds.emplace(excludeLayer); |
| 7042 | } else { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7043 | ALOGD("Invalid layer handle passed as excludeLayer to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7044 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7045 | return; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7046 | } |
| 7047 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7048 | } |
| 7049 | |
Melody Hsu | eddfe93 | 2024-06-04 18:10:41 +0000 | [diff] [blame] | 7050 | GetLayerSnapshotsFunction getLayerSnapshotsFn = |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7051 | getLayerSnapshotsForScreenshots(layerStack, captureArgs.uid, |
| 7052 | std::move(excludeLayerIds)); |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 7053 | |
Vishnu Nair | 871886e | 2024-06-26 17:17:51 -0700 | [diff] [blame] | 7054 | ftl::Flags<RenderArea::Options> options; |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7055 | if (captureArgs.captureSecureLayers) options |= RenderArea::Options::CAPTURE_SECURE_LAYERS; |
| 7056 | if (captureArgs.hintForSeamlessTransition) |
Vishnu Nair | 871886e | 2024-06-26 17:17:51 -0700 | [diff] [blame] | 7057 | options |= RenderArea::Options::HINT_FOR_SEAMLESS_TRANSITION; |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 7058 | captureScreenCommon(RenderAreaBuilderVariant(std::in_place_type<DisplayRenderAreaBuilder>, |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7059 | gui::aidl_utils::fromARect(captureArgs.sourceCrop), |
| 7060 | reqSize, |
| 7061 | static_cast<ui::Dataspace>(captureArgs.dataspace), |
Vishnu Nair | 871886e | 2024-06-26 17:17:51 -0700 | [diff] [blame] | 7062 | displayWeak, options), |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7063 | getLayerSnapshotsFn, reqSize, |
| 7064 | static_cast<ui::PixelFormat>(captureArgs.pixelFormat), |
Alec Mouri | 1b1853f | 2024-07-15 22:46:58 +0000 | [diff] [blame] | 7065 | captureArgs.allowProtected, captureArgs.grayscale, |
| 7066 | captureArgs.attachGainmap, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7067 | } |
| 7068 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7069 | void SurfaceFlinger::captureDisplay(DisplayId displayId, const CaptureArgs& args, |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7070 | const sp<IScreenCaptureListener>& captureListener) { |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7071 | ui::LayerStack layerStack; |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7072 | wp<const DisplayDevice> displayWeak; |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7073 | ui::Size size; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7074 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7075 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7076 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7077 | const auto display = getDisplayDeviceLocked(displayId); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7078 | if (!display) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7079 | ALOGD("Unable to find display device for captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7080 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7081 | return; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7082 | } |
| 7083 | |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7084 | displayWeak = display; |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7085 | layerStack = display->getLayerStack(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7086 | size = display->getLayerStackSpaceRect().getSize(); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7087 | } |
| 7088 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7089 | size.width *= args.frameScaleX; |
| 7090 | size.height *= args.frameScaleY; |
| 7091 | |
| 7092 | // We could query a real value for this but it'll be a long, long time until we support |
| 7093 | // displays that need upwards of 1GB per buffer so... |
| 7094 | constexpr auto kMaxTextureSize = 16384; |
| 7095 | if (size.width <= 0 || size.height <= 0 || size.width >= kMaxTextureSize || |
| 7096 | size.height >= kMaxTextureSize) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7097 | 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] | 7098 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7099 | return; |
| 7100 | } |
| 7101 | |
Melody Hsu | eddfe93 | 2024-06-04 18:10:41 +0000 | [diff] [blame] | 7102 | GetLayerSnapshotsFunction getLayerSnapshotsFn = |
| 7103 | getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID, |
| 7104 | /*snapshotFilterFn=*/nullptr); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7105 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7106 | if (captureListener == nullptr) { |
| 7107 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7108 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7109 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7110 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7111 | |
| 7112 | constexpr bool kAllowProtected = false; |
| 7113 | constexpr bool kGrayscale = false; |
| 7114 | |
Vishnu Nair | 871886e | 2024-06-26 17:17:51 -0700 | [diff] [blame] | 7115 | ftl::Flags<RenderArea::Options> options; |
| 7116 | if (args.hintForSeamlessTransition) |
| 7117 | options |= RenderArea::Options::HINT_FOR_SEAMLESS_TRANSITION; |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 7118 | captureScreenCommon(RenderAreaBuilderVariant(std::in_place_type<DisplayRenderAreaBuilder>, |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7119 | Rect(), size, |
| 7120 | static_cast<ui::Dataspace>(args.dataspace), |
| 7121 | displayWeak, options), |
| 7122 | getLayerSnapshotsFn, size, static_cast<ui::PixelFormat>(args.pixelFormat), |
Alec Mouri | 1b1853f | 2024-07-15 22:46:58 +0000 | [diff] [blame] | 7123 | kAllowProtected, kGrayscale, args.attachGainmap, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7124 | } |
| 7125 | |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 7126 | ScreenCaptureResults SurfaceFlinger::captureLayersSync(const LayerCaptureArgs& args) { |
| 7127 | sp<SyncScreenCaptureListener> captureListener = sp<SyncScreenCaptureListener>::make(); |
| 7128 | captureLayers(args, captureListener); |
| 7129 | return captureListener->waitForResults(); |
| 7130 | } |
| 7131 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7132 | void SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, |
| 7133 | const sp<IScreenCaptureListener>& captureListener) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 7134 | SFTRACE_CALL(); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7135 | |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7136 | const auto& captureArgs = args.captureArgs; |
| 7137 | |
| 7138 | status_t validate = validateScreenshotPermissions(captureArgs); |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7139 | if (validate != OK) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7140 | ALOGD("Permission denied to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7141 | invokeScreenCaptureError(validate, captureListener); |
| 7142 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7143 | } |
| 7144 | |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7145 | auto crop = gui::aidl_utils::fromARect(captureArgs.sourceCrop); |
| 7146 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7147 | ui::Size reqSize; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7148 | sp<Layer> parent; |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7149 | std::unordered_set<uint32_t> excludeLayerIds; |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7150 | ui::Dataspace dataspace = static_cast<ui::Dataspace>(captureArgs.dataspace); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7151 | |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7152 | if (captureArgs.captureSecureLayers && !hasCaptureBlackoutContentPermission()) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7153 | ALOGD("Attempting to capture secure layers without CAPTURE_BLACKOUT_CONTENT"); |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 7154 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 7155 | return; |
| 7156 | } |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7157 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7158 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7159 | Mutex::Autolock lock(mStateLock); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7160 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 7161 | parent = LayerHandle::getLayer(args.layerHandle); |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7162 | if (parent == nullptr) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7163 | ALOGD("captureLayers called with an invalid or removed parent"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7164 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7165 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7166 | } |
| 7167 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 7168 | Rect parentSourceBounds = parent->getCroppedBufferSize(parent->getDrawingState()); |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7169 | if (crop.width() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7170 | crop.left = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7171 | crop.right = parentSourceBounds.getWidth(); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7172 | } |
| 7173 | |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7174 | if (crop.height() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7175 | crop.top = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7176 | crop.bottom = parentSourceBounds.getHeight(); |
| 7177 | } |
| 7178 | |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7179 | if (crop.isEmpty() || captureArgs.frameScaleX <= 0.0f || captureArgs.frameScaleY <= 0.0f) { |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7180 | // Error out if the layer has no source bounds (i.e. they are boundless) and a source |
| 7181 | // crop was not specified, or an invalid frame scale was provided. |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7182 | ALOGD("Boundless layer, unspecified crop, or invalid frame scale to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7183 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7184 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7185 | } |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7186 | reqSize = ui::Size(crop.width() * captureArgs.frameScaleX, |
| 7187 | crop.height() * captureArgs.frameScaleY); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7188 | |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7189 | for (const auto& handle : captureArgs.excludeHandles) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7190 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7191 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7192 | excludeLayerIds.emplace(excludeLayer); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7193 | } else { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7194 | ALOGD("Invalid layer handle passed as excludeLayer to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7195 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7196 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7197 | } |
| 7198 | } |
| 7199 | } // mStateLock |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7200 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7201 | // really small crop or frameScale |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7202 | if (reqSize.width <= 0 || reqSize.height <= 0) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7203 | ALOGD("Failed to captureLayers: crop or scale too small"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7204 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7205 | return; |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7206 | } |
| 7207 | |
Melody Hsu | eddfe93 | 2024-06-04 18:10:41 +0000 | [diff] [blame] | 7208 | std::optional<FloatRect> parentCrop = std::nullopt; |
| 7209 | if (args.childrenOnly) { |
| 7210 | parentCrop = crop.isEmpty() ? FloatRect(0, 0, reqSize.width, reqSize.height) |
| 7211 | : crop.toFloatRect(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7212 | } |
Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 7213 | |
Melody Hsu | eddfe93 | 2024-06-04 18:10:41 +0000 | [diff] [blame] | 7214 | GetLayerSnapshotsFunction getLayerSnapshotsFn = |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7215 | getLayerSnapshotsForScreenshots(parent->sequence, captureArgs.uid, |
| 7216 | std::move(excludeLayerIds), args.childrenOnly, |
| 7217 | parentCrop); |
Melody Hsu | eddfe93 | 2024-06-04 18:10:41 +0000 | [diff] [blame] | 7218 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7219 | if (captureListener == nullptr) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7220 | ALOGD("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7221 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7222 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7223 | } |
| 7224 | |
Vishnu Nair | 871886e | 2024-06-26 17:17:51 -0700 | [diff] [blame] | 7225 | ftl::Flags<RenderArea::Options> options; |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7226 | if (captureArgs.captureSecureLayers) options |= RenderArea::Options::CAPTURE_SECURE_LAYERS; |
| 7227 | if (captureArgs.hintForSeamlessTransition) |
Vishnu Nair | 871886e | 2024-06-26 17:17:51 -0700 | [diff] [blame] | 7228 | options |= RenderArea::Options::HINT_FOR_SEAMLESS_TRANSITION; |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 7229 | captureScreenCommon(RenderAreaBuilderVariant(std::in_place_type<LayerRenderAreaBuilder>, crop, |
Vishnu Nair | 871886e | 2024-06-26 17:17:51 -0700 | [diff] [blame] | 7230 | reqSize, dataspace, parent, args.childrenOnly, |
| 7231 | options), |
Alec Mouri | bae6786 | 2024-08-06 14:53:46 +0000 | [diff] [blame] | 7232 | getLayerSnapshotsFn, reqSize, |
| 7233 | static_cast<ui::PixelFormat>(captureArgs.pixelFormat), |
Alec Mouri | 1b1853f | 2024-07-15 22:46:58 +0000 | [diff] [blame] | 7234 | captureArgs.allowProtected, captureArgs.grayscale, |
| 7235 | captureArgs.attachGainmap, captureListener); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7236 | } |
| 7237 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 7238 | // Creates a Future release fence for a layer and keeps track of it in a list to |
| 7239 | // release the buffer when the Future is complete. Calls from composittion |
| 7240 | // involve needing to refresh the composition start time for stats. |
| 7241 | void SurfaceFlinger::attachReleaseFenceFutureToLayer(Layer* layer, LayerFE* layerFE, |
| 7242 | ui::LayerStack layerStack) { |
| 7243 | ftl::Future<FenceResult> futureFence = layerFE->createReleaseFenceFuture(); |
Vishnu Nair | 620fefd | 2024-08-15 12:28:18 +0000 | [diff] [blame] | 7244 | layer->prepareReleaseCallbacks(std::move(futureFence), layerStack); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 7245 | } |
| 7246 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7247 | // Loop over all visible layers to see whether there's any protected layer. A protected layer is |
| 7248 | // typically a layer with DRM contents, or have the GRALLOC_USAGE_PROTECTED set on the buffer. |
| 7249 | // A protected layer has no implication on whether it's secure, which is explicitly set by |
| 7250 | // application to avoid being screenshot or drawn via unsecure display. |
Melody Hsu | 0b80c74 | 2024-10-29 07:24:29 +0000 | [diff] [blame] | 7251 | bool SurfaceFlinger::layersHasProtectedLayer( |
| 7252 | const std::vector<std::pair<Layer*, sp<LayerFE>>>& layers) const { |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 7253 | bool protectedLayerFound = false; |
Melody Hsu | 0b80c74 | 2024-10-29 07:24:29 +0000 | [diff] [blame] | 7254 | for (auto& [_, layerFE] : layers) { |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 7255 | protectedLayerFound |= |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7256 | (layerFE->mSnapshot->isVisible && layerFE->mSnapshot->hasProtectedContent); |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 7257 | if (protectedLayerFound) { |
| 7258 | break; |
| 7259 | } |
| 7260 | } |
| 7261 | return protectedLayerFound; |
| 7262 | } |
| 7263 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7264 | // Getting layer snapshots and display should take place on main thread. |
| 7265 | // Accessing display requires mStateLock, and contention for this lock |
| 7266 | // is reduced when grabbed from the main thread, thus also reducing |
| 7267 | // risk of deadlocks. |
Vishnu Nair | 5a93ccb | 2024-06-26 00:38:32 +0000 | [diff] [blame] | 7268 | std::optional<SurfaceFlinger::OutputCompositionState> SurfaceFlinger::getSnapshotsFromMainThread( |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7269 | RenderAreaBuilderVariant& renderAreaBuilder, GetLayerSnapshotsFunction getLayerSnapshotsFn, |
Melody Hsu | 0b80c74 | 2024-10-29 07:24:29 +0000 | [diff] [blame] | 7270 | std::vector<std::pair<Layer*, sp<LayerFE>>>& layers) { |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7271 | return mScheduler |
Melody Hsu | 0b80c74 | 2024-10-29 07:24:29 +0000 | [diff] [blame] | 7272 | ->schedule([=, this, &renderAreaBuilder, &layers]() REQUIRES(kMainThreadContext) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 7273 | SFTRACE_NAME("getSnapshotsFromMainThread"); |
Melody Hsu | 0b80c74 | 2024-10-29 07:24:29 +0000 | [diff] [blame] | 7274 | layers = getLayerSnapshotsFn(); |
| 7275 | // Non-threaded RenderEngine eventually returns to the main thread a 2nd time |
| 7276 | // to complete the screenshot. Release fences should only be added during the 2nd |
| 7277 | // hop to main thread in order to avoid potential deadlocks from waiting for the |
| 7278 | // the future fence to fire. |
| 7279 | if (mRenderEngine->isThreaded()) { |
| 7280 | for (auto& [layer, layerFE] : layers) { |
| 7281 | attachReleaseFenceFutureToLayer(layer, layerFE.get(), |
| 7282 | ui::INVALID_LAYER_STACK); |
| 7283 | } |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7284 | } |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7285 | return getDisplayStateFromRenderAreaBuilder(renderAreaBuilder); |
| 7286 | }) |
| 7287 | .get(); |
| 7288 | } |
| 7289 | |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 7290 | void SurfaceFlinger::captureScreenCommon(RenderAreaBuilderVariant renderAreaBuilder, |
Melody Hsu | eddfe93 | 2024-06-04 18:10:41 +0000 | [diff] [blame] | 7291 | GetLayerSnapshotsFunction getLayerSnapshotsFn, |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7292 | ui::Size bufferSize, ui::PixelFormat reqPixelFormat, |
Alec Mouri | 1b1853f | 2024-07-15 22:46:58 +0000 | [diff] [blame] | 7293 | bool allowProtected, bool grayscale, bool attachGainmap, |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7294 | const sp<IScreenCaptureListener>& captureListener) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 7295 | SFTRACE_CALL(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 7296 | |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 7297 | if (exceedsMaxRenderTargetSize(bufferSize.getWidth(), bufferSize.getHeight())) { |
| 7298 | ALOGE("Attempted to capture screen with size (%" PRId32 ", %" PRId32 |
| 7299 | ") that exceeds render target size limit.", |
| 7300 | bufferSize.getWidth(), bufferSize.getHeight()); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7301 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7302 | return; |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 7303 | } |
| 7304 | |
Melody Hsu | 16c4c32 | 2024-10-29 07:50:14 +0000 | [diff] [blame] | 7305 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers; |
| 7306 | auto displayState = getSnapshotsFromMainThread(renderAreaBuilder, getLayerSnapshotsFn, layers); |
Alec Mouri | 7013b6f | 2021-02-12 11:16:54 -0800 | [diff] [blame] | 7307 | |
Melody Hsu | 16c4c32 | 2024-10-29 07:50:14 +0000 | [diff] [blame] | 7308 | const bool supportsProtected = getRenderEngine().supportsProtectedContent(); |
| 7309 | bool hasProtectedLayer = false; |
| 7310 | if (allowProtected && supportsProtected) { |
| 7311 | hasProtectedLayer = layersHasProtectedLayer(layers); |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 7312 | } |
Melody Hsu | 16c4c32 | 2024-10-29 07:50:14 +0000 | [diff] [blame] | 7313 | const bool isProtected = hasProtectedLayer && allowProtected && supportsProtected; |
| 7314 | const uint32_t usage = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER | |
| 7315 | GRALLOC_USAGE_HW_TEXTURE | |
| 7316 | (isProtected ? GRALLOC_USAGE_PROTECTED |
| 7317 | : GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
| 7318 | sp<GraphicBuffer> buffer = |
| 7319 | getFactory().createGraphicBuffer(bufferSize.getWidth(), bufferSize.getHeight(), |
| 7320 | static_cast<android_pixel_format>(reqPixelFormat), |
| 7321 | 1 /* layerCount */, usage, "screenshot"); |
| 7322 | |
| 7323 | const status_t bufferStatus = buffer->initCheck(); |
| 7324 | if (bufferStatus != OK) { |
| 7325 | // Animations may end up being really janky, but don't crash here. |
| 7326 | // Otherwise an irreponsible process may cause an SF crash by allocating |
| 7327 | // too much. |
| 7328 | ALOGE("%s: Buffer failed to allocate: %d", __func__, bufferStatus); |
| 7329 | invokeScreenCaptureError(bufferStatus, captureListener); |
| 7330 | return; |
| 7331 | } |
| 7332 | const std::shared_ptr<renderengine::ExternalTexture> texture = std::make_shared< |
| 7333 | renderengine::impl::ExternalTexture>(buffer, getRenderEngine(), |
| 7334 | renderengine::impl::ExternalTexture::Usage:: |
| 7335 | WRITEABLE); |
| 7336 | auto futureFence = |
| 7337 | captureScreenshot(renderAreaBuilder, texture, false /* regionSampling */, grayscale, |
| 7338 | isProtected, attachGainmap, captureListener, displayState, layers); |
| 7339 | futureFence.get(); |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 7340 | } |
| 7341 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7342 | std::optional<SurfaceFlinger::OutputCompositionState> |
| 7343 | SurfaceFlinger::getDisplayStateFromRenderAreaBuilder(RenderAreaBuilderVariant& renderAreaBuilder) { |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 7344 | sp<const DisplayDevice> display = nullptr; |
| 7345 | { |
| 7346 | Mutex::Autolock lock(mStateLock); |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 7347 | if (auto* layerRenderAreaBuilder = |
| 7348 | std::get_if<LayerRenderAreaBuilder>(&renderAreaBuilder)) { |
| 7349 | // LayerSnapshotBuilder should only be accessed from the main thread. |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 7350 | const frontend::LayerSnapshot* snapshot = |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 7351 | mLayerSnapshotBuilder.getSnapshot(layerRenderAreaBuilder->layer->getSequence()); |
| 7352 | if (!snapshot) { |
| 7353 | ALOGW("Couldn't find layer snapshot for %d", |
| 7354 | layerRenderAreaBuilder->layer->getSequence()); |
| 7355 | } else { |
Melody Hsu | 50c151a | 2024-05-14 06:11:12 +0000 | [diff] [blame] | 7356 | layerRenderAreaBuilder->setLayerSnapshot(*snapshot); |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 7357 | display = findDisplay( |
| 7358 | [layerStack = snapshot->outputFilter.layerStack](const auto& display) { |
| 7359 | return display.getLayerStack() == layerStack; |
| 7360 | }); |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 7361 | } |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 7362 | } else if (auto* displayRenderAreaBuilder = |
| 7363 | std::get_if<DisplayRenderAreaBuilder>(&renderAreaBuilder)) { |
| 7364 | display = displayRenderAreaBuilder->displayWeak.promote(); |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 7365 | } |
| 7366 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 7367 | if (display == nullptr) { |
| 7368 | display = getDefaultDisplayDeviceLocked(); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 7369 | } |
| 7370 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 7371 | if (display != nullptr) { |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7372 | return std::optional{display->getCompositionDisplay()->getState()}; |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 7373 | } |
| 7374 | } |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7375 | return std::nullopt; |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 7376 | } |
| 7377 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 7378 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenshot( |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7379 | const RenderAreaBuilderVariant& renderAreaBuilder, |
| 7380 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
Alec Mouri | 1b1853f | 2024-07-15 22:46:58 +0000 | [diff] [blame] | 7381 | bool grayscale, bool isProtected, bool attachGainmap, |
| 7382 | const sp<IScreenCaptureListener>& captureListener, |
Melody Hsu | 0b80c74 | 2024-10-29 07:24:29 +0000 | [diff] [blame] | 7383 | std::optional<OutputCompositionState>& displayState, |
| 7384 | std::vector<std::pair<Layer*, sp<LayerFE>>>& layers) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 7385 | SFTRACE_CALL(); |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7386 | |
| 7387 | ScreenCaptureResults captureResults; |
| 7388 | std::unique_ptr<const RenderArea> renderArea = |
| 7389 | std::visit([](auto&& arg) -> std::unique_ptr<RenderArea> { return arg.build(); }, |
| 7390 | renderAreaBuilder); |
| 7391 | |
| 7392 | if (!renderArea) { |
| 7393 | ALOGW("Skipping screen capture because of invalid render area."); |
| 7394 | if (captureListener) { |
| 7395 | captureResults.fenceResult = base::unexpected(NO_MEMORY); |
| 7396 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7397 | } |
| 7398 | return ftl::yield<FenceResult>(base::unexpected(NO_ERROR)).share(); |
| 7399 | } |
Alec Mouri | 1b1853f | 2024-07-15 22:46:58 +0000 | [diff] [blame] | 7400 | float displayBrightnessNits = displayState.value().displayBrightnessNits; |
| 7401 | float sdrWhitePointNits = displayState.value().sdrWhitePointNits; |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7402 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7403 | ftl::SharedFuture<FenceResult> renderFuture = |
Alec Mouri | 1b1853f | 2024-07-15 22:46:58 +0000 | [diff] [blame] | 7404 | renderScreenImpl(renderArea.get(), buffer, regionSampling, grayscale, isProtected, |
Melody Hsu | 16c4c32 | 2024-10-29 07:50:14 +0000 | [diff] [blame] | 7405 | captureResults, displayState, layers); |
Alec Mouri | 1b1853f | 2024-07-15 22:46:58 +0000 | [diff] [blame] | 7406 | |
| 7407 | if (captureResults.capturedHdrLayers && attachGainmap && |
| 7408 | FlagManager::getInstance().true_hdr_screenshots()) { |
| 7409 | sp<GraphicBuffer> hdrBuffer = |
| 7410 | getFactory().createGraphicBuffer(buffer->getWidth(), buffer->getHeight(), |
| 7411 | HAL_PIXEL_FORMAT_RGBA_FP16, 1 /* layerCount */, |
| 7412 | buffer->getUsage(), "screenshot-hdr"); |
| 7413 | sp<GraphicBuffer> gainmapBuffer = |
| 7414 | getFactory().createGraphicBuffer(buffer->getWidth(), buffer->getHeight(), |
| 7415 | buffer->getPixelFormat(), 1 /* layerCount */, |
| 7416 | buffer->getUsage(), "screenshot-gainmap"); |
| 7417 | |
| 7418 | const status_t bufferStatus = hdrBuffer->initCheck(); |
| 7419 | const status_t gainmapBufferStatus = gainmapBuffer->initCheck(); |
| 7420 | |
| 7421 | if (bufferStatus != OK) { |
| 7422 | ALOGW("%s: Buffer failed to allocate for hdr: %d. Screenshoting SDR instead.", __func__, |
| 7423 | bufferStatus); |
| 7424 | } else if (gainmapBufferStatus != OK) { |
| 7425 | ALOGW("%s: Buffer failed to allocate for gainmap: %d. Screenshoting SDR instead.", |
| 7426 | __func__, gainmapBufferStatus); |
| 7427 | } else { |
| 7428 | captureResults.optionalGainMap = gainmapBuffer; |
| 7429 | const auto hdrTexture = std::make_shared< |
| 7430 | renderengine::impl::ExternalTexture>(hdrBuffer, getRenderEngine(), |
| 7431 | renderengine::impl::ExternalTexture:: |
| 7432 | Usage::WRITEABLE); |
| 7433 | const auto gainmapTexture = std::make_shared< |
| 7434 | renderengine::impl::ExternalTexture>(gainmapBuffer, getRenderEngine(), |
| 7435 | renderengine::impl::ExternalTexture:: |
| 7436 | Usage::WRITEABLE); |
| 7437 | ScreenCaptureResults unusedResults; |
| 7438 | ftl::SharedFuture<FenceResult> hdrRenderFuture = |
| 7439 | renderScreenImpl(renderArea.get(), hdrTexture, regionSampling, grayscale, |
Melody Hsu | 16c4c32 | 2024-10-29 07:50:14 +0000 | [diff] [blame] | 7440 | isProtected, unusedResults, displayState, layers); |
Alec Mouri | 1b1853f | 2024-07-15 22:46:58 +0000 | [diff] [blame] | 7441 | |
| 7442 | renderFuture = |
| 7443 | ftl::Future(std::move(renderFuture)) |
| 7444 | .then([&, hdrRenderFuture = std::move(hdrRenderFuture), |
| 7445 | displayBrightnessNits, sdrWhitePointNits, |
| 7446 | dataspace = captureResults.capturedDataspace, buffer, hdrTexture, |
| 7447 | gainmapTexture](FenceResult fenceResult) -> FenceResult { |
| 7448 | if (!fenceResult.ok()) { |
| 7449 | return fenceResult; |
| 7450 | } |
| 7451 | |
| 7452 | auto hdrFenceResult = hdrRenderFuture.get(); |
| 7453 | |
| 7454 | if (!hdrFenceResult.ok()) { |
| 7455 | return hdrFenceResult; |
| 7456 | } |
| 7457 | |
| 7458 | return getRenderEngine() |
| 7459 | .drawGainmap(buffer, fenceResult.value()->get(), hdrTexture, |
| 7460 | hdrFenceResult.value()->get(), |
| 7461 | displayBrightnessNits / sdrWhitePointNits, |
| 7462 | static_cast<ui::Dataspace>(dataspace), |
| 7463 | gainmapTexture) |
| 7464 | .get(); |
| 7465 | }) |
| 7466 | .share(); |
| 7467 | }; |
| 7468 | } |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7469 | |
| 7470 | if (captureListener) { |
| 7471 | // Defer blocking on renderFuture back to the Binder thread. |
| 7472 | return ftl::Future(std::move(renderFuture)) |
Alec Mouri | 1b1853f | 2024-07-15 22:46:58 +0000 | [diff] [blame] | 7473 | .then([captureListener, captureResults = std::move(captureResults), |
| 7474 | displayBrightnessNits, |
| 7475 | sdrWhitePointNits](FenceResult fenceResult) mutable -> FenceResult { |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7476 | captureResults.fenceResult = std::move(fenceResult); |
Alec Mouri | 1b1853f | 2024-07-15 22:46:58 +0000 | [diff] [blame] | 7477 | captureResults.hdrSdrRatio = displayBrightnessNits / sdrWhitePointNits; |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7478 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7479 | return base::unexpected(NO_ERROR); |
| 7480 | }) |
| 7481 | .share(); |
| 7482 | } |
| 7483 | return renderFuture; |
| 7484 | } |
| 7485 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7486 | ftl::SharedFuture<FenceResult> SurfaceFlinger::renderScreenImpl( |
Alec Mouri | 1b1853f | 2024-07-15 22:46:58 +0000 | [diff] [blame] | 7487 | const RenderArea* renderArea, const std::shared_ptr<renderengine::ExternalTexture>& buffer, |
Melody Hsu | 16c4c32 | 2024-10-29 07:50:14 +0000 | [diff] [blame] | 7488 | bool regionSampling, bool grayscale, bool isProtected, ScreenCaptureResults& captureResults, |
| 7489 | std::optional<OutputCompositionState>& displayState, |
Melody Hsu | 0b80c74 | 2024-10-29 07:24:29 +0000 | [diff] [blame] | 7490 | std::vector<std::pair<Layer*, sp<LayerFE>>>& layers) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 7491 | SFTRACE_CALL(); |
Alec Mouri | b4814de | 2023-09-11 22:09:03 +0000 | [diff] [blame] | 7492 | |
Melody Hsu | 0b80c74 | 2024-10-29 07:24:29 +0000 | [diff] [blame] | 7493 | for (auto& [_, layerFE] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7494 | frontend::LayerSnapshot* snapshot = layerFE->mSnapshot.get(); |
| 7495 | captureResults.capturedSecureLayers |= (snapshot->isVisible && snapshot->isSecure); |
| 7496 | captureResults.capturedHdrLayers |= isHdrLayer(*snapshot); |
| 7497 | layerFE->mSnapshot->geomLayerTransform = |
| 7498 | renderArea->getTransform() * layerFE->mSnapshot->geomLayerTransform; |
Patrick Williams | c6e0cce | 2023-02-28 23:04:45 -0600 | [diff] [blame] | 7499 | layerFE->mSnapshot->geomInverseLayerTransform = |
| 7500 | layerFE->mSnapshot->geomLayerTransform.inverse(); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7501 | } |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7502 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7503 | auto capturedBuffer = buffer; |
| 7504 | |
| 7505 | auto requestedDataspace = renderArea->getReqDataSpace(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7506 | auto parent = renderArea->getParentLayer(); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 7507 | auto renderIntent = RenderIntent::TONE_MAP_COLORIMETRIC; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 7508 | auto sdrWhitePointNits = DisplayDevice::sDefaultMaxLumiance; |
| 7509 | auto displayBrightnessNits = DisplayDevice::sDefaultMaxLumiance; |
| 7510 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7511 | captureResults.capturedDataspace = requestedDataspace; |
| 7512 | |
Alec Mouri | a7e752e | 2024-05-24 18:21:21 +0000 | [diff] [blame] | 7513 | const bool enableLocalTonemapping = FlagManager::getInstance().local_tonemap_screenshots() && |
| 7514 | !renderArea->getHintForSeamlessTransition(); |
| 7515 | |
Melody Hsu | 8c42cf1 | 2024-06-05 00:07:03 +0000 | [diff] [blame] | 7516 | if (displayState) { |
| 7517 | const auto& state = displayState.value(); |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 7518 | captureResults.capturedDataspace = |
Melody Hsu | 683fe04 | 2024-06-04 17:22:04 +0000 | [diff] [blame] | 7519 | pickBestDataspace(requestedDataspace, state, captureResults.capturedHdrLayers, |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 7520 | renderArea->getHintForSeamlessTransition()); |
| 7521 | sdrWhitePointNits = state.sdrWhitePointNits; |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 7522 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 7523 | if (!captureResults.capturedHdrLayers) { |
| 7524 | displayBrightnessNits = sdrWhitePointNits; |
| 7525 | } else { |
| 7526 | displayBrightnessNits = state.displayBrightnessNits; |
| 7527 | if (!enableLocalTonemapping) { |
| 7528 | // Only clamp the display brightness if this is not a seamless transition. |
| 7529 | // Otherwise for seamless transitions it's important to match the current |
| 7530 | // display state as the buffer will be shown under these same conditions, and we |
| 7531 | // want to avoid any flickers |
| 7532 | if (sdrWhitePointNits > 1.0f && !renderArea->getHintForSeamlessTransition()) { |
| 7533 | // Restrict the amount of HDR "headroom" in the screenshot to avoid |
| 7534 | // over-dimming the SDR portion. 2.0 chosen by experimentation |
| 7535 | constexpr float kMaxScreenshotHeadroom = 2.0f; |
| 7536 | displayBrightnessNits = std::min(sdrWhitePointNits * kMaxScreenshotHeadroom, |
| 7537 | displayBrightnessNits); |
Alec Mouri | b4814de | 2023-09-11 22:09:03 +0000 | [diff] [blame] | 7538 | } |
Alec Mouri | 5e488f8 | 2023-09-15 01:27:49 +0000 | [diff] [blame] | 7539 | } |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 7540 | } |
Alec Mouri | ffb3221 | 2023-09-16 19:29:15 +0000 | [diff] [blame] | 7541 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 7542 | // Screenshots leaving the device should be colorimetric |
| 7543 | if (requestedDataspace == ui::Dataspace::UNKNOWN && |
| 7544 | renderArea->getHintForSeamlessTransition()) { |
| 7545 | renderIntent = state.renderIntent; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7546 | } |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 7547 | } |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7548 | |
| 7549 | captureResults.buffer = capturedBuffer->getBuffer(); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7550 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7551 | ui::LayerStack layerStack{ui::DEFAULT_LAYER_STACK}; |
Melody Hsu | 0b80c74 | 2024-10-29 07:24:29 +0000 | [diff] [blame] | 7552 | if (!layers.empty()) { |
| 7553 | const sp<LayerFE>& layerFE = layers.back().second; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7554 | layerStack = layerFE->getCompositionState()->outputFilter.layerStack; |
Yichi Chen | 40773d9 | 2020-04-01 10:10:18 +0800 | [diff] [blame] | 7555 | } |
Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 7556 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7557 | auto present = [this, buffer = capturedBuffer, dataspace = captureResults.capturedDataspace, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 7558 | sdrWhitePointNits, displayBrightnessNits, grayscale, isProtected, |
Melody Hsu | 0b80c74 | 2024-10-29 07:24:29 +0000 | [diff] [blame] | 7559 | layers = std::move(layers), layerStack, regionSampling, |
Alec Mouri | a7e752e | 2024-05-24 18:21:21 +0000 | [diff] [blame] | 7560 | renderArea = std::move(renderArea), renderIntent, |
| 7561 | enableLocalTonemapping]() -> FenceResult { |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7562 | std::unique_ptr<compositionengine::CompositionEngine> compositionEngine = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7563 | mFactory.createCompositionEngine(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7564 | compositionEngine->setRenderEngine(mRenderEngine.get()); |
| 7565 | |
Melody Hsu | 0b80c74 | 2024-10-29 07:24:29 +0000 | [diff] [blame] | 7566 | std::vector<sp<compositionengine::LayerFE>> layerFEs; |
| 7567 | layerFEs.reserve(layers.size()); |
| 7568 | for (auto& [layer, layerFE] : layers) { |
| 7569 | // Release fences were not yet added for non-threaded render engine. To avoid |
| 7570 | // deadlocks between main thread and binder threads waiting for the future fence |
| 7571 | // result, fences should be added to layers in the same hop onto the main thread. |
| 7572 | if (!mRenderEngine->isThreaded()) { |
| 7573 | attachReleaseFenceFutureToLayer(layer, layerFE.get(), ui::INVALID_LAYER_STACK); |
| 7574 | } |
| 7575 | layerFEs.push_back(layerFE); |
| 7576 | } |
| 7577 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7578 | compositionengine::Output::ColorProfile colorProfile{.dataspace = dataspace, |
| 7579 | .renderIntent = renderIntent}; |
| 7580 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7581 | float targetBrightness = 1.0f; |
Alec Mouri | a7e752e | 2024-05-24 18:21:21 +0000 | [diff] [blame] | 7582 | if (enableLocalTonemapping) { |
| 7583 | // Boost the whole scene so that SDR white is at 1.0 while still communicating the hdr |
| 7584 | // sdr ratio via display brightness / sdrWhite nits. |
| 7585 | targetBrightness = sdrWhitePointNits / displayBrightnessNits; |
| 7586 | } else if (dataspace == ui::Dataspace::BT2020_HLG) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7587 | const float maxBrightnessNits = displayBrightnessNits / sdrWhitePointNits * 203; |
| 7588 | // With a low dimming ratio, don't fit the entire curve. Otherwise mixed content |
| 7589 | // will appear way too bright. |
| 7590 | if (maxBrightnessNits < 1000.f) { |
| 7591 | targetBrightness = 1000.f / maxBrightnessNits; |
| 7592 | } |
| 7593 | } |
| 7594 | |
Alec Mouri | ffb3221 | 2023-09-16 19:29:15 +0000 | [diff] [blame] | 7595 | // Screenshots leaving the device must not dim in gamma space. |
| 7596 | const bool dimInGammaSpaceForEnhancedScreenshots = mDimInGammaSpaceForEnhancedScreenshots && |
| 7597 | renderArea->getHintForSeamlessTransition(); |
| 7598 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7599 | std::shared_ptr<ScreenCaptureOutput> output = createScreenCaptureOutput( |
| 7600 | ScreenCaptureOutputArgs{.compositionEngine = *compositionEngine, |
| 7601 | .colorProfile = colorProfile, |
| 7602 | .renderArea = *renderArea, |
| 7603 | .layerStack = layerStack, |
| 7604 | .buffer = std::move(buffer), |
| 7605 | .sdrWhitePointNits = sdrWhitePointNits, |
| 7606 | .displayBrightnessNits = displayBrightnessNits, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7607 | .targetBrightness = targetBrightness, |
Alec Mouri | 7dae9c1 | 2023-07-13 19:40:53 +0000 | [diff] [blame] | 7608 | .regionSampling = regionSampling, |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 7609 | .treat170mAsSrgb = mTreat170mAsSrgb, |
| 7610 | .dimInGammaSpaceForEnhancedScreenshots = |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 7611 | dimInGammaSpaceForEnhancedScreenshots, |
Alec Mouri | a7e752e | 2024-05-24 18:21:21 +0000 | [diff] [blame] | 7612 | .isProtected = isProtected, |
| 7613 | .enableLocalTonemapping = enableLocalTonemapping}); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7614 | |
| 7615 | const float colorSaturation = grayscale ? 0 : 1; |
| 7616 | compositionengine::CompositionRefreshArgs refreshArgs{ |
| 7617 | .outputs = {output}, |
| 7618 | .layers = std::move(layerFEs), |
| 7619 | .updatingOutputGeometryThisFrame = true, |
| 7620 | .updatingGeometryThisFrame = true, |
| 7621 | .colorTransformMatrix = calculateColorMatrix(colorSaturation), |
| 7622 | }; |
| 7623 | compositionEngine->present(refreshArgs); |
| 7624 | |
| 7625 | return output->getRenderSurface()->getClientTargetAcquireFence(); |
| 7626 | }; |
| 7627 | |
| 7628 | // If RenderEngine is threaded, we can safely call CompositionEngine::present off the main |
| 7629 | // thread as the RenderEngine::drawLayers call will run on RenderEngine's thread. Otherwise, |
| 7630 | // we need RenderEngine to run on the main thread so we call CompositionEngine::present |
| 7631 | // immediately. |
| 7632 | // |
| 7633 | // TODO(b/196334700) Once we use RenderEngineThreaded everywhere we can always defer the call |
| 7634 | // to CompositionEngine::present. |
Melody Hsu | 16c4c32 | 2024-10-29 07:50:14 +0000 | [diff] [blame] | 7635 | ftl::SharedFuture<FenceResult> presentFuture = mRenderEngine->isThreaded() |
| 7636 | ? ftl::yield(present()).share() |
| 7637 | : mScheduler->schedule(std::move(present)).share(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7638 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7639 | return presentFuture; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 7640 | } |
| 7641 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7642 | void SurfaceFlinger::traverseLegacyLayers(const LayerVector::Visitor& visitor) const { |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 7643 | for (auto& layer : mLegacyLayers) { |
| 7644 | visitor(layer.second.get()); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7645 | } |
| 7646 | } |
| 7647 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 7648 | // --------------------------------------------------------------------------- |
| 7649 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7650 | ftl::Optional<scheduler::FrameRateMode> SurfaceFlinger::getPreferredDisplayMode( |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7651 | PhysicalDisplayId displayId, DisplayModeId defaultModeId) const { |
| 7652 | if (const auto schedulerMode = mScheduler->getPreferredDisplayMode(); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7653 | schedulerMode.modePtr->getPhysicalDisplayId() == displayId) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7654 | return schedulerMode; |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7655 | } |
| 7656 | |
| 7657 | return mPhysicalDisplays.get(displayId) |
| 7658 | .transform(&PhysicalDisplay::snapshotRef) |
| 7659 | .and_then([&](const display::DisplaySnapshot& snapshot) { |
| 7660 | return snapshot.displayModes().get(defaultModeId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 7661 | }) |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7662 | .transform([](const DisplayModePtr& modePtr) { |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 7663 | return scheduler::FrameRateMode{modePtr->getPeakFps(), ftl::as_non_null(modePtr)}; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7664 | }); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7665 | } |
| 7666 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7667 | status_t SurfaceFlinger::setDesiredDisplayModeSpecsInternal( |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 7668 | const sp<DisplayDevice>& display, |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7669 | const scheduler::RefreshRateSelector::PolicyVariant& policy) { |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 7670 | const auto displayId = display->getPhysicalId(); |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 7671 | SFTRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 7672 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 7673 | Mutex::Autolock lock(mStateLock); |
| 7674 | |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7675 | if (mDebugDisplayModeSetByBackdoor) { |
| 7676 | // ignore this request as mode is overridden by backdoor |
| 7677 | return NO_ERROR; |
| 7678 | } |
| 7679 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7680 | auto& selector = display->refreshRateSelector(); |
| 7681 | using SetPolicyResult = scheduler::RefreshRateSelector::SetPolicyResult; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7682 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7683 | switch (selector.setPolicy(policy)) { |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7684 | case SetPolicyResult::Invalid: |
| 7685 | return BAD_VALUE; |
| 7686 | case SetPolicyResult::Unchanged: |
| 7687 | return NO_ERROR; |
| 7688 | case SetPolicyResult::Changed: |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7689 | break; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7690 | } |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7691 | |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7692 | return applyRefreshRateSelectorPolicy(displayId, selector); |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 7693 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7694 | |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 7695 | status_t SurfaceFlinger::applyRefreshRateSelectorPolicy( |
Dominik Laskowski | 1746afd | 2024-04-10 19:21:37 -0400 | [diff] [blame] | 7696 | PhysicalDisplayId displayId, const scheduler::RefreshRateSelector& selector) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7697 | const scheduler::RefreshRateSelector::Policy currentPolicy = selector.getCurrentPolicy(); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7698 | ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str()); |
Adrian Salido | ab6ef6c | 2019-08-28 10:02:49 -0700 | [diff] [blame] | 7699 | |
Dominik Laskowski | bda5236 | 2024-08-04 00:41:46 -0400 | [diff] [blame] | 7700 | if (const bool isPacesetter = |
Ady Abraham | fc48edc | 2024-11-05 19:29:49 -0800 | [diff] [blame] | 7701 | mScheduler->onDisplayModeChanged(displayId, selector.getActiveMode(), |
| 7702 | /*clearContentRequirements*/ true)) { |
Dominik Laskowski | 4383967 | 2024-08-04 02:01:48 -0400 | [diff] [blame] | 7703 | mDisplayModeController.updateKernelIdleTimer(displayId); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7704 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 7705 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 7706 | auto preferredModeOpt = getPreferredDisplayMode(displayId, currentPolicy.defaultMode); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7707 | if (!preferredModeOpt) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 7708 | ALOGE("%s: Preferred mode is unknown", __func__); |
| 7709 | return NAME_NOT_FOUND; |
| 7710 | } |
| 7711 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7712 | auto preferredMode = std::move(*preferredModeOpt); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7713 | const auto preferredModeId = preferredMode.modePtr->getId(); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 7714 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7715 | const Fps preferredFps = preferredMode.fps; |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 7716 | ALOGV("Switching to Scheduler preferred mode %d (%s)", ftl::to_underlying(preferredModeId), |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7717 | to_string(preferredFps).c_str()); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7718 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7719 | if (!selector.isModeAllowed(preferredMode)) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 7720 | ALOGE("%s: Preferred mode %d is disallowed", __func__, ftl::to_underlying(preferredModeId)); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7721 | return INVALID_OPERATION; |
Dominik Laskowski | 4f1dd8c | 2019-04-17 15:54:30 -0700 | [diff] [blame] | 7722 | } |
| 7723 | |
Dominik Laskowski | 1746afd | 2024-04-10 19:21:37 -0400 | [diff] [blame] | 7724 | setDesiredMode({std::move(preferredMode), .emitEvent = true}); |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 7725 | |
| 7726 | // Update the frameRateOverride list as the display render rate might have changed |
Dominik Laskowski | 1d7be06 | 2024-07-24 13:59:07 -0400 | [diff] [blame] | 7727 | mScheduler->updateFrameRateOverrides(scheduler::GlobalSignals{}, preferredFps); |
Ady Abraham | d9b3ea6 | 2019-02-26 14:08:03 -0800 | [diff] [blame] | 7728 | return NO_ERROR; |
| 7729 | } |
| 7730 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7731 | namespace { |
| 7732 | FpsRange translate(const gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange& aidlRange) { |
| 7733 | return FpsRange{Fps::fromValue(aidlRange.min), Fps::fromValue(aidlRange.max)}; |
| 7734 | } |
| 7735 | |
| 7736 | FpsRanges translate(const gui::DisplayModeSpecs::RefreshRateRanges& aidlRanges) { |
| 7737 | return FpsRanges{translate(aidlRanges.physical), translate(aidlRanges.render)}; |
| 7738 | } |
| 7739 | |
| 7740 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange translate(const FpsRange& range) { |
| 7741 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange aidlRange; |
| 7742 | aidlRange.min = range.min.getValue(); |
| 7743 | aidlRange.max = range.max.getValue(); |
| 7744 | return aidlRange; |
| 7745 | } |
| 7746 | |
| 7747 | gui::DisplayModeSpecs::RefreshRateRanges translate(const FpsRanges& ranges) { |
| 7748 | gui::DisplayModeSpecs::RefreshRateRanges aidlRanges; |
| 7749 | aidlRanges.physical = translate(ranges.physical); |
| 7750 | aidlRanges.render = translate(ranges.render); |
| 7751 | return aidlRanges; |
| 7752 | } |
| 7753 | |
| 7754 | } // namespace |
| 7755 | |
| 7756 | status_t SurfaceFlinger::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 7757 | const gui::DisplayModeSpecs& specs) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 7758 | SFTRACE_CALL(); |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 7759 | |
| 7760 | if (!displayToken) { |
| 7761 | return BAD_VALUE; |
| 7762 | } |
| 7763 | |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 7764 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7765 | const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayToken)); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7766 | if (!display) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7767 | ALOGE("Attempt to set desired display modes for invalid display token %p", |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7768 | displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 7769 | return NAME_NOT_FOUND; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7770 | } else if (display->isVirtual()) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7771 | ALOGW("Attempt to set desired display modes for virtual display"); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 7772 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7773 | } else { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7774 | using Policy = scheduler::RefreshRateSelector::DisplayManagerPolicy; |
Ady Abraham | 6723172 | 2024-03-21 18:06:21 -0700 | [diff] [blame] | 7775 | const auto idleScreenConfigOpt = |
| 7776 | FlagManager::getInstance().idle_screen_refresh_rate_timeout() |
| 7777 | ? specs.idleScreenRefreshRateConfig |
| 7778 | : std::nullopt; |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7779 | const Policy policy{DisplayModeId(specs.defaultMode), translate(specs.primaryRanges), |
Ady Abraham | 6723172 | 2024-03-21 18:06:21 -0700 | [diff] [blame] | 7780 | translate(specs.appRequestRanges), specs.allowGroupSwitching, |
| 7781 | idleScreenConfigOpt}; |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 7782 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7783 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 7784 | } |
| 7785 | }); |
| 7786 | |
| 7787 | return future.get(); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7788 | } |
| 7789 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 7790 | status_t SurfaceFlinger::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7791 | gui::DisplayModeSpecs* outSpecs) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 7792 | SFTRACE_CALL(); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7793 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7794 | if (!displayToken || !outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7795 | return BAD_VALUE; |
| 7796 | } |
| 7797 | |
| 7798 | Mutex::Autolock lock(mStateLock); |
| 7799 | const auto display = getDisplayDeviceLocked(displayToken); |
| 7800 | if (!display) { |
| 7801 | return NAME_NOT_FOUND; |
| 7802 | } |
| 7803 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7804 | if (display->isVirtual()) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7805 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7806 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7807 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7808 | scheduler::RefreshRateSelector::Policy policy = |
| 7809 | display->refreshRateSelector().getDisplayManagerPolicy(); |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 7810 | outSpecs->defaultMode = ftl::to_underlying(policy.defaultMode); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7811 | outSpecs->allowGroupSwitching = policy.allowGroupSwitching; |
| 7812 | outSpecs->primaryRanges = translate(policy.primaryRanges); |
| 7813 | outSpecs->appRequestRanges = translate(policy.appRequestRanges); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7814 | return NO_ERROR; |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 7815 | } |
| 7816 | |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 7817 | void SurfaceFlinger::onLayerFirstRef(Layer* layer) { |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 7818 | mNumLayers++; |
Vishnu Nair | a12c5c7 | 2024-08-28 15:42:17 -0700 | [diff] [blame] | 7819 | mScheduler->registerLayer(layer, scheduler::FrameRateCompatibility::Default); |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 7820 | } |
| 7821 | |
| 7822 | void SurfaceFlinger::onLayerDestroyed(Layer* layer) { |
| 7823 | mNumLayers--; |
Vishnu Nair | a12c5c7 | 2024-08-28 15:42:17 -0700 | [diff] [blame] | 7824 | mScheduler->deregisterLayer(layer); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7825 | if (mTransactionTracing) { |
| 7826 | mTransactionTracing->onLayerRemoved(layer->getSequence()); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 7827 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 7828 | mScheduler->onLayerDestroyed(layer); |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 7829 | } |
| 7830 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 7831 | void SurfaceFlinger::onLayerUpdate() { |
| 7832 | scheduleCommit(FrameHint::kActive); |
| 7833 | } |
| 7834 | |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 7835 | status_t SurfaceFlinger::setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, |
| 7836 | float lightPosY, float lightPosZ, |
| 7837 | float lightRadius) { |
| 7838 | Mutex::Autolock _l(mStateLock); |
| 7839 | mCurrentState.globalShadowSettings.ambientColor = vec4(ambientColor); |
| 7840 | mCurrentState.globalShadowSettings.spotColor = vec4(spotColor); |
| 7841 | mCurrentState.globalShadowSettings.lightPos.y = lightPosY; |
| 7842 | mCurrentState.globalShadowSettings.lightPos.z = lightPosZ; |
| 7843 | mCurrentState.globalShadowSettings.lightRadius = lightRadius; |
| 7844 | |
| 7845 | // these values are overridden when calculating the shadow settings for a layer. |
| 7846 | mCurrentState.globalShadowSettings.lightPos.x = 0.f; |
| 7847 | mCurrentState.globalShadowSettings.length = 0.f; |
Vishnu Nair | b13bb95 | 2019-11-15 10:24:08 -0800 | [diff] [blame] | 7848 | return NO_ERROR; |
| 7849 | } |
| 7850 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 7851 | const std::unordered_map<std::string, uint32_t>& SurfaceFlinger::getGenericLayerMetadataKeyMap() |
| 7852 | const { |
| 7853 | // TODO(b/149500060): Remove this fixed/static mapping. Please prefer taking |
| 7854 | // on the work to remove the table in that bug rather than adding more to |
| 7855 | // it. |
| 7856 | static const std::unordered_map<std::string, uint32_t> genericLayerMetadataKeyMap{ |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 7857 | {"org.chromium.arc.V1_0.TaskId", gui::METADATA_TASK_ID}, |
| 7858 | {"org.chromium.arc.V1_0.CursorInfo", gui::METADATA_MOUSE_CURSOR}, |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 7859 | }; |
| 7860 | return genericLayerMetadataKeyMap; |
| 7861 | } |
| 7862 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 7863 | status_t SurfaceFlinger::setGameModeFrameRateOverride(uid_t uid, float frameRate) { |
Dominik Laskowski | 1d7be06 | 2024-07-24 13:59:07 -0400 | [diff] [blame] | 7864 | mScheduler->setGameModeFrameRateForUid(FrameRateOverride{uid, frameRate}); |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 7865 | return NO_ERROR; |
| 7866 | } |
| 7867 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 7868 | status_t SurfaceFlinger::setGameDefaultFrameRateOverride(uid_t uid, float frameRate) { |
| 7869 | if (FlagManager::getInstance().game_default_frame_rate()) { |
| 7870 | mScheduler->setGameDefaultFrameRateForUid( |
| 7871 | FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
| 7872 | } |
| 7873 | return NO_ERROR; |
| 7874 | } |
| 7875 | |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 7876 | status_t SurfaceFlinger::updateSmallAreaDetection( |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 7877 | std::vector<std::pair<int32_t, float>>& appIdThresholdMappings) { |
| 7878 | mScheduler->updateSmallAreaDetection(appIdThresholdMappings); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 7879 | return NO_ERROR; |
| 7880 | } |
| 7881 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 7882 | status_t SurfaceFlinger::setSmallAreaDetectionThreshold(int32_t appId, float threshold) { |
| 7883 | mScheduler->setSmallAreaDetectionThreshold(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 7884 | return NO_ERROR; |
| 7885 | } |
| 7886 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7887 | void SurfaceFlinger::enableRefreshRateOverlay(bool enable) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 7888 | bool setByHwc = getHwComposer().hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG); |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 7889 | for (const auto& [displayId, physical] : mPhysicalDisplays) { |
| 7890 | if (physical.snapshot().connectionType() == ui::DisplayConnectionType::Internal || |
Sally Qi | de329f2 | 2023-09-26 16:21:39 -0700 | [diff] [blame] | 7891 | FlagManager::getInstance().refresh_rate_overlay_on_external_display()) { |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 7892 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 7893 | const auto enableOverlay = [&](bool setByHwc) FTL_FAKE_GUARD(kMainThreadContext) { |
| 7894 | const auto activeMode = mDisplayModeController.getActiveMode(displayId); |
| 7895 | const Fps refreshRate = activeMode.modePtr->getVsyncRate(); |
| 7896 | const Fps renderFps = activeMode.fps; |
| 7897 | |
| 7898 | display->enableRefreshRateOverlay(enable, setByHwc, refreshRate, renderFps, |
| 7899 | mRefreshRateOverlaySpinner, |
| 7900 | mRefreshRateOverlayRenderRate, |
| 7901 | mRefreshRateOverlayShowInMiddle); |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 7902 | }; |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 7903 | |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 7904 | enableOverlay(setByHwc); |
| 7905 | if (setByHwc) { |
| 7906 | const auto status = |
Dominik Laskowski | 5c989f5 | 2024-04-11 13:57:14 -0400 | [diff] [blame] | 7907 | getHwComposer().setRefreshRateChangedCallbackDebugEnabled(displayId, |
| 7908 | enable); |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 7909 | if (status != NO_ERROR) { |
Ying Wei | 22d59cc | 2024-05-11 02:41:08 +0000 | [diff] [blame] | 7910 | ALOGE("Error %s refresh rate changed callback debug", |
| 7911 | enable ? "enabling" : "disabling"); |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 7912 | enableOverlay(/*setByHwc*/ false); |
| 7913 | } |
| 7914 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 7915 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7916 | } |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 7917 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7918 | } |
| 7919 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 7920 | void SurfaceFlinger::enableHdrSdrRatioOverlay(bool enable) { |
| 7921 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 7922 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal) { |
| 7923 | if (const auto device = getDisplayDeviceLocked(id)) { |
| 7924 | device->enableHdrSdrRatioOverlay(enable); |
| 7925 | } |
| 7926 | } |
| 7927 | } |
| 7928 | } |
| 7929 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7930 | int SurfaceFlinger::getGpuContextPriority() { |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 7931 | return getRenderEngine().getContextPriority(); |
Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 7932 | } |
| 7933 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 7934 | int SurfaceFlinger::calculateMaxAcquiredBufferCount(Fps refreshRate, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7935 | std::chrono::nanoseconds presentLatency) { |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 7936 | auto pipelineDepth = presentLatency.count() / refreshRate.getPeriodNsecs(); |
| 7937 | if (presentLatency.count() % refreshRate.getPeriodNsecs()) { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 7938 | pipelineDepth++; |
| 7939 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7940 | return std::max(minAcquiredBuffers, static_cast<int64_t>(pipelineDepth - 1)); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 7941 | } |
| 7942 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 7943 | status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 7944 | Fps maxRefreshRate = 60_Hz; |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7945 | |
| 7946 | if (!getHwComposer().isHeadless()) { |
| 7947 | if (const auto display = getDefaultDisplayDevice()) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7948 | maxRefreshRate = display->refreshRateSelector().getSupportedRefreshRateRange().max; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7949 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7950 | } |
| 7951 | |
| 7952 | *buffers = getMaxAcquiredBufferCountForRefreshRate(maxRefreshRate); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 7953 | return NO_ERROR; |
| 7954 | } |
| 7955 | |
rnlee | ed20fa4 | 2021-08-10 18:00:03 -0700 | [diff] [blame] | 7956 | uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 7957 | Fps refreshRate = 60_Hz; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7958 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7959 | if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) { |
| 7960 | refreshRate = *frameRateOverride; |
| 7961 | } else if (!getHwComposer().isHeadless()) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7962 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked())) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7963 | refreshRate = display->refreshRateSelector().getActiveMode().fps; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7964 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7965 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7966 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 7967 | return getMaxAcquiredBufferCountForRefreshRate(refreshRate); |
| 7968 | } |
| 7969 | |
| 7970 | int SurfaceFlinger::getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 7971 | const auto vsyncConfig = |
| 7972 | mScheduler->getVsyncConfiguration().getConfigsForRefreshRate(refreshRate).late; |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 7973 | const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration; |
| 7974 | return calculateMaxAcquiredBufferCount(refreshRate, presentLatency); |
| 7975 | } |
| 7976 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 7977 | void SurfaceFlinger::sample() { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7978 | if (!mLumaSampling || !mRegionSamplingThread) { |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 7979 | return; |
| 7980 | } |
| 7981 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 7982 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 7983 | const auto scheduleFrameTimeOpt = scheduledFrameResultOpt |
| 7984 | ? std::optional{scheduledFrameResultOpt->callbackTime} |
| 7985 | : std::nullopt; |
| 7986 | mRegionSamplingThread->onCompositionComplete(scheduleFrameTimeOpt); |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 7987 | } |
| 7988 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 7989 | void SurfaceFlinger::onActiveDisplaySizeChanged(const DisplayDevice& activeDisplay) { |
| 7990 | mScheduler->onActiveDisplayAreaChanged(activeDisplay.getWidth() * activeDisplay.getHeight()); |
| 7991 | getRenderEngine().onActiveDisplaySizeChanged(activeDisplay.getSize()); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7992 | } |
| 7993 | |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 7994 | sp<DisplayDevice> SurfaceFlinger::getActivatableDisplay() const { |
| 7995 | if (mPhysicalDisplays.size() == 1) return nullptr; |
| 7996 | |
| 7997 | // TODO(b/255635821): Choose the pacesetter display, considering both internal and external |
| 7998 | // displays. For now, pick the other internal display, assuming a dual-display foldable. |
| 7999 | return findDisplay([this](const DisplayDevice& display) REQUIRES(mStateLock) { |
| 8000 | const auto idOpt = PhysicalDisplayId::tryCast(display.getId()); |
| 8001 | return idOpt && *idOpt != mActiveDisplayId && display.isPoweredOn() && |
| 8002 | mPhysicalDisplays.get(*idOpt) |
| 8003 | .transform(&PhysicalDisplay::isInternal) |
| 8004 | .value_or(false); |
| 8005 | }); |
| 8006 | } |
| 8007 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8008 | void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveDisplayPtr, |
| 8009 | const DisplayDevice& activeDisplay) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 8010 | SFTRACE_CALL(); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8011 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8012 | if (inactiveDisplayPtr) { |
| 8013 | inactiveDisplayPtr->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false); |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 8014 | } |
| 8015 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8016 | mActiveDisplayId = activeDisplay.getPhysicalId(); |
| 8017 | activeDisplay.getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 8018 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8019 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8020 | mScheduler->setModeChangePending(false); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8021 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 8022 | mScheduler->setPacesetterDisplay(mActiveDisplayId); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 8023 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8024 | onActiveDisplaySizeChanged(activeDisplay); |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8025 | mActiveDisplayTransformHint = activeDisplay.getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 8026 | sActiveDisplayRotationFlags = ui::Transform::toRotationFlags(activeDisplay.getOrientation()); |
Ady Abraham | 85d692d | 2021-09-28 14:08:54 -0700 | [diff] [blame] | 8027 | |
Dominik Laskowski | 1746afd | 2024-04-10 19:21:37 -0400 | [diff] [blame] | 8028 | // Whether or not the policy of the new active/pacesetter display changed while it was inactive |
| 8029 | // (in which case its preferred mode has already been propagated to HWC via setDesiredMode), the |
| 8030 | // Scheduler's cachedModeChangedParams must be initialized to the newly active mode, and the |
| 8031 | // kernel idle timer of the newly active display must be toggled. |
| 8032 | applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay.refreshRateSelector()); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8033 | } |
| 8034 | |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 8035 | status_t SurfaceFlinger::addWindowInfosListener(const sp<IWindowInfosListener>& windowInfosListener, |
| 8036 | gui::WindowInfosListenerInfo* outInfo) { |
| 8037 | mWindowInfosListenerInvoker->addWindowInfosListener(windowInfosListener, outInfo); |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 8038 | setTransactionFlags(eInputInfoUpdateNeeded); |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 8039 | return NO_ERROR; |
| 8040 | } |
| 8041 | |
| 8042 | status_t SurfaceFlinger::removeWindowInfosListener( |
| 8043 | const sp<IWindowInfosListener>& windowInfosListener) const { |
| 8044 | mWindowInfosListenerInvoker->removeWindowInfosListener(windowInfosListener); |
| 8045 | return NO_ERROR; |
| 8046 | } |
| 8047 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 8048 | status_t SurfaceFlinger::getStalledTransactionInfo( |
| 8049 | int pid, std::optional<TransactionHandler::StalledTransactionInfo>& result) { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 8050 | // Used to add a stalled transaction which uses an internal lock. |
| 8051 | ftl::FakeGuard guard(kMainThreadContext); |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 8052 | result = mTransactionHandler.getStalledTransactionInfo(pid); |
| 8053 | return NO_ERROR; |
| 8054 | } |
| 8055 | |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 8056 | void SurfaceFlinger::updateHdcpLevels(hal::HWDisplayId hwcDisplayId, int32_t connectedLevel, |
| 8057 | int32_t maxLevel) { |
| 8058 | if (!FlagManager::getInstance().connected_display()) { |
| 8059 | return; |
| 8060 | } |
| 8061 | |
| 8062 | Mutex::Autolock lock(mStateLock); |
| 8063 | |
| 8064 | const auto idOpt = getHwComposer().toPhysicalDisplayId(hwcDisplayId); |
| 8065 | if (!idOpt) { |
| 8066 | ALOGE("No display found for HDCP level changed event: connected=%d, max=%d for " |
| 8067 | "display=%" PRIu64, |
| 8068 | connectedLevel, maxLevel, hwcDisplayId); |
| 8069 | return; |
| 8070 | } |
| 8071 | |
| 8072 | const bool isInternalDisplay = |
| 8073 | mPhysicalDisplays.get(*idOpt).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 8074 | if (isInternalDisplay) { |
| 8075 | ALOGW("Unexpected HDCP level changed for internal display: connected=%d, max=%d for " |
| 8076 | "display=%" PRIu64, |
| 8077 | connectedLevel, maxLevel, hwcDisplayId); |
| 8078 | return; |
| 8079 | } |
| 8080 | |
| 8081 | static_cast<void>(mScheduler->schedule([this, displayId = *idOpt, connectedLevel, maxLevel]() { |
| 8082 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayId))) { |
| 8083 | Mutex::Autolock lock(mStateLock); |
| 8084 | display->setSecure(connectedLevel >= 2 /* HDCP_V1 */); |
| 8085 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8086 | mScheduler->onHdcpLevelsChanged(scheduler::Cycle::Render, displayId, connectedLevel, |
| 8087 | maxLevel); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 8088 | })); |
| 8089 | } |
| 8090 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8091 | std::shared_ptr<renderengine::ExternalTexture> SurfaceFlinger::getExternalTextureFromBufferData( |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8092 | BufferData& bufferData, const char* layerName, uint64_t transactionId) { |
| 8093 | if (bufferData.buffer && |
| 8094 | exceedsMaxRenderTargetSize(bufferData.buffer->getWidth(), bufferData.buffer->getHeight())) { |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 8095 | std::string errorMessage = |
| 8096 | base::StringPrintf("Attempted to create an ExternalTexture with size (%u, %u) for " |
| 8097 | "layer %s that exceeds render target size limit of %u.", |
| 8098 | bufferData.buffer->getWidth(), bufferData.buffer->getHeight(), |
| 8099 | layerName, static_cast<uint32_t>(mMaxRenderTargetSize)); |
| 8100 | ALOGD("%s", errorMessage.c_str()); |
| 8101 | if (bufferData.releaseBufferListener) { |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 8102 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
| 8103 | String8(errorMessage.c_str())); |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 8104 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8105 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8106 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8107 | |
| 8108 | bool cachedBufferChanged = |
| 8109 | bufferData.flags.test(BufferData::BufferDataChange::cachedBufferChanged); |
| 8110 | if (cachedBufferChanged && bufferData.buffer) { |
| 8111 | auto result = ClientCache::getInstance().add(bufferData.cachedBuffer, bufferData.buffer); |
| 8112 | if (result.ok()) { |
| 8113 | return result.value(); |
| 8114 | } |
| 8115 | |
| 8116 | if (result.error() == ClientCache::AddError::CacheFull) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 8117 | ALOGE("Attempted to create an ExternalTexture for layer %s but CacheFull", layerName); |
| 8118 | |
| 8119 | if (bufferData.releaseBufferListener) { |
| 8120 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 8121 | String8("Buffer processing hung due to full buffer cache")); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 8122 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8123 | } |
| 8124 | |
| 8125 | return nullptr; |
| 8126 | } |
| 8127 | |
| 8128 | if (cachedBufferChanged) { |
| 8129 | return ClientCache::getInstance().get(bufferData.cachedBuffer); |
| 8130 | } |
| 8131 | |
| 8132 | if (bufferData.buffer) { |
| 8133 | return std::make_shared< |
| 8134 | renderengine::impl::ExternalTexture>(bufferData.buffer, getRenderEngine(), |
| 8135 | renderengine::impl::ExternalTexture::Usage:: |
| 8136 | READABLE); |
| 8137 | } |
| 8138 | |
| 8139 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8140 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8141 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8142 | void SurfaceFlinger::moveSnapshotsFromCompositionArgs( |
| 8143 | compositionengine::CompositionRefreshArgs& refreshArgs, |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 8144 | const std::vector<std::pair<Layer*, LayerFE*>>& layers) { |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 8145 | std::vector<std::unique_ptr<frontend::LayerSnapshot>>& snapshots = |
| 8146 | mLayerSnapshotBuilder.getSnapshots(); |
| 8147 | for (auto [_, layerFE] : layers) { |
| 8148 | auto i = layerFE->mSnapshot->globalZ; |
| 8149 | snapshots[i] = std::move(layerFE->mSnapshot); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8150 | } |
| 8151 | } |
| 8152 | |
| 8153 | std::vector<std::pair<Layer*, LayerFE*>> SurfaceFlinger::moveSnapshotsToCompositionArgs( |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 8154 | compositionengine::CompositionRefreshArgs& refreshArgs, bool cursorOnly) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8155 | std::vector<std::pair<Layer*, LayerFE*>> layers; |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 8156 | nsecs_t currentTime = systemTime(); |
| 8157 | const bool needsMetadata = mCompositionEngine->getFeatureFlags().test( |
| 8158 | compositionengine::Feature::kSnapshotLayerMetadata); |
| 8159 | mLayerSnapshotBuilder.forEachSnapshot( |
| 8160 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) FTL_FAKE_GUARD( |
| 8161 | kMainThreadContext) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8162 | if (cursorOnly && |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 8163 | snapshot->compositionType != |
| 8164 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8165 | return; |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 8166 | } |
| 8167 | |
| 8168 | if (!snapshot->hasSomethingToDraw()) { |
| 8169 | return; |
| 8170 | } |
| 8171 | |
| 8172 | auto it = mLegacyLayers.find(snapshot->sequence); |
| 8173 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 8174 | "Couldnt find layer object for %s", |
| 8175 | snapshot->getDebugString().c_str()); |
| 8176 | auto& legacyLayer = it->second; |
| 8177 | sp<LayerFE> layerFE = legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
| 8178 | snapshot->fps = getLayerFramerate(currentTime, snapshot->sequence); |
| 8179 | layerFE->mSnapshot = std::move(snapshot); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8180 | refreshArgs.layers.push_back(layerFE); |
Melody Hsu | 86ab512 | 2024-04-17 20:47:55 +0000 | [diff] [blame] | 8181 | layers.emplace_back(legacyLayer.get(), layerFE.get()); |
| 8182 | }, |
| 8183 | [needsMetadata](const frontend::LayerSnapshot& snapshot) { |
| 8184 | return snapshot.isVisible || |
| 8185 | (needsMetadata && |
| 8186 | snapshot.changes.test(frontend::RequestedLayerState::Changes::Metadata)); |
| 8187 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8188 | return layers; |
| 8189 | } |
| 8190 | |
| 8191 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8192 | SurfaceFlinger::getLayerSnapshotsForScreenshots( |
| 8193 | std::optional<ui::LayerStack> layerStack, uint32_t uid, |
| 8194 | std::function<bool(const frontend::LayerSnapshot&, bool& outStopTraversal)> |
| 8195 | snapshotFilterFn) { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 8196 | return [&, layerStack, uid]() FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8197 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers; |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8198 | bool stopTraversal = false; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8199 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 8200 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) FTL_FAKE_GUARD( |
| 8201 | kMainThreadContext) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8202 | if (stopTraversal) { |
| 8203 | return; |
| 8204 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8205 | if (layerStack && snapshot->outputFilter.layerStack != *layerStack) { |
| 8206 | return; |
| 8207 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 8208 | if (uid != CaptureArgs::UNSET_UID && snapshot->uid != gui::Uid(uid)) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8209 | return; |
| 8210 | } |
| 8211 | if (!snapshot->hasSomethingToDraw()) { |
| 8212 | return; |
| 8213 | } |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8214 | if (snapshotFilterFn && !snapshotFilterFn(*snapshot, stopTraversal)) { |
| 8215 | return; |
| 8216 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8217 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8218 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 8219 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 8220 | "Couldnt find layer object for %s", |
| 8221 | snapshot->getDebugString().c_str()); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8222 | Layer* legacyLayer = (it == mLegacyLayers.end()) ? nullptr : it->second.get(); |
Lloyd Pique | 70ddc67 | 2024-04-30 18:20:40 -0700 | [diff] [blame] | 8223 | sp<LayerFE> layerFE = getFactory().createLayerFE(snapshot->name, legacyLayer); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8224 | layerFE->mSnapshot = std::make_unique<frontend::LayerSnapshot>(*snapshot); |
| 8225 | layers.emplace_back(legacyLayer, std::move(layerFE)); |
| 8226 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8227 | |
| 8228 | return layers; |
| 8229 | }; |
| 8230 | } |
| 8231 | |
| 8232 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8233 | SurfaceFlinger::getLayerSnapshotsForScreenshots(std::optional<ui::LayerStack> layerStack, |
| 8234 | uint32_t uid, |
| 8235 | std::unordered_set<uint32_t> excludeLayerIds) { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 8236 | return [&, layerStack, uid, |
| 8237 | excludeLayerIds = std::move(excludeLayerIds)]() FTL_FAKE_GUARD(kMainThreadContext) { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8238 | if (excludeLayerIds.empty()) { |
| 8239 | auto getLayerSnapshotsFn = |
| 8240 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 8241 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 8242 | return layers; |
| 8243 | } |
| 8244 | |
| 8245 | frontend::LayerSnapshotBuilder::Args |
| 8246 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 8247 | .layerLifecycleManager = mLayerLifecycleManager, |
| 8248 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
| 8249 | .displays = mFrontEndDisplayInfos, |
| 8250 | .displayChanges = true, |
| 8251 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8252 | .supportsBlur = mSupportsBlur, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8253 | .forceFullDamage = mForceFullDamage, |
| 8254 | .excludeLayerIds = std::move(excludeLayerIds), |
| 8255 | .supportedLayerGenericMetadata = |
| 8256 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 8257 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 8258 | .skipRoundCornersWhenProtected = |
| 8259 | !getRenderEngine().supportsProtectedContent()}; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8260 | mLayerSnapshotBuilder.update(args); |
| 8261 | |
| 8262 | auto getLayerSnapshotsFn = |
| 8263 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 8264 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 8265 | |
| 8266 | args.excludeLayerIds.clear(); |
| 8267 | mLayerSnapshotBuilder.update(args); |
| 8268 | |
| 8269 | return layers; |
| 8270 | }; |
| 8271 | } |
| 8272 | |
| 8273 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8274 | SurfaceFlinger::getLayerSnapshotsForScreenshots(uint32_t rootLayerId, uint32_t uid, |
| 8275 | std::unordered_set<uint32_t> excludeLayerIds, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8276 | bool childrenOnly, |
| 8277 | const std::optional<FloatRect>& parentCrop) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8278 | return [&, rootLayerId, uid, excludeLayerIds = std::move(excludeLayerIds), childrenOnly, |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 8279 | parentCrop]() FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8280 | auto root = mLayerHierarchyBuilder.getPartialHierarchy(rootLayerId, childrenOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8281 | frontend::LayerSnapshotBuilder::Args |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8282 | args{.root = root, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8283 | .layerLifecycleManager = mLayerLifecycleManager, |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8284 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8285 | .displays = mFrontEndDisplayInfos, |
| 8286 | .displayChanges = true, |
| 8287 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8288 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8289 | .forceFullDamage = mForceFullDamage, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8290 | .parentCrop = parentCrop, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 8291 | .excludeLayerIds = std::move(excludeLayerIds), |
| 8292 | .supportedLayerGenericMetadata = |
| 8293 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 8294 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 8295 | .skipRoundCornersWhenProtected = |
| 8296 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | c54fdb0 | 2023-11-21 17:19:58 -0800 | [diff] [blame] | 8297 | // The layer may not exist if it was just created and a screenshot was requested immediately |
| 8298 | // after. In this case, the hierarchy will be empty so we will not render any layers. |
| 8299 | args.rootSnapshot.isSecure = mLayerLifecycleManager.getLayerFromId(rootLayerId) && |
| 8300 | mLayerLifecycleManager.isLayerSecure(rootLayerId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8301 | mLayerSnapshotBuilder.update(args); |
| 8302 | |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8303 | auto getLayerSnapshotsFn = |
| 8304 | getLayerSnapshotsForScreenshots({}, uid, /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8305 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 8306 | args.root = mLayerHierarchyBuilder.getHierarchy(); |
| 8307 | args.parentCrop.reset(); |
| 8308 | args.excludeLayerIds.clear(); |
| 8309 | mLayerSnapshotBuilder.update(args); |
| 8310 | return layers; |
| 8311 | }; |
| 8312 | } |
| 8313 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 8314 | void SurfaceFlinger::doActiveLayersTracingIfNeeded(bool isCompositionComputed, |
| 8315 | bool visibleRegionDirty, TimePoint time, |
| 8316 | VsyncId vsyncId) { |
| 8317 | if (!mLayerTracing.isActiveTracingStarted()) { |
| 8318 | return; |
| 8319 | } |
| 8320 | if (isCompositionComputed != |
| 8321 | mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_COMPOSITION)) { |
| 8322 | return; |
| 8323 | } |
| 8324 | if (!visibleRegionDirty && |
| 8325 | !mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_BUFFERS)) { |
| 8326 | return; |
| 8327 | } |
| 8328 | auto snapshot = takeLayersSnapshotProto(mLayerTracing.getActiveTracingFlags(), time, vsyncId, |
| 8329 | visibleRegionDirty); |
| 8330 | mLayerTracing.addProtoSnapshotToOstream(std::move(snapshot), LayerTracing::Mode::MODE_ACTIVE); |
| 8331 | } |
| 8332 | |
| 8333 | perfetto::protos::LayersSnapshotProto SurfaceFlinger::takeLayersSnapshotProto( |
| 8334 | uint32_t traceFlags, TimePoint time, VsyncId vsyncId, bool visibleRegionDirty) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 8335 | SFTRACE_CALL(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 8336 | perfetto::protos::LayersSnapshotProto snapshot; |
| 8337 | snapshot.set_elapsed_realtime_nanos(time.ns()); |
| 8338 | snapshot.set_vsync_id(ftl::to_underlying(vsyncId)); |
| 8339 | snapshot.set_where(visibleRegionDirty ? "visibleRegionsDirty" : "bufferLatched"); |
| 8340 | snapshot.set_excludes_composition_state((traceFlags & LayerTracing::Flag::TRACE_COMPOSITION) == |
| 8341 | 0); |
| 8342 | |
| 8343 | auto layers = dumpDrawingStateProto(traceFlags); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 8344 | *snapshot.mutable_layers() = std::move(layers); |
| 8345 | |
| 8346 | if (traceFlags & LayerTracing::Flag::TRACE_HWC) { |
| 8347 | std::string hwcDump; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8348 | dumpHwc(hwcDump); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 8349 | snapshot.set_hwc_blob(std::move(hwcDump)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8350 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 8351 | |
| 8352 | *snapshot.mutable_displays() = dumpDisplayProto(); |
| 8353 | |
| 8354 | return snapshot; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8355 | } |
| 8356 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 8357 | // sfdo functions |
| 8358 | |
| 8359 | void SurfaceFlinger::sfdo_enableRefreshRateOverlay(bool active) { |
| 8360 | auto future = mScheduler->schedule( |
| 8361 | [&]() FTL_FAKE_GUARD(mStateLock) |
| 8362 | FTL_FAKE_GUARD(kMainThreadContext) { enableRefreshRateOverlay(active); }); |
| 8363 | future.wait(); |
| 8364 | } |
| 8365 | |
| 8366 | void SurfaceFlinger::sfdo_setDebugFlash(int delay) { |
| 8367 | if (delay > 0) { |
| 8368 | mDebugFlashDelay = delay; |
| 8369 | } else { |
| 8370 | mDebugFlashDelay = mDebugFlashDelay ? 0 : 1; |
| 8371 | } |
| 8372 | scheduleRepaint(); |
| 8373 | } |
| 8374 | |
| 8375 | void SurfaceFlinger::sfdo_scheduleComposite() { |
| 8376 | scheduleComposite(SurfaceFlinger::FrameHint::kActive); |
| 8377 | } |
| 8378 | |
| 8379 | void SurfaceFlinger::sfdo_scheduleCommit() { |
| 8380 | Mutex::Autolock lock(mStateLock); |
| 8381 | setTransactionFlags(eTransactionNeeded | eDisplayTransactionNeeded | eTraversalNeeded); |
| 8382 | } |
| 8383 | |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 8384 | void SurfaceFlinger::sfdo_forceClientComposition(bool enabled) { |
| 8385 | mDebugDisableHWC = enabled; |
| 8386 | scheduleRepaint(); |
| 8387 | } |
| 8388 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8389 | // gui::ISurfaceComposer |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8390 | |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8391 | binder::Status SurfaceComposerAIDL::bootFinished() { |
| 8392 | status_t status = checkAccessPermission(); |
| 8393 | if (status != OK) { |
| 8394 | return binderStatusFromStatusT(status); |
| 8395 | } |
| 8396 | mFlinger->bootFinished(); |
| 8397 | return binder::Status::ok(); |
| 8398 | } |
| 8399 | |
| 8400 | binder::Status SurfaceComposerAIDL::createDisplayEventConnection( |
| 8401 | VsyncSource vsyncSource, EventRegistration eventRegistration, |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 8402 | const sp<IBinder>& layerHandle, sp<IDisplayEventConnection>* outConnection) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8403 | sp<IDisplayEventConnection> conn = |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 8404 | mFlinger->createDisplayEventConnection(vsyncSource, eventRegistration, layerHandle); |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8405 | if (conn == nullptr) { |
| 8406 | *outConnection = nullptr; |
| 8407 | return binderStatusFromStatusT(BAD_VALUE); |
| 8408 | } else { |
| 8409 | *outConnection = conn; |
| 8410 | return binder::Status::ok(); |
| 8411 | } |
| 8412 | } |
| 8413 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8414 | binder::Status SurfaceComposerAIDL::createConnection(sp<gui::ISurfaceComposerClient>* outClient) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 8415 | const sp<Client> client = sp<Client>::make(mFlinger); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8416 | if (client->initCheck() == NO_ERROR) { |
| 8417 | *outClient = client; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 8418 | if (FlagManager::getInstance().misc1()) { |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 8419 | const int policy = SCHED_FIFO; |
| 8420 | client->setMinSchedulerPolicy(policy, sched_get_priority_min(policy)); |
| 8421 | } |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8422 | return binder::Status::ok(); |
| 8423 | } else { |
| 8424 | *outClient = nullptr; |
| 8425 | return binderStatusFromStatusT(BAD_VALUE); |
| 8426 | } |
| 8427 | } |
| 8428 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 8429 | binder::Status SurfaceComposerAIDL::createVirtualDisplay(const std::string& displayName, |
| 8430 | bool isSecure, const std::string& uniqueId, |
| 8431 | float requestedRefreshRate, |
| 8432 | sp<IBinder>* outDisplay) { |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8433 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8434 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8435 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8436 | } |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 8437 | *outDisplay = |
| 8438 | mFlinger->createVirtualDisplay(displayName, isSecure, uniqueId, requestedRefreshRate); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8439 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8440 | } |
| 8441 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 8442 | binder::Status SurfaceComposerAIDL::destroyVirtualDisplay(const sp<IBinder>& displayToken) { |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8443 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8444 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8445 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8446 | } |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 8447 | return binder::Status::fromStatusT(mFlinger->destroyVirtualDisplay(displayToken)); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8448 | } |
| 8449 | |
| 8450 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) { |
| 8451 | std::vector<PhysicalDisplayId> physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); |
| 8452 | std::vector<int64_t> displayIds; |
| 8453 | displayIds.reserve(physicalDisplayIds.size()); |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 8454 | for (const auto id : physicalDisplayIds) { |
| 8455 | displayIds.push_back(static_cast<int64_t>(id.value)); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8456 | } |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 8457 | *outDisplayIds = std::move(displayIds); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8458 | return binder::Status::ok(); |
| 8459 | } |
| 8460 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8461 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, |
| 8462 | sp<IBinder>* outDisplay) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8463 | status_t status = checkAccessPermission(); |
| 8464 | if (status != OK) { |
| 8465 | return binderStatusFromStatusT(status); |
| 8466 | } |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8467 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 8468 | *outDisplay = mFlinger->getPhysicalDisplayToken(*id); |
| 8469 | return binder::Status::ok(); |
| 8470 | } |
| 8471 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8472 | binder::Status SurfaceComposerAIDL::setPowerMode(const sp<IBinder>& display, int mode) { |
| 8473 | status_t status = checkAccessPermission(); |
| 8474 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8475 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8476 | } |
| 8477 | mFlinger->setPowerMode(display, mode); |
| 8478 | return binder::Status::ok(); |
| 8479 | } |
| 8480 | |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 8481 | binder::Status SurfaceComposerAIDL::getSupportedFrameTimestamps( |
| 8482 | std::vector<FrameEvent>* outSupported) { |
| 8483 | status_t status; |
| 8484 | if (!outSupported) { |
| 8485 | status = UNEXPECTED_NULL; |
| 8486 | } else { |
| 8487 | outSupported->clear(); |
| 8488 | status = mFlinger->getSupportedFrameTimestamps(outSupported); |
| 8489 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8490 | return binderStatusFromStatusT(status); |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 8491 | } |
| 8492 | |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8493 | binder::Status SurfaceComposerAIDL::getDisplayStats(const sp<IBinder>& display, |
| 8494 | gui::DisplayStatInfo* outStatInfo) { |
| 8495 | DisplayStatInfo statInfo; |
| 8496 | status_t status = mFlinger->getDisplayStats(display, &statInfo); |
| 8497 | if (status == NO_ERROR) { |
| 8498 | outStatInfo->vsyncTime = static_cast<long>(statInfo.vsyncTime); |
| 8499 | outStatInfo->vsyncPeriod = static_cast<long>(statInfo.vsyncPeriod); |
| 8500 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8501 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8502 | } |
| 8503 | |
| 8504 | binder::Status SurfaceComposerAIDL::getDisplayState(const sp<IBinder>& display, |
| 8505 | gui::DisplayState* outState) { |
| 8506 | ui::DisplayState state; |
| 8507 | status_t status = mFlinger->getDisplayState(display, &state); |
| 8508 | if (status == NO_ERROR) { |
| 8509 | outState->layerStack = state.layerStack.id; |
| 8510 | outState->orientation = static_cast<gui::Rotation>(state.orientation); |
| 8511 | outState->layerStackSpaceRect.width = state.layerStackSpaceRect.width; |
| 8512 | outState->layerStackSpaceRect.height = state.layerStackSpaceRect.height; |
| 8513 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8514 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8515 | } |
| 8516 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8517 | binder::Status SurfaceComposerAIDL::getStaticDisplayInfo(int64_t displayId, |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8518 | gui::StaticDisplayInfo* outInfo) { |
| 8519 | using Tag = gui::DeviceProductInfo::ManufactureOrModelDate::Tag; |
| 8520 | ui::StaticDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8521 | |
| 8522 | status_t status = mFlinger->getStaticDisplayInfo(displayId, &info); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8523 | if (status == NO_ERROR) { |
| 8524 | // convert ui::StaticDisplayInfo to gui::StaticDisplayInfo |
| 8525 | outInfo->connectionType = static_cast<gui::DisplayConnectionType>(info.connectionType); |
| 8526 | outInfo->density = info.density; |
| 8527 | outInfo->secure = info.secure; |
| 8528 | outInfo->installOrientation = static_cast<gui::Rotation>(info.installOrientation); |
| 8529 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 8530 | if (const std::optional<DeviceProductInfo> dpi = info.deviceProductInfo) { |
| 8531 | gui::DeviceProductInfo dinfo; |
| 8532 | dinfo.name = std::move(dpi->name); |
| 8533 | dinfo.manufacturerPnpId = std::vector<uint8_t>(dpi->manufacturerPnpId.begin(), |
| 8534 | dpi->manufacturerPnpId.end()); |
| 8535 | dinfo.productId = dpi->productId; |
| 8536 | dinfo.relativeAddress = |
| 8537 | std::vector<uint8_t>(dpi->relativeAddress.begin(), dpi->relativeAddress.end()); |
| 8538 | if (const auto* model = |
| 8539 | std::get_if<DeviceProductInfo::ModelYear>(&dpi->manufactureOrModelDate)) { |
| 8540 | gui::DeviceProductInfo::ModelYear modelYear; |
| 8541 | modelYear.year = model->year; |
| 8542 | dinfo.manufactureOrModelDate.set<Tag::modelYear>(modelYear); |
| 8543 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureYear>( |
| 8544 | &dpi->manufactureOrModelDate)) { |
| 8545 | gui::DeviceProductInfo::ManufactureYear date; |
| 8546 | date.modelYear.year = manufacture->year; |
| 8547 | dinfo.manufactureOrModelDate.set<Tag::manufactureYear>(date); |
| 8548 | } else if (const auto* manufacture = |
| 8549 | std::get_if<DeviceProductInfo::ManufactureWeekAndYear>( |
| 8550 | &dpi->manufactureOrModelDate)) { |
| 8551 | gui::DeviceProductInfo::ManufactureWeekAndYear date; |
| 8552 | date.manufactureYear.modelYear.year = manufacture->year; |
| 8553 | date.week = manufacture->week; |
| 8554 | dinfo.manufactureOrModelDate.set<Tag::manufactureWeekAndYear>(date); |
| 8555 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8556 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 8557 | outInfo->deviceProductInfo = dinfo; |
| 8558 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8559 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8560 | return binderStatusFromStatusT(status); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8561 | } |
| 8562 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8563 | void SurfaceComposerAIDL::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo& info, |
| 8564 | gui::DynamicDisplayInfo*& outInfo) { |
| 8565 | // convert ui::DynamicDisplayInfo to gui::DynamicDisplayInfo |
| 8566 | outInfo->supportedDisplayModes.clear(); |
| 8567 | outInfo->supportedDisplayModes.reserve(info.supportedDisplayModes.size()); |
| 8568 | for (const auto& mode : info.supportedDisplayModes) { |
| 8569 | gui::DisplayMode outMode; |
| 8570 | outMode.id = mode.id; |
| 8571 | outMode.resolution.width = mode.resolution.width; |
| 8572 | outMode.resolution.height = mode.resolution.height; |
| 8573 | outMode.xDpi = mode.xDpi; |
| 8574 | outMode.yDpi = mode.yDpi; |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 8575 | outMode.peakRefreshRate = mode.peakRefreshRate; |
Alec Mouri | d122a1c | 2023-09-30 01:36:33 +0000 | [diff] [blame] | 8576 | outMode.vsyncRate = mode.vsyncRate; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8577 | outMode.appVsyncOffset = mode.appVsyncOffset; |
| 8578 | outMode.sfVsyncOffset = mode.sfVsyncOffset; |
| 8579 | outMode.presentationDeadline = mode.presentationDeadline; |
| 8580 | outMode.group = mode.group; |
| 8581 | std::transform(mode.supportedHdrTypes.begin(), mode.supportedHdrTypes.end(), |
| 8582 | std::back_inserter(outMode.supportedHdrTypes), |
| 8583 | [](const ui::Hdr& value) { return static_cast<int32_t>(value); }); |
| 8584 | outInfo->supportedDisplayModes.push_back(outMode); |
| 8585 | } |
| 8586 | |
| 8587 | outInfo->activeDisplayModeId = info.activeDisplayModeId; |
| 8588 | outInfo->renderFrameRate = info.renderFrameRate; |
ramindani | 89fbb6e | 2024-09-26 11:30:24 -0700 | [diff] [blame] | 8589 | outInfo->hasArrSupport = info.hasArrSupport; |
ramindani | d2a0e72 | 2024-10-18 15:25:20 -0700 | [diff] [blame] | 8590 | gui::FrameRateCategoryRate& frameRateCategoryRate = outInfo->frameRateCategoryRate; |
| 8591 | frameRateCategoryRate.normal = info.frameRateCategoryRate.getNormal(); |
| 8592 | frameRateCategoryRate.high = info.frameRateCategoryRate.getHigh(); |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8593 | |
| 8594 | outInfo->supportedColorModes.clear(); |
| 8595 | outInfo->supportedColorModes.reserve(info.supportedColorModes.size()); |
| 8596 | for (const auto& cmode : info.supportedColorModes) { |
| 8597 | outInfo->supportedColorModes.push_back(static_cast<int32_t>(cmode)); |
| 8598 | } |
| 8599 | |
| 8600 | outInfo->activeColorMode = static_cast<int32_t>(info.activeColorMode); |
| 8601 | |
| 8602 | gui::HdrCapabilities& hdrCapabilities = outInfo->hdrCapabilities; |
| 8603 | hdrCapabilities.supportedHdrTypes.clear(); |
| 8604 | hdrCapabilities.supportedHdrTypes.reserve(info.hdrCapabilities.getSupportedHdrTypes().size()); |
| 8605 | for (const auto& hdr : info.hdrCapabilities.getSupportedHdrTypes()) { |
| 8606 | hdrCapabilities.supportedHdrTypes.push_back(static_cast<int32_t>(hdr)); |
| 8607 | } |
| 8608 | hdrCapabilities.maxLuminance = info.hdrCapabilities.getDesiredMaxLuminance(); |
| 8609 | hdrCapabilities.maxAverageLuminance = info.hdrCapabilities.getDesiredMaxAverageLuminance(); |
| 8610 | hdrCapabilities.minLuminance = info.hdrCapabilities.getDesiredMinLuminance(); |
| 8611 | |
| 8612 | outInfo->autoLowLatencyModeSupported = info.autoLowLatencyModeSupported; |
| 8613 | outInfo->gameContentTypeSupported = info.gameContentTypeSupported; |
| 8614 | outInfo->preferredBootDisplayMode = info.preferredBootDisplayMode; |
| 8615 | } |
| 8616 | |
| 8617 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromToken( |
| 8618 | const sp<IBinder>& display, gui::DynamicDisplayInfo* outInfo) { |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 8619 | ui::DynamicDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8620 | status_t status = mFlinger->getDynamicDisplayInfoFromToken(display, &info); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 8621 | if (status == NO_ERROR) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8622 | getDynamicDisplayInfoInternal(info, outInfo); |
| 8623 | } |
| 8624 | return binderStatusFromStatusT(status); |
| 8625 | } |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 8626 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8627 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromId(int64_t displayId, |
| 8628 | gui::DynamicDisplayInfo* outInfo) { |
| 8629 | ui::DynamicDisplayInfo info; |
| 8630 | status_t status = mFlinger->getDynamicDisplayInfoFromId(displayId, &info); |
| 8631 | if (status == NO_ERROR) { |
| 8632 | getDynamicDisplayInfoInternal(info, outInfo); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 8633 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8634 | return binderStatusFromStatusT(status); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 8635 | } |
| 8636 | |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8637 | binder::Status SurfaceComposerAIDL::getDisplayNativePrimaries(const sp<IBinder>& display, |
| 8638 | gui::DisplayPrimaries* outPrimaries) { |
| 8639 | ui::DisplayPrimaries primaries; |
| 8640 | status_t status = mFlinger->getDisplayNativePrimaries(display, primaries); |
| 8641 | if (status == NO_ERROR) { |
| 8642 | outPrimaries->red.X = primaries.red.X; |
| 8643 | outPrimaries->red.Y = primaries.red.Y; |
| 8644 | outPrimaries->red.Z = primaries.red.Z; |
| 8645 | |
| 8646 | outPrimaries->green.X = primaries.green.X; |
| 8647 | outPrimaries->green.Y = primaries.green.Y; |
| 8648 | outPrimaries->green.Z = primaries.green.Z; |
| 8649 | |
| 8650 | outPrimaries->blue.X = primaries.blue.X; |
| 8651 | outPrimaries->blue.Y = primaries.blue.Y; |
| 8652 | outPrimaries->blue.Z = primaries.blue.Z; |
| 8653 | |
| 8654 | outPrimaries->white.X = primaries.white.X; |
| 8655 | outPrimaries->white.Y = primaries.white.Y; |
| 8656 | outPrimaries->white.Z = primaries.white.Z; |
| 8657 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8658 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8659 | } |
| 8660 | |
| 8661 | binder::Status SurfaceComposerAIDL::setActiveColorMode(const sp<IBinder>& display, int colorMode) { |
| 8662 | status_t status = checkAccessPermission(); |
| 8663 | if (status == OK) { |
| 8664 | status = mFlinger->setActiveColorMode(display, static_cast<ui::ColorMode>(colorMode)); |
| 8665 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8666 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8667 | } |
| 8668 | |
| 8669 | binder::Status SurfaceComposerAIDL::setBootDisplayMode(const sp<IBinder>& display, |
| 8670 | int displayModeId) { |
| 8671 | status_t status = checkAccessPermission(); |
| 8672 | if (status == OK) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8673 | status = mFlinger->setBootDisplayMode(display, DisplayModeId{displayModeId}); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8674 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8675 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8676 | } |
| 8677 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8678 | binder::Status SurfaceComposerAIDL::clearBootDisplayMode(const sp<IBinder>& display) { |
| 8679 | status_t status = checkAccessPermission(); |
| 8680 | if (status == OK) { |
| 8681 | status = mFlinger->clearBootDisplayMode(display); |
| 8682 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8683 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8684 | } |
| 8685 | |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 8686 | binder::Status SurfaceComposerAIDL::getOverlaySupport(gui::OverlayProperties* outProperties) { |
| 8687 | status_t status = checkAccessPermission(); |
| 8688 | if (status == OK) { |
| 8689 | status = mFlinger->getOverlaySupport(outProperties); |
| 8690 | } |
| 8691 | return binderStatusFromStatusT(status); |
| 8692 | } |
| 8693 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8694 | binder::Status SurfaceComposerAIDL::getBootDisplayModeSupport(bool* outMode) { |
| 8695 | status_t status = checkAccessPermission(); |
| 8696 | if (status == OK) { |
| 8697 | status = mFlinger->getBootDisplayModeSupport(outMode); |
| 8698 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8699 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8700 | } |
| 8701 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 8702 | binder::Status SurfaceComposerAIDL::getHdrConversionCapabilities( |
| 8703 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) { |
| 8704 | status_t status = checkAccessPermission(); |
| 8705 | if (status == OK) { |
| 8706 | status = mFlinger->getHdrConversionCapabilities(hdrConversionCapabilities); |
| 8707 | } |
| 8708 | return binderStatusFromStatusT(status); |
| 8709 | } |
| 8710 | |
| 8711 | binder::Status SurfaceComposerAIDL::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 8712 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 8713 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 8714 | status_t status = checkAccessPermission(); |
| 8715 | if (status == OK) { |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 8716 | status = mFlinger->setHdrConversionStrategy(hdrConversionStrategy, |
| 8717 | outPreferredHdrOutputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 8718 | } |
| 8719 | return binderStatusFromStatusT(status); |
| 8720 | } |
| 8721 | |
| 8722 | binder::Status SurfaceComposerAIDL::getHdrOutputConversionSupport(bool* outMode) { |
| 8723 | status_t status = checkAccessPermission(); |
| 8724 | if (status == OK) { |
| 8725 | status = mFlinger->getHdrOutputConversionSupport(outMode); |
| 8726 | } |
| 8727 | return binderStatusFromStatusT(status); |
| 8728 | } |
| 8729 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8730 | binder::Status SurfaceComposerAIDL::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) { |
| 8731 | status_t status = checkAccessPermission(); |
| 8732 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8733 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8734 | } |
| 8735 | mFlinger->setAutoLowLatencyMode(display, on); |
| 8736 | return binder::Status::ok(); |
| 8737 | } |
| 8738 | |
| 8739 | binder::Status SurfaceComposerAIDL::setGameContentType(const sp<IBinder>& display, bool on) { |
| 8740 | status_t status = checkAccessPermission(); |
| 8741 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8742 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8743 | } |
| 8744 | mFlinger->setGameContentType(display, on); |
| 8745 | return binder::Status::ok(); |
| 8746 | } |
| 8747 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8748 | binder::Status SurfaceComposerAIDL::captureDisplay( |
| 8749 | const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8750 | mFlinger->captureDisplay(args, captureListener); |
| 8751 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8752 | } |
| 8753 | |
| 8754 | binder::Status SurfaceComposerAIDL::captureDisplayById( |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 8755 | int64_t displayId, const CaptureArgs& args, |
| 8756 | const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8757 | // status_t status; |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8758 | IPCThreadState* ipc = IPCThreadState::self(); |
| 8759 | const int uid = ipc->getCallingUid(); |
| 8760 | if (uid == AID_ROOT || uid == AID_GRAPHICS || uid == AID_SYSTEM || uid == AID_SHELL) { |
| 8761 | std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId)); |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 8762 | mFlinger->captureDisplay(*id, args, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8763 | } else { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8764 | ALOGD("Permission denied to captureDisplayById"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8765 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8766 | } |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8767 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8768 | } |
| 8769 | |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 8770 | binder::Status SurfaceComposerAIDL::captureLayersSync(const LayerCaptureArgs& args, |
| 8771 | ScreenCaptureResults* outResults) { |
| 8772 | *outResults = mFlinger->captureLayersSync(args); |
| 8773 | return binderStatusFromStatusT(NO_ERROR); |
| 8774 | } |
| 8775 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8776 | binder::Status SurfaceComposerAIDL::captureLayers( |
| 8777 | const LayerCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8778 | mFlinger->captureLayers(args, captureListener); |
| 8779 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8780 | } |
| 8781 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8782 | binder::Status SurfaceComposerAIDL::overrideHdrTypes(const sp<IBinder>& display, |
| 8783 | const std::vector<int32_t>& hdrTypes) { |
| 8784 | // overrideHdrTypes is used by CTS tests, which acquire the necessary |
| 8785 | // permission dynamically. Don't use the permission cache for this check. |
| 8786 | status_t status = checkAccessPermission(false); |
| 8787 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8788 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8789 | } |
| 8790 | |
| 8791 | std::vector<ui::Hdr> hdrTypesVector; |
| 8792 | for (int32_t i : hdrTypes) { |
| 8793 | hdrTypesVector.push_back(static_cast<ui::Hdr>(i)); |
| 8794 | } |
| 8795 | status = mFlinger->overrideHdrTypes(display, hdrTypesVector); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8796 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8797 | } |
| 8798 | |
| 8799 | binder::Status SurfaceComposerAIDL::onPullAtom(int32_t atomId, gui::PullAtomData* outPullData) { |
| 8800 | status_t status; |
| 8801 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 8802 | if (uid != AID_SYSTEM) { |
| 8803 | status = PERMISSION_DENIED; |
| 8804 | } else { |
| 8805 | status = mFlinger->onPullAtom(atomId, &outPullData->data, &outPullData->success); |
| 8806 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8807 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8808 | } |
| 8809 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8810 | binder::Status SurfaceComposerAIDL::getCompositionPreference(gui::CompositionPreference* outPref) { |
| 8811 | ui::Dataspace dataspace; |
| 8812 | ui::PixelFormat pixelFormat; |
| 8813 | ui::Dataspace wideColorGamutDataspace; |
| 8814 | ui::PixelFormat wideColorGamutPixelFormat; |
| 8815 | status_t status = |
| 8816 | mFlinger->getCompositionPreference(&dataspace, &pixelFormat, &wideColorGamutDataspace, |
| 8817 | &wideColorGamutPixelFormat); |
| 8818 | if (status == NO_ERROR) { |
| 8819 | outPref->defaultDataspace = static_cast<int32_t>(dataspace); |
| 8820 | outPref->defaultPixelFormat = static_cast<int32_t>(pixelFormat); |
| 8821 | outPref->wideColorGamutDataspace = static_cast<int32_t>(wideColorGamutDataspace); |
| 8822 | outPref->wideColorGamutPixelFormat = static_cast<int32_t>(wideColorGamutPixelFormat); |
| 8823 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8824 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8825 | } |
| 8826 | |
| 8827 | binder::Status SurfaceComposerAIDL::getDisplayedContentSamplingAttributes( |
| 8828 | const sp<IBinder>& display, gui::ContentSamplingAttributes* outAttrs) { |
| 8829 | status_t status = checkAccessPermission(); |
| 8830 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8831 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8832 | } |
| 8833 | |
| 8834 | ui::PixelFormat format; |
| 8835 | ui::Dataspace dataspace; |
| 8836 | uint8_t componentMask; |
| 8837 | status = mFlinger->getDisplayedContentSamplingAttributes(display, &format, &dataspace, |
| 8838 | &componentMask); |
| 8839 | if (status == NO_ERROR) { |
| 8840 | outAttrs->format = static_cast<int32_t>(format); |
| 8841 | outAttrs->dataspace = static_cast<int32_t>(dataspace); |
| 8842 | outAttrs->componentMask = static_cast<int8_t>(componentMask); |
| 8843 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8844 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8845 | } |
| 8846 | |
| 8847 | binder::Status SurfaceComposerAIDL::setDisplayContentSamplingEnabled(const sp<IBinder>& display, |
| 8848 | bool enable, |
| 8849 | int8_t componentMask, |
| 8850 | int64_t maxFrames) { |
| 8851 | status_t status = checkAccessPermission(); |
| 8852 | if (status == OK) { |
| 8853 | status = mFlinger->setDisplayContentSamplingEnabled(display, enable, |
| 8854 | static_cast<uint8_t>(componentMask), |
| 8855 | static_cast<uint64_t>(maxFrames)); |
| 8856 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8857 | return binderStatusFromStatusT(status); |
| 8858 | } |
| 8859 | |
| 8860 | binder::Status SurfaceComposerAIDL::getDisplayedContentSample(const sp<IBinder>& display, |
| 8861 | int64_t maxFrames, int64_t timestamp, |
| 8862 | gui::DisplayedFrameStats* outStats) { |
| 8863 | if (!outStats) { |
| 8864 | return binderStatusFromStatusT(BAD_VALUE); |
| 8865 | } |
| 8866 | |
| 8867 | status_t status = checkAccessPermission(); |
| 8868 | if (status != OK) { |
| 8869 | return binderStatusFromStatusT(status); |
| 8870 | } |
| 8871 | |
| 8872 | DisplayedFrameStats stats; |
| 8873 | status = mFlinger->getDisplayedContentSample(display, static_cast<uint64_t>(maxFrames), |
| 8874 | static_cast<uint64_t>(timestamp), &stats); |
| 8875 | if (status == NO_ERROR) { |
| 8876 | // convert from ui::DisplayedFrameStats to gui::DisplayedFrameStats |
| 8877 | outStats->numFrames = static_cast<int64_t>(stats.numFrames); |
| 8878 | outStats->component_0_sample.reserve(stats.component_0_sample.size()); |
| 8879 | for (const auto& s : stats.component_0_sample) { |
| 8880 | outStats->component_0_sample.push_back(static_cast<int64_t>(s)); |
| 8881 | } |
| 8882 | outStats->component_1_sample.reserve(stats.component_1_sample.size()); |
| 8883 | for (const auto& s : stats.component_1_sample) { |
| 8884 | outStats->component_1_sample.push_back(static_cast<int64_t>(s)); |
| 8885 | } |
| 8886 | outStats->component_2_sample.reserve(stats.component_2_sample.size()); |
| 8887 | for (const auto& s : stats.component_2_sample) { |
| 8888 | outStats->component_2_sample.push_back(static_cast<int64_t>(s)); |
| 8889 | } |
| 8890 | outStats->component_3_sample.reserve(stats.component_3_sample.size()); |
| 8891 | for (const auto& s : stats.component_3_sample) { |
| 8892 | outStats->component_3_sample.push_back(static_cast<int64_t>(s)); |
| 8893 | } |
| 8894 | } |
| 8895 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8896 | } |
| 8897 | |
| 8898 | binder::Status SurfaceComposerAIDL::getProtectedContentSupport(bool* outSupported) { |
| 8899 | status_t status = mFlinger->getProtectedContentSupport(outSupported); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8900 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8901 | } |
| 8902 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8903 | binder::Status SurfaceComposerAIDL::isWideColorDisplay(const sp<IBinder>& token, |
| 8904 | bool* outIsWideColorDisplay) { |
| 8905 | status_t status = mFlinger->isWideColorDisplay(token, outIsWideColorDisplay); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8906 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8907 | } |
| 8908 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8909 | binder::Status SurfaceComposerAIDL::addRegionSamplingListener( |
| 8910 | const gui::ARect& samplingArea, const sp<IBinder>& stopLayerHandle, |
| 8911 | const sp<gui::IRegionSamplingListener>& listener) { |
| 8912 | status_t status = checkReadFrameBufferPermission(); |
| 8913 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8914 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8915 | } |
| 8916 | android::Rect rect; |
| 8917 | rect.left = samplingArea.left; |
| 8918 | rect.top = samplingArea.top; |
| 8919 | rect.right = samplingArea.right; |
| 8920 | rect.bottom = samplingArea.bottom; |
| 8921 | status = mFlinger->addRegionSamplingListener(rect, stopLayerHandle, listener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8922 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8923 | } |
| 8924 | |
| 8925 | binder::Status SurfaceComposerAIDL::removeRegionSamplingListener( |
| 8926 | const sp<gui::IRegionSamplingListener>& listener) { |
| 8927 | status_t status = checkReadFrameBufferPermission(); |
| 8928 | if (status == OK) { |
| 8929 | status = mFlinger->removeRegionSamplingListener(listener); |
| 8930 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8931 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8932 | } |
| 8933 | |
| 8934 | binder::Status SurfaceComposerAIDL::addFpsListener(int32_t taskId, |
| 8935 | const sp<gui::IFpsListener>& listener) { |
| 8936 | status_t status = checkReadFrameBufferPermission(); |
| 8937 | if (status == OK) { |
| 8938 | status = mFlinger->addFpsListener(taskId, listener); |
| 8939 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8940 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8941 | } |
| 8942 | |
| 8943 | binder::Status SurfaceComposerAIDL::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 8944 | status_t status = checkReadFrameBufferPermission(); |
| 8945 | if (status == OK) { |
| 8946 | status = mFlinger->removeFpsListener(listener); |
| 8947 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8948 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8949 | } |
| 8950 | |
| 8951 | binder::Status SurfaceComposerAIDL::addTunnelModeEnabledListener( |
| 8952 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 8953 | status_t status = checkAccessPermission(); |
| 8954 | if (status == OK) { |
| 8955 | status = mFlinger->addTunnelModeEnabledListener(listener); |
| 8956 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8957 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8958 | } |
| 8959 | |
| 8960 | binder::Status SurfaceComposerAIDL::removeTunnelModeEnabledListener( |
| 8961 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 8962 | status_t status = checkAccessPermission(); |
| 8963 | if (status == OK) { |
| 8964 | status = mFlinger->removeTunnelModeEnabledListener(listener); |
| 8965 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8966 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8967 | } |
| 8968 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8969 | binder::Status SurfaceComposerAIDL::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 8970 | const gui::DisplayModeSpecs& specs) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8971 | status_t status = checkAccessPermission(); |
| 8972 | if (status == OK) { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8973 | status = mFlinger->setDesiredDisplayModeSpecs(displayToken, specs); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8974 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8975 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8976 | } |
| 8977 | |
| 8978 | binder::Status SurfaceComposerAIDL::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 8979 | gui::DisplayModeSpecs* outSpecs) { |
| 8980 | if (!outSpecs) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8981 | return binderStatusFromStatusT(BAD_VALUE); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8982 | } |
| 8983 | |
| 8984 | status_t status = checkAccessPermission(); |
| 8985 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8986 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8987 | } |
| 8988 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8989 | status = mFlinger->getDesiredDisplayModeSpecs(displayToken, outSpecs); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8990 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8991 | } |
| 8992 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8993 | binder::Status SurfaceComposerAIDL::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 8994 | bool* outSupport) { |
| 8995 | status_t status = mFlinger->getDisplayBrightnessSupport(displayToken, outSupport); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8996 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8997 | } |
| 8998 | |
| 8999 | binder::Status SurfaceComposerAIDL::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 9000 | const gui::DisplayBrightness& brightness) { |
| 9001 | status_t status = checkControlDisplayBrightnessPermission(); |
| 9002 | if (status == OK) { |
| 9003 | status = mFlinger->setDisplayBrightness(displayToken, brightness); |
| 9004 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9005 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9006 | } |
| 9007 | |
| 9008 | binder::Status SurfaceComposerAIDL::addHdrLayerInfoListener( |
| 9009 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 9010 | status_t status = checkControlDisplayBrightnessPermission(); |
| 9011 | if (status == OK) { |
| 9012 | status = mFlinger->addHdrLayerInfoListener(displayToken, listener); |
| 9013 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9014 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9015 | } |
| 9016 | |
| 9017 | binder::Status SurfaceComposerAIDL::removeHdrLayerInfoListener( |
| 9018 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 9019 | status_t status = checkControlDisplayBrightnessPermission(); |
| 9020 | if (status == OK) { |
| 9021 | status = mFlinger->removeHdrLayerInfoListener(displayToken, listener); |
| 9022 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9023 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9024 | } |
| 9025 | |
| 9026 | binder::Status SurfaceComposerAIDL::notifyPowerBoost(int boostId) { |
| 9027 | status_t status = checkAccessPermission(); |
| 9028 | if (status == OK) { |
| 9029 | status = mFlinger->notifyPowerBoost(boostId); |
| 9030 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9031 | return binderStatusFromStatusT(status); |
| 9032 | } |
| 9033 | |
| 9034 | binder::Status SurfaceComposerAIDL::setGlobalShadowSettings(const gui::Color& ambientColor, |
| 9035 | const gui::Color& spotColor, |
| 9036 | float lightPosY, float lightPosZ, |
| 9037 | float lightRadius) { |
| 9038 | status_t status = checkAccessPermission(); |
| 9039 | if (status != OK) { |
| 9040 | return binderStatusFromStatusT(status); |
| 9041 | } |
| 9042 | |
| 9043 | half4 ambientColorHalf = {ambientColor.r, ambientColor.g, ambientColor.b, ambientColor.a}; |
| 9044 | half4 spotColorHalf = {spotColor.r, spotColor.g, spotColor.b, spotColor.a}; |
| 9045 | status = mFlinger->setGlobalShadowSettings(ambientColorHalf, spotColorHalf, lightPosY, |
| 9046 | lightPosZ, lightRadius); |
| 9047 | return binderStatusFromStatusT(status); |
| 9048 | } |
| 9049 | |
| 9050 | binder::Status SurfaceComposerAIDL::getDisplayDecorationSupport( |
| 9051 | const sp<IBinder>& displayToken, std::optional<gui::DisplayDecorationSupport>* outSupport) { |
| 9052 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport> support; |
| 9053 | status_t status = mFlinger->getDisplayDecorationSupport(displayToken, &support); |
| 9054 | if (status != NO_ERROR) { |
| 9055 | ALOGE("getDisplayDecorationSupport failed with error %d", status); |
| 9056 | return binderStatusFromStatusT(status); |
| 9057 | } |
| 9058 | |
| 9059 | if (!support || !support.has_value()) { |
| 9060 | outSupport->reset(); |
| 9061 | } else { |
| 9062 | outSupport->emplace(); |
| 9063 | outSupport->value().format = static_cast<int32_t>(support->format); |
| 9064 | outSupport->value().alphaInterpretation = |
| 9065 | static_cast<int32_t>(support->alphaInterpretation); |
| 9066 | } |
| 9067 | |
| 9068 | return binder::Status::ok(); |
| 9069 | } |
| 9070 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 9071 | binder::Status SurfaceComposerAIDL::setGameModeFrameRateOverride(int32_t uid, float frameRate) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9072 | status_t status; |
| 9073 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 9074 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 9075 | status = mFlinger->setGameModeFrameRateOverride(uid, frameRate); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9076 | } else { |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 9077 | ALOGE("setGameModeFrameRateOverride() permission denied for uid: %d", c_uid); |
| 9078 | status = PERMISSION_DENIED; |
| 9079 | } |
| 9080 | return binderStatusFromStatusT(status); |
| 9081 | } |
| 9082 | |
| 9083 | binder::Status SurfaceComposerAIDL::setGameDefaultFrameRateOverride(int32_t uid, float frameRate) { |
| 9084 | status_t status; |
| 9085 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 9086 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 9087 | status = mFlinger->setGameDefaultFrameRateOverride(uid, frameRate); |
| 9088 | } else { |
| 9089 | ALOGE("setGameDefaultFrameRateOverride() permission denied for uid: %d", c_uid); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9090 | status = PERMISSION_DENIED; |
| 9091 | } |
| 9092 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9093 | } |
| 9094 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 9095 | binder::Status SurfaceComposerAIDL::enableRefreshRateOverlay(bool active) { |
| 9096 | mFlinger->sfdo_enableRefreshRateOverlay(active); |
| 9097 | return binder::Status::ok(); |
| 9098 | } |
| 9099 | |
| 9100 | binder::Status SurfaceComposerAIDL::setDebugFlash(int delay) { |
| 9101 | mFlinger->sfdo_setDebugFlash(delay); |
| 9102 | return binder::Status::ok(); |
| 9103 | } |
| 9104 | |
| 9105 | binder::Status SurfaceComposerAIDL::scheduleComposite() { |
| 9106 | mFlinger->sfdo_scheduleComposite(); |
| 9107 | return binder::Status::ok(); |
| 9108 | } |
| 9109 | |
| 9110 | binder::Status SurfaceComposerAIDL::scheduleCommit() { |
| 9111 | mFlinger->sfdo_scheduleCommit(); |
| 9112 | return binder::Status::ok(); |
| 9113 | } |
| 9114 | |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 9115 | binder::Status SurfaceComposerAIDL::forceClientComposition(bool enabled) { |
| 9116 | mFlinger->sfdo_forceClientComposition(enabled); |
| 9117 | return binder::Status::ok(); |
| 9118 | } |
| 9119 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 9120 | binder::Status SurfaceComposerAIDL::updateSmallAreaDetection(const std::vector<int32_t>& appIds, |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9121 | const std::vector<float>& thresholds) { |
| 9122 | status_t status; |
| 9123 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 9124 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 9125 | if (appIds.size() != thresholds.size()) return binderStatusFromStatusT(BAD_VALUE); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9126 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 9127 | std::vector<std::pair<int32_t, float>> mappings; |
| 9128 | const size_t size = appIds.size(); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9129 | mappings.reserve(size); |
| 9130 | for (int i = 0; i < size; i++) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 9131 | auto row = std::make_pair(appIds[i], thresholds[i]); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9132 | mappings.push_back(row); |
| 9133 | } |
| 9134 | status = mFlinger->updateSmallAreaDetection(mappings); |
| 9135 | } else { |
| 9136 | ALOGE("updateSmallAreaDetection() permission denied for uid: %d", c_uid); |
| 9137 | status = PERMISSION_DENIED; |
| 9138 | } |
| 9139 | return binderStatusFromStatusT(status); |
| 9140 | } |
| 9141 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 9142 | binder::Status SurfaceComposerAIDL::setSmallAreaDetectionThreshold(int32_t appId, float threshold) { |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9143 | status_t status; |
| 9144 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 9145 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 9146 | status = mFlinger->setSmallAreaDetectionThreshold(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9147 | } else { |
| 9148 | ALOGE("setSmallAreaDetectionThreshold() permission denied for uid: %d", c_uid); |
| 9149 | status = PERMISSION_DENIED; |
| 9150 | } |
| 9151 | return binderStatusFromStatusT(status); |
| 9152 | } |
| 9153 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9154 | binder::Status SurfaceComposerAIDL::getGpuContextPriority(int32_t* outPriority) { |
| 9155 | *outPriority = mFlinger->getGpuContextPriority(); |
| 9156 | return binder::Status::ok(); |
| 9157 | } |
| 9158 | |
| 9159 | binder::Status SurfaceComposerAIDL::getMaxAcquiredBufferCount(int32_t* buffers) { |
| 9160 | status_t status = mFlinger->getMaxAcquiredBufferCount(buffers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9161 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9162 | } |
| 9163 | |
| 9164 | binder::Status SurfaceComposerAIDL::addWindowInfosListener( |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 9165 | const sp<gui::IWindowInfosListener>& windowInfosListener, |
| 9166 | gui::WindowInfosListenerInfo* outInfo) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9167 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9168 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9169 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9170 | // TODO(b/270566761) update permissions check so that only system_server and shell can add |
| 9171 | // WindowInfosListeners |
| 9172 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 9173 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 9174 | status = mFlinger->addWindowInfosListener(windowInfosListener, outInfo); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9175 | } else { |
| 9176 | status = PERMISSION_DENIED; |
| 9177 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9178 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9179 | } |
| 9180 | |
| 9181 | binder::Status SurfaceComposerAIDL::removeWindowInfosListener( |
| 9182 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 9183 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9184 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9185 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9186 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 9187 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9188 | status = mFlinger->removeWindowInfosListener(windowInfosListener); |
| 9189 | } else { |
| 9190 | status = PERMISSION_DENIED; |
| 9191 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9192 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9193 | } |
| 9194 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 9195 | binder::Status SurfaceComposerAIDL::getStalledTransactionInfo( |
| 9196 | int pid, std::optional<gui::StalledTransactionInfo>* outInfo) { |
| 9197 | const int callingPid = IPCThreadState::self()->getCallingPid(); |
| 9198 | const int callingUid = IPCThreadState::self()->getCallingUid(); |
| 9199 | if (!checkPermission(sAccessSurfaceFlinger, callingPid, callingUid)) { |
| 9200 | return binderStatusFromStatusT(PERMISSION_DENIED); |
| 9201 | } |
| 9202 | |
| 9203 | std::optional<TransactionHandler::StalledTransactionInfo> stalledTransactionInfo; |
| 9204 | status_t status = mFlinger->getStalledTransactionInfo(pid, stalledTransactionInfo); |
| 9205 | if (stalledTransactionInfo) { |
| 9206 | gui::StalledTransactionInfo result; |
| 9207 | result.layerName = String16{stalledTransactionInfo->layerName.c_str()}, |
| 9208 | result.bufferId = stalledTransactionInfo->bufferId, |
| 9209 | result.frameNumber = stalledTransactionInfo->frameNumber, |
| 9210 | outInfo->emplace(std::move(result)); |
| 9211 | } else { |
| 9212 | outInfo->reset(); |
| 9213 | } |
| 9214 | return binderStatusFromStatusT(status); |
| 9215 | } |
| 9216 | |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 9217 | binder::Status SurfaceComposerAIDL::getSchedulingPolicy(gui::SchedulingPolicy* outPolicy) { |
| 9218 | return gui::getSchedulingPolicy(outPolicy); |
| 9219 | } |
| 9220 | |
Wenhui Yang | eafc18a | 2024-05-14 17:15:52 +0000 | [diff] [blame] | 9221 | binder::Status SurfaceComposerAIDL::notifyShutdown() { |
| 9222 | TransactionTraceWriter::getInstance().invoke("systemShutdown_", /* overwrite= */ false); |
| 9223 | return ::android::binder::Status::ok(); |
| 9224 | } |
| 9225 | |
Pascal Mütschard | d56514e | 2024-05-24 17:37:13 +0200 | [diff] [blame] | 9226 | binder::Status SurfaceComposerAIDL::addJankListener(const sp<IBinder>& layerHandle, |
| 9227 | const sp<gui::IJankListener>& listener) { |
| 9228 | sp<Layer> layer = LayerHandle::getLayer(layerHandle); |
| 9229 | if (layer == nullptr) { |
| 9230 | return binder::Status::fromExceptionCode(binder::Status::EX_NULL_POINTER); |
| 9231 | } |
| 9232 | JankTracker::addJankListener(layer->sequence, IInterface::asBinder(listener)); |
| 9233 | return binder::Status::ok(); |
| 9234 | } |
| 9235 | |
| 9236 | binder::Status SurfaceComposerAIDL::flushJankData(int32_t layerId) { |
| 9237 | JankTracker::flushJankData(layerId); |
| 9238 | return binder::Status::ok(); |
| 9239 | } |
| 9240 | |
| 9241 | binder::Status SurfaceComposerAIDL::removeJankListener(int32_t layerId, |
| 9242 | const sp<gui::IJankListener>& listener, |
| 9243 | int64_t afterVsync) { |
| 9244 | JankTracker::removeJankListener(layerId, IInterface::asBinder(listener), afterVsync); |
| 9245 | return binder::Status::ok(); |
| 9246 | } |
| 9247 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9248 | status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { |
| 9249 | if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
| 9250 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9251 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", ipc->getCallingPid(), |
| 9252 | ipc->getCallingUid()); |
| 9253 | return PERMISSION_DENIED; |
| 9254 | } |
| 9255 | return OK; |
| 9256 | } |
| 9257 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9258 | status_t SurfaceComposerAIDL::checkControlDisplayBrightnessPermission() { |
| 9259 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9260 | const int pid = ipc->getCallingPid(); |
| 9261 | const int uid = ipc->getCallingUid(); |
Rheygine Medel | 9e9281e | 2022-09-22 10:13:56 -0700 | [diff] [blame] | 9262 | if ((uid != AID_GRAPHICS) && (uid != AID_SYSTEM) && |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9263 | !PermissionCache::checkPermission(sControlDisplayBrightness, pid, uid)) { |
| 9264 | ALOGE("Permission Denial: can't control brightness pid=%d, uid=%d", pid, uid); |
| 9265 | return PERMISSION_DENIED; |
| 9266 | } |
| 9267 | return OK; |
| 9268 | } |
| 9269 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9270 | status_t SurfaceComposerAIDL::checkReadFrameBufferPermission() { |
| 9271 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9272 | const int pid = ipc->getCallingPid(); |
| 9273 | const int uid = ipc->getCallingUid(); |
| 9274 | if ((uid != AID_GRAPHICS) && !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 9275 | ALOGE("Permission Denial: can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 9276 | return PERMISSION_DENIED; |
| 9277 | } |
| 9278 | return OK; |
| 9279 | } |
| 9280 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 9281 | void SurfaceFlinger::forceFutureUpdate(int delayInMs) { |
| 9282 | static_cast<void>(mScheduler->scheduleDelayed([&]() { scheduleRepaint(); }, ms2ns(delayInMs))); |
| 9283 | } |
| 9284 | |
Vishnu Nair | 2f65e97 | 2023-04-04 16:36:28 +0000 | [diff] [blame] | 9285 | const DisplayDevice* SurfaceFlinger::getDisplayFromLayerStack(ui::LayerStack layerStack) { |
| 9286 | for (const auto& [_, display] : mDisplays) { |
| 9287 | if (display->getLayerStack() == layerStack) { |
| 9288 | return display.get(); |
| 9289 | } |
| 9290 | } |
| 9291 | return nullptr; |
| 9292 | } |
| 9293 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 9294 | } // namespace android |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 9295 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 9296 | #if defined(__gl_h_) |
| 9297 | #error "don't include gl/gl.h in this file" |
| 9298 | #endif |
| 9299 | |
| 9300 | #if defined(__gl2_h_) |
| 9301 | #error "don't include gl2/gl2.h in this file" |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 9302 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 9303 | |
| 9304 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 9305 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |