The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 20 | #pragma clang diagnostic ignored "-Wextra" |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 21 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 22 | //#define LOG_NDEBUG 0 |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 23 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 24 | |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 25 | #include "SurfaceFlinger.h" |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 26 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 27 | #include <aidl/android/hardware/power/Boost.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 28 | #include <android-base/parseint.h> |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 29 | #include <android-base/properties.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 30 | #include <android-base/stringprintf.h> |
| 31 | #include <android-base/strings.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 32 | #include <android/configuration.h> |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 33 | #include <android/gui/IDisplayEventConnection.h> |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 34 | #include <android/gui/StaticDisplayInfo.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 35 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 36 | #include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h> |
| 37 | #include <android/hardware/configstore/1.1/types.h> |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 38 | #include <android/native_window.h> |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 39 | #include <android/os/IInputFlinger.h> |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 40 | #include <binder/IPCThreadState.h> |
| 41 | #include <binder/IServiceManager.h> |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 42 | #include <binder/PermissionCache.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 43 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 44 | #include <compositionengine/CompositionRefreshArgs.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 45 | #include <compositionengine/Display.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 46 | #include <compositionengine/DisplayColorProfile.h> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 47 | #include <compositionengine/DisplayColorProfileCreationArgs.h> |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 48 | #include <compositionengine/DisplayCreationArgs.h> |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 49 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 50 | #include <compositionengine/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 51 | #include <compositionengine/RenderSurface.h> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 52 | #include <compositionengine/impl/DisplayColorProfile.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 53 | #include <compositionengine/impl/OutputCompositionState.h> |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 54 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 55 | #include <configstore/Utils.h> |
| 56 | #include <cutils/compiler.h> |
| 57 | #include <cutils/properties.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 58 | #include <ftl/algorithm.h> |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 59 | #include <ftl/concat.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 60 | #include <ftl/fake_guard.h> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 61 | #include <ftl/future.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 62 | #include <ftl/unit.h> |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 63 | #include <gui/AidlStatusUtil.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 64 | #include <gui/BufferQueue.h> |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 65 | #include <gui/DebugEGLImageTracker.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 66 | #include <gui/IProducerListener.h> |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 67 | #include <gui/LayerDebugInfo.h> |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 68 | #include <gui/LayerMetadata.h> |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 69 | #include <gui/LayerState.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 70 | #include <gui/Surface.h> |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 71 | #include <gui/SurfaceComposerClient.h> |
rnlee | 60f46b5 | 2021-05-21 15:14:07 -0700 | [diff] [blame] | 72 | #include <gui/TraceUtils.h> |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 73 | #include <hidl/ServiceManagement.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 74 | #include <layerproto/LayerProtoParser.h> |
| 75 | #include <log/log.h> |
| 76 | #include <private/android_filesystem_config.h> |
| 77 | #include <private/gui/SyncFeatures.h> |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 78 | #include <processgroup/processgroup.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 79 | #include <renderengine/RenderEngine.h> |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 80 | #include <renderengine/impl/ExternalTexture.h> |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 81 | #include <scheduler/FrameTargeter.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 82 | #include <sys/types.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 83 | #include <ui/ColorSpace.h> |
| 84 | #include <ui/DebugUtils.h> |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 85 | #include <ui/DisplayId.h> |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 86 | #include <ui/DisplayMode.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 87 | #include <ui/DisplayStatInfo.h> |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 88 | #include <ui/DisplayState.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 89 | #include <ui/DynamicDisplayInfo.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 90 | #include <ui/GraphicBufferAllocator.h> |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 91 | #include <ui/HdrRenderTypeUtils.h> |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 92 | #include <ui/LayerStack.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 93 | #include <ui/PixelFormat.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 94 | #include <ui/StaticDisplayInfo.h> |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 95 | #include <unistd.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | #include <utils/StopWatch.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 97 | #include <utils/String16.h> |
| 98 | #include <utils/String8.h> |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 99 | #include <utils/Timers.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 100 | #include <utils/misc.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 101 | #include <algorithm> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 102 | #include <cerrno> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 103 | #include <cinttypes> |
| 104 | #include <cmath> |
| 105 | #include <cstdint> |
| 106 | #include <functional> |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 107 | #include <memory> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 108 | #include <mutex> |
| 109 | #include <optional> |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 110 | #include <string> |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 111 | #include <type_traits> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 112 | #include <unordered_map> |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 113 | #include <vector> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 115 | #include <gui/LayerStatePermissions.h> |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 116 | #include <ui/DisplayIdentification.h> |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 117 | #include "BackgroundExecutor.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 118 | #include "Client.h" |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 119 | #include "ClientCache.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 120 | #include "Colorizer.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 121 | #include "DisplayDevice.h" |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 122 | #include "DisplayHardware/ComposerHal.h" |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 123 | #include "DisplayHardware/FramebufferSurface.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 124 | #include "DisplayHardware/HWComposer.h" |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 125 | #include "DisplayHardware/Hal.h" |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 126 | #include "DisplayHardware/PowerAdvisor.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 127 | #include "DisplayHardware/VirtualDisplaySurface.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 128 | #include "DisplayRenderArea.h" |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 129 | #include "Effects/Daltonizer.h" |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 130 | #include "FlagManager.h" |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 131 | #include "FpsReporter.h" |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 132 | #include "FrameTimeline/FrameTimeline.h" |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 133 | #include "FrameTracer/FrameTracer.h" |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 134 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 135 | #include "FrontEnd/LayerHandle.h" |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 136 | #include "FrontEnd/LayerLifecycleManager.h" |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 137 | #include "FrontEnd/LayerLog.h" |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 138 | #include "FrontEnd/LayerSnapshot.h" |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 139 | #include "HdrLayerInfoReporter.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 140 | #include "Layer.h" |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 141 | #include "LayerProtoHelper.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 142 | #include "LayerRenderArea.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 143 | #include "LayerVector.h" |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 144 | #include "MutexUtils.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 145 | #include "NativeWindowSurface.h" |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 146 | #include "RegionSamplingThread.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 147 | #include "Scheduler/EventThread.h" |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 148 | #include "Scheduler/LayerHistory.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 149 | #include "Scheduler/Scheduler.h" |
Ady Abraham | c581d3c | 2020-08-06 17:34:27 -0700 | [diff] [blame] | 150 | #include "Scheduler/VsyncConfiguration.h" |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 151 | #include "Scheduler/VsyncModulator.h" |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 152 | #include "ScreenCaptureOutput.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 153 | #include "StartPropertySetThread.h" |
| 154 | #include "SurfaceFlingerProperties.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 155 | #include "TimeStats/TimeStats.h" |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 156 | #include "TunnelModeEnabledReporter.h" |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 157 | #include "Utils/Dumper.h" |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 158 | #include "WindowInfosListenerInvoker.h" |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 159 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 160 | #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 161 | #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 162 | #include <aidl/android/hardware/graphics/composer3/RenderIntent.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 163 | |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 164 | #include <com_android_graphics_surfaceflinger_flags.h> |
| 165 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 166 | #undef NO_THREAD_SAFETY_ANALYSIS |
| 167 | #define NO_THREAD_SAFETY_ANALYSIS \ |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 168 | _Pragma("GCC error \"Prefer <ftl/fake_guard.h> or MutexUtils.h helpers.\"") |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 169 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 170 | // To enable layer borders in the system, change the below flag to true. |
| 171 | #undef DOES_CONTAIN_BORDER |
| 172 | #define DOES_CONTAIN_BORDER false |
| 173 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | namespace android { |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 175 | using namespace com::android::graphics::surfaceflinger; |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 176 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 177 | using namespace std::chrono_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 178 | using namespace std::string_literals; |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 179 | using namespace std::string_view_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 180 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 181 | using namespace hardware::configstore; |
| 182 | using namespace hardware::configstore::V1_0; |
| 183 | using namespace sysprop; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 184 | using ftl::Flags; |
| 185 | using namespace ftl::flag_operators; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 186 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 187 | using aidl::android::hardware::graphics::common::DisplayDecorationSupport; |
| 188 | using aidl::android::hardware::graphics::composer3::Capability; |
| 189 | using aidl::android::hardware::graphics::composer3::DisplayCapability; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 190 | using CompositionStrategyPredictionState = android::compositionengine::impl:: |
| 191 | OutputCompositionState::CompositionStrategyPredictionState; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 192 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 193 | using base::StringAppendF; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 194 | using display::PhysicalDisplay; |
| 195 | using display::PhysicalDisplays; |
Vishnu Nair | af6d297 | 2022-11-18 06:26:38 +0000 | [diff] [blame] | 196 | using frontend::TransactionHandler; |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 197 | using gui::DisplayInfo; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 198 | using gui::GameMode; |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 199 | using gui::IDisplayEventConnection; |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 200 | using gui::IWindowInfosListener; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 201 | using gui::LayerMetadata; |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 202 | using gui::WindowInfo; |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 203 | using gui::aidl_utils::binderStatusFromStatusT; |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 204 | using scheduler::VsyncModulator; |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 205 | using ui::Dataspace; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 206 | using ui::DisplayPrimaries; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 207 | using ui::RenderIntent; |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 208 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 209 | using KernelIdleTimerController = scheduler::RefreshRateSelector::KernelIdleTimerController; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 210 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 211 | namespace hal = android::hardware::graphics::composer::hal; |
| 212 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 213 | namespace { |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 214 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 215 | static constexpr int FOUR_K_WIDTH = 3840; |
| 216 | static constexpr int FOUR_K_HEIGHT = 2160; |
| 217 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 218 | // TODO(b/141333600): Consolidate with DisplayMode::Builder::getDefaultDensity. |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 219 | constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 220 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 221 | float getDensityFromProperty(const char* property, bool required) { |
| 222 | char value[PROPERTY_VALUE_MAX]; |
| 223 | const float density = property_get(property, value, nullptr) > 0 ? std::atof(value) : 0.f; |
| 224 | if (!density && required) { |
| 225 | ALOGE("%s must be defined as a build property", property); |
| 226 | return FALLBACK_DENSITY; |
| 227 | } |
| 228 | return density; |
| 229 | } |
| 230 | |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 231 | // Currently we only support V0_SRGB and DISPLAY_P3 as composition preference. |
| 232 | bool validateCompositionDataspace(Dataspace dataspace) { |
| 233 | return dataspace == Dataspace::V0_SRGB || dataspace == Dataspace::DISPLAY_P3; |
| 234 | } |
| 235 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 236 | std::chrono::milliseconds getIdleTimerTimeout(DisplayId displayId) { |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 237 | const auto displayIdleTimerMsKey = [displayId] { |
| 238 | std::stringstream ss; |
| 239 | ss << "debug.sf.set_idle_timer_ms_" << displayId.value; |
| 240 | return ss.str(); |
| 241 | }(); |
| 242 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 243 | const int32_t displayIdleTimerMs = base::GetIntProperty(displayIdleTimerMsKey, 0); |
| 244 | if (displayIdleTimerMs > 0) { |
| 245 | return std::chrono::milliseconds(displayIdleTimerMs); |
| 246 | } |
| 247 | |
| 248 | const int32_t setIdleTimerMs = base::GetIntProperty("debug.sf.set_idle_timer_ms", 0); |
| 249 | const int32_t millis = setIdleTimerMs ? setIdleTimerMs : sysprop::set_idle_timer_ms(0); |
| 250 | return std::chrono::milliseconds(millis); |
| 251 | } |
| 252 | |
| 253 | bool getKernelIdleTimerSyspropConfig(DisplayId displayId) { |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 254 | const auto displaySupportKernelIdleTimerKey = [displayId] { |
| 255 | std::stringstream ss; |
| 256 | ss << "debug.sf.support_kernel_idle_timer_" << displayId.value; |
| 257 | return ss.str(); |
| 258 | }(); |
| 259 | |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 260 | const auto displaySupportKernelIdleTimer = |
| 261 | base::GetBoolProperty(displaySupportKernelIdleTimerKey, false); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 262 | return displaySupportKernelIdleTimer || sysprop::support_kernel_idle_timer(false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 265 | bool isAbove4k30(const ui::DisplayMode& outMode) { |
| 266 | using fps_approx_ops::operator>; |
| 267 | Fps refreshRate = Fps::fromValue(outMode.refreshRate); |
| 268 | return outMode.resolution.getWidth() >= FOUR_K_WIDTH && |
| 269 | outMode.resolution.getHeight() >= FOUR_K_HEIGHT && refreshRate > 30_Hz; |
| 270 | } |
| 271 | |
| 272 | void excludeDolbyVisionIf4k30Present(const std::vector<ui::Hdr>& displayHdrTypes, |
| 273 | ui::DisplayMode& outMode) { |
| 274 | if (isAbove4k30(outMode) && |
| 275 | std::any_of(displayHdrTypes.begin(), displayHdrTypes.end(), |
| 276 | [](ui::Hdr type) { return type == ui::Hdr::DOLBY_VISION_4K30; })) { |
| 277 | for (ui::Hdr type : displayHdrTypes) { |
| 278 | if (type != ui::Hdr::DOLBY_VISION_4K30 && type != ui::Hdr::DOLBY_VISION) { |
| 279 | outMode.supportedHdrTypes.push_back(type); |
| 280 | } |
| 281 | } |
| 282 | } else { |
| 283 | for (ui::Hdr type : displayHdrTypes) { |
| 284 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 285 | outMode.supportedHdrTypes.push_back(type); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | HdrCapabilities filterOut4k30(const HdrCapabilities& displayHdrCapabilities) { |
| 292 | std::vector<ui::Hdr> hdrTypes; |
| 293 | for (ui::Hdr type : displayHdrCapabilities.getSupportedHdrTypes()) { |
| 294 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 295 | hdrTypes.push_back(type); |
| 296 | } |
| 297 | } |
| 298 | return {hdrTypes, displayHdrCapabilities.getDesiredMaxLuminance(), |
| 299 | displayHdrCapabilities.getDesiredMaxAverageLuminance(), |
| 300 | displayHdrCapabilities.getDesiredMinLuminance()}; |
| 301 | } |
| 302 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 303 | uint32_t getLayerIdFromSurfaceControl(sp<SurfaceControl> surfaceControl) { |
| 304 | if (!surfaceControl) { |
| 305 | return UNASSIGNED_LAYER_ID; |
| 306 | } |
| 307 | return LayerHandle::getLayerId(surfaceControl->getHandle()); |
| 308 | } |
| 309 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 310 | } // namespace anonymous |
| 311 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | // --------------------------------------------------------------------------- |
| 313 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 314 | const String16 sHardwareTest("android.permission.HARDWARE_TEST"); |
| 315 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 316 | const String16 sRotateSurfaceFlinger("android.permission.ROTATE_SURFACE_FLINGER"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 317 | const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER"); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 318 | const String16 sControlDisplayBrightness("android.permission.CONTROL_DISPLAY_BRIGHTNESS"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 319 | const String16 sDump("android.permission.DUMP"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 320 | const String16 sCaptureBlackoutContent("android.permission.CAPTURE_BLACKOUT_CONTENT"); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 321 | const String16 sInternalSystemWindow("android.permission.INTERNAL_SYSTEM_WINDOW"); |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 322 | const String16 sWakeupSurfaceFlinger("android.permission.WAKEUP_SURFACE_FLINGER"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 323 | |
Amy Hsu | c8cdfef | 2020-05-07 13:06:25 +0800 | [diff] [blame] | 324 | const char* KERNEL_IDLE_TIMER_PROP = "graphics.display.kernel_idle_timer.enabled"; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 325 | |
| 326 | // --------------------------------------------------------------------------- |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 327 | int64_t SurfaceFlinger::dispSyncPresentTimeOffset; |
| 328 | bool SurfaceFlinger::useHwcForRgbToYuv; |
| 329 | bool SurfaceFlinger::hasSyncFramework; |
| 330 | int64_t SurfaceFlinger::maxFrameBufferAcquiredBuffers; |
| 331 | int64_t SurfaceFlinger::minAcquiredBuffers = 1; |
| 332 | uint32_t SurfaceFlinger::maxGraphicsWidth; |
| 333 | uint32_t SurfaceFlinger::maxGraphicsHeight; |
| 334 | bool SurfaceFlinger::useContextPriority; |
| 335 | Dataspace SurfaceFlinger::defaultCompositionDataspace = Dataspace::V0_SRGB; |
| 336 | ui::PixelFormat SurfaceFlinger::defaultCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
| 337 | Dataspace SurfaceFlinger::wideColorGamutCompositionDataspace = Dataspace::V0_SRGB; |
| 338 | ui::PixelFormat SurfaceFlinger::wideColorGamutCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 339 | LatchUnsignaledConfig SurfaceFlinger::enableLatchUnsignaledConfig; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 340 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 341 | std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) { |
| 342 | switch(displayColorSetting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 343 | case DisplayColorSetting::kManaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 344 | return std::string("Managed"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 345 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 346 | return std::string("Unmanaged"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 347 | case DisplayColorSetting::kEnhanced: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 348 | return std::string("Enhanced"); |
| 349 | default: |
| 350 | return std::string("Unknown ") + |
| 351 | std::to_string(static_cast<int>(displayColorSetting)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 352 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 353 | } |
| 354 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 355 | bool callingThreadHasPermission(const String16& permission) { |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 356 | IPCThreadState* ipc = IPCThreadState::self(); |
| 357 | const int pid = ipc->getCallingPid(); |
| 358 | const int uid = ipc->getCallingUid(); |
| 359 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 360 | PermissionCache::checkPermission(permission, pid, uid); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 363 | ui::Transform::RotationFlags SurfaceFlinger::sActiveDisplayRotationFlags = ui::Transform::ROT_0; |
| 364 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 365 | SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag) |
| 366 | : mFactory(factory), |
| 367 | mPid(getpid()), |
Yiwei Zhang | f0229a7 | 2019-09-09 19:28:02 -0700 | [diff] [blame] | 368 | mTimeStats(std::make_shared<impl::TimeStats>()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 369 | mFrameTracer(mFactory.createFrameTracer()), |
| 370 | mFrameTimeline(mFactory.createFrameTimeline(mTimeStats, mPid)), |
| 371 | mCompositionEngine(mFactory.createCompositionEngine()), |
| 372 | mHwcServiceName(base::GetProperty("debug.sf.hwc_service_name"s, "default"s)), |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 373 | mTunnelModeEnabledReporter(sp<TunnelModeEnabledReporter>::make()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 374 | mEmulatedDisplayDensity(getDensityFromProperty("qemu.sf.lcd_density", false)), |
| 375 | mInternalDisplayDensity( |
| 376 | getDensityFromProperty("ro.sf.lcd_density", !mEmulatedDisplayDensity)), |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 377 | mPowerAdvisor(std::make_unique<Hwc2::impl::PowerAdvisor>(*this)), |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 378 | mWindowInfosListenerInvoker(sp<WindowInfosListenerInvoker>::make()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 379 | ALOGI("Using HWComposer service: %s", mHwcServiceName.c_str()); |
| 380 | } |
Fabien Sanglard | 0cc1938 | 2017-03-06 11:54:40 -0800 | [diff] [blame] | 381 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 382 | SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { |
| 383 | ATRACE_CALL(); |
| 384 | ALOGI("SurfaceFlinger is starting"); |
| 385 | |
| 386 | hasSyncFramework = running_without_sync_framework(true); |
| 387 | |
| 388 | dispSyncPresentTimeOffset = present_time_offset_from_vsync_ns(0); |
| 389 | |
| 390 | useHwcForRgbToYuv = force_hwc_copy_for_virtual_displays(false); |
| 391 | |
| 392 | maxFrameBufferAcquiredBuffers = max_frame_buffer_acquired_buffers(2); |
| 393 | minAcquiredBuffers = |
| 394 | SurfaceFlingerProperties::min_acquired_buffers().value_or(minAcquiredBuffers); |
| 395 | |
| 396 | maxGraphicsWidth = std::max(max_graphics_width(0), 0); |
| 397 | maxGraphicsHeight = std::max(max_graphics_height(0), 0); |
| 398 | |
| 399 | mSupportsWideColor = has_wide_color_display(false); |
| 400 | mDefaultCompositionDataspace = |
| 401 | static_cast<ui::Dataspace>(default_composition_dataspace(Dataspace::V0_SRGB)); |
| 402 | mWideColorGamutCompositionDataspace = static_cast<ui::Dataspace>(wcg_composition_dataspace( |
| 403 | mSupportsWideColor ? Dataspace::DISPLAY_P3 : Dataspace::V0_SRGB)); |
| 404 | defaultCompositionDataspace = mDefaultCompositionDataspace; |
| 405 | wideColorGamutCompositionDataspace = mWideColorGamutCompositionDataspace; |
| 406 | defaultCompositionPixelFormat = static_cast<ui::PixelFormat>( |
| 407 | default_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 408 | wideColorGamutCompositionPixelFormat = |
| 409 | static_cast<ui::PixelFormat>(wcg_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 410 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 411 | mLayerCachingEnabled = [] { |
| 412 | const bool enable = |
| 413 | android::sysprop::SurfaceFlingerProperties::enable_layer_caching().value_or(false); |
| 414 | return base::GetBoolProperty(std::string("debug.sf.enable_layer_caching"), enable); |
| 415 | }(); |
| 416 | |
| 417 | useContextPriority = use_context_priority(true); |
| 418 | |
| 419 | mInternalDisplayPrimaries = sysprop::getDisplayNativePrimaries(); |
| 420 | |
| 421 | // debugging stuff... |
| 422 | char value[PROPERTY_VALUE_MAX]; |
| 423 | |
| 424 | property_get("ro.build.type", value, "user"); |
| 425 | mIsUserBuild = strcmp(value, "user") == 0; |
| 426 | |
| 427 | mDebugFlashDelay = base::GetUintProperty("debug.sf.showupdates"s, 0u); |
| 428 | |
| 429 | mBackpressureGpuComposition = base::GetBoolProperty("debug.sf.enable_gl_backpressure"s, true); |
| 430 | ALOGI_IF(mBackpressureGpuComposition, "Enabling backpressure for GPU composition"); |
| 431 | |
| 432 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 433 | bool supportsBlurs = atoi(value); |
| 434 | mSupportsBlur = supportsBlurs; |
| 435 | ALOGI_IF(!mSupportsBlur, "Disabling blur effects, they are not supported."); |
| 436 | |
| 437 | const size_t defaultListSize = MAX_LAYERS; |
| 438 | auto listSize = property_get_int32("debug.sf.max_igbp_list_size", int32_t(defaultListSize)); |
| 439 | mMaxGraphicBufferProducerListSize = (listSize > 0) ? size_t(listSize) : defaultListSize; |
| 440 | mGraphicBufferProducerListSizeLogThreshold = |
| 441 | std::max(static_cast<int>(0.95 * |
| 442 | static_cast<double>(mMaxGraphicBufferProducerListSize)), |
| 443 | 1); |
| 444 | |
| 445 | property_get("debug.sf.luma_sampling", value, "1"); |
| 446 | mLumaSampling = atoi(value); |
| 447 | |
| 448 | property_get("debug.sf.disable_client_composition_cache", value, "0"); |
| 449 | mDisableClientCompositionCache = atoi(value); |
| 450 | |
| 451 | property_get("debug.sf.predict_hwc_composition_strategy", value, "1"); |
| 452 | mPredictCompositionStrategy = atoi(value); |
| 453 | |
| 454 | property_get("debug.sf.treat_170m_as_sRGB", value, "0"); |
| 455 | mTreat170mAsSrgb = atoi(value); |
| 456 | |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 457 | property_get("debug.sf.dim_in_gamma_in_enhanced_screenshots", value, 0); |
| 458 | mDimInGammaSpaceForEnhancedScreenshots = atoi(value); |
| 459 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 460 | mIgnoreHwcPhysicalDisplayOrientation = |
| 461 | base::GetBoolProperty("debug.sf.ignore_hwc_physical_display_orientation"s, false); |
| 462 | |
| 463 | // We should be reading 'persist.sys.sf.color_saturation' here |
| 464 | // but since /data may be encrypted, we need to wait until after vold |
| 465 | // comes online to attempt to read the property. The property is |
| 466 | // instead read after the boot animation |
| 467 | |
| 468 | if (base::GetBoolProperty("debug.sf.treble_testing_override"s, false)) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 469 | // Without the override SurfaceFlinger cannot connect to HIDL |
| 470 | // services that are not listed in the manifests. Considered |
| 471 | // deriving the setting from the set service name, but it |
| 472 | // would be brittle if the name that's not 'default' is used |
| 473 | // for production purposes later on. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 474 | ALOGI("Enabling Treble testing override"); |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 475 | android::hardware::details::setTrebleTestingOverride(true); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 476 | } |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 477 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 478 | // TODO (b/270966065) Update the HWC based refresh rate overlay to support spinner |
| 479 | mRefreshRateOverlaySpinner = property_get_bool("debug.sf.show_refresh_rate_overlay_spinner", 0); |
| 480 | mRefreshRateOverlayRenderRate = |
| 481 | property_get_bool("debug.sf.show_refresh_rate_overlay_render_rate", 0); |
| 482 | mRefreshRateOverlayShowInMiddle = |
| 483 | property_get_bool("debug.sf.show_refresh_rate_overlay_in_middle", 0); |
| 484 | |
| 485 | if (!mIsUserBuild && base::GetBoolProperty("debug.sf.enable_transaction_tracing"s, true)) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 486 | mTransactionTracing.emplace(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 487 | mLayerTracing.setTransactionTracing(*mTransactionTracing); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 488 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 489 | |
| 490 | mIgnoreHdrCameraLayers = ignore_hdr_camera_layers(false); |
| 491 | |
| 492 | mLayerLifecycleManagerEnabled = |
Vishnu Nair | f42d9bd | 2023-08-23 21:35:33 +0000 | [diff] [blame] | 493 | base::GetBoolProperty("persist.debug.sf.enable_layer_lifecycle_manager"s, true); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 494 | mLegacyFrontEndEnabled = !mLayerLifecycleManagerEnabled || |
| 495 | base::GetBoolProperty("persist.debug.sf.enable_legacy_frontend"s, false); |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 496 | |
Brian Johnson | c99f638 | 2023-09-07 10:52:30 -0700 | [diff] [blame] | 497 | // Trunk-Stable flags |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 498 | mMiscFlagValue = flags::misc1(); |
Brian Johnson | c99f638 | 2023-09-07 10:52:30 -0700 | [diff] [blame] | 499 | mConnectedDisplayFlagValue = flags::connected_display(); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | LatchUnsignaledConfig SurfaceFlinger::getLatchUnsignaledConfig() { |
Ady Abraham | d9e8d1b | 2022-02-25 00:36:10 +0000 | [diff] [blame] | 503 | if (base::GetBoolProperty("debug.sf.auto_latch_unsignaled"s, true)) { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 504 | return LatchUnsignaledConfig::AutoSingleLayer; |
| 505 | } |
| 506 | |
| 507 | return LatchUnsignaledConfig::Disabled; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | } |
| 509 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 510 | SurfaceFlinger::~SurfaceFlinger() = default; |
| 511 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 512 | void SurfaceFlinger::binderDied(const wp<IBinder>&) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 513 | // the window manager died on us. prepare its eulogy. |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 514 | mBootFinished = false; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 515 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 516 | static_cast<void>(mScheduler->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 517 | // Sever the link to inputflinger since it's gone as well. |
| 518 | mInputFlinger.clear(); |
Vishnu Nair | b9df470 | 2021-03-01 11:53:15 -0800 | [diff] [blame] | 519 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 520 | initializeDisplays(); |
| 521 | })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 522 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 523 | startBootAnim(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 526 | void SurfaceFlinger::run() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 527 | mScheduler->run(); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 528 | } |
| 529 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 530 | sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName, bool secure, |
| 531 | float requestedRefreshRate) { |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 532 | // onTransact already checks for some permissions, but adding an additional check here. |
| 533 | // This is to ensure that only system and graphics can request to create a secure |
| 534 | // display. Secure displays can show secure content so we add an additional restriction on it. |
| 535 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 536 | if (secure && uid != AID_GRAPHICS && uid != AID_SYSTEM) { |
| 537 | ALOGE("Only privileged processes can create a secure display"); |
| 538 | return nullptr; |
| 539 | } |
| 540 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 541 | class DisplayToken : public BBinder { |
| 542 | sp<SurfaceFlinger> flinger; |
| 543 | virtual ~DisplayToken() { |
| 544 | // no more references, this display must be terminated |
| 545 | Mutex::Autolock _l(flinger->mStateLock); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 546 | flinger->mCurrentState.displays.removeItem(wp<IBinder>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 547 | flinger->setTransactionFlags(eDisplayTransactionNeeded); |
| 548 | } |
| 549 | public: |
Chih-Hung Hsieh | c406791 | 2016-05-03 14:03:27 -0700 | [diff] [blame] | 550 | explicit DisplayToken(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 551 | : flinger(flinger) { |
| 552 | } |
| 553 | }; |
| 554 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 555 | sp<BBinder> token = sp<DisplayToken>::make(sp<SurfaceFlinger>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 556 | |
| 557 | Mutex::Autolock _l(mStateLock); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 558 | // Display ID is assigned when virtual display is allocated by HWC. |
| 559 | DisplayDeviceState state; |
| 560 | state.isSecure = secure; |
| 561 | state.displayName = displayName; |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 562 | state.requestedRefreshRate = Fps::fromValue(requestedRefreshRate); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 563 | mCurrentState.displays.add(token, state); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 564 | return token; |
| 565 | } |
| 566 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 567 | void SurfaceFlinger::destroyDisplay(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 568 | Mutex::Autolock lock(mStateLock); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 569 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 570 | const ssize_t index = mCurrentState.displays.indexOfKey(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 571 | if (index < 0) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 572 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 573 | return; |
| 574 | } |
| 575 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 576 | const DisplayDeviceState& state = mCurrentState.displays.valueAt(index); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 577 | if (state.physical) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 578 | ALOGE("%s: Invalid operation on physical display", __func__); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 579 | return; |
| 580 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 581 | mCurrentState.displays.removeItemsAt(index); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 582 | setTransactionFlags(eDisplayTransactionNeeded); |
| 583 | } |
| 584 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 585 | void SurfaceFlinger::enableHalVirtualDisplays(bool enable) { |
| 586 | auto& generator = mVirtualDisplayIdGenerators.hal; |
| 587 | if (!generator && enable) { |
| 588 | ALOGI("Enabling HAL virtual displays"); |
| 589 | generator.emplace(getHwComposer().getMaxVirtualDisplayCount()); |
| 590 | } else if (generator && !enable) { |
| 591 | ALOGW_IF(generator->inUse(), "Disabling HAL virtual displays while in use"); |
| 592 | generator.reset(); |
| 593 | } |
| 594 | } |
| 595 | |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 596 | VirtualDisplayId SurfaceFlinger::acquireVirtualDisplay(ui::Size resolution, |
| 597 | ui::PixelFormat format) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 598 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 599 | if (const auto id = generator->generateId()) { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 600 | if (getHwComposer().allocateVirtualDisplay(*id, resolution, &format)) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 601 | return *id; |
| 602 | } |
| 603 | |
| 604 | generator->releaseId(*id); |
| 605 | } else { |
| 606 | ALOGW("%s: Exhausted HAL virtual displays", __func__); |
| 607 | } |
| 608 | |
| 609 | ALOGW("%s: Falling back to GPU virtual display", __func__); |
| 610 | } |
| 611 | |
| 612 | const auto id = mVirtualDisplayIdGenerators.gpu.generateId(); |
| 613 | LOG_ALWAYS_FATAL_IF(!id, "Failed to generate ID for GPU virtual display"); |
| 614 | return *id; |
| 615 | } |
| 616 | |
| 617 | void SurfaceFlinger::releaseVirtualDisplay(VirtualDisplayId displayId) { |
| 618 | if (const auto id = HalVirtualDisplayId::tryCast(displayId)) { |
| 619 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 620 | generator->releaseId(*id); |
| 621 | } |
| 622 | return; |
| 623 | } |
| 624 | |
| 625 | const auto id = GpuVirtualDisplayId::tryCast(displayId); |
| 626 | LOG_ALWAYS_FATAL_IF(!id); |
| 627 | mVirtualDisplayIdGenerators.gpu.releaseId(*id); |
| 628 | } |
| 629 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 630 | std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdsLocked() const { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 631 | std::vector<PhysicalDisplayId> displayIds; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 632 | displayIds.reserve(mPhysicalDisplays.size()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 633 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 634 | const auto defaultDisplayId = getDefaultDisplayDeviceLocked()->getPhysicalId(); |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 635 | displayIds.push_back(defaultDisplayId); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 636 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 637 | for (const auto& [id, display] : mPhysicalDisplays) { |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 638 | if (id != defaultDisplayId) { |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 639 | displayIds.push_back(id); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 640 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 641 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 642 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 643 | return displayIds; |
| 644 | } |
| 645 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 646 | std::optional<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdLocked( |
| 647 | const sp<display::DisplayToken>& displayToken) const { |
| 648 | return ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 649 | .transform(&ftl::to_key<PhysicalDisplays>); |
| 650 | } |
| 651 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 652 | sp<IBinder> SurfaceFlinger::getPhysicalDisplayToken(PhysicalDisplayId displayId) const { |
| 653 | Mutex::Autolock lock(mStateLock); |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 654 | return getPhysicalDisplayTokenLocked(displayId); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 657 | HWComposer& SurfaceFlinger::getHwComposer() const { |
| 658 | return mCompositionEngine->getHwComposer(); |
| 659 | } |
| 660 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 661 | renderengine::RenderEngine& SurfaceFlinger::getRenderEngine() const { |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 662 | return *mRenderEngine; |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 665 | compositionengine::CompositionEngine& SurfaceFlinger::getCompositionEngine() const { |
| 666 | return *mCompositionEngine.get(); |
| 667 | } |
| 668 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 669 | void SurfaceFlinger::bootFinished() { |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 670 | if (mBootFinished == true) { |
| 671 | ALOGE("Extra call to bootFinished"); |
| 672 | return; |
| 673 | } |
| 674 | mBootFinished = true; |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 675 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 676 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 677 | } |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 678 | |
| 679 | if (mRenderEnginePrimeCacheFuture.valid()) { |
| 680 | mRenderEnginePrimeCacheFuture.get(); |
| 681 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | const nsecs_t now = systemTime(); |
| 683 | const nsecs_t duration = now - mBootTime; |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 684 | ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 685 | |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 686 | mFrameTracer->initialize(); |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 687 | mFrameTimeline->onBootFinished(); |
Robert Carr | 9b623c3 | 2022-03-21 15:55:22 -0700 | [diff] [blame] | 688 | getRenderEngine().setEnableTracing(mFlagManager.use_skia_tracing()); |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 689 | |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 690 | // wait patiently for the window manager death |
| 691 | const String16 name("window"); |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 692 | mWindowManager = defaultServiceManager()->waitForService(name); |
Steven Moreland | a904bb9 | 2019-07-02 17:37:23 -0700 | [diff] [blame] | 693 | if (mWindowManager != 0) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 694 | mWindowManager->linkToDeath(sp<IBinder::DeathRecipient>::fromExisting(this)); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | // stop boot animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 698 | // formerly we would just kill the process, but we now ask it to exit so it |
| 699 | // can choose where to stop the animation. |
| 700 | property_set("service.bootanim.exit", "1"); |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 701 | |
| 702 | const int LOGTAG_SF_STOP_BOOTANIM = 60110; |
| 703 | LOG_EVENT_LONG(LOGTAG_SF_STOP_BOOTANIM, |
| 704 | ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 705 | |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 706 | sp<IBinder> input(defaultServiceManager()->waitForService(String16("inputflinger"))); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 707 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 708 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(kMainThreadContext) { |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 709 | if (input == nullptr) { |
| 710 | ALOGE("Failed to link to input service"); |
| 711 | } else { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 712 | mInputFlinger = interface_cast<os::IInputFlinger>(input); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 713 | } |
| 714 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 715 | readPersistentProperties(); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 716 | mPowerAdvisor->onBootFinished(); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 717 | const bool hintSessionEnabled = mFlagManager.use_adpf_cpu_hint(); |
| 718 | mPowerAdvisor->enablePowerHintSession(hintSessionEnabled); |
| 719 | const bool hintSessionUsed = mPowerAdvisor->usePowerHintSession(); |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 720 | ALOGD("Power hint is %s", |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 721 | hintSessionUsed ? "supported" : (hintSessionEnabled ? "unsupported" : "disabled")); |
| 722 | if (hintSessionUsed) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 723 | std::optional<pid_t> renderEngineTid = getRenderEngine().getRenderEngineTid(); |
| 724 | std::vector<int32_t> tidList; |
| 725 | tidList.emplace_back(gettid()); |
| 726 | if (renderEngineTid.has_value()) { |
| 727 | tidList.emplace_back(*renderEngineTid); |
| 728 | } |
| 729 | if (!mPowerAdvisor->startPowerHintSession(tidList)) { |
| 730 | ALOGW("Cannot start power hint session"); |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 731 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 732 | } |
| 733 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 734 | mBootStage = BootStage::FINISHED; |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 735 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 736 | if (base::GetBoolProperty("sf.debug.show_refresh_rate_overlay"s, false)) { |
| 737 | ftl::FakeGuard guard(mStateLock); |
| 738 | enableRefreshRateOverlay(true); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 739 | } |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 740 | })); |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 741 | |
| 742 | LOG_ALWAYS_FATAL_IF(flags::misc1() != mMiscFlagValue, "misc1 flag is not boot stable!"); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | } |
| 744 | |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 745 | static std::optional<renderengine::RenderEngine::RenderEngineType> |
| 746 | chooseRenderEngineTypeViaSysProp() { |
| 747 | char prop[PROPERTY_VALUE_MAX]; |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 748 | property_get(PROPERTY_DEBUG_RENDERENGINE_BACKEND, prop, "skiaglthreaded"); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 749 | |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 750 | if (strcmp(prop, "skiagl") == 0) { |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 751 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL; |
| 752 | } else if (strcmp(prop, "skiaglthreaded") == 0) { |
| 753 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL_THREADED; |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 754 | } else if (strcmp(prop, "skiavk") == 0) { |
| 755 | return renderengine::RenderEngine::RenderEngineType::SKIA_VK; |
| 756 | } else if (strcmp(prop, "skiavkthreaded") == 0) { |
| 757 | return renderengine::RenderEngine::RenderEngineType::SKIA_VK_THREADED; |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 758 | } else { |
| 759 | ALOGE("Unrecognized RenderEngineType %s; ignoring!", prop); |
| 760 | return {}; |
| 761 | } |
| 762 | } |
| 763 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 764 | // Do not call property_set on main thread which will be blocked by init |
| 765 | // Use StartPropertySetThread instead. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 766 | void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) { |
Parth Sane | 343626c | 2023-04-06 16:17:04 +0000 | [diff] [blame] | 767 | ATRACE_CALL(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 768 | ALOGI( "SurfaceFlinger's main thread ready to run. " |
| 769 | "Initializing graphics H/W..."); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 770 | addTransactionReadyFilters(); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 771 | Mutex::Autolock lock(mStateLock); |
Kevin DuBois | 413287f | 2019-02-25 08:46:47 -0800 | [diff] [blame] | 772 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 773 | // Get a RenderEngine for the given display / config (can't fail) |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 774 | // 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] | 775 | // Sending maxFrameBufferAcquiredBuffers as the cache size is tightly tuned to single-display. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 776 | auto builder = renderengine::RenderEngineCreationArgs::Builder() |
| 777 | .setPixelFormat(static_cast<int32_t>(defaultCompositionPixelFormat)) |
| 778 | .setImageCacheSize(maxFrameBufferAcquiredBuffers) |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 779 | .setEnableProtectedContext(enable_protected_contents(false)) |
| 780 | .setPrecacheToneMapperShaderOnly(false) |
| 781 | .setSupportsBackgroundBlur(mSupportsBlur) |
| 782 | .setContextPriority( |
| 783 | useContextPriority |
| 784 | ? renderengine::RenderEngine::ContextPriority::REALTIME |
| 785 | : renderengine::RenderEngine::ContextPriority::MEDIUM); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 786 | if (auto type = chooseRenderEngineTypeViaSysProp()) { |
| 787 | builder.setRenderEngineType(type.value()); |
| 788 | } |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 789 | mRenderEngine = renderengine::RenderEngine::create(builder.build()); |
| 790 | mCompositionEngine->setRenderEngine(mRenderEngine.get()); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 791 | mMaxRenderTargetSize = |
| 792 | std::min(getRenderEngine().getMaxTextureSize(), getRenderEngine().getMaxViewportDims()); |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 793 | |
| 794 | // Set SF main policy after initializing RenderEngine which has its own policy. |
| 795 | if (!SetTaskProfiles(0, {"SFMainPolicy"})) { |
| 796 | ALOGW("Failed to set main task profile"); |
| 797 | } |
| 798 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 799 | mCompositionEngine->setTimeStats(mTimeStats); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 800 | mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName)); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 801 | mCompositionEngine->getHwComposer().setCallback(*this); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 802 | ClientCache::getInstance().setRenderEngine(&getRenderEngine()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 803 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 804 | enableLatchUnsignaledConfig = getLatchUnsignaledConfig(); |
| 805 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 806 | if (base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false)) { |
| 807 | enableHalVirtualDisplays(true); |
| 808 | } |
| 809 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 810 | // Process hotplug for displays connected at boot. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 811 | LOG_ALWAYS_FATAL_IF(!configureLocked(), |
| 812 | "Initial display configuration failed: HWC did not hotplug"); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 813 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 814 | // Commit primary display. |
| 815 | sp<const DisplayDevice> display; |
| 816 | if (const auto indexOpt = mCurrentState.getDisplayIndex(getPrimaryDisplayIdLocked())) { |
| 817 | const auto& displays = mCurrentState.displays; |
| 818 | |
| 819 | const auto& token = displays.keyAt(*indexOpt); |
| 820 | const auto& state = displays.valueAt(*indexOpt); |
| 821 | |
| 822 | processDisplayAdded(token, state); |
| 823 | mDrawingState.displays.add(token, state); |
| 824 | |
| 825 | display = getDefaultDisplayDeviceLocked(); |
| 826 | } |
| 827 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 828 | LOG_ALWAYS_FATAL_IF(!display, "Failed to configure the primary display"); |
| 829 | LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(display->getPhysicalId()), |
| 830 | "Primary display is disconnected"); |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 831 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 832 | // TODO(b/241285876): The Scheduler needlessly depends on creating the CompositionEngine part of |
| 833 | // the DisplayDevice, hence the above commit of the primary display. Remove that special case by |
| 834 | // initializing the Scheduler after configureLocked, once decoupled from DisplayDevice. |
| 835 | initScheduler(display); |
| 836 | dispatchDisplayHotplugEvent(display->getPhysicalId(), true); |
| 837 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 838 | mLayerTracing.setTakeLayersSnapshotProtoFunction([&](uint32_t traceFlags) { |
| 839 | auto snapshot = perfetto::protos::LayersSnapshotProto{}; |
| 840 | mScheduler |
| 841 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 842 | snapshot = takeLayersSnapshotProto(traceFlags, TimePoint::now(), |
| 843 | mLastCommittedVsyncId, true); |
| 844 | }) |
| 845 | .wait(); |
| 846 | return snapshot; |
| 847 | }); |
| 848 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 849 | // Commit secondary display(s). |
| 850 | processDisplayChangesLocked(); |
| 851 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 852 | // initialize our drawing state |
| 853 | mDrawingState = mCurrentState; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 854 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 855 | onActiveDisplayChangedLocked(nullptr, *display); |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 856 | |
| 857 | static_cast<void>(mScheduler->schedule( |
| 858 | [this]() FTL_FAKE_GUARD(kMainThreadContext) { initializeDisplays(); })); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 859 | |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 860 | mPowerAdvisor->init(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 861 | |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 862 | char primeShaderCache[PROPERTY_VALUE_MAX]; |
| 863 | property_get("service.sf.prime_shader_cache", primeShaderCache, "1"); |
| 864 | if (atoi(primeShaderCache)) { |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 865 | if (setSchedFifo(false) != NO_ERROR) { |
| 866 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 867 | } |
| 868 | |
| 869 | mRenderEnginePrimeCacheFuture = getRenderEngine().primeCache(); |
| 870 | |
| 871 | if (setSchedFifo(true) != NO_ERROR) { |
| 872 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 873 | } |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 874 | } |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 875 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 876 | // Inform native graphics APIs whether the present timestamp is supported: |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 877 | |
| 878 | const bool presentFenceReliable = |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 879 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE); |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 880 | mStartPropertySetThread = getFactory().createStartPropertySetThread(presentFenceReliable); |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 881 | |
| 882 | if (mStartPropertySetThread->Start() != NO_ERROR) { |
| 883 | ALOGE("Run StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 884 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 885 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 886 | initTransactionTraceWriter(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 887 | ALOGV("Done initializing"); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 888 | } |
| 889 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 890 | void SurfaceFlinger::initTransactionTraceWriter() { |
| 891 | if (!mTransactionTracing) { |
| 892 | return; |
| 893 | } |
| 894 | TransactionTraceWriter::getInstance().setWriterFunction( |
| 895 | [&](const std::string& filename, bool overwrite) { |
| 896 | auto writeFn = [&]() { |
| 897 | if (!overwrite && access(filename.c_str(), F_OK) == 0) { |
| 898 | ALOGD("TransactionTraceWriter: file=%s already exists", filename.c_str()); |
| 899 | return; |
| 900 | } |
| 901 | mTransactionTracing->flush(); |
| 902 | mTransactionTracing->writeToFile(filename); |
| 903 | }; |
| 904 | if (std::this_thread::get_id() == mMainThreadId) { |
| 905 | writeFn(); |
| 906 | } else { |
| 907 | mScheduler->schedule(writeFn).get(); |
| 908 | } |
| 909 | }); |
| 910 | } |
| 911 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 912 | void SurfaceFlinger::readPersistentProperties() { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 913 | Mutex::Autolock _l(mStateLock); |
| 914 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 915 | char value[PROPERTY_VALUE_MAX]; |
| 916 | |
| 917 | property_get("persist.sys.sf.color_saturation", value, "1.0"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 918 | mGlobalSaturationFactor = atof(value); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 919 | updateColorMatrixLocked(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 920 | ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 921 | |
| 922 | property_get("persist.sys.sf.native_mode", value, "0"); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 923 | mDisplayColorSetting = static_cast<DisplayColorSetting>(atoi(value)); |
Peiyong Lin | a3ea559 | 2019-02-10 14:45:00 -0800 | [diff] [blame] | 924 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 925 | mForceColorMode = |
| 926 | 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] | 927 | } |
| 928 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 929 | void SurfaceFlinger::startBootAnim() { |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 930 | // Start boot animation service by setting a property mailbox |
| 931 | // if property setting thread is already running, Start() will be just a NOP |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 932 | mStartPropertySetThread->Start(); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 933 | // Wait until property was set |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 934 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 935 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 936 | } |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 937 | } |
| 938 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | // ---------------------------------------------------------------------------- |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 940 | |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 941 | status_t SurfaceFlinger::getSupportedFrameTimestamps( |
| 942 | std::vector<FrameEvent>* outSupported) const { |
| 943 | *outSupported = { |
| 944 | FrameEvent::REQUESTED_PRESENT, |
| 945 | FrameEvent::ACQUIRE, |
| 946 | FrameEvent::LATCH, |
| 947 | FrameEvent::FIRST_REFRESH_START, |
| 948 | FrameEvent::LAST_REFRESH_START, |
| 949 | FrameEvent::GPU_COMPOSITION_DONE, |
| 950 | FrameEvent::DEQUEUE_READY, |
| 951 | FrameEvent::RELEASE, |
| 952 | }; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 953 | |
| 954 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 955 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 956 | if (!getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 957 | outSupported->push_back(FrameEvent::DISPLAY_PRESENT); |
| 958 | } |
| 959 | return NO_ERROR; |
| 960 | } |
| 961 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 962 | status_t SurfaceFlinger::getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState* state) { |
| 963 | if (!displayToken || !state) { |
| 964 | return BAD_VALUE; |
| 965 | } |
| 966 | |
| 967 | Mutex::Autolock lock(mStateLock); |
| 968 | |
| 969 | const auto display = getDisplayDeviceLocked(displayToken); |
| 970 | if (!display) { |
| 971 | return NAME_NOT_FOUND; |
| 972 | } |
| 973 | |
| 974 | state->layerStack = display->getLayerStack(); |
| 975 | state->orientation = display->getOrientation(); |
| 976 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 977 | const Rect layerStackRect = display->getLayerStackSpaceRect(); |
| 978 | state->layerStackSpaceRect = |
| 979 | layerStackRect.isValid() ? layerStackRect.getSize() : display->getSize(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 980 | |
| 981 | return NO_ERROR; |
| 982 | } |
| 983 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 984 | status_t SurfaceFlinger::getStaticDisplayInfo(int64_t displayId, ui::StaticDisplayInfo* info) { |
| 985 | if (!info) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 986 | return BAD_VALUE; |
| 987 | } |
| 988 | |
| 989 | Mutex::Autolock lock(mStateLock); |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 990 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 991 | const auto displayOpt = mPhysicalDisplays.get(*id).and_then(getDisplayDeviceAndSnapshot()); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 992 | |
| 993 | if (!displayOpt) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 994 | return NAME_NOT_FOUND; |
| 995 | } |
| 996 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 997 | const auto& [display, snapshotRef] = *displayOpt; |
| 998 | const auto& snapshot = snapshotRef.get(); |
| 999 | |
| 1000 | info->connectionType = snapshot.connectionType(); |
| 1001 | info->deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1002 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1003 | if (mEmulatedDisplayDensity) { |
| 1004 | info->density = mEmulatedDisplayDensity; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1005 | } else { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1006 | info->density = info->connectionType == ui::DisplayConnectionType::Internal |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1007 | ? mInternalDisplayDensity |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1008 | : FALLBACK_DENSITY; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1009 | } |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 1010 | info->density /= ACONFIGURATION_DENSITY_MEDIUM; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1011 | |
| 1012 | info->secure = display->isSecure(); |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1013 | info->installOrientation = display->getPhysicalOrientation(); |
Vishnu Nair | d0a8965 | 2022-01-13 12:05:54 -0800 | [diff] [blame] | 1014 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1015 | return NO_ERROR; |
| 1016 | } |
| 1017 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1018 | void SurfaceFlinger::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo*& info, |
| 1019 | const sp<DisplayDevice>& display, |
| 1020 | const display::DisplaySnapshot& snapshot) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1021 | const auto& displayModes = snapshot.displayModes(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1022 | info->supportedDisplayModes.clear(); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1023 | info->supportedDisplayModes.reserve(displayModes.size()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1024 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1025 | for (const auto& [id, mode] : displayModes) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1026 | ui::DisplayMode outMode; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1027 | outMode.id = static_cast<int32_t>(id.value()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1028 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1029 | auto [width, height] = mode->getResolution(); |
| 1030 | auto [xDpi, yDpi] = mode->getDpi(); |
Yiwei Zhang | 27de5df | 2018-08-23 17:04:51 -0700 | [diff] [blame] | 1031 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1032 | if (const auto physicalOrientation = display->getPhysicalOrientation(); |
| 1033 | physicalOrientation == ui::ROTATION_90 || physicalOrientation == ui::ROTATION_270) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1034 | std::swap(width, height); |
| 1035 | std::swap(xDpi, yDpi); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1038 | outMode.resolution = ui::Size(width, height); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1039 | |
Huan Song | f7eeb10 | 2022-03-28 11:02:38 -0700 | [diff] [blame] | 1040 | outMode.xDpi = xDpi; |
| 1041 | outMode.yDpi = yDpi; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1042 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1043 | const nsecs_t period = mode->getVsyncPeriod(); |
| 1044 | outMode.refreshRate = Fps::fromPeriodNsecs(period).getValue(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1045 | |
Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 1046 | const auto vsyncConfigSet = |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 1047 | mVsyncConfiguration->getConfigsForRefreshRate(Fps::fromValue(outMode.refreshRate)); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1048 | outMode.appVsyncOffset = vsyncConfigSet.late.appOffset; |
| 1049 | outMode.sfVsyncOffset = vsyncConfigSet.late.sfOffset; |
| 1050 | outMode.group = mode->getGroup(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1051 | |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1052 | // This is how far in advance a buffer must be queued for |
| 1053 | // presentation at a given time. If you want a buffer to appear |
| 1054 | // on the screen at time N, you must submit the buffer before |
| 1055 | // (N - presentationDeadline). |
| 1056 | // |
| 1057 | // Normally it's one full refresh period (to give SF a chance to |
| 1058 | // latch the buffer), but this can be reduced by configuring a |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 1059 | // VsyncController offset. Any additional delays introduced by the hardware |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1060 | // composer or panel must be accounted for here. |
| 1061 | // |
| 1062 | // We add an additional 1ms to allow for processing time and |
| 1063 | // differences between the ideal and actual refresh rate. |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1064 | outMode.presentationDeadline = period - outMode.sfVsyncOffset + 1000000; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1065 | excludeDolbyVisionIf4k30Present(display->getHdrCapabilities().getSupportedHdrTypes(), |
| 1066 | outMode); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1067 | info->supportedDisplayModes.push_back(outMode); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1070 | info->supportedColorModes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1071 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1072 | const PhysicalDisplayId displayId = snapshot.displayId(); |
| 1073 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1074 | const auto mode = display->refreshRateSelector().getActiveMode(); |
| 1075 | info->activeDisplayModeId = mode.modePtr->getId().value(); |
| 1076 | info->renderFrameRate = mode.fps.getValue(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1077 | info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1078 | info->hdrCapabilities = filterOut4k30(display->getHdrCapabilities()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1079 | |
Marin Shalamanov | b173f75 | 2021-02-16 19:38:36 +0100 | [diff] [blame] | 1080 | info->autoLowLatencyModeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1081 | getHwComposer().hasDisplayCapability(displayId, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1082 | DisplayCapability::AUTO_LOW_LATENCY_MODE); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1083 | info->gameContentTypeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1084 | getHwComposer().supportsContentType(displayId, hal::ContentType::GAME); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1085 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1086 | info->preferredBootDisplayMode = static_cast<ui::DisplayModeId>(-1); |
Kriti Dang | ac0a74d | 2022-03-16 11:52:35 +0100 | [diff] [blame] | 1087 | |
| 1088 | if (getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG)) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1089 | if (const auto hwcId = getHwComposer().getPreferredBootDisplayMode(displayId)) { |
| 1090 | if (const auto modeId = snapshot.translateModeId(*hwcId)) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1091 | info->preferredBootDisplayMode = modeId->value(); |
| 1092 | } |
| 1093 | } |
| 1094 | } |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1095 | } |
Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame] | 1096 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1097 | status_t SurfaceFlinger::getDynamicDisplayInfoFromId(int64_t physicalDisplayId, |
| 1098 | ui::DynamicDisplayInfo* info) { |
| 1099 | if (!info) { |
| 1100 | return BAD_VALUE; |
| 1101 | } |
| 1102 | |
| 1103 | Mutex::Autolock lock(mStateLock); |
| 1104 | |
| 1105 | const auto id_ = |
| 1106 | DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(physicalDisplayId)); |
| 1107 | const auto displayOpt = mPhysicalDisplays.get(*id_).and_then(getDisplayDeviceAndSnapshot()); |
| 1108 | |
| 1109 | if (!displayOpt) { |
| 1110 | return NAME_NOT_FOUND; |
| 1111 | } |
| 1112 | |
| 1113 | const auto& [display, snapshotRef] = *displayOpt; |
| 1114 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
| 1115 | return NO_ERROR; |
| 1116 | } |
| 1117 | |
| 1118 | status_t SurfaceFlinger::getDynamicDisplayInfoFromToken(const sp<IBinder>& displayToken, |
| 1119 | ui::DynamicDisplayInfo* info) { |
| 1120 | if (!displayToken || !info) { |
| 1121 | return BAD_VALUE; |
| 1122 | } |
| 1123 | |
| 1124 | Mutex::Autolock lock(mStateLock); |
| 1125 | |
| 1126 | const auto displayOpt = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1127 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1128 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1129 | |
| 1130 | if (!displayOpt) { |
| 1131 | return NAME_NOT_FOUND; |
| 1132 | } |
| 1133 | |
| 1134 | const auto& [display, snapshotRef] = *displayOpt; |
| 1135 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1136 | return NO_ERROR; |
| 1137 | } |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 1138 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1139 | status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>& displayToken, |
| 1140 | DisplayStatInfo* outStats) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1141 | if (!outStats) { |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1142 | return BAD_VALUE; |
| 1143 | } |
| 1144 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1145 | std::optional<PhysicalDisplayId> displayIdOpt; |
| 1146 | { |
| 1147 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1148 | if (displayToken) { |
| 1149 | displayIdOpt = getPhysicalDisplayIdLocked(displayToken); |
| 1150 | if (!displayIdOpt) { |
| 1151 | ALOGW("%s: Invalid physical display token %p", __func__, displayToken.get()); |
| 1152 | return NAME_NOT_FOUND; |
| 1153 | } |
| 1154 | } else { |
| 1155 | // TODO (b/277364366): Clients should be updated to pass in the display they |
| 1156 | // want, rather than us picking an arbitrary one (the active display, in this |
| 1157 | // case). |
| 1158 | displayIdOpt = mActiveDisplayId; |
| 1159 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1160 | } |
| 1161 | |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1162 | const auto schedule = mScheduler->getVsyncSchedule(displayIdOpt); |
| 1163 | if (!schedule) { |
| 1164 | ALOGE("%s: Missing VSYNC schedule for display %s!", __func__, |
| 1165 | to_string(*displayIdOpt).c_str()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1166 | return NAME_NOT_FOUND; |
| 1167 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1168 | outStats->vsyncTime = schedule->vsyncDeadlineAfter(TimePoint::now()).ns(); |
| 1169 | outStats->vsyncPeriod = schedule->period().ns(); |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1170 | return NO_ERROR; |
| 1171 | } |
| 1172 | |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 1173 | void SurfaceFlinger::setDesiredActiveMode(display::DisplayModeRequest&& request, bool force) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1174 | const auto displayId = request.mode.modePtr->getPhysicalDisplayId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1175 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
| 1176 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1177 | const auto display = getDisplayDeviceLocked(displayId); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1178 | if (!display) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1179 | ALOGW("%s: display is no longer valid", __func__); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1180 | return; |
| 1181 | } |
| 1182 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1183 | const auto mode = request.mode; |
| 1184 | const bool emitEvent = request.emitEvent; |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 1185 | |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 1186 | switch (display->setDesiredActiveMode(DisplayDevice::ActiveModeInfo(std::move(request)), |
| 1187 | force)) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1188 | case DisplayDevice::DesiredActiveModeAction::InitiateDisplayModeSwitch: |
Ady Abraham | 95a37e2 | 2023-01-18 22:57:28 -0800 | [diff] [blame] | 1189 | // Set the render rate as setDesiredActiveMode updated it. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1190 | mScheduler->setRenderRate(displayId, |
| 1191 | display->refreshRateSelector().getActiveMode().fps); |
Ady Abraham | 95a37e2 | 2023-01-18 22:57:28 -0800 | [diff] [blame] | 1192 | |
| 1193 | // Schedule a new frame to initiate the display mode switch. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1194 | scheduleComposite(FrameHint::kNone); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1195 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1196 | // Start receiving vsync samples now, so that we can detect a period |
| 1197 | // switch. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1198 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, |
| 1199 | mode.modePtr->getFps()); |
| 1200 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1201 | // As we called to set period, we will call to onRefreshRateChangeCompleted once |
| 1202 | // VsyncController model is locked. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1203 | mScheduler->modulateVsync(displayId, &VsyncModulator::onRefreshRateChangeInitiated); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1204 | |
| 1205 | if (displayId == mActiveDisplayId) { |
| 1206 | updatePhaseConfiguration(mode.fps); |
| 1207 | } |
| 1208 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1209 | mScheduler->setModeChangePending(true); |
| 1210 | break; |
| 1211 | case DisplayDevice::DesiredActiveModeAction::InitiateRenderRateSwitch: |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1212 | mScheduler->setRenderRate(displayId, mode.fps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1213 | |
| 1214 | if (displayId == mActiveDisplayId) { |
| 1215 | updatePhaseConfiguration(mode.fps); |
| 1216 | mRefreshRateStats->setRefreshRate(mode.fps); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1217 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1218 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1219 | if (emitEvent) { |
| 1220 | dispatchDisplayModeChangeEvent(displayId, mode); |
| 1221 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1222 | break; |
| 1223 | case DisplayDevice::DesiredActiveModeAction::None: |
| 1224 | break; |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1225 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1226 | } |
| 1227 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1228 | status_t SurfaceFlinger::setActiveModeFromBackdoor(const sp<display::DisplayToken>& displayToken, |
| 1229 | DisplayModeId modeId) { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1230 | ATRACE_CALL(); |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1231 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 1232 | if (!displayToken) { |
| 1233 | return BAD_VALUE; |
| 1234 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1235 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1236 | const char* const whence = __func__; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1237 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1238 | const auto displayOpt = |
| 1239 | FTL_FAKE_GUARD(mStateLock, |
| 1240 | ftl::find_if(mPhysicalDisplays, |
| 1241 | PhysicalDisplay::hasToken(displayToken)) |
| 1242 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1243 | .and_then(getDisplayDeviceAndSnapshot())); |
| 1244 | if (!displayOpt) { |
| 1245 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1246 | return NAME_NOT_FOUND; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1247 | } |
| 1248 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1249 | const auto& [display, snapshotRef] = *displayOpt; |
| 1250 | const auto& snapshot = snapshotRef.get(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1251 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1252 | const auto fpsOpt = snapshot.displayModes().get(modeId).transform( |
| 1253 | [](const DisplayModePtr& mode) { return mode->getFps(); }); |
| 1254 | |
| 1255 | if (!fpsOpt) { |
| 1256 | ALOGE("%s: Invalid mode %d for display %s", whence, modeId.value(), |
| 1257 | to_string(snapshot.displayId()).c_str()); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1258 | return BAD_VALUE; |
| 1259 | } |
| 1260 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1261 | const Fps fps = *fpsOpt; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1262 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1263 | // Keep the old switching type. |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1264 | const bool allowGroupSwitching = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1265 | display->refreshRateSelector().getCurrentPolicy().allowGroupSwitching; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1266 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1267 | const scheduler::RefreshRateSelector::DisplayManagerPolicy policy{modeId, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 1268 | {fps, fps}, |
| 1269 | allowGroupSwitching}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1270 | |
| 1271 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1272 | }); |
| 1273 | |
| 1274 | return future.get(); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1275 | } |
| 1276 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1277 | void SurfaceFlinger::finalizeDisplayModeChange(DisplayDevice& display) { |
| 1278 | const auto displayId = display.getPhysicalId(); |
| 1279 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1280 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1281 | const auto upcomingModeInfo = display.getUpcomingActiveMode(); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1282 | if (!upcomingModeInfo.modeOpt) { |
Ady Abraham | faac6da | 2021-07-15 10:04:40 -0700 | [diff] [blame] | 1283 | // There is no pending mode change. This can happen if the active |
| 1284 | // display changed and the mode change happened on a different display. |
| 1285 | return; |
| 1286 | } |
| 1287 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1288 | if (display.getActiveMode().modePtr->getResolution() != |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1289 | upcomingModeInfo.modeOpt->modePtr->getResolution()) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1290 | auto& state = mCurrentState.displays.editValueFor(display.getDisplayToken()); |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1291 | // We need to generate new sequenceId in order to recreate the display (and this |
| 1292 | // way the framebuffer). |
| 1293 | state.sequenceId = DisplayDeviceState{}.sequenceId; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1294 | state.physical->activeMode = upcomingModeInfo.modeOpt->modePtr.get(); |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1295 | processDisplayChangesLocked(); |
| 1296 | |
| 1297 | // processDisplayChangesLocked will update all necessary components so we're done here. |
| 1298 | return; |
| 1299 | } |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 1300 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1301 | const auto& activeMode = *upcomingModeInfo.modeOpt; |
| 1302 | display.finalizeModeChange(activeMode.modePtr->getId(), activeMode.modePtr->getFps(), |
| 1303 | activeMode.fps); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1304 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1305 | if (displayId == mActiveDisplayId) { |
| 1306 | mRefreshRateStats->setRefreshRate(activeMode.fps); |
| 1307 | updatePhaseConfiguration(activeMode.fps); |
| 1308 | } |
Dominik Laskowski | 22488f6 | 2019-03-28 09:53:04 -0700 | [diff] [blame] | 1309 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 1310 | if (upcomingModeInfo.event != scheduler::DisplayModeEvent::None) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1311 | dispatchDisplayModeChangeEvent(displayId, activeMode); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 1312 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1313 | } |
| 1314 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1315 | void SurfaceFlinger::clearDesiredActiveModeState(const sp<DisplayDevice>& display) { |
| 1316 | display->clearDesiredActiveModeState(); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 1317 | if (display->getPhysicalId() == mActiveDisplayId) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1318 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1319 | mScheduler->setModeChangePending(false); |
| 1320 | } |
Ady Abraham | 53852a5 | 2019-05-28 18:07:44 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1323 | void SurfaceFlinger::desiredActiveModeChangeDone(const sp<DisplayDevice>& display) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1324 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
| 1325 | const auto& modeOpt = desiredActiveMode->modeOpt; |
| 1326 | const auto displayId = modeOpt->modePtr->getPhysicalDisplayId(); |
| 1327 | const auto displayFps = modeOpt->modePtr->getFps(); |
| 1328 | const auto renderFps = modeOpt->fps; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1329 | clearDesiredActiveModeState(display); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1330 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, displayFps); |
| 1331 | mScheduler->setRenderRate(displayId, renderFps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1332 | |
| 1333 | if (displayId == mActiveDisplayId) { |
| 1334 | updatePhaseConfiguration(renderFps); |
| 1335 | } |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1336 | } |
| 1337 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1338 | void SurfaceFlinger::initiateDisplayModeChanges() { |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1339 | ATRACE_CALL(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1340 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1341 | std::optional<PhysicalDisplayId> displayToUpdateImmediately; |
| 1342 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1343 | for (const auto& [id, physical] : mPhysicalDisplays) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1344 | const auto display = getDisplayDeviceLocked(id); |
| 1345 | if (!display) continue; |
| 1346 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1347 | // Store the local variable to release the lock. |
| 1348 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
| 1349 | if (!desiredActiveMode) { |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 1350 | // No desired active mode pending to be applied. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1351 | continue; |
| 1352 | } |
| 1353 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1354 | if (!display->isPoweredOn()) { |
| 1355 | // Display is no longer powered on, so abort the mode change. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1356 | clearDesiredActiveModeState(display); |
| 1357 | continue; |
| 1358 | } |
| 1359 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1360 | const auto desiredModeId = desiredActiveMode->modeOpt->modePtr->getId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1361 | const auto displayModePtrOpt = physical.snapshot().displayModes().get(desiredModeId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1362 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1363 | if (!displayModePtrOpt) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1364 | ALOGW("Desired display mode is no longer supported. Mode ID = %d", |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1365 | desiredModeId.value()); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1366 | clearDesiredActiveModeState(display); |
| 1367 | continue; |
| 1368 | } |
| 1369 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1370 | ALOGV("%s changing active mode to %d(%s) for display %s", __func__, desiredModeId.value(), |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1371 | to_string(displayModePtrOpt->get()->getFps()).c_str(), |
| 1372 | to_string(display->getId()).c_str()); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1373 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1374 | if (display->getActiveMode() == desiredActiveMode->modeOpt) { |
Marin Shalamanov | 85b2bdf | 2021-11-03 14:31:21 +0100 | [diff] [blame] | 1375 | // we are already in the requested mode, there is nothing left to do |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1376 | desiredActiveModeChangeDone(display); |
| 1377 | continue; |
| 1378 | } |
| 1379 | |
| 1380 | // Desired active mode was set, it is different than the mode currently in use, however |
| 1381 | // allowed modes might have changed by the time we process the refresh. |
| 1382 | // Make sure the desired mode is still allowed |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1383 | const auto displayModeAllowed = |
| 1384 | display->refreshRateSelector().isModeAllowed(*desiredActiveMode->modeOpt); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1385 | if (!displayModeAllowed) { |
Marin Shalamanov | dd00c00 | 2021-11-04 16:54:38 +0100 | [diff] [blame] | 1386 | clearDesiredActiveModeState(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1387 | continue; |
| 1388 | } |
| 1389 | |
| 1390 | // TODO(b/142753666) use constrains |
| 1391 | hal::VsyncPeriodChangeConstraints constraints; |
| 1392 | constraints.desiredTimeNanos = systemTime(); |
| 1393 | constraints.seamlessRequired = false; |
| 1394 | hal::VsyncPeriodChangeTimeline outTimeline; |
| 1395 | |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 1396 | const auto status = |
| 1397 | display->initiateModeChange(*desiredActiveMode, constraints, &outTimeline); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1398 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1399 | if (status != NO_ERROR) { |
| 1400 | // initiateModeChange may fail if a hotplug event is just about |
| 1401 | // to be sent. We just log the error in this case. |
| 1402 | ALOGW("initiateModeChange failed: %d", status); |
| 1403 | continue; |
| 1404 | } |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1405 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1406 | display->refreshRateSelector().onModeChangeInitiated(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1407 | mScheduler->onNewVsyncPeriodChangeTimeline(outTimeline); |
| 1408 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1409 | if (outTimeline.refreshRequired) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 1410 | scheduleComposite(FrameHint::kNone); |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1411 | } else { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1412 | // TODO(b/255635711): Remove `displayToUpdateImmediately` to `finalizeDisplayModeChange` |
| 1413 | // for all displays. This was only needed when the loop iterated over `mDisplays` rather |
| 1414 | // than `mPhysicalDisplays`. |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1415 | displayToUpdateImmediately = display->getPhysicalId(); |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | if (displayToUpdateImmediately) { |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1420 | const auto display = getDisplayDeviceLocked(*displayToUpdateImmediately); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1421 | finalizeDisplayModeChange(*display); |
| 1422 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1423 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1424 | if (desiredActiveMode && display->getActiveMode() == desiredActiveMode->modeOpt) { |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1425 | desiredActiveModeChangeDone(display); |
| 1426 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1427 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1428 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1429 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1430 | void SurfaceFlinger::disableExpensiveRendering() { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1431 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1432 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1433 | ATRACE_NAME(whence); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1434 | if (mPowerAdvisor->isUsingExpensiveRendering()) { |
Dominik Laskowski | bc6c860 | 2022-01-11 08:53:24 -0800 | [diff] [blame] | 1435 | for (const auto& [_, display] : mDisplays) { |
| 1436 | constexpr bool kDisable = false; |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1437 | mPowerAdvisor->setExpensiveRenderingExpected(display->getId(), kDisable); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1438 | } |
| 1439 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1440 | }); |
| 1441 | |
| 1442 | future.wait(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1445 | status_t SurfaceFlinger::getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1446 | ui::DisplayPrimaries& primaries) { |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1447 | if (!displayToken) { |
| 1448 | return BAD_VALUE; |
| 1449 | } |
| 1450 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1451 | Mutex::Autolock lock(mStateLock); |
| 1452 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1453 | const auto display = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1454 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>); |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1455 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1456 | return NAME_NOT_FOUND; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1457 | } |
| 1458 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1459 | if (!display.transform(&PhysicalDisplay::isInternal).value()) { |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1460 | return INVALID_OPERATION; |
| 1461 | } |
| 1462 | |
| 1463 | // 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] | 1464 | primaries = mInternalDisplayPrimaries; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1465 | return NO_ERROR; |
| 1466 | } |
| 1467 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1468 | status_t SurfaceFlinger::setActiveColorMode(const sp<IBinder>& displayToken, ui::ColorMode mode) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1469 | if (!displayToken) { |
| 1470 | return BAD_VALUE; |
| 1471 | } |
| 1472 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1473 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1474 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1475 | const auto displayOpt = |
| 1476 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1477 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1478 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1479 | |
| 1480 | if (!displayOpt) { |
| 1481 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1482 | return NAME_NOT_FOUND; |
| 1483 | } |
| 1484 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1485 | const auto& [display, snapshotRef] = *displayOpt; |
| 1486 | const auto& snapshot = snapshotRef.get(); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1487 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1488 | const auto modes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1489 | const bool exists = std::find(modes.begin(), modes.end(), mode) != modes.end(); |
| 1490 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1491 | if (mode < ui::ColorMode::NATIVE || !exists) { |
| 1492 | ALOGE("%s: Invalid color mode %s (%d) for display %s", whence, |
| 1493 | decodeColorMode(mode).c_str(), mode, to_string(snapshot.displayId()).c_str()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1494 | return BAD_VALUE; |
| 1495 | } |
| 1496 | |
| 1497 | display->getCompositionDisplay()->setColorProfile( |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 1498 | {mode, Dataspace::UNKNOWN, RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1499 | |
| 1500 | return NO_ERROR; |
| 1501 | }); |
| 1502 | |
Dominik Laskowski | 0a5f921 | 2021-08-05 17:00:04 -0700 | [diff] [blame] | 1503 | // TODO(b/195698395): Propagate error. |
| 1504 | future.wait(); |
| 1505 | return NO_ERROR; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1506 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1507 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1508 | status_t SurfaceFlinger::getBootDisplayModeSupport(bool* outSupport) const { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1509 | auto future = mScheduler->schedule( |
| 1510 | [this] { return getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG); }); |
| 1511 | |
| 1512 | *outSupport = future.get(); |
| 1513 | return NO_ERROR; |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1514 | } |
| 1515 | |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1516 | status_t SurfaceFlinger::getOverlaySupport(gui::OverlayProperties* outProperties) const { |
| 1517 | const auto& aidlProperties = getHwComposer().getOverlaySupport(); |
| 1518 | // convert aidl OverlayProperties to gui::OverlayProperties |
| 1519 | outProperties->combinations.reserve(aidlProperties.combinations.size()); |
| 1520 | for (const auto& combination : aidlProperties.combinations) { |
| 1521 | std::vector<int32_t> pixelFormats; |
| 1522 | pixelFormats.reserve(combination.pixelFormats.size()); |
| 1523 | std::transform(combination.pixelFormats.cbegin(), combination.pixelFormats.cend(), |
| 1524 | std::back_inserter(pixelFormats), |
| 1525 | [](const auto& val) { return static_cast<int32_t>(val); }); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1526 | std::vector<int32_t> standards; |
| 1527 | standards.reserve(combination.standards.size()); |
| 1528 | std::transform(combination.standards.cbegin(), combination.standards.cend(), |
| 1529 | std::back_inserter(standards), |
| 1530 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1531 | std::vector<int32_t> transfers; |
| 1532 | transfers.reserve(combination.transfers.size()); |
| 1533 | std::transform(combination.transfers.cbegin(), combination.transfers.cend(), |
| 1534 | std::back_inserter(transfers), |
| 1535 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1536 | std::vector<int32_t> ranges; |
| 1537 | ranges.reserve(combination.ranges.size()); |
| 1538 | std::transform(combination.ranges.cbegin(), combination.ranges.cend(), |
| 1539 | std::back_inserter(ranges), |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1540 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1541 | gui::OverlayProperties::SupportedBufferCombinations outCombination; |
| 1542 | outCombination.pixelFormats = std::move(pixelFormats); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1543 | outCombination.standards = std::move(standards); |
| 1544 | outCombination.transfers = std::move(transfers); |
| 1545 | outCombination.ranges = std::move(ranges); |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1546 | outProperties->combinations.emplace_back(outCombination); |
| 1547 | } |
Sally Qi | 8b4cb55 | 2022-12-14 16:24:31 -0800 | [diff] [blame] | 1548 | outProperties->supportMixedColorSpaces = aidlProperties.supportMixedColorSpaces; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 1549 | return NO_ERROR; |
| 1550 | } |
| 1551 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1552 | status_t SurfaceFlinger::setBootDisplayMode(const sp<display::DisplayToken>& displayToken, |
| 1553 | DisplayModeId modeId) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1554 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1555 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1556 | const auto snapshotOpt = |
| 1557 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1558 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1559 | .transform(&PhysicalDisplay::snapshotRef); |
| 1560 | |
| 1561 | if (!snapshotOpt) { |
| 1562 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1563 | return NAME_NOT_FOUND; |
| 1564 | } |
Kriti Dang | f50d677 | 2022-02-18 15:09:12 +0100 | [diff] [blame] | 1565 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1566 | const auto& snapshot = snapshotOpt->get(); |
| 1567 | const auto hwcIdOpt = snapshot.displayModes().get(modeId).transform( |
| 1568 | [](const DisplayModePtr& mode) { return mode->getHwcId(); }); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1569 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1570 | if (!hwcIdOpt) { |
| 1571 | ALOGE("%s: Invalid mode %d for display %s", whence, modeId.value(), |
| 1572 | to_string(snapshot.displayId()).c_str()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1573 | return BAD_VALUE; |
| 1574 | } |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1575 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1576 | return getHwComposer().setBootDisplayMode(snapshot.displayId(), *hwcIdOpt); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1577 | }); |
| 1578 | return future.get(); |
| 1579 | } |
| 1580 | |
| 1581 | status_t SurfaceFlinger::clearBootDisplayMode(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1582 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1583 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1584 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1585 | return getHwComposer().clearBootDisplayMode(*displayId); |
| 1586 | } else { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1587 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1588 | return BAD_VALUE; |
| 1589 | } |
| 1590 | }); |
| 1591 | return future.get(); |
| 1592 | } |
| 1593 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1594 | status_t SurfaceFlinger::getHdrConversionCapabilities( |
| 1595 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) const { |
| 1596 | bool hdrOutputConversionSupport; |
| 1597 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1598 | if (hdrOutputConversionSupport == false) { |
| 1599 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1600 | return INVALID_OPERATION; |
| 1601 | } |
| 1602 | const auto aidlConversionCapability = getHwComposer().getHdrConversionCapabilities(); |
| 1603 | for (auto capability : aidlConversionCapability) { |
| 1604 | gui::HdrConversionCapability tempCapability; |
Kriti Dang | 3c243dc | 2023-03-07 15:00:13 +0100 | [diff] [blame] | 1605 | tempCapability.sourceType = static_cast<int>(capability.sourceType); |
| 1606 | tempCapability.outputType = static_cast<int>(capability.outputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1607 | tempCapability.addsLatency = capability.addsLatency; |
| 1608 | hdrConversionCapabilities->push_back(tempCapability); |
| 1609 | } |
| 1610 | return NO_ERROR; |
| 1611 | } |
| 1612 | |
| 1613 | status_t SurfaceFlinger::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1614 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 1615 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1616 | bool hdrOutputConversionSupport; |
| 1617 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1618 | if (hdrOutputConversionSupport == false) { |
| 1619 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1620 | return INVALID_OPERATION; |
| 1621 | } |
| 1622 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) mutable -> status_t { |
| 1623 | using AidlHdrConversionStrategy = |
| 1624 | aidl::android::hardware::graphics::common::HdrConversionStrategy; |
| 1625 | using GuiHdrConversionStrategyTag = gui::HdrConversionStrategy::Tag; |
| 1626 | AidlHdrConversionStrategy aidlConversionStrategy; |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1627 | status_t status; |
| 1628 | aidl::android::hardware::graphics::common::Hdr aidlPreferredHdrOutputType; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1629 | switch (hdrConversionStrategy.getTag()) { |
| 1630 | case GuiHdrConversionStrategyTag::passthrough: { |
| 1631 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::passthrough>( |
| 1632 | hdrConversionStrategy.get<GuiHdrConversionStrategyTag::passthrough>()); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1633 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1634 | &aidlPreferredHdrOutputType); |
| 1635 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1636 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1637 | } |
| 1638 | case GuiHdrConversionStrategyTag::autoAllowedHdrTypes: { |
| 1639 | auto autoHdrTypes = |
| 1640 | hdrConversionStrategy |
| 1641 | .get<GuiHdrConversionStrategyTag::autoAllowedHdrTypes>(); |
| 1642 | std::vector<aidl::android::hardware::graphics::common::Hdr> aidlAutoHdrTypes; |
| 1643 | for (auto type : autoHdrTypes) { |
| 1644 | aidlAutoHdrTypes.push_back( |
| 1645 | static_cast<aidl::android::hardware::graphics::common::Hdr>(type)); |
| 1646 | } |
| 1647 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::autoAllowedHdrTypes>( |
| 1648 | aidlAutoHdrTypes); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1649 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1650 | &aidlPreferredHdrOutputType); |
| 1651 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1652 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1653 | } |
| 1654 | case GuiHdrConversionStrategyTag::forceHdrConversion: { |
| 1655 | auto forceHdrConversion = |
| 1656 | hdrConversionStrategy |
| 1657 | .get<GuiHdrConversionStrategyTag::forceHdrConversion>(); |
| 1658 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::forceHdrConversion>( |
| 1659 | static_cast<aidl::android::hardware::graphics::common::Hdr>( |
| 1660 | forceHdrConversion)); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1661 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1662 | &aidlPreferredHdrOutputType); |
| 1663 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1664 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1665 | } |
| 1666 | } |
| 1667 | }); |
| 1668 | return future.get(); |
| 1669 | } |
| 1670 | |
| 1671 | status_t SurfaceFlinger::getHdrOutputConversionSupport(bool* outSupport) const { |
| 1672 | auto future = mScheduler->schedule([this] { |
| 1673 | return getHwComposer().hasCapability(Capability::HDR_OUTPUT_CONVERSION_CONFIG); |
| 1674 | }); |
| 1675 | |
| 1676 | *outSupport = future.get(); |
| 1677 | return NO_ERROR; |
| 1678 | } |
| 1679 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1680 | void SurfaceFlinger::setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1681 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1682 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1683 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1684 | getHwComposer().setAutoLowLatencyMode(*displayId, on); |
| 1685 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1686 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1687 | } |
| 1688 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1689 | } |
| 1690 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1691 | void SurfaceFlinger::setGameContentType(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1692 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1693 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1694 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1695 | const auto type = on ? hal::ContentType::GAME : hal::ContentType::NONE; |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1696 | getHwComposer().setContentType(*displayId, type); |
| 1697 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1698 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1699 | } |
| 1700 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1701 | } |
| 1702 | |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1703 | status_t SurfaceFlinger::overrideHdrTypes(const sp<IBinder>& displayToken, |
| 1704 | const std::vector<ui::Hdr>& hdrTypes) { |
| 1705 | Mutex::Autolock lock(mStateLock); |
| 1706 | |
| 1707 | auto display = getDisplayDeviceLocked(displayToken); |
| 1708 | if (!display) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1709 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1710 | return NAME_NOT_FOUND; |
| 1711 | } |
| 1712 | |
| 1713 | display->overrideHdrTypes(hdrTypes); |
| 1714 | dispatchDisplayHotplugEvent(display->getPhysicalId(), true /* connected */); |
| 1715 | return NO_ERROR; |
| 1716 | } |
| 1717 | |
Huihong Luo | 30aa437 | 2022-10-03 14:54:12 -0700 | [diff] [blame] | 1718 | status_t SurfaceFlinger::onPullAtom(const int32_t atomId, std::vector<uint8_t>* pulledData, |
| 1719 | bool* success) { |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 1720 | *success = mTimeStats->onPullAtom(atomId, pulledData); |
| 1721 | return NO_ERROR; |
| 1722 | } |
| 1723 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1724 | status_t SurfaceFlinger::getDisplayedContentSamplingAttributes(const sp<IBinder>& displayToken, |
| 1725 | ui::PixelFormat* outFormat, |
| 1726 | ui::Dataspace* outDataspace, |
| 1727 | uint8_t* outComponentMask) const { |
| 1728 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 1729 | return BAD_VALUE; |
| 1730 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1731 | |
| 1732 | Mutex::Autolock lock(mStateLock); |
| 1733 | |
| 1734 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1735 | if (!displayId) { |
| 1736 | return NAME_NOT_FOUND; |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1737 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1738 | |
| 1739 | return getHwComposer().getDisplayedContentSamplingAttributes(*displayId, outFormat, |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1740 | outDataspace, outComponentMask); |
| 1741 | } |
| 1742 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1743 | status_t SurfaceFlinger::setDisplayContentSamplingEnabled(const sp<IBinder>& displayToken, |
| 1744 | bool enable, uint8_t componentMask, |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1745 | uint64_t maxFrames) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1746 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1747 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1748 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1749 | return getHwComposer().setDisplayContentSamplingEnabled(*displayId, enable, |
| 1750 | componentMask, maxFrames); |
| 1751 | } else { |
| 1752 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
| 1753 | return NAME_NOT_FOUND; |
| 1754 | } |
| 1755 | }); |
| 1756 | |
| 1757 | return future.get(); |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1758 | } |
| 1759 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1760 | status_t SurfaceFlinger::getDisplayedContentSample(const sp<IBinder>& displayToken, |
| 1761 | uint64_t maxFrames, uint64_t timestamp, |
| 1762 | DisplayedFrameStats* outStats) const { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1763 | Mutex::Autolock lock(mStateLock); |
| 1764 | |
| 1765 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1766 | if (!displayId) { |
| 1767 | return NAME_NOT_FOUND; |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1770 | return getHwComposer().getDisplayedContentSample(*displayId, maxFrames, timestamp, outStats); |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
Peiyong Lin | 3c2791e | 2019-01-14 17:05:18 -0800 | [diff] [blame] | 1773 | status_t SurfaceFlinger::getProtectedContentSupport(bool* outSupported) const { |
| 1774 | if (!outSupported) { |
| 1775 | return BAD_VALUE; |
| 1776 | } |
| 1777 | *outSupported = getRenderEngine().supportsProtectedContent(); |
| 1778 | return NO_ERROR; |
| 1779 | } |
| 1780 | |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1781 | status_t SurfaceFlinger::isWideColorDisplay(const sp<IBinder>& displayToken, |
| 1782 | bool* outIsWideColorDisplay) const { |
| 1783 | if (!displayToken || !outIsWideColorDisplay) { |
| 1784 | return BAD_VALUE; |
| 1785 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1786 | |
| 1787 | Mutex::Autolock lock(mStateLock); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1788 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1789 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1790 | return NAME_NOT_FOUND; |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1791 | } |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 1792 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1793 | *outIsWideColorDisplay = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1794 | display->isPrimary() ? mSupportsWideColor : display->hasWideColorGamut(); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1795 | return NO_ERROR; |
| 1796 | } |
| 1797 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 1798 | status_t SurfaceFlinger::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1799 | outLayers->clear(); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1800 | auto future = mScheduler->schedule([=] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1801 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Vishnu Nair | 43bccf8 | 2020-06-05 10:53:37 -0700 | [diff] [blame] | 1802 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 1803 | outLayers->push_back(layer->getLayerDebugInfo(display.get())); |
| 1804 | }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1805 | }); |
| 1806 | |
| 1807 | future.wait(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1808 | return NO_ERROR; |
| 1809 | } |
| 1810 | |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1811 | status_t SurfaceFlinger::getCompositionPreference( |
| 1812 | Dataspace* outDataspace, ui::PixelFormat* outPixelFormat, |
| 1813 | Dataspace* outWideColorGamutDataspace, |
| 1814 | ui::PixelFormat* outWideColorGamutPixelFormat) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1815 | *outDataspace = mDefaultCompositionDataspace; |
| 1816 | *outPixelFormat = defaultCompositionPixelFormat; |
| 1817 | *outWideColorGamutDataspace = mWideColorGamutCompositionDataspace; |
| 1818 | *outWideColorGamutPixelFormat = wideColorGamutCompositionPixelFormat; |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 1819 | return NO_ERROR; |
| 1820 | } |
| 1821 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1822 | status_t SurfaceFlinger::addRegionSamplingListener(const Rect& samplingArea, |
| 1823 | const sp<IBinder>& stopLayerHandle, |
| 1824 | const sp<IRegionSamplingListener>& listener) { |
Leon Scroggins III | ae16b80 | 2022-01-12 11:42:05 -0500 | [diff] [blame] | 1825 | if (!listener || samplingArea == Rect::INVALID_RECT || samplingArea.isEmpty()) { |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1826 | return BAD_VALUE; |
| 1827 | } |
Alec Mouri | 9a02eda | 2020-04-21 17:39:34 -0700 | [diff] [blame] | 1828 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 1829 | // LayerHandle::getLayer promotes the layer object in a binder thread but we will not destroy |
| 1830 | // 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] | 1831 | const sp<Layer> stopLayer = LayerHandle::getLayer(stopLayerHandle); |
| 1832 | mRegionSamplingThread->addListener(samplingArea, |
| 1833 | stopLayer ? stopLayer->getSequence() : UNASSIGNED_LAYER_ID, |
| 1834 | listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1835 | return NO_ERROR; |
| 1836 | } |
| 1837 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1838 | status_t SurfaceFlinger::removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) { |
tangrobin | af45f01 | 2019-02-26 18:10:10 +0800 | [diff] [blame] | 1839 | if (!listener) { |
| 1840 | return BAD_VALUE; |
| 1841 | } |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1842 | mRegionSamplingThread->removeListener(listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1843 | return NO_ERROR; |
| 1844 | } |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1845 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1846 | status_t SurfaceFlinger::addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) { |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1847 | if (!listener) { |
| 1848 | return BAD_VALUE; |
| 1849 | } |
| 1850 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1851 | mFpsReporter->addListener(listener, taskId); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1852 | return NO_ERROR; |
| 1853 | } |
| 1854 | |
| 1855 | status_t SurfaceFlinger::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 1856 | if (!listener) { |
| 1857 | return BAD_VALUE; |
| 1858 | } |
| 1859 | mFpsReporter->removeListener(listener); |
| 1860 | return NO_ERROR; |
| 1861 | } |
| 1862 | |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 1863 | status_t SurfaceFlinger::addTunnelModeEnabledListener( |
| 1864 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1865 | if (!listener) { |
| 1866 | return BAD_VALUE; |
| 1867 | } |
| 1868 | |
| 1869 | mTunnelModeEnabledReporter->addListener(listener); |
| 1870 | return NO_ERROR; |
| 1871 | } |
| 1872 | |
| 1873 | status_t SurfaceFlinger::removeTunnelModeEnabledListener( |
| 1874 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1875 | if (!listener) { |
| 1876 | return BAD_VALUE; |
| 1877 | } |
| 1878 | |
| 1879 | mTunnelModeEnabledReporter->removeListener(listener); |
| 1880 | return NO_ERROR; |
| 1881 | } |
| 1882 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1883 | status_t SurfaceFlinger::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 1884 | bool* outSupport) const { |
| 1885 | if (!displayToken || !outSupport) { |
| 1886 | return BAD_VALUE; |
| 1887 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1888 | |
| 1889 | Mutex::Autolock lock(mStateLock); |
| 1890 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1891 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1892 | if (!displayId) { |
| 1893 | return NAME_NOT_FOUND; |
| 1894 | } |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1895 | *outSupport = getHwComposer().hasDisplayCapability(*displayId, DisplayCapability::BRIGHTNESS); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1896 | return NO_ERROR; |
| 1897 | } |
| 1898 | |
John Reck | 22be696 | 2021-03-10 12:59:54 -0500 | [diff] [blame] | 1899 | status_t SurfaceFlinger::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 1900 | const gui::DisplayBrightness& brightness) { |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1901 | if (!displayToken) { |
| 1902 | return BAD_VALUE; |
| 1903 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1904 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1905 | const char* const whence = __func__; |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 1906 | return ftl::Future(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 1907 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1908 | const bool supportsDisplayBrightnessCommand = |
| 1909 | getHwComposer().getComposer()->isSupported( |
| 1910 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 1911 | // If we support applying display brightness as a command, then we also support |
| 1912 | // dimming SDR layers. |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1913 | if (supportsDisplayBrightnessCommand) { |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1914 | auto compositionDisplay = display->getCompositionDisplay(); |
| 1915 | float currentDimmingRatio = |
| 1916 | compositionDisplay->editState().sdrWhitePointNits / |
| 1917 | compositionDisplay->editState().displayBrightnessNits; |
Sally Qi | 0ea47b5 | 2023-06-22 13:27:20 -0700 | [diff] [blame] | 1918 | static constexpr float kDimmingThreshold = 0.02f; |
| 1919 | if (brightness.sdrWhitePointNits == 0.f || |
| 1920 | abs(brightness.sdrWhitePointNits - brightness.displayBrightnessNits) / |
| 1921 | brightness.sdrWhitePointNits >= |
| 1922 | kDimmingThreshold) { |
| 1923 | // to optimize, skip brightness setter if the brightness difference ratio |
| 1924 | // is lower than threshold |
| 1925 | compositionDisplay |
| 1926 | ->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 1927 | brightness.displayBrightnessNits); |
| 1928 | } else { |
| 1929 | compositionDisplay->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 1930 | brightness.sdrWhitePointNits); |
| 1931 | } |
| 1932 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1933 | FTL_FAKE_GUARD(kMainThreadContext, |
| 1934 | display->stageBrightness(brightness.displayBrightness)); |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 1935 | float currentHdrSdrRatio = |
| 1936 | compositionDisplay->editState().displayBrightnessNits / |
| 1937 | compositionDisplay->editState().sdrWhitePointNits; |
| 1938 | FTL_FAKE_GUARD(kMainThreadContext, |
| 1939 | display->updateHdrSdrRatioOverlayRatio(currentHdrSdrRatio)); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1940 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1941 | if (brightness.sdrWhitePointNits / brightness.displayBrightnessNits != |
| 1942 | currentDimmingRatio) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1943 | scheduleComposite(FrameHint::kNone); |
| 1944 | } else { |
| 1945 | scheduleCommit(FrameHint::kNone); |
| 1946 | } |
| 1947 | return ftl::yield<status_t>(OK); |
| 1948 | } else { |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1949 | return getHwComposer() |
| 1950 | .setDisplayBrightness(display->getPhysicalId(), |
| 1951 | brightness.displayBrightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 1952 | brightness.displayBrightnessNits, |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1953 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 1954 | .applyImmediately = true}); |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 1955 | } |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1956 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1957 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1958 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 1959 | return ftl::yield<status_t>(NAME_NOT_FOUND); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1960 | } |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 1961 | })) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 1962 | .then([](ftl::Future<status_t> task) { return task; }) |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1963 | .get(); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 1966 | status_t SurfaceFlinger::addHdrLayerInfoListener(const sp<IBinder>& displayToken, |
| 1967 | const sp<gui::IHdrLayerInfoListener>& listener) { |
| 1968 | if (!displayToken) { |
| 1969 | return BAD_VALUE; |
| 1970 | } |
| 1971 | |
| 1972 | Mutex::Autolock lock(mStateLock); |
| 1973 | |
| 1974 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1975 | if (!display) { |
| 1976 | return NAME_NOT_FOUND; |
| 1977 | } |
| 1978 | const auto displayId = display->getId(); |
| 1979 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 1980 | if (!hdrInfoReporter) { |
| 1981 | hdrInfoReporter = sp<HdrLayerInfoReporter>::make(); |
| 1982 | } |
| 1983 | hdrInfoReporter->addListener(listener); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 1984 | |
| 1985 | |
| 1986 | mAddingHDRLayerInfoListener = true; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 1987 | return OK; |
| 1988 | } |
| 1989 | |
| 1990 | status_t SurfaceFlinger::removeHdrLayerInfoListener( |
| 1991 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 1992 | if (!displayToken) { |
| 1993 | return BAD_VALUE; |
| 1994 | } |
| 1995 | |
| 1996 | Mutex::Autolock lock(mStateLock); |
| 1997 | |
| 1998 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1999 | if (!display) { |
| 2000 | return NAME_NOT_FOUND; |
| 2001 | } |
| 2002 | const auto displayId = display->getId(); |
| 2003 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2004 | if (hdrInfoReporter) { |
| 2005 | hdrInfoReporter->removeListener(listener); |
| 2006 | } |
| 2007 | return OK; |
| 2008 | } |
| 2009 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2010 | status_t SurfaceFlinger::notifyPowerBoost(int32_t boostId) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 2011 | using aidl::android::hardware::power::Boost; |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2012 | Boost powerBoost = static_cast<Boost>(boostId); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2013 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2014 | if (powerBoost == Boost::INTERACTION) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2015 | mScheduler->onTouchHint(); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | return NO_ERROR; |
| 2019 | } |
| 2020 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2021 | status_t SurfaceFlinger::getDisplayDecorationSupport( |
| 2022 | const sp<IBinder>& displayToken, |
| 2023 | std::optional<DisplayDecorationSupport>* outSupport) const { |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2024 | if (!displayToken || !outSupport) { |
| 2025 | return BAD_VALUE; |
| 2026 | } |
| 2027 | |
| 2028 | Mutex::Autolock lock(mStateLock); |
| 2029 | |
| 2030 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 2031 | if (!displayId) { |
| 2032 | return NAME_NOT_FOUND; |
| 2033 | } |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2034 | getHwComposer().getDisplayDecorationSupport(*displayId, outSupport); |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2035 | return NO_ERROR; |
| 2036 | } |
| 2037 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 2038 | // ---------------------------------------------------------------------------- |
| 2039 | |
Jorim Jaggi | b1e2f8d | 2017-06-08 15:43:59 -0700 | [diff] [blame] | 2040 | sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection( |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 2041 | gui::ISurfaceComposer::VsyncSource vsyncSource, EventRegistrationFlags eventRegistration, |
| 2042 | const sp<IBinder>& layerHandle) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 2043 | const auto& handle = |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 2044 | vsyncSource == gui::ISurfaceComposer::VsyncSource::eVsyncSourceSurfaceFlinger |
| 2045 | ? mSfConnectionHandle |
| 2046 | : mAppConnectionHandle; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 2047 | |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 2048 | return mScheduler->createDisplayEventConnection(handle, eventRegistration, layerHandle); |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2051 | void SurfaceFlinger::scheduleCommit(FrameHint hint) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2052 | if (hint == FrameHint::kActive) { |
| 2053 | mScheduler->resetIdleTimer(); |
| 2054 | } |
Matt Buckley | 15ecd1c | 2022-11-01 21:57:16 +0000 | [diff] [blame] | 2055 | mPowerAdvisor->notifyDisplayUpdateImminentAndCpuReset(); |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 2056 | mScheduler->scheduleFrame(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2057 | } |
| 2058 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2059 | void SurfaceFlinger::scheduleComposite(FrameHint hint) { |
| 2060 | mMustComposite = true; |
| 2061 | scheduleCommit(hint); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | void SurfaceFlinger::scheduleRepaint() { |
| 2065 | mGeometryDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2066 | scheduleComposite(FrameHint::kActive); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2067 | } |
| 2068 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2069 | void SurfaceFlinger::scheduleSample() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2070 | static_cast<void>(mScheduler->schedule([this] { sample(); })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2071 | } |
| 2072 | |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 2073 | nsecs_t SurfaceFlinger::getVsyncPeriodFromHWC() const { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2074 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
| 2075 | return display->getVsyncPeriodFromHWC(); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2076 | } |
| 2077 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2078 | return 0; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2079 | } |
| 2080 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2081 | void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp, |
| 2082 | std::optional<hal::VsyncPeriodNanos> vsyncPeriod) { |
Dominik Laskowski | 3d48304 | 2023-02-22 17:58:56 -0500 | [diff] [blame] | 2083 | ATRACE_NAME(vsyncPeriod |
| 2084 | ? ftl::Concat(__func__, ' ', hwcDisplayId, ' ', *vsyncPeriod, "ns").c_str() |
| 2085 | : ftl::Concat(__func__, ' ', hwcDisplayId).c_str()); |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 2086 | |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2087 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2088 | if (const auto displayIdOpt = getHwComposer().onVsync(hwcDisplayId, timestamp)) { |
| 2089 | if (mScheduler->addResyncSample(*displayIdOpt, timestamp, vsyncPeriod)) { |
| 2090 | // period flushed |
| 2091 | mScheduler->modulateVsync(displayIdOpt, &VsyncModulator::onRefreshRateChangeCompleted); |
| 2092 | } |
Alec Mouri | 754c98a | 2019-03-18 18:53:42 -0700 | [diff] [blame] | 2093 | } |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2096 | void SurfaceFlinger::onComposerHalHotplug(hal::HWDisplayId hwcDisplayId, |
| 2097 | hal::Connection connection) { |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2098 | { |
| 2099 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 2100 | mPendingHotplugEvents.push_back(HotplugEvent{hwcDisplayId, connection}); |
Jiwen 'Steve' Cai | ccfd682 | 2018-02-21 16:15:58 -0800 | [diff] [blame] | 2101 | } |
| 2102 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2103 | if (mScheduler) { |
| 2104 | mScheduler->scheduleConfigure(); |
| 2105 | } |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2108 | void SurfaceFlinger::onComposerHalVsyncPeriodTimingChanged( |
| 2109 | hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline& timeline) { |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2110 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2111 | mScheduler->onNewVsyncPeriodChangeTimeline(timeline); |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2112 | |
| 2113 | if (timeline.refreshRequired) { |
| 2114 | scheduleComposite(FrameHint::kNone); |
| 2115 | } |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2118 | void SurfaceFlinger::onComposerHalSeamlessPossible(hal::HWDisplayId) { |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 2119 | // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and |
Ady Abraham | b0433bc | 2020-01-08 17:31:06 -0800 | [diff] [blame] | 2120 | // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE. |
| 2121 | } |
| 2122 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2123 | void SurfaceFlinger::onComposerHalRefresh(hal::HWDisplayId) { |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2124 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2125 | scheduleComposite(FrameHint::kNone); |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2126 | } |
| 2127 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2128 | void SurfaceFlinger::onComposerHalVsyncIdle(hal::HWDisplayId) { |
Ady Abraham | e9befd7 | 2022-02-24 17:24:44 -0800 | [diff] [blame] | 2129 | ATRACE_CALL(); |
| 2130 | mScheduler->forceNextResync(); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2131 | } |
| 2132 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 2133 | void SurfaceFlinger::onRefreshRateChangedDebug(const RefreshRateChangedDebugData& data) { |
| 2134 | ATRACE_CALL(); |
| 2135 | if (const auto displayId = getHwComposer().toPhysicalDisplayId(data.display); displayId) { |
| 2136 | const Fps fps = Fps::fromPeriodNsecs(data.vsyncPeriodNanos); |
| 2137 | ATRACE_FORMAT("%s Fps %d", __func__, fps.getIntValue()); |
| 2138 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
| 2139 | { |
| 2140 | { |
| 2141 | const auto display = getDisplayDeviceLocked(*displayId); |
| 2142 | FTL_FAKE_GUARD(kMainThreadContext, |
| 2143 | display->updateRefreshRateOverlayRate(fps, |
| 2144 | display->getActiveMode() |
| 2145 | .fps, |
| 2146 | /* setByHwc */ true)); |
| 2147 | } |
| 2148 | } |
| 2149 | })); |
| 2150 | } |
ramindani | 12bfe6b | 2023-02-03 13:29:19 -0800 | [diff] [blame] | 2151 | } |
| 2152 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2153 | void SurfaceFlinger::configure() { |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2154 | Mutex::Autolock lock(mStateLock); |
| 2155 | if (configureLocked()) { |
| 2156 | setTransactionFlags(eDisplayTransactionNeeded); |
| 2157 | } |
| 2158 | } |
| 2159 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2160 | bool SurfaceFlinger::updateLayerSnapshotsLegacy(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2161 | bool flushTransactions, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2162 | bool& outTransactionsAreEmpty) { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2163 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2164 | frontend::Update update; |
| 2165 | if (flushTransactions) { |
| 2166 | update = flushLifecycleUpdates(); |
| 2167 | if (mTransactionTracing) { |
| 2168 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2169 | update, mFrontEndDisplayInfos, |
| 2170 | mFrontEndDisplayInfosChanged); |
| 2171 | } |
| 2172 | } |
| 2173 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2174 | bool needsTraversal = false; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2175 | if (flushTransactions) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2176 | needsTraversal |= commitMirrorDisplays(vsyncId); |
| 2177 | needsTraversal |= commitCreatedLayers(vsyncId, update.layerCreatedStates); |
| 2178 | needsTraversal |= applyTransactions(update.transactions, vsyncId); |
| 2179 | } |
| 2180 | outTransactionsAreEmpty = !needsTraversal; |
| 2181 | const bool shouldCommit = (getTransactionFlags() & ~eTransactionFlushNeeded) || needsTraversal; |
| 2182 | if (shouldCommit) { |
| 2183 | commitTransactions(); |
| 2184 | } |
| 2185 | |
| 2186 | bool mustComposite = latchBuffers() || shouldCommit; |
| 2187 | updateLayerGeometry(); |
| 2188 | return mustComposite; |
| 2189 | } |
| 2190 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2191 | void SurfaceFlinger::updateLayerHistory(const frontend::LayerSnapshot& snapshot) { |
| 2192 | using Changes = frontend::RequestedLayerState::Changes; |
| 2193 | if (snapshot.path.isClone() || |
| 2194 | !snapshot.changes.any(Changes::FrameRate | Changes::Buffer | Changes::Animation)) { |
| 2195 | return; |
| 2196 | } |
| 2197 | |
| 2198 | const auto layerProps = scheduler::LayerProps{ |
| 2199 | .visible = snapshot.isVisible, |
| 2200 | .bounds = snapshot.geomLayerBounds, |
| 2201 | .transform = snapshot.geomLayerTransform, |
| 2202 | .setFrameRateVote = snapshot.frameRate, |
| 2203 | .frameRateSelectionPriority = snapshot.frameRateSelectionPriority, |
| 2204 | }; |
| 2205 | |
| 2206 | auto it = mLegacyLayers.find(snapshot.sequence); |
| 2207 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), "Couldnt find layer object for %s", |
| 2208 | snapshot.getDebugString().c_str()); |
| 2209 | |
| 2210 | if (snapshot.changes.test(Changes::Animation)) { |
| 2211 | it->second->recordLayerHistoryAnimationTx(layerProps); |
| 2212 | } |
| 2213 | |
| 2214 | if (snapshot.changes.test(Changes::FrameRate)) { |
| 2215 | it->second->setFrameRateForLayerTree(snapshot.frameRate, layerProps); |
| 2216 | } |
| 2217 | |
| 2218 | if (snapshot.changes.test(Changes::Buffer)) { |
| 2219 | it->second->recordLayerHistoryBufferUpdate(layerProps); |
| 2220 | } |
| 2221 | } |
| 2222 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2223 | bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2224 | bool flushTransactions, bool& outTransactionsAreEmpty) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2225 | using Changes = frontend::RequestedLayerState::Changes; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2226 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2227 | frontend::Update update; |
| 2228 | if (flushTransactions) { |
| 2229 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 2230 | // Locking: |
| 2231 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 2232 | // we must keep a copy of the transactions (specifically the composer |
| 2233 | // states) around outside the scope of the lock. |
| 2234 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 2235 | // transactions with layers still in the createdLayer queue, collect the transactions |
| 2236 | // before committing the created layers. |
| 2237 | // 3. Transactions can only be flushed after adding layers, since the layer can be a newly |
| 2238 | // created one |
| 2239 | mTransactionHandler.collectTransactions(); |
| 2240 | { |
| 2241 | // TODO(b/238781169) lockless queue this and keep order. |
| 2242 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 2243 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 2244 | mCreatedLayers.clear(); |
| 2245 | update.newLayers = std::move(mNewLayers); |
| 2246 | mNewLayers.clear(); |
| 2247 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 2248 | mNewLayerArgs.clear(); |
| 2249 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 2250 | mDestroyedHandles.clear(); |
| 2251 | } |
| 2252 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2253 | mLayerLifecycleManager.addLayers(std::move(update.newLayers)); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2254 | update.transactions = mTransactionHandler.flushTransactions(); |
| 2255 | if (mTransactionTracing) { |
| 2256 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2257 | update, mFrontEndDisplayInfos, |
| 2258 | mFrontEndDisplayInfosChanged); |
| 2259 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2260 | mLayerLifecycleManager.applyTransactions(update.transactions); |
| 2261 | mLayerLifecycleManager.onHandlesDestroyed(update.destroyedHandles); |
| 2262 | for (auto& legacyLayer : update.layerCreatedStates) { |
| 2263 | sp<Layer> layer = legacyLayer.layer.promote(); |
| 2264 | if (layer) { |
| 2265 | mLegacyLayers[layer->sequence] = layer; |
| 2266 | } |
| 2267 | } |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2268 | if (mLayerLifecycleManager.getGlobalChanges().test(Changes::Hierarchy)) { |
| 2269 | ATRACE_NAME("LayerHierarchyBuilder:update"); |
| 2270 | mLayerHierarchyBuilder.update(mLayerLifecycleManager.getLayers(), |
| 2271 | mLayerLifecycleManager.getDestroyedLayers()); |
| 2272 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2273 | } |
| 2274 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2275 | bool mustComposite = false; |
| 2276 | mustComposite |= applyAndCommitDisplayTransactionStates(update.transactions); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2277 | |
| 2278 | { |
| 2279 | ATRACE_NAME("LayerSnapshotBuilder:update"); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2280 | frontend::LayerSnapshotBuilder::Args |
| 2281 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 2282 | .layerLifecycleManager = mLayerLifecycleManager, |
| 2283 | .displays = mFrontEndDisplayInfos, |
| 2284 | .displayChanges = mFrontEndDisplayInfosChanged, |
| 2285 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2286 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2287 | .forceFullDamage = mForceFullDamage, |
| 2288 | .supportedLayerGenericMetadata = |
| 2289 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 2290 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 2291 | .skipRoundCornersWhenProtected = |
| 2292 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2293 | mLayerSnapshotBuilder.update(args); |
| 2294 | } |
| 2295 | |
| 2296 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Geometry | Changes::Input | |
Vishnu Nair | 40d0228 | 2023-02-28 21:11:40 +0000 | [diff] [blame] | 2297 | Changes::Hierarchy | Changes::Visibility)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2298 | mUpdateInputInfo = true; |
| 2299 | } |
| 2300 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::VisibleRegion | Changes::Hierarchy | |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2301 | Changes::Visibility | Changes::Geometry)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2302 | mVisibleRegionsDirty = true; |
| 2303 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2304 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Hierarchy | Changes::FrameRate)) { |
| 2305 | // The frame rate of attached choreographers can only change as a result of a |
| 2306 | // FrameRate change (including when Hierarchy changes). |
| 2307 | mUpdateAttachedChoreographer = true; |
| 2308 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2309 | outTransactionsAreEmpty = mLayerLifecycleManager.getGlobalChanges().get() == 0; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2310 | mustComposite |= mLayerLifecycleManager.getGlobalChanges().get() != 0; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2311 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2312 | bool newDataLatched = false; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2313 | if (!mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2314 | ATRACE_NAME("DisplayCallbackAndStatsUpdates"); |
Vishnu Nair | d2a38f9 | 2023-08-23 18:43:01 -0700 | [diff] [blame] | 2315 | mustComposite |= applyTransactions(update.transactions, vsyncId); |
Vishnu Nair | c1d19d7 | 2023-08-10 12:35:11 -0700 | [diff] [blame] | 2316 | traverseLegacyLayers([&](Layer* layer) { layer->commitTransaction(); }); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2317 | const nsecs_t latchTime = systemTime(); |
| 2318 | bool unused = false; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2319 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2320 | for (auto& layer : mLayerLifecycleManager.getLayers()) { |
| 2321 | if (layer->changes.test(frontend::RequestedLayerState::Changes::Created) && |
| 2322 | layer->bgColorLayer) { |
| 2323 | sp<Layer> bgColorLayer = getFactory().createEffectLayer( |
| 2324 | LayerCreationArgs(this, nullptr, layer->name, |
| 2325 | ISurfaceComposerClient::eFXSurfaceEffect, LayerMetadata(), |
Vishnu Nair | e4af095 | 2023-05-01 09:11:33 -0700 | [diff] [blame] | 2326 | std::make_optional(layer->id), true)); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2327 | mLegacyLayers[bgColorLayer->sequence] = bgColorLayer; |
| 2328 | } |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2329 | const bool willReleaseBufferOnLatch = layer->willReleaseBufferOnLatch(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2330 | |
| 2331 | auto it = mLegacyLayers.find(layer->id); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2332 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), "Couldnt find layer object for %s", |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2333 | layer->getDebugString().c_str()); |
Vishnu Nair | f32ff9b | 2023-08-23 14:32:30 -0700 | [diff] [blame] | 2334 | if (!layer->hasReadyFrame() && !willReleaseBufferOnLatch) { |
| 2335 | if (!it->second->hasBuffer()) { |
| 2336 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 2337 | // instead of a missed frame. This is used to identify scenarios where we |
| 2338 | // could not latch a buffer or apply a transaction due to backpressure. |
| 2339 | // We only update the latch time for buffer less layers here, the latch time |
| 2340 | // is updated for buffer layers when the buffer is latched. |
| 2341 | it->second->updateLastLatchTime(latchTime); |
| 2342 | } |
| 2343 | continue; |
| 2344 | } |
| 2345 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2346 | const bool bgColorOnly = |
| 2347 | !layer->externalTexture && (layer->bgColorLayerId != UNASSIGNED_LAYER_ID); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2348 | if (willReleaseBufferOnLatch) { |
| 2349 | mLayersWithBuffersRemoved.emplace(it->second); |
| 2350 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2351 | it->second->latchBufferImpl(unused, latchTime, bgColorOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2352 | newDataLatched = true; |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2353 | |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2354 | mLayersWithQueuedFrames.emplace(it->second); |
| 2355 | mLayersIdsWithQueuedFrames.emplace(it->second->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2356 | } |
| 2357 | |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2358 | mLayerSnapshotBuilder.forEachVisibleSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 2359 | updateLayerHistory(snapshot); |
| 2360 | if (mLayersIdsWithQueuedFrames.find(snapshot.path.id) == |
| 2361 | mLayersIdsWithQueuedFrames.end()) |
| 2362 | return; |
| 2363 | Region visibleReg; |
| 2364 | visibleReg.set(snapshot.transformedBoundsWithoutTransparentRegion); |
| 2365 | invalidateLayerStack(snapshot.outputFilter, visibleReg); |
| 2366 | }); |
| 2367 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2368 | for (auto& destroyedLayer : mLayerLifecycleManager.getDestroyedLayers()) { |
| 2369 | mLegacyLayers.erase(destroyedLayer->id); |
| 2370 | } |
| 2371 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2372 | { |
| 2373 | ATRACE_NAME("LLM:commitChanges"); |
| 2374 | mLayerLifecycleManager.commitChanges(); |
| 2375 | } |
| 2376 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 2377 | commitTransactions(); |
| 2378 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2379 | // enter boot animation on first buffer latch |
| 2380 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 2381 | ALOGI("Enter boot animation"); |
| 2382 | mBootStage = BootStage::BOOTANIMATION; |
| 2383 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2384 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2385 | mustComposite |= (getTransactionFlags() & ~eTransactionFlushNeeded) || newDataLatched; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2386 | return mustComposite; |
| 2387 | } |
| 2388 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2389 | bool SurfaceFlinger::commit(PhysicalDisplayId pacesetterId, |
| 2390 | const scheduler::FrameTargets& frameTargets) { |
| 2391 | const scheduler::FrameTarget& pacesetterFrameTarget = *frameTargets.get(pacesetterId)->get(); |
| 2392 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2393 | const VsyncId vsyncId = pacesetterFrameTarget.vsyncId(); |
| 2394 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2395 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2396 | if (pacesetterFrameTarget.didMissFrame()) { |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2397 | mTimeStats->incrementMissedFrames(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2398 | } |
| 2399 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2400 | // If a mode set is pending and the fence hasn't fired yet, wait for the next commit. |
| 2401 | if (std::any_of(frameTargets.begin(), frameTargets.end(), |
| 2402 | [this](const auto& pair) FTL_FAKE_GUARD(mStateLock) |
| 2403 | FTL_FAKE_GUARD(kMainThreadContext) { |
| 2404 | if (!pair.second->isFramePending()) return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2405 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2406 | if (const auto display = getDisplayDeviceLocked(pair.first)) { |
| 2407 | return display->isModeSetPending(); |
| 2408 | } |
| 2409 | |
| 2410 | return false; |
| 2411 | })) { |
| 2412 | mScheduler->scheduleFrame(); |
| 2413 | return false; |
| 2414 | } |
| 2415 | |
| 2416 | { |
| 2417 | Mutex::Autolock lock(mStateLock); |
| 2418 | |
| 2419 | for (const auto [id, target] : frameTargets) { |
| 2420 | // TODO(b/241285876): This is `nullptr` when the DisplayDevice is about to be removed in |
| 2421 | // this commit, since the PhysicalDisplay has already been removed. Rather than checking |
| 2422 | // for `nullptr` below, change Scheduler::onFrameSignal to filter out the FrameTarget of |
| 2423 | // the removed display. |
| 2424 | const auto display = getDisplayDeviceLocked(id); |
| 2425 | |
| 2426 | if (display && display->isModeSetPending()) { |
| 2427 | finalizeDisplayModeChange(*display); |
| 2428 | } |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2429 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2432 | if (pacesetterFrameTarget.isFramePending()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2433 | if (mBackpressureGpuComposition || pacesetterFrameTarget.didMissHwcFrame()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2434 | scheduleCommit(FrameHint::kNone); |
| 2435 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2436 | } |
| 2437 | } |
| 2438 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2439 | const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); |
| 2440 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2441 | // Save this once per commit + composite to ensure consistency |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2442 | // TODO (b/240619471): consider removing active display check once AOD is fixed |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 2443 | const auto activeDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(mActiveDisplayId)); |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2444 | mPowerHintSessionEnabled = mPowerAdvisor->usePowerHintSession() && activeDisplay && |
| 2445 | activeDisplay->getPowerMode() == hal::PowerMode::ON; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2446 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2447 | mPowerAdvisor->setCommitStart(pacesetterFrameTarget.frameBeginTime()); |
| 2448 | mPowerAdvisor->setExpectedPresentTime(pacesetterFrameTarget.expectedPresentTime()); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2449 | |
| 2450 | // 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] | 2451 | const Duration idealSfWorkDuration = |
| 2452 | mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2453 | const Duration frameDelay = |
| 2454 | idealSfWorkDuration - pacesetterFrameTarget.expectedFrameDuration(); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2455 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2456 | mPowerAdvisor->setFrameDelay(frameDelay); |
| 2457 | mPowerAdvisor->setTotalFrameTargetWorkDuration(idealSfWorkDuration); |
Matt Buckley | 676e439 | 2023-05-25 22:09:26 +0000 | [diff] [blame] | 2458 | |
| 2459 | const auto& display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get(); |
| 2460 | const Period idealVsyncPeriod = display->getActiveMode().fps.getPeriod(); |
| 2461 | mPowerAdvisor->updateTargetWorkDuration(idealVsyncPeriod); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2464 | if (mRefreshRateOverlaySpinner || mHdrSdrRatioOverlay) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 2465 | Mutex::Autolock lock(mStateLock); |
| 2466 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2467 | display->animateOverlay(); |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2468 | } |
| 2469 | } |
| 2470 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2471 | // Composite if transactions were committed, or if requested by HWC. |
| 2472 | bool mustComposite = mMustComposite.exchange(false); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2473 | { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2474 | mFrameTimeline->setSfWakeUp(ftl::to_underlying(vsyncId), |
| 2475 | pacesetterFrameTarget.frameBeginTime().ns(), |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2476 | Fps::fromPeriodNsecs(vsyncPeriod.ns())); |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 2477 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2478 | const bool flushTransactions = clearTransactionFlags(eTransactionFlushNeeded); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2479 | bool transactionsAreEmpty; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2480 | if (mLegacyFrontEndEnabled) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2481 | mustComposite |= |
| 2482 | updateLayerSnapshotsLegacy(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2483 | flushTransactions, transactionsAreEmpty); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2484 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2485 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2486 | mustComposite |= |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2487 | updateLayerSnapshots(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2488 | flushTransactions, transactionsAreEmpty); |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | if (transactionFlushNeeded()) { |
| 2492 | setTransactionFlags(eTransactionFlushNeeded); |
| 2493 | } |
| 2494 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2495 | // This has to be called after latchBuffers because we want to include the layers that have |
| 2496 | // been latched in the commit callback |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2497 | if (transactionsAreEmpty) { |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2498 | // Invoke empty transaction callbacks early. |
| 2499 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 2500 | } else { |
| 2501 | // Invoke OnCommit callbacks. |
| 2502 | mTransactionCallbackInvoker.sendCallbacks(true /* onCommitOnly */); |
| 2503 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2504 | } |
| 2505 | |
| 2506 | // Layers need to get updated (in the previous line) before we can use them for |
| 2507 | // choosing the refresh rate. |
| 2508 | // Hold mStateLock as chooseRefreshRateForContent promotes wp<Layer> to sp<Layer> |
| 2509 | // and may eventually call to ~Layer() if it holds the last reference |
| 2510 | { |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2511 | bool updateAttachedChoreographer = mUpdateAttachedChoreographer; |
| 2512 | mUpdateAttachedChoreographer = false; |
| 2513 | |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 2514 | Mutex::Autolock lock(mStateLock); |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2515 | mScheduler->chooseRefreshRateForContent(mLayerLifecycleManagerEnabled |
| 2516 | ? &mLayerHierarchyBuilder.getHierarchy() |
| 2517 | : nullptr, |
| 2518 | updateAttachedChoreographer); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2519 | initiateDisplayModeChanges(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2522 | updateCursorAsync(); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2523 | if (!mustComposite) { |
| 2524 | updateInputFlinger(vsyncId, pacesetterFrameTarget.frameBeginTime()); |
| 2525 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2526 | doActiveLayersTracingIfNeeded(false, mVisibleRegionsDirty, |
| 2527 | pacesetterFrameTarget.frameBeginTime(), vsyncId); |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 2528 | |
Pablo Gamito | 6be8244 | 2022-06-13 11:04:34 +0000 | [diff] [blame] | 2529 | mLastCommittedVsyncId = vsyncId; |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2530 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2531 | persistDisplayBrightness(mustComposite); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2532 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2533 | return mustComposite && CC_LIKELY(mBootStage != BootStage::BOOTLOADER); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2534 | } |
| 2535 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2536 | CompositeResultsPerDisplay SurfaceFlinger::composite( |
| 2537 | PhysicalDisplayId pacesetterId, const scheduler::FrameTargeters& frameTargeters) { |
| 2538 | const scheduler::FrameTarget& pacesetterTarget = |
| 2539 | frameTargeters.get(pacesetterId)->get()->target(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2540 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2541 | const VsyncId vsyncId = pacesetterTarget.vsyncId(); |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2542 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2543 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2544 | compositionengine::CompositionRefreshArgs refreshArgs; |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 2545 | refreshArgs.powerCallback = this; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2546 | const auto& displays = FTL_FAKE_GUARD(mStateLock, mDisplays); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2547 | refreshArgs.outputs.reserve(displays.size()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2548 | |
| 2549 | // Add outputs for physical displays. |
| 2550 | for (const auto& [id, targeter] : frameTargeters) { |
| 2551 | ftl::FakeGuard guard(mStateLock); |
| 2552 | |
| 2553 | if (const auto display = getCompositionDisplayLocked(id)) { |
| 2554 | refreshArgs.outputs.push_back(display); |
| 2555 | } |
| 2556 | } |
| 2557 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2558 | std::vector<DisplayId> displayIds; |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2559 | for (const auto& [_, display] : displays) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2560 | displayIds.push_back(display->getId()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2561 | display->tracePowerMode(); |
| 2562 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2563 | // Add outputs for virtual displays. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2564 | if (display->isVirtual()) { |
| 2565 | const Fps refreshRate = display->getAdjustedRefreshRate(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2566 | |
| 2567 | if (!refreshRate.isValid() || |
| 2568 | mScheduler->isVsyncInPhase(pacesetterTarget.frameBeginTime(), refreshRate)) { |
| 2569 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2570 | } |
| 2571 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2572 | } |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2573 | mPowerAdvisor->setDisplays(displayIds); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2574 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 2575 | const bool updateTaskMetadata = mCompositionEngine->getFeatureFlags().test( |
| 2576 | compositionengine::Feature::kSnapshotLayerMetadata); |
| 2577 | if (updateTaskMetadata && (mVisibleRegionsDirty || mLayerMetadataSnapshotNeeded)) { |
| 2578 | updateLayerMetadataSnapshot(); |
| 2579 | mLayerMetadataSnapshotNeeded = false; |
| 2580 | } |
| 2581 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2582 | if (DOES_CONTAIN_BORDER) { |
| 2583 | refreshArgs.borderInfoList.clear(); |
| 2584 | mDrawingState.traverse([&refreshArgs](Layer* layer) { |
| 2585 | if (layer->isBorderEnabled()) { |
| 2586 | compositionengine::BorderRenderInfo info; |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 2587 | info.width = layer->getBorderWidth(); |
| 2588 | info.color = layer->getBorderColor(); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2589 | layer->traverse(LayerVector::StateSet::Drawing, [&info](Layer* ilayer) { |
| 2590 | info.layerIds.push_back(ilayer->getSequence()); |
| 2591 | }); |
| 2592 | refreshArgs.borderInfoList.emplace_back(std::move(info)); |
| 2593 | } |
| 2594 | }); |
| 2595 | } |
| 2596 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 2597 | refreshArgs.bufferIdsToUncache = std::move(mBufferIdsToUncache); |
| 2598 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2599 | refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); |
Alec Mouri | 5c9c960 | 2020-09-01 15:10:40 -0700 | [diff] [blame] | 2600 | for (auto layer : mLayersWithQueuedFrames) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 2601 | if (auto layerFE = layer->getCompositionEngineLayerFE()) |
| 2602 | refreshArgs.layersWithQueuedFrames.push_back(layerFE); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2603 | } |
| 2604 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 2605 | refreshArgs.outputColorSetting = mDisplayColorSetting; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 2606 | refreshArgs.forceOutputColorMode = mForceColorMode; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2607 | |
| 2608 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2609 | refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || mVisibleRegionsDirty; |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 2610 | refreshArgs.internalDisplayRotationFlags = getActiveDisplayRotationFlags(); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2611 | |
| 2612 | if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) { |
| 2613 | refreshArgs.colorTransformMatrix = mDrawingState.colorMatrix; |
| 2614 | mDrawingState.colorMatrixChanged = false; |
| 2615 | } |
| 2616 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2617 | refreshArgs.devOptForceClientComposition = mDebugDisableHWC; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2618 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2619 | if (mDebugFlashDelay != 0) { |
| 2620 | refreshArgs.devOptForceClientComposition = true; |
| 2621 | refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay); |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 2622 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2623 | |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2624 | const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2625 | |
Dominik Laskowski | 42ccc93 | 2023-04-20 10:08:04 -0400 | [diff] [blame] | 2626 | if (!getHwComposer().getComposer()->isSupported( |
| 2627 | Hwc2::Composer::OptionalFeature::ExpectedPresentTime) && |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2628 | pacesetterTarget.wouldPresentEarly(vsyncPeriod)) { |
Dominik Laskowski | 42ccc93 | 2023-04-20 10:08:04 -0400 | [diff] [blame] | 2629 | const auto hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration; |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2630 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2631 | // TODO(b/255601557): Calculate and pass per-display values for each FrameTarget. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2632 | refreshArgs.earliestPresentTime = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2633 | pacesetterTarget.previousFrameVsyncTime(vsyncPeriod) - hwcMinWorkDuration; |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2634 | } |
| 2635 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2636 | refreshArgs.scheduledFrameTime = mScheduler->getScheduledFrameTime(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2637 | refreshArgs.expectedPresentTime = pacesetterTarget.expectedPresentTime().ns(); |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 2638 | refreshArgs.hasTrustedPresentationListener = mNumTrustedPresentationListeners > 0; |
Ady Abraham | 3645e64 | 2021-04-20 18:39:00 -0700 | [diff] [blame] | 2639 | |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2640 | // Store the present time just before calling to the composition engine so we could notify |
| 2641 | // the scheduler. |
| 2642 | const auto presentTime = systemTime(); |
| 2643 | |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2644 | constexpr bool kCursorOnly = false; |
| 2645 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
| 2646 | |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2647 | if (mLayerLifecycleManagerEnabled && !mVisibleRegionsDirty) { |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2648 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 2649 | auto compositionDisplay = display->getCompositionDisplay(); |
| 2650 | if (!compositionDisplay->getState().isEnabled) continue; |
| 2651 | for (auto outputLayer : compositionDisplay->getOutputLayersOrderedByZ()) { |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2652 | if (outputLayer->getLayerFE().getCompositionState() == nullptr) { |
| 2653 | // This is unexpected but instead of crashing, capture traces to disk |
| 2654 | // and recover gracefully by forcing CE to rebuild layer stack. |
| 2655 | ALOGE("Output layer %s for display %s %" PRIu64 " has a null " |
| 2656 | "snapshot. Forcing mVisibleRegionsDirty", |
| 2657 | outputLayer->getLayerFE().getDebugName(), |
| 2658 | compositionDisplay->getName().c_str(), compositionDisplay->getId().value); |
| 2659 | |
| 2660 | TransactionTraceWriter::getInstance().invoke(__func__, /* overwrite= */ false); |
| 2661 | mVisibleRegionsDirty = true; |
| 2662 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
| 2663 | refreshArgs.updatingGeometryThisFrame = mVisibleRegionsDirty; |
| 2664 | } |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2665 | } |
| 2666 | } |
| 2667 | } |
| 2668 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2669 | mCompositionEngine->present(refreshArgs); |
| 2670 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2671 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2672 | for (auto [layer, layerFE] : layers) { |
| 2673 | CompositionResult compositionResult{layerFE->stealCompositionResult()}; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2674 | layer->onPreComposition(compositionResult.refreshStartTime); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2675 | for (auto& [releaseFence, layerStack] : compositionResult.releaseFences) { |
Vishnu Nair | 332e6ba | 2023-01-25 17:16:19 -0800 | [diff] [blame] | 2676 | Layer* clonedFrom = layer->getClonedFrom().get(); |
| 2677 | auto owningLayer = clonedFrom ? clonedFrom : layer; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2678 | owningLayer->onLayerDisplayed(std::move(releaseFence), layerStack); |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2679 | } |
| 2680 | if (compositionResult.lastClientCompositionFence) { |
| 2681 | layer->setWasClientComposed(compositionResult.lastClientCompositionFence); |
| 2682 | } |
| 2683 | } |
| 2684 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2685 | mTimeStats->recordFrameDuration(pacesetterTarget.frameBeginTime().ns(), systemTime()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2686 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2687 | // Send a power hint after presentation is finished. |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2688 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2689 | // Now that the current frame has been presented above, PowerAdvisor needs the present time |
| 2690 | // of the previous frame (whose fence is signaled by now) to determine how long the HWC had |
| 2691 | // waited on that fence to retire before presenting. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2692 | const auto& previousPresentFence = pacesetterTarget.presentFenceForPreviousFrame(); |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2693 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2694 | mPowerAdvisor->setSfPresentTiming(TimePoint::fromNs(previousPresentFence->getSignalTime()), |
| 2695 | TimePoint::now()); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 2696 | mPowerAdvisor->reportActualWorkDuration(); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2697 | } |
| 2698 | |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2699 | if (mScheduler->onPostComposition(presentTime)) { |
| 2700 | scheduleComposite(FrameHint::kNone); |
| 2701 | } |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2702 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2703 | postComposition(pacesetterId, frameTargeters, presentTime); |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 2704 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2705 | const bool hadGpuComposited = |
| 2706 | multiDisplayUnion(mCompositionCoverage).test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2707 | mCompositionCoverage.clear(); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2708 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2709 | TimeStats::ClientCompositionRecord clientCompositionRecord; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2710 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2711 | for (const auto& [_, display] : displays) { |
| 2712 | const auto& state = display->getCompositionDisplay()->getState(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2713 | CompositionCoverageFlags& flags = |
| 2714 | mCompositionCoverage.try_emplace(display->getId()).first->second; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2715 | |
| 2716 | if (state.usesDeviceComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2717 | flags |= CompositionCoverage::Hwc; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | if (state.reusedClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2721 | flags |= CompositionCoverage::GpuReuse; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2722 | } else if (state.usesClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2723 | flags |= CompositionCoverage::Gpu; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2724 | } |
| 2725 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2726 | clientCompositionRecord.predicted |= |
| 2727 | (state.strategyPrediction != CompositionStrategyPredictionState::DISABLED); |
| 2728 | clientCompositionRecord.predictionSucceeded |= |
| 2729 | (state.strategyPrediction == CompositionStrategyPredictionState::SUCCESS); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2730 | } |
| 2731 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2732 | const auto coverage = multiDisplayUnion(mCompositionCoverage); |
| 2733 | const bool hasGpuComposited = coverage.test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2734 | |
| 2735 | clientCompositionRecord.hadClientComposition = hasGpuComposited; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2736 | clientCompositionRecord.reused = coverage.test(CompositionCoverage::GpuReuse); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2737 | clientCompositionRecord.changed = hadGpuComposited != hasGpuComposited; |
| 2738 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2739 | mTimeStats->pushCompositionStrategyState(clientCompositionRecord); |
| 2740 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2741 | using namespace ftl::flag_operators; |
| 2742 | |
| 2743 | // TODO(b/160583065): Enable skip validation when SF caches all client composition layers. |
| 2744 | const bool hasGpuUseOrReuse = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2745 | coverage.any(CompositionCoverage::Gpu | CompositionCoverage::GpuReuse); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2746 | mScheduler->modulateVsync({}, &VsyncModulator::onDisplayRefresh, hasGpuUseOrReuse); |
Dan Stoza | 14cd37c | 2015-07-09 12:43:33 -0700 | [diff] [blame] | 2747 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 2748 | mLayersWithQueuedFrames.clear(); |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2749 | mLayersIdsWithQueuedFrames.clear(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2750 | doActiveLayersTracingIfNeeded(true, mVisibleRegionsDirty, pacesetterTarget.frameBeginTime(), |
| 2751 | vsyncId); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2752 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2753 | updateInputFlinger(vsyncId, pacesetterTarget.frameBeginTime()); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2754 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2755 | if (mVisibleRegionsDirty) mHdrLayerInfoChanged = true; |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 2756 | mVisibleRegionsDirty = false; |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2757 | |
| 2758 | if (mCompositionEngine->needsAnotherUpdate()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2759 | scheduleCommit(FrameHint::kNone); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2760 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2761 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2762 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2763 | mPowerAdvisor->setCompositeEnd(TimePoint::now()); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2764 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2765 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2766 | CompositeResultsPerDisplay resultsPerDisplay; |
| 2767 | |
| 2768 | // Filter out virtual displays. |
| 2769 | for (const auto& [id, coverage] : mCompositionCoverage) { |
| 2770 | if (const auto idOpt = PhysicalDisplayId::tryCast(id)) { |
| 2771 | resultsPerDisplay.try_emplace(*idOpt, CompositeResult{coverage}); |
| 2772 | } |
| 2773 | } |
| 2774 | |
| 2775 | return resultsPerDisplay; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2776 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2777 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2778 | void SurfaceFlinger::updateLayerGeometry() { |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2779 | ATRACE_CALL(); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 2780 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2781 | if (mVisibleRegionsDirty) { |
| 2782 | computeLayerBounds(); |
| 2783 | } |
| 2784 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2785 | for (auto& layer : mLayersPendingRefresh) { |
| 2786 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2787 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2788 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2789 | } |
| 2790 | mLayersPendingRefresh.clear(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2791 | } |
| 2792 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2793 | bool SurfaceFlinger::isHdrLayer(const frontend::LayerSnapshot& snapshot) const { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2794 | // Even though the camera layer may be using an HDR transfer function or otherwise be "HDR" |
| 2795 | // the device may need to avoid boosting the brightness as a result of these layers to |
| 2796 | // reduce power consumption during camera recording |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2797 | if (mIgnoreHdrCameraLayers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2798 | if (snapshot.externalTexture && |
| 2799 | (snapshot.externalTexture->getUsage() & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) { |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2800 | return false; |
| 2801 | } |
| 2802 | } |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 2803 | // RANGE_EXTENDED layer may identify themselves as being "HDR" |
| 2804 | // via a desired hdr/sdr ratio |
| 2805 | auto pixelFormat = snapshot.buffer |
| 2806 | ? std::make_optional(static_cast<ui::PixelFormat>(snapshot.buffer->getPixelFormat())) |
| 2807 | : std::nullopt; |
| 2808 | |
| 2809 | if (getHdrRenderType(snapshot.dataspace, pixelFormat, snapshot.desiredHdrSdrRatio) != |
| 2810 | HdrRenderType::SDR) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2811 | return true; |
| 2812 | } |
| 2813 | // If the layer is not allowed to be dimmed, treat it as HDR. WindowManager may disable |
| 2814 | // dimming in order to keep animations invoking SDR screenshots of HDR layers seamless. |
| 2815 | // Treat such tagged layers as HDR so that DisplayManagerService does not try to change |
| 2816 | // the screen brightness |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2817 | if (!snapshot.dimmingEnabled) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2818 | return true; |
| 2819 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2820 | return false; |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2821 | } |
| 2822 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2823 | ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId, |
| 2824 | bool isPrimary) const { |
| 2825 | const auto id = PhysicalDisplayId::tryCast(displayId); |
| 2826 | if (!id) { |
| 2827 | return ui::ROTATION_0; |
| 2828 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2829 | if (!mIgnoreHwcPhysicalDisplayOrientation && |
Neha Jain | 7b31cca | 2023-01-09 23:10:42 +0000 | [diff] [blame] | 2830 | getHwComposer().getComposer()->isSupported( |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2831 | Hwc2::Composer::OptionalFeature::PhysicalDisplayOrientation)) { |
| 2832 | switch (getHwComposer().getPhysicalDisplayOrientation(*id)) { |
| 2833 | case Hwc2::AidlTransform::ROT_90: |
| 2834 | return ui::ROTATION_90; |
| 2835 | case Hwc2::AidlTransform::ROT_180: |
| 2836 | return ui::ROTATION_180; |
| 2837 | case Hwc2::AidlTransform::ROT_270: |
| 2838 | return ui::ROTATION_270; |
| 2839 | default: |
| 2840 | return ui::ROTATION_0; |
| 2841 | } |
| 2842 | } |
| 2843 | |
| 2844 | if (isPrimary) { |
| 2845 | using Values = SurfaceFlingerProperties::primary_display_orientation_values; |
| 2846 | switch (primary_display_orientation(Values::ORIENTATION_0)) { |
| 2847 | case Values::ORIENTATION_90: |
| 2848 | return ui::ROTATION_90; |
| 2849 | case Values::ORIENTATION_180: |
| 2850 | return ui::ROTATION_180; |
| 2851 | case Values::ORIENTATION_270: |
| 2852 | return ui::ROTATION_270; |
| 2853 | default: |
| 2854 | break; |
| 2855 | } |
| 2856 | } |
| 2857 | return ui::ROTATION_0; |
| 2858 | } |
| 2859 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2860 | void SurfaceFlinger::postComposition(PhysicalDisplayId pacesetterId, |
| 2861 | const scheduler::FrameTargeters& frameTargeters, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2862 | nsecs_t presentStartTime) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2863 | ATRACE_CALL(); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2864 | ALOGV(__func__); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2865 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2866 | ui::PhysicalDisplayMap<PhysicalDisplayId, std::shared_ptr<FenceTime>> presentFences; |
| 2867 | ui::PhysicalDisplayMap<PhysicalDisplayId, const sp<Fence>> gpuCompositionDoneFences; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2868 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2869 | for (const auto& [id, targeter] : frameTargeters) { |
| 2870 | auto presentFence = getHwComposer().getPresentFence(id); |
| 2871 | |
| 2872 | if (id == pacesetterId) { |
| 2873 | mTransactionCallbackInvoker.addPresentFence(presentFence); |
| 2874 | } |
| 2875 | |
| 2876 | if (auto fenceTime = targeter->setPresentFence(std::move(presentFence)); |
| 2877 | fenceTime->isValid()) { |
| 2878 | presentFences.try_emplace(id, std::move(fenceTime)); |
| 2879 | } |
| 2880 | |
| 2881 | ftl::FakeGuard guard(mStateLock); |
| 2882 | if (const auto display = getCompositionDisplayLocked(id); |
| 2883 | display && display->getState().usesClientComposition) { |
| 2884 | gpuCompositionDoneFences |
| 2885 | .try_emplace(id, display->getRenderSurface()->getClientTargetAcquireFence()); |
| 2886 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2887 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2888 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2889 | const auto pacesetterDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(pacesetterId)); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2890 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2891 | std::shared_ptr<FenceTime> pacesetterPresentFenceTime = |
| 2892 | presentFences.get(pacesetterId) |
| 2893 | .transform([](const FenceTimePtr& ptr) { return ptr; }) |
| 2894 | .value_or(FenceTime::NO_FENCE); |
| 2895 | |
| 2896 | std::shared_ptr<FenceTime> pacesetterGpuCompositionDoneFenceTime = |
| 2897 | gpuCompositionDoneFences.get(pacesetterId) |
| 2898 | .transform([](sp<Fence> fence) { |
| 2899 | return std::make_shared<FenceTime>(std::move(fence)); |
| 2900 | }) |
| 2901 | .value_or(FenceTime::NO_FENCE); |
| 2902 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2903 | const TimePoint presentTime = TimePoint::now(); |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 2904 | |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 2905 | // Set presentation information before calling Layer::releasePendingBuffer, such that jank |
| 2906 | // information from previous' frame classification is already available when sending jank info |
| 2907 | // to clients, so they get jank classification as early as possible. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2908 | mFrameTimeline->setSfPresent(presentTime.ns(), pacesetterPresentFenceTime, |
| 2909 | pacesetterGpuCompositionDoneFenceTime); |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 2910 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2911 | // We use the CompositionEngine::getLastFrameRefreshTimestamp() which might |
| 2912 | // 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] | 2913 | // but that should be okay since CompositorTiming has snapping logic. |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 2914 | const TimePoint compositeTime = |
| 2915 | TimePoint::fromNs(mCompositionEngine->getLastFrameRefreshTimestamp()); |
| 2916 | const Duration presentLatency = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2917 | getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE) |
| 2918 | ? Duration::zero() |
| 2919 | : mPresentLatencyTracker.trackPendingFrame(compositeTime, pacesetterPresentFenceTime); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2920 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2921 | const auto schedule = mScheduler->getVsyncSchedule(); |
| 2922 | const TimePoint vsyncDeadline = schedule->vsyncDeadlineAfter(presentTime); |
| 2923 | const Period vsyncPeriod = schedule->period(); |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 2924 | const nsecs_t vsyncPhase = mVsyncConfiguration->getCurrentConfigs().late.sfOffset; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2925 | |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 2926 | const CompositorTiming compositorTiming(vsyncDeadline.ns(), vsyncPeriod.ns(), vsyncPhase, |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 2927 | presentLatency.ns()); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2928 | |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 2929 | ui::DisplayMap<ui::LayerStack, const DisplayDevice*> layerStackToDisplay; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2930 | { |
| 2931 | if (!mLayersWithBuffersRemoved.empty() || mNumTrustedPresentationListeners > 0) { |
| 2932 | Mutex::Autolock lock(mStateLock); |
| 2933 | for (const auto& [token, display] : mDisplays) { |
| 2934 | layerStackToDisplay.emplace_or_replace(display->getLayerStack(), display.get()); |
| 2935 | } |
| 2936 | } |
| 2937 | } |
| 2938 | |
| 2939 | for (auto layer : mLayersWithBuffersRemoved) { |
Vishnu Nair | f10a87b | 2023-05-01 14:02:51 -0700 | [diff] [blame] | 2940 | std::vector<ui::LayerStack> previouslyPresentedLayerStacks = |
| 2941 | std::move(layer->mPreviouslyPresentedLayerStacks); |
| 2942 | layer->mPreviouslyPresentedLayerStacks.clear(); |
| 2943 | for (auto layerStack : previouslyPresentedLayerStacks) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2944 | auto optDisplay = layerStackToDisplay.get(layerStack); |
| 2945 | if (optDisplay && !optDisplay->get()->isVirtual()) { |
| 2946 | auto fence = getHwComposer().getPresentFence(optDisplay->get()->getPhysicalId()); |
| 2947 | layer->onLayerDisplayed(ftl::yield<FenceResult>(fence).share(), |
| 2948 | ui::INVALID_LAYER_STACK); |
| 2949 | } |
| 2950 | } |
| 2951 | layer->releasePendingBuffer(presentTime.ns()); |
| 2952 | } |
| 2953 | mLayersWithBuffersRemoved.clear(); |
| 2954 | |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 2955 | for (const auto& layer: mLayersWithQueuedFrames) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2956 | layer->onPostComposition(pacesetterDisplay.get(), pacesetterGpuCompositionDoneFenceTime, |
| 2957 | pacesetterPresentFenceTime, compositorTiming); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2958 | layer->releasePendingBuffer(presentTime.ns()); |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 2959 | } |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 2960 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2961 | std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>> |
| 2962 | hdrInfoListeners; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2963 | bool haveNewListeners = false; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 2964 | { |
| 2965 | Mutex::Autolock lock(mStateLock); |
| 2966 | if (mFpsReporter) { |
| 2967 | mFpsReporter->dispatchLayerFps(); |
| 2968 | } |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 2969 | |
| 2970 | if (mTunnelModeEnabledReporter) { |
| 2971 | mTunnelModeEnabledReporter->updateTunnelModeStatus(); |
| 2972 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2973 | hdrInfoListeners.reserve(mHdrLayerInfoListeners.size()); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 2974 | for (const auto& [displayId, reporter] : mHdrLayerInfoListeners) { |
| 2975 | if (reporter && reporter->hasListeners()) { |
| 2976 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 2977 | hdrInfoListeners.emplace_back(display->getCompositionDisplay(), reporter); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2978 | } |
| 2979 | } |
| 2980 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2981 | haveNewListeners = mAddingHDRLayerInfoListener; // grab this with state lock |
| 2982 | mAddingHDRLayerInfoListener = false; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2983 | } |
| 2984 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2985 | if (haveNewListeners || mHdrLayerInfoChanged) { |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2986 | for (auto& [compositionDisplay, listener] : hdrInfoListeners) { |
| 2987 | HdrLayerInfoReporter::HdrLayerInfo info; |
| 2988 | int32_t maxArea = 0; |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 2989 | auto updateInfoFn = |
| 2990 | [&](const std::shared_ptr<compositionengine::Display>& compositionDisplay, |
| 2991 | const frontend::LayerSnapshot& snapshot, const sp<LayerFE>& layerFe) { |
| 2992 | if (snapshot.isVisible && |
| 2993 | compositionDisplay->includesLayer(snapshot.outputFilter)) { |
| 2994 | if (isHdrLayer(snapshot)) { |
| 2995 | const auto* outputLayer = |
| 2996 | compositionDisplay->getOutputLayerForLayer(layerFe); |
| 2997 | if (outputLayer) { |
| 2998 | const float desiredHdrSdrRatio = |
| 2999 | snapshot.desiredHdrSdrRatio <= 1.f |
| 3000 | ? std::numeric_limits<float>::infinity() |
| 3001 | : snapshot.desiredHdrSdrRatio; |
| 3002 | info.mergeDesiredRatio(desiredHdrSdrRatio); |
| 3003 | info.numberOfHdrLayers++; |
| 3004 | const auto displayFrame = outputLayer->getState().displayFrame; |
| 3005 | const int32_t area = |
| 3006 | displayFrame.width() * displayFrame.height(); |
| 3007 | if (area > maxArea) { |
| 3008 | maxArea = area; |
| 3009 | info.maxW = displayFrame.width(); |
| 3010 | info.maxH = displayFrame.height(); |
| 3011 | } |
| 3012 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3013 | } |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 3014 | } |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3015 | }; |
| 3016 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3017 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3018 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 3019 | [&, compositionDisplay = compositionDisplay]( |
| 3020 | std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 3021 | auto it = mLegacyLayers.find(snapshot->sequence); |
| 3022 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), |
| 3023 | "Couldnt find layer object for %s", |
| 3024 | snapshot->getDebugString().c_str()); |
| 3025 | auto& legacyLayer = it->second; |
| 3026 | sp<LayerFE> layerFe = |
| 3027 | legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
| 3028 | |
| 3029 | updateInfoFn(compositionDisplay, *snapshot, layerFe); |
| 3030 | }); |
| 3031 | } else { |
| 3032 | mDrawingState.traverse([&, compositionDisplay = compositionDisplay](Layer* layer) { |
| 3033 | const auto layerFe = layer->getCompositionEngineLayerFE(); |
| 3034 | const frontend::LayerSnapshot& snapshot = *layer->getLayerSnapshot(); |
| 3035 | updateInfoFn(compositionDisplay, snapshot, layerFe); |
| 3036 | }); |
| 3037 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3038 | listener->dispatchHdrLayerInfo(info); |
| 3039 | } |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3040 | } |
| 3041 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3042 | mHdrLayerInfoChanged = false; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3043 | |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 3044 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 3045 | mTransactionCallbackInvoker.clearCompletedTransactions(); |
| 3046 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3047 | mTimeStats->incrementTotalFrames(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3048 | mTimeStats->setPresentFenceGlobal(pacesetterPresentFenceTime); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3049 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3050 | for (auto&& [id, presentFence] : presentFences) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3051 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3052 | const bool isInternalDisplay = |
| 3053 | mPhysicalDisplays.get(id).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 3054 | |
| 3055 | if (isInternalDisplay) { |
| 3056 | mScheduler->addPresentFence(id, std::move(presentFence)); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3057 | } |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3060 | const bool hasPacesetterDisplay = |
| 3061 | pacesetterDisplay && getHwComposer().isConnected(pacesetterId); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3062 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3063 | if (!hasSyncFramework) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3064 | if (hasPacesetterDisplay && pacesetterDisplay->isPoweredOn()) { |
| 3065 | mScheduler->enableHardwareVsync(pacesetterId); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3066 | } |
| 3067 | } |
| 3068 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3069 | if (hasPacesetterDisplay && !pacesetterDisplay->isPoweredOn()) { |
Lars Svensson | d9e5469 | 2021-12-21 07:41:57 +0100 | [diff] [blame] | 3070 | getRenderEngine().cleanupPostRender(); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 3071 | return; |
| 3072 | } |
| 3073 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 3074 | // Cleanup any outstanding resources due to rendering a prior frame. |
| 3075 | getRenderEngine().cleanupPostRender(); |
| 3076 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3077 | if (mNumTrustedPresentationListeners > 0) { |
| 3078 | // We avoid any reverse traversal upwards so this shouldn't be too expensive |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3079 | traverseLegacyLayers([&](Layer* layer) { |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3080 | if (!layer->hasTrustedPresentationListener()) { |
| 3081 | return; |
| 3082 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3083 | const frontend::LayerSnapshot* snapshot = mLayerLifecycleManagerEnabled |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3084 | ? mLayerSnapshotBuilder.getSnapshot(layer->sequence) |
| 3085 | : layer->getLayerSnapshot(); |
| 3086 | std::optional<const DisplayDevice*> displayOpt = std::nullopt; |
| 3087 | if (snapshot) { |
| 3088 | displayOpt = layerStackToDisplay.get(snapshot->outputFilter.layerStack); |
| 3089 | } |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 3090 | const DisplayDevice* display = displayOpt.value_or(nullptr); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3091 | layer->updateTrustedPresentationState(display, snapshot, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 3092 | nanoseconds_to_milliseconds(presentStartTime), |
| 3093 | false); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3094 | }); |
| 3095 | } |
| 3096 | |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3097 | // Even though ATRACE_INT64 already checks if tracing is enabled, it doesn't prevent the |
| 3098 | // side-effect of getTotalSize(), so we check that again here |
| 3099 | if (ATRACE_ENABLED()) { |
Marissa Wall | 22b2de1 | 2019-12-02 18:11:43 -0800 | [diff] [blame] | 3100 | // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3101 | ATRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize()); |
| 3102 | } |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3103 | |
| 3104 | logFrameStats(presentTime); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 3105 | } |
| 3106 | |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3107 | FloatRect SurfaceFlinger::getMaxDisplayBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3108 | const ui::Size maxSize = [this] { |
| 3109 | ftl::FakeGuard guard(mStateLock); |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3110 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3111 | // The LayerTraceGenerator tool runs without displays. |
| 3112 | if (mDisplays.empty()) return ui::Size{5000, 5000}; |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3113 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3114 | return std::accumulate(mDisplays.begin(), mDisplays.end(), ui::kEmptySize, |
| 3115 | [](ui::Size size, const auto& pair) -> ui::Size { |
| 3116 | const auto& display = pair.second; |
| 3117 | return {std::max(size.getWidth(), display->getWidth()), |
| 3118 | std::max(size.getHeight(), display->getHeight())}; |
| 3119 | }); |
| 3120 | }(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3121 | |
| 3122 | // Ignore display bounds for now since they will be computed later. Use a large Rect bound |
| 3123 | // to ensure it's bigger than an actual display will be. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3124 | const float xMax = maxSize.getWidth() * 10.f; |
| 3125 | const float yMax = maxSize.getHeight() * 10.f; |
| 3126 | |
| 3127 | return {-xMax, -yMax, xMax, yMax}; |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3128 | } |
| 3129 | |
| 3130 | void SurfaceFlinger::computeLayerBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3131 | const FloatRect maxBounds = getMaxDisplayBounds(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3132 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 3133 | layer->computeBounds(maxBounds, ui::Transform(), 0.f /* shadowRadius */); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3134 | } |
| 3135 | } |
| 3136 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3137 | void SurfaceFlinger::commitTransactions() { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 3138 | ATRACE_CALL(); |
| 3139 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3140 | // Keep a copy of the drawing state (that is going to be overwritten |
| 3141 | // by commitTransactionsLocked) outside of mStateLock so that the side |
| 3142 | // effects of the State assignment don't happen with mStateLock held, |
| 3143 | // which can cause deadlocks. |
Mathias Agopian | 7cc6df5 | 2013-06-05 14:30:54 -0700 | [diff] [blame] | 3144 | State drawingState(mDrawingState); |
| 3145 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3146 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 3147 | mDebugInTransaction = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3148 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3149 | // Here we're guaranteed that some transaction flags are set |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3150 | // so we can call commitTransactionsLocked unconditionally. |
| 3151 | // We clear the flags with mStateLock held to guarantee that |
| 3152 | // mCurrentState won't change until the transaction is committed. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3153 | mScheduler->modulateVsync({}, &VsyncModulator::onTransactionCommit); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3154 | commitTransactionsLocked(clearTransactionFlags(eTransactionMask)); |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 3155 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3156 | mDebugInTransaction = 0; |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 3157 | } |
| 3158 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3159 | std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes( |
| 3160 | PhysicalDisplayId displayId) const { |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3161 | std::vector<HWComposer::HWCDisplayMode> hwcModes; |
| 3162 | std::optional<hal::HWDisplayId> activeModeHwcId; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3163 | |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3164 | int attempt = 0; |
| 3165 | constexpr int kMaxAttempts = 3; |
| 3166 | do { |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 3167 | hwcModes = getHwComposer().getModes(displayId, |
| 3168 | scheduler::RefreshRateSelector::kMinSupportedFrameRate |
| 3169 | .getPeriodNsecs()); |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3170 | activeModeHwcId = getHwComposer().getActiveMode(displayId); |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3171 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3172 | const auto isActiveMode = [activeModeHwcId](const HWComposer::HWCDisplayMode& mode) { |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3173 | return mode.hwcId == activeModeHwcId; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3174 | }; |
| 3175 | |
| 3176 | if (std::any_of(hwcModes.begin(), hwcModes.end(), isActiveMode)) { |
| 3177 | break; |
| 3178 | } |
| 3179 | } while (++attempt < kMaxAttempts); |
| 3180 | |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3181 | if (attempt == kMaxAttempts) { |
| 3182 | const std::string activeMode = |
| 3183 | activeModeHwcId ? std::to_string(*activeModeHwcId) : "unknown"s; |
| 3184 | ALOGE("HWC failed to report an active mode that is supported: activeModeHwcId=%s, " |
| 3185 | "hwcModes={%s}", |
| 3186 | activeMode.c_str(), base::Join(hwcModes, ", ").c_str()); |
| 3187 | return {}; |
| 3188 | } |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3189 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3190 | const DisplayModes oldModes = mPhysicalDisplays.get(displayId) |
| 3191 | .transform([](const PhysicalDisplay& display) { |
| 3192 | return display.snapshot().displayModes(); |
| 3193 | }) |
| 3194 | .value_or(DisplayModes{}); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3195 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3196 | ui::DisplayModeId nextModeId = 1 + |
| 3197 | std::accumulate(oldModes.begin(), oldModes.end(), static_cast<ui::DisplayModeId>(-1), |
| 3198 | [](ui::DisplayModeId max, const auto& pair) { |
| 3199 | return std::max(max, pair.first.value()); |
| 3200 | }); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3201 | |
| 3202 | DisplayModes newModes; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3203 | for (const auto& hwcMode : hwcModes) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3204 | const DisplayModeId id{nextModeId++}; |
| 3205 | newModes.try_emplace(id, |
| 3206 | DisplayMode::Builder(hwcMode.hwcId) |
| 3207 | .setId(id) |
| 3208 | .setPhysicalDisplayId(displayId) |
| 3209 | .setResolution({hwcMode.width, hwcMode.height}) |
| 3210 | .setVsyncPeriod(hwcMode.vsyncPeriod) |
| 3211 | .setDpiX(hwcMode.dpiX) |
| 3212 | .setDpiY(hwcMode.dpiY) |
| 3213 | .setGroup(hwcMode.configGroup) |
| 3214 | .build()); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3215 | } |
| 3216 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3217 | const bool sameModes = |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3218 | std::equal(newModes.begin(), newModes.end(), oldModes.begin(), oldModes.end(), |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3219 | [](const auto& lhs, const auto& rhs) { |
| 3220 | return equalsExceptDisplayModeId(*lhs.second, *rhs.second); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3221 | }); |
| 3222 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3223 | // Keep IDs if modes have not changed. |
| 3224 | const auto& modes = sameModes ? oldModes : newModes; |
| 3225 | const DisplayModePtr activeMode = |
| 3226 | std::find_if(modes.begin(), modes.end(), [activeModeHwcId](const auto& pair) { |
| 3227 | return pair.second->getHwcId() == activeModeHwcId; |
| 3228 | })->second; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3229 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3230 | return {modes, activeMode}; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3231 | } |
| 3232 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3233 | bool SurfaceFlinger::configureLocked() { |
| 3234 | std::vector<HotplugEvent> events; |
| 3235 | { |
| 3236 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 3237 | events = std::move(mPendingHotplugEvents); |
| 3238 | } |
| 3239 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3240 | for (const auto [hwcDisplayId, connection] : events) { |
| 3241 | if (auto info = getHwComposer().onHotplug(hwcDisplayId, connection)) { |
| 3242 | const auto displayId = info->id; |
| 3243 | const bool connected = connection == hal::Connection::CONNECTED; |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3244 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3245 | if (const char* const log = |
| 3246 | processHotplug(displayId, hwcDisplayId, connected, std::move(*info))) { |
| 3247 | ALOGI("%s display %s (HAL ID %" PRIu64 ")", log, to_string(displayId).c_str(), |
| 3248 | hwcDisplayId); |
| 3249 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3250 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3251 | } |
| 3252 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3253 | return !events.empty(); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3254 | } |
| 3255 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3256 | const char* SurfaceFlinger::processHotplug(PhysicalDisplayId displayId, |
| 3257 | hal::HWDisplayId hwcDisplayId, bool connected, |
| 3258 | DisplayIdentificationInfo&& info) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3259 | const auto displayOpt = mPhysicalDisplays.get(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3260 | if (!connected) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3261 | LOG_ALWAYS_FATAL_IF(!displayOpt); |
| 3262 | const auto& display = displayOpt->get(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3263 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3264 | if (const ssize_t index = mCurrentState.displays.indexOfKey(display.token()); index >= 0) { |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3265 | mCurrentState.displays.removeItemsAt(index); |
| 3266 | } |
| 3267 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3268 | mPhysicalDisplays.erase(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3269 | return "Disconnecting"; |
| 3270 | } |
| 3271 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3272 | auto [displayModes, activeMode] = loadDisplayModes(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3273 | if (!activeMode) { |
| 3274 | // TODO(b/241286153): Report hotplug failure to the framework. |
| 3275 | ALOGE("Failed to hotplug display %s", to_string(displayId).c_str()); |
| 3276 | getHwComposer().disconnectDisplay(displayId); |
| 3277 | return nullptr; |
| 3278 | } |
| 3279 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3280 | ui::ColorModes colorModes = getHwComposer().getColorModes(displayId); |
| 3281 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3282 | if (displayOpt) { |
| 3283 | const auto& display = displayOpt->get(); |
| 3284 | const auto& snapshot = display.snapshot(); |
| 3285 | |
| 3286 | std::optional<DeviceProductInfo> deviceProductInfo; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3287 | if (getHwComposer().updatesDeviceProductInfoOnHotplugReconnect()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3288 | deviceProductInfo = std::move(info.deviceProductInfo); |
| 3289 | } else { |
| 3290 | deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3291 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3292 | |
| 3293 | const auto it = |
| 3294 | mPhysicalDisplays.try_replace(displayId, display.token(), displayId, |
| 3295 | snapshot.connectionType(), std::move(displayModes), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3296 | std::move(colorModes), std::move(deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3297 | |
| 3298 | auto& state = mCurrentState.displays.editValueFor(it->second.token()); |
| 3299 | state.sequenceId = DisplayDeviceState{}.sequenceId; // Generate new sequenceId. |
| 3300 | state.physical->activeMode = std::move(activeMode); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3301 | return "Reconnecting"; |
| 3302 | } |
| 3303 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3304 | const sp<IBinder> token = sp<BBinder>::make(); |
| 3305 | |
| 3306 | mPhysicalDisplays.try_emplace(displayId, token, displayId, |
| 3307 | getHwComposer().getDisplayConnectionType(displayId), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3308 | std::move(displayModes), std::move(colorModes), |
| 3309 | std::move(info.deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3310 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3311 | DisplayDeviceState state; |
| 3312 | state.physical = {.id = displayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3313 | .hwcDisplayId = hwcDisplayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3314 | .activeMode = std::move(activeMode)}; |
| 3315 | state.isSecure = true; // All physical displays are currently considered secure. |
| 3316 | state.displayName = std::move(info.name); |
| 3317 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3318 | mCurrentState.displays.add(token, state); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3319 | return "Connecting"; |
| 3320 | } |
| 3321 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 3322 | void SurfaceFlinger::dispatchDisplayHotplugEvent(PhysicalDisplayId displayId, bool connected) { |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 3323 | mScheduler->onHotplugReceived(mAppConnectionHandle, displayId, connected); |
| 3324 | mScheduler->onHotplugReceived(mSfConnectionHandle, displayId, connected); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 3325 | } |
| 3326 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3327 | void SurfaceFlinger::dispatchDisplayModeChangeEvent(PhysicalDisplayId displayId, |
| 3328 | const scheduler::FrameRateMode& mode) { |
| 3329 | // TODO(b/255635821): Merge code paths and move to Scheduler. |
| 3330 | const auto onDisplayModeChanged = displayId == mActiveDisplayId |
| 3331 | ? &scheduler::Scheduler::onPrimaryDisplayModeChanged |
| 3332 | : &scheduler::Scheduler::onNonPrimaryDisplayModeChanged; |
| 3333 | |
| 3334 | ((*mScheduler).*onDisplayModeChanged)(mAppConnectionHandle, mode); |
| 3335 | } |
| 3336 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3337 | sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3338 | const wp<IBinder>& displayToken, |
| 3339 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3340 | const DisplayDeviceState& state, |
| 3341 | const sp<compositionengine::DisplaySurface>& displaySurface, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3342 | const sp<IGraphicBufferProducer>& producer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3343 | DisplayDeviceCreationArgs creationArgs(sp<SurfaceFlinger>::fromExisting(this), getHwComposer(), |
| 3344 | displayToken, compositionDisplay); |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 3345 | creationArgs.sequenceId = state.sequenceId; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3346 | creationArgs.isSecure = state.isSecure; |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3347 | creationArgs.displaySurface = displaySurface; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3348 | creationArgs.hasWideColorGamut = false; |
| 3349 | creationArgs.supportedPerFrameMetadata = 0; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 3350 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3351 | if (const auto& physical = state.physical) { |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3352 | creationArgs.activeModeId = physical->activeMode->getId(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3353 | const auto [kernelIdleTimerController, idleTimerTimeoutMs] = |
| 3354 | getKernelIdleTimerProperties(compositionDisplay->getId()); |
| 3355 | |
Ady Abraham | 0c8b723 | 2023-01-27 21:12:16 -0800 | [diff] [blame] | 3356 | using Config = scheduler::RefreshRateSelector::Config; |
| 3357 | const auto enableFrameRateOverride = sysprop::enable_frame_rate_override(true) |
| 3358 | ? Config::FrameRateOverride::Enabled |
| 3359 | : Config::FrameRateOverride::Disabled; |
Ady Abraham | 0d4b41c | 2023-02-14 23:28:40 +0000 | [diff] [blame] | 3360 | Config config = |
Ady Abraham | 8ca643a | 2022-10-18 18:26:47 -0700 | [diff] [blame] | 3361 | {.enableFrameRateOverride = enableFrameRateOverride, |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3362 | .frameRateMultipleThreshold = |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 3363 | base::GetIntProperty("debug.sf.frame_rate_multiple_threshold", 0), |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3364 | .idleTimerTimeout = idleTimerTimeoutMs, |
| 3365 | .kernelIdleTimerController = kernelIdleTimerController}; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3366 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3367 | creationArgs.refreshRateSelector = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3368 | mPhysicalDisplays.get(physical->id) |
| 3369 | .transform(&PhysicalDisplay::snapshotRef) |
| 3370 | .transform([&](const display::DisplaySnapshot& snapshot) { |
| 3371 | return std::make_shared< |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3372 | scheduler::RefreshRateSelector>(snapshot.displayModes(), |
| 3373 | creationArgs.activeModeId, |
| 3374 | config); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3375 | }) |
| 3376 | .value_or(nullptr); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3377 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3378 | creationArgs.isPrimary = physical->id == getPrimaryDisplayIdLocked(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3379 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 3380 | mPhysicalDisplays.get(physical->id) |
| 3381 | .transform(&PhysicalDisplay::snapshotRef) |
| 3382 | .transform(ftl::unit_fn([&](const display::DisplaySnapshot& snapshot) { |
| 3383 | for (const auto mode : snapshot.colorModes()) { |
| 3384 | creationArgs.hasWideColorGamut |= ui::isWideColorMode(mode); |
| 3385 | creationArgs.hwcColorModes |
| 3386 | .emplace(mode, |
| 3387 | getHwComposer().getRenderIntents(physical->id, mode)); |
| 3388 | } |
| 3389 | })); |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 3390 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3391 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3392 | if (const auto id = HalDisplayId::tryCast(compositionDisplay->getId())) { |
| 3393 | getHwComposer().getHdrCapabilities(*id, &creationArgs.hdrCapabilities); |
| 3394 | creationArgs.supportedPerFrameMetadata = getHwComposer().getSupportedPerFrameMetadata(*id); |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 3395 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3396 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 3397 | auto nativeWindowSurface = getFactory().createNativeWindowSurface(producer); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3398 | auto nativeWindow = nativeWindowSurface->getNativeWindow(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3399 | creationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3400 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3401 | // Make sure that composition can never be stalled by a virtual display |
| 3402 | // 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] | 3403 | // here, in case the display is composed entirely by HWC. |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 3404 | if (state.isVirtual()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3405 | nativeWindow->setSwapInterval(nativeWindow.get(), 0); |
| 3406 | } |
| 3407 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 3408 | creationArgs.physicalOrientation = |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3409 | getPhysicalDisplayOrientation(compositionDisplay->getId(), creationArgs.isPrimary); |
| 3410 | ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 3411 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3412 | // virtual displays are always considered enabled |
linpeter | 1c69cd3 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 3413 | creationArgs.initialPowerMode = |
| 3414 | state.isVirtual() ? std::make_optional(hal::PowerMode::ON) : std::nullopt; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3415 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3416 | creationArgs.requestedRefreshRate = state.requestedRefreshRate; |
| 3417 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3418 | sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3419 | |
Ady Abraham | 8565ad2 | 2021-06-22 17:45:44 -0700 | [diff] [blame] | 3420 | nativeWindowSurface->preallocateBuffers(); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3421 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3422 | ui::ColorMode defaultColorMode = ui::ColorMode::NATIVE; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 3423 | Dataspace defaultDataSpace = Dataspace::UNKNOWN; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3424 | if (display->hasWideColorGamut()) { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3425 | defaultColorMode = ui::ColorMode::SRGB; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 3426 | defaultDataSpace = Dataspace::V0_SRGB; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3427 | } |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 3428 | display->getCompositionDisplay()->setColorProfile( |
| 3429 | compositionengine::Output::ColorProfile{defaultColorMode, defaultDataSpace, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 3430 | RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3431 | |
| 3432 | if (const auto& physical = state.physical) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3433 | const auto& mode = *physical->activeMode; |
| 3434 | display->setActiveMode(mode.getId(), mode.getFps(), mode.getFps()); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 3435 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3436 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3437 | display->setLayerFilter(makeLayerFilterForDisplay(display->getId(), state.layerStack)); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3438 | display->setProjection(state.orientation, state.layerStackSpaceRect, |
| 3439 | state.orientedDisplaySpaceRect); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3440 | display->setDisplayName(state.displayName); |
Vishnu Nair | a119aaa | 2021-09-24 07:19:35 -0700 | [diff] [blame] | 3441 | display->setFlags(state.flags); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3442 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3443 | return display; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3444 | } |
| 3445 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3446 | void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, |
| 3447 | const DisplayDeviceState& state) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3448 | ui::Size resolution(0, 0); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3449 | ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN); |
| 3450 | if (state.physical) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3451 | resolution = state.physical->activeMode->getResolution(); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3452 | pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888); |
| 3453 | } else if (state.surface != nullptr) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3454 | int status = state.surface->query(NATIVE_WINDOW_WIDTH, &resolution.width); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3455 | ALOGE_IF(status != NO_ERROR, "Unable to query width (%d)", status); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3456 | status = state.surface->query(NATIVE_WINDOW_HEIGHT, &resolution.height); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3457 | ALOGE_IF(status != NO_ERROR, "Unable to query height (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3458 | int format; |
| 3459 | status = state.surface->query(NATIVE_WINDOW_FORMAT, &format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3460 | ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3461 | pixelFormat = static_cast<ui::PixelFormat>(format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3462 | } else { |
| 3463 | // Virtual displays without a surface are dormant: |
| 3464 | // they have external state (layer stack, projection, |
| 3465 | // etc.) but no internal state (i.e. a DisplayDevice). |
| 3466 | return; |
| 3467 | } |
| 3468 | |
| 3469 | compositionengine::DisplayCreationArgsBuilder builder; |
| 3470 | if (const auto& physical = state.physical) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3471 | builder.setId(physical->id); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3472 | } else { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 3473 | builder.setId(acquireVirtualDisplay(resolution, pixelFormat)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3474 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3475 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3476 | builder.setPixels(resolution); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3477 | builder.setIsSecure(state.isSecure); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 3478 | builder.setPowerAdvisor(mPowerAdvisor.get()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3479 | builder.setName(state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3480 | auto compositionDisplay = getCompositionEngine().createDisplay(builder.build()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3481 | compositionDisplay->setLayerCachingEnabled(mLayerCachingEnabled); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3482 | |
| 3483 | sp<compositionengine::DisplaySurface> displaySurface; |
| 3484 | sp<IGraphicBufferProducer> producer; |
| 3485 | sp<IGraphicBufferProducer> bqProducer; |
| 3486 | sp<IGraphicBufferConsumer> bqConsumer; |
| 3487 | getFactory().createBufferQueue(&bqProducer, &bqConsumer, /*consumerIsSurfaceFlinger =*/false); |
| 3488 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3489 | if (state.isVirtual()) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3490 | const auto displayId = VirtualDisplayId::tryCast(compositionDisplay->getId()); |
| 3491 | LOG_FATAL_IF(!displayId); |
| 3492 | auto surface = sp<VirtualDisplaySurface>::make(getHwComposer(), *displayId, state.surface, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3493 | bqProducer, bqConsumer, state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3494 | displaySurface = surface; |
| 3495 | producer = std::move(surface); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3496 | } else { |
| 3497 | ALOGE_IF(state.surface != nullptr, |
| 3498 | "adding a supported display, but rendering " |
| 3499 | "surface is provided (%p), ignoring it", |
| 3500 | state.surface.get()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3501 | const auto displayId = PhysicalDisplayId::tryCast(compositionDisplay->getId()); |
| 3502 | LOG_FATAL_IF(!displayId); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3503 | displaySurface = |
| 3504 | sp<FramebufferSurface>::make(getHwComposer(), *displayId, bqConsumer, |
| 3505 | state.physical->activeMode->getResolution(), |
| 3506 | ui::Size(maxGraphicsWidth, maxGraphicsHeight)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3507 | producer = bqProducer; |
| 3508 | } |
| 3509 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3510 | LOG_FATAL_IF(!displaySurface); |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3511 | auto display = setupNewDisplayDeviceInternal(displayToken, std::move(compositionDisplay), state, |
| 3512 | displaySurface, producer); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3513 | |
| 3514 | if (mScheduler && !display->isVirtual()) { |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3515 | const auto displayId = display->getPhysicalId(); |
| 3516 | { |
Dominik Laskowski | 59db956 | 2022-10-27 16:18:53 -0400 | [diff] [blame] | 3517 | // TODO(b/241285876): Annotate `processDisplayAdded` instead. |
| 3518 | ftl::FakeGuard guard(kMainThreadContext); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3519 | |
| 3520 | // For hotplug reconnect, renew the registration since display modes have been reloaded. |
| 3521 | mScheduler->registerDisplay(displayId, display->holdRefreshRateSelector()); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3522 | } |
Dominik Laskowski | b5a094b | 2022-10-27 12:00:12 -0400 | [diff] [blame] | 3523 | |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3524 | dispatchDisplayHotplugEvent(displayId, true); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3525 | } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3526 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3527 | if (display->isVirtual()) { |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 3528 | display->adjustRefreshRate(mScheduler->getPacesetterRefreshRate()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3529 | } |
| 3530 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3531 | mDisplays.try_emplace(displayToken, std::move(display)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3532 | } |
| 3533 | |
| 3534 | void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3535 | auto display = getDisplayDeviceLocked(displayToken); |
| 3536 | if (display) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3537 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3538 | |
| 3539 | if (display->isVirtual()) { |
| 3540 | releaseVirtualDisplay(display->getVirtualId()); |
| 3541 | } else { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3542 | dispatchDisplayHotplugEvent(display->getPhysicalId(), false); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 3543 | mScheduler->unregisterDisplay(display->getPhysicalId()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3544 | } |
| 3545 | } |
| 3546 | |
| 3547 | mDisplays.erase(displayToken); |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3548 | |
| 3549 | if (display && display->isVirtual()) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 3550 | static_cast<void>(mScheduler->schedule([display = std::move(display)] { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3551 | // Destroy the display without holding the mStateLock. |
| 3552 | // This is a temporary solution until we can manage transaction queues without |
| 3553 | // holding the mStateLock. |
| 3554 | // With blast, the IGBP that is passed to the VirtualDisplaySurface is owned by the |
| 3555 | // client. When the IGBP is disconnected, its buffer cache in SF will be cleared |
| 3556 | // via SurfaceComposerClient::doUncacheBufferTransaction. This call from the client |
| 3557 | // ends up running on the main thread causing a deadlock since setTransactionstate |
| 3558 | // will try to acquire the mStateLock. Instead we extend the lifetime of |
| 3559 | // DisplayDevice and destroy it in the main thread without holding the mStateLock. |
| 3560 | // The display will be disconnected and removed from the mDisplays list so it will |
| 3561 | // not be accessible. |
| 3562 | })); |
| 3563 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, |
| 3567 | const DisplayDeviceState& currentState, |
| 3568 | const DisplayDeviceState& drawingState) { |
| 3569 | const sp<IBinder> currentBinder = IInterface::asBinder(currentState.surface); |
| 3570 | const sp<IBinder> drawingBinder = IInterface::asBinder(drawingState.surface); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3571 | |
| 3572 | // Recreate the DisplayDevice if the surface or sequence ID changed. |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3573 | if (currentBinder != drawingBinder || currentState.sequenceId != drawingState.sequenceId) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3574 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3575 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3576 | if (display->isVirtual()) { |
| 3577 | releaseVirtualDisplay(display->getVirtualId()); |
| 3578 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3579 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3580 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3581 | mDisplays.erase(displayToken); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3582 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3583 | if (const auto& physical = currentState.physical) { |
| 3584 | getHwComposer().allocatePhysicalDisplay(physical->hwcDisplayId, physical->id); |
| 3585 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3586 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3587 | processDisplayAdded(displayToken, currentState); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3588 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3589 | if (currentState.physical) { |
Marin Shalamanov | 4c5e301 | 2020-06-04 21:41:42 +0200 | [diff] [blame] | 3590 | const auto display = getDisplayDeviceLocked(displayToken); |
| 3591 | setPowerModeInternal(display, hal::PowerMode::ON); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3592 | |
| 3593 | // TODO(b/175678251) Call a listener instead. |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 3594 | if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) { |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 3595 | resetPhaseConfiguration(display->getActiveMode().fps); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3596 | } |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3597 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3598 | return; |
| 3599 | } |
| 3600 | |
| 3601 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3602 | if (currentState.layerStack != drawingState.layerStack) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3603 | display->setLayerFilter( |
| 3604 | makeLayerFilterForDisplay(display->getId(), currentState.layerStack)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3605 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 3606 | if (currentState.flags != drawingState.flags) { |
| 3607 | display->setFlags(currentState.flags); |
| 3608 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3609 | if ((currentState.orientation != drawingState.orientation) || |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3610 | (currentState.layerStackSpaceRect != drawingState.layerStackSpaceRect) || |
| 3611 | (currentState.orientedDisplaySpaceRect != drawingState.orientedDisplaySpaceRect)) { |
| 3612 | display->setProjection(currentState.orientation, currentState.layerStackSpaceRect, |
| 3613 | currentState.orientedDisplaySpaceRect); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3614 | if (display->getId() == mActiveDisplayId) { |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 3615 | mActiveDisplayTransformHint = display->getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 3616 | sActiveDisplayRotationFlags = |
| 3617 | ui::Transform::toRotationFlags(display->getOrientation()); |
Arthur Hung | b6aa9a0 | 2021-06-09 14:23:01 +0800 | [diff] [blame] | 3618 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3619 | } |
| 3620 | if (currentState.width != drawingState.width || |
| 3621 | currentState.height != drawingState.height) { |
| 3622 | display->setDisplaySize(currentState.width, currentState.height); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 3623 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3624 | if (display->getId() == mActiveDisplayId) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 3625 | onActiveDisplaySizeChanged(*display); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3626 | } |
| 3627 | } |
| 3628 | } |
| 3629 | } |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 3630 | |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 3631 | void SurfaceFlinger::resetPhaseConfiguration(Fps refreshRate) { |
| 3632 | // Cancel the pending refresh rate change, if any, before updating the phase configuration. |
| 3633 | mScheduler->vsyncModulator().cancelRefreshRateChange(); |
| 3634 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3635 | mVsyncConfiguration->reset(); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3636 | updatePhaseConfiguration(refreshRate); |
| 3637 | mRefreshRateStats->setRefreshRate(refreshRate); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3638 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3639 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3640 | void SurfaceFlinger::processDisplayChangesLocked() { |
| 3641 | // here we take advantage of Vector's copy-on-write semantics to |
| 3642 | // improve performance by skipping the transaction entirely when |
| 3643 | // know that the lists are identical |
| 3644 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays); |
| 3645 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays); |
| 3646 | if (!curr.isIdenticalTo(draw)) { |
| 3647 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3648 | mUpdateInputInfo = true; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3649 | |
| 3650 | // find the displays that were removed |
| 3651 | // (ie: in drawing state but not in current state) |
| 3652 | // also handle displays that changed |
| 3653 | // (ie: displays that are in both lists) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3654 | for (size_t i = 0; i < draw.size(); i++) { |
| 3655 | const wp<IBinder>& displayToken = draw.keyAt(i); |
| 3656 | const ssize_t j = curr.indexOfKey(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3657 | if (j < 0) { |
| 3658 | // in drawing state but not in current state |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3659 | processDisplayRemoved(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3660 | } else { |
| 3661 | // this display is in both lists. see if something changed. |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3662 | const DisplayDeviceState& currentState = curr[j]; |
| 3663 | const DisplayDeviceState& drawingState = draw[i]; |
| 3664 | processDisplayChanged(displayToken, currentState, drawingState); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3665 | } |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | // find displays that were added |
| 3669 | // (ie: in current state but not in drawing state) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3670 | for (size_t i = 0; i < curr.size(); i++) { |
| 3671 | const wp<IBinder>& displayToken = curr.keyAt(i); |
| 3672 | if (draw.indexOfKey(displayToken) < 0) { |
| 3673 | processDisplayAdded(displayToken, curr[i]); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3674 | } |
| 3675 | } |
| 3676 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3677 | |
| 3678 | mDrawingState.displays = mCurrentState.displays; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3679 | } |
| 3680 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3681 | void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { |
| 3682 | // Commit display transactions. |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3683 | const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3684 | mFrontEndDisplayInfosChanged = displayTransactionNeeded; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3685 | if (displayTransactionNeeded && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3686 | processDisplayChangesLocked(); |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 3687 | mFrontEndDisplayInfos.clear(); |
| 3688 | for (const auto& [_, display] : mDisplays) { |
| 3689 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 3690 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3691 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 3692 | mForceTransactionDisplayChange = displayTransactionNeeded; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3693 | |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3694 | if (mSomeChildrenChanged) { |
| 3695 | mVisibleRegionsDirty = true; |
| 3696 | mSomeChildrenChanged = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3697 | mUpdateInputInfo = true; |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3698 | } |
| 3699 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3700 | // Update transform hint. |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 3701 | if (transactionFlags & (eTransformHintUpdateNeeded | eDisplayTransactionNeeded)) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3702 | // Layers and/or displays have changed, so update the transform hint for each layer. |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3703 | // |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 3704 | // NOTE: we do this here, rather than when presenting the display so that |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3705 | // the hint is set before we acquire a buffer from the surface texture. |
| 3706 | // |
| 3707 | // NOTE: layer transactions have taken place already, so we use their |
| 3708 | // drawing state. However, SurfaceFlinger's own transaction has not |
| 3709 | // happened yet, so we must use the current state layer list |
| 3710 | // (soon to become the drawing state list). |
| 3711 | // |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3712 | sp<const DisplayDevice> hintDisplay; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3713 | ui::LayerStack layerStack; |
| 3714 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3715 | mCurrentState.traverse([&](Layer* layer) REQUIRES(mStateLock) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3716 | // NOTE: we rely on the fact that layers are sorted by |
| 3717 | // layerStack first (so we don't have to traverse the list |
| 3718 | // of displays for every layer). |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3719 | if (const auto filter = layer->getOutputFilter(); layerStack != filter.layerStack) { |
| 3720 | layerStack = filter.layerStack; |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3721 | hintDisplay = nullptr; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3722 | |
| 3723 | // Find the display that includes the layer. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3724 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3725 | if (!display->getCompositionDisplay()->includesLayer(filter)) { |
| 3726 | continue; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3727 | } |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3728 | |
| 3729 | // Pick the primary display if another display mirrors the layer. |
| 3730 | if (hintDisplay) { |
| 3731 | hintDisplay = nullptr; |
| 3732 | break; |
| 3733 | } |
| 3734 | |
| 3735 | hintDisplay = display; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3736 | } |
| 3737 | } |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 3738 | |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3739 | if (!hintDisplay) { |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3740 | // NOTE: TEMPORARY FIX ONLY. Real fix should cause layers to |
| 3741 | // redraw after transform hint changes. See bug 8508397. |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3742 | // could be null when this layer is using a layerStack |
| 3743 | // that is not visible on any display. Also can occur at |
| 3744 | // screen off/on times. |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3745 | // U Update: Don't provide stale hints to the clients. For |
| 3746 | // special cases where we want the app to draw its |
| 3747 | // first frame before the display is available, we rely |
| 3748 | // on WMS and DMS to provide the right information |
| 3749 | // so the client can calculate the hint. |
| 3750 | ALOGV("Skipping reporting transform hint update for %s", layer->getDebugName()); |
| 3751 | layer->skipReportingTransformHint(); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3752 | } else { |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3753 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3754 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3755 | }); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3756 | } |
| 3757 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3758 | if (mLayersAdded) { |
| 3759 | mLayersAdded = false; |
| 3760 | // Layers have been added. |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3761 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3762 | mUpdateInputInfo = true; |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3763 | } |
| 3764 | |
| 3765 | // some layers might have been removed, so |
| 3766 | // we need to update the regions they're exposing. |
| 3767 | if (mLayersRemoved) { |
| 3768 | mLayersRemoved = false; |
| 3769 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3770 | mUpdateInputInfo = true; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3771 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3772 | if (mLayersPendingRemoval.indexOf(sp<Layer>::fromExisting(layer)) >= 0) { |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3773 | // this layer is not visible anymore |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3774 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3775 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3776 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 3777 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3778 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3779 | } |
| 3780 | |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 3781 | if (transactionFlags & eInputInfoUpdateNeeded) { |
| 3782 | mUpdateInputInfo = true; |
| 3783 | } |
| 3784 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3785 | doCommitTransactions(); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 3786 | } |
| 3787 | |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3788 | void SurfaceFlinger::updateInputFlinger(VsyncId vsyncId, TimePoint frameTime) { |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3789 | if (!mInputFlinger || (!mUpdateInputInfo && mInputWindowCommands.empty())) { |
Vishnu Nair | 42a27b5 | 2021-11-18 15:35:22 -0800 | [diff] [blame] | 3790 | return; |
| 3791 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3792 | ATRACE_CALL(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3793 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3794 | std::vector<WindowInfo> windowInfos; |
| 3795 | std::vector<DisplayInfo> displayInfos; |
| 3796 | bool updateWindowInfo = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3797 | if (mUpdateInputInfo) { |
| 3798 | mUpdateInputInfo = false; |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3799 | updateWindowInfo = true; |
| 3800 | buildWindowInfos(windowInfos, displayInfos); |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3801 | } |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3802 | |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3803 | std::unordered_set<int32_t> visibleWindowIds; |
| 3804 | for (WindowInfo& windowInfo : windowInfos) { |
| 3805 | if (!windowInfo.inputConfig.test(WindowInfo::InputConfig::NOT_VISIBLE)) { |
| 3806 | visibleWindowIds.insert(windowInfo.id); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3807 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3808 | } |
| 3809 | bool visibleWindowsChanged = false; |
| 3810 | if (visibleWindowIds != mVisibleWindowIds) { |
| 3811 | visibleWindowsChanged = true; |
| 3812 | mVisibleWindowIds = std::move(visibleWindowIds); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3813 | } |
| 3814 | |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 3815 | BackgroundExecutor::getInstance().sendCallbacks({[updateWindowInfo, |
| 3816 | windowInfos = std::move(windowInfos), |
| 3817 | displayInfos = std::move(displayInfos), |
| 3818 | inputWindowCommands = |
| 3819 | std::move(mInputWindowCommands), |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3820 | inputFlinger = mInputFlinger, this, |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3821 | visibleWindowsChanged, vsyncId, frameTime]() { |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3822 | ATRACE_NAME("BackgroundExecutor::updateInputFlinger"); |
| 3823 | if (updateWindowInfo) { |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 3824 | mWindowInfosListenerInvoker |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3825 | ->windowInfosChanged(gui::WindowInfosUpdate{std::move(windowInfos), |
| 3826 | std::move(displayInfos), |
| 3827 | ftl::to_underlying(vsyncId), |
| 3828 | frameTime.ns()}, |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3829 | std::move( |
| 3830 | inputWindowCommands.windowInfosReportedListeners), |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3831 | /* forceImmediateCall= */ visibleWindowsChanged || |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3832 | !inputWindowCommands.focusRequests.empty()); |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 3833 | } else { |
| 3834 | // If there are listeners but no changes to input windows, call the listeners |
| 3835 | // immediately. |
| 3836 | for (const auto& listener : inputWindowCommands.windowInfosReportedListeners) { |
| 3837 | if (IInterface::asBinder(listener)->isBinderAlive()) { |
| 3838 | listener->onWindowInfosReported(); |
| 3839 | } |
| 3840 | } |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3841 | } |
| 3842 | for (const auto& focusRequest : inputWindowCommands.focusRequests) { |
| 3843 | inputFlinger->setFocusedWindow(focusRequest); |
| 3844 | } |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 3845 | }}); |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 3846 | |
Arthur Hung | 6cbb975 | 2019-09-05 16:38:18 +0800 | [diff] [blame] | 3847 | mInputWindowCommands.clear(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3848 | } |
| 3849 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3850 | void SurfaceFlinger::persistDisplayBrightness(bool needsComposite) { |
| 3851 | const bool supportsDisplayBrightnessCommand = getHwComposer().getComposer()->isSupported( |
| 3852 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 3853 | if (!supportsDisplayBrightnessCommand) { |
| 3854 | return; |
| 3855 | } |
| 3856 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3857 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3858 | if (const auto brightness = display->getStagedBrightness(); brightness) { |
| 3859 | if (!needsComposite) { |
| 3860 | const status_t error = |
| 3861 | getHwComposer() |
| 3862 | .setDisplayBrightness(display->getPhysicalId(), *brightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 3863 | display->getCompositionDisplay() |
| 3864 | ->getState() |
| 3865 | .displayBrightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3866 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 3867 | .applyImmediately = true}) |
| 3868 | .get(); |
| 3869 | |
| 3870 | ALOGE_IF(error != NO_ERROR, |
| 3871 | "Error setting display brightness for display %s: %d (%s)", |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 3872 | to_string(display->getId()).c_str(), error, strerror(error)); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3873 | } |
| 3874 | display->persistBrightness(needsComposite); |
| 3875 | } |
| 3876 | } |
| 3877 | } |
| 3878 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3879 | void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, |
| 3880 | std::vector<DisplayInfo>& outDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3881 | static size_t sNumWindowInfos = 0; |
| 3882 | outWindowInfos.reserve(sNumWindowInfos); |
| 3883 | sNumWindowInfos = 0; |
| 3884 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3885 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3886 | mLayerSnapshotBuilder.forEachInputSnapshot( |
| 3887 | [&outWindowInfos](const frontend::LayerSnapshot& snapshot) { |
| 3888 | outWindowInfos.push_back(snapshot.inputInfo); |
| 3889 | }); |
| 3890 | } else { |
| 3891 | mDrawingState.traverseInReverseZOrder([&](Layer* layer) { |
| 3892 | if (!layer->needsInputInfo()) return; |
| 3893 | const auto opt = |
| 3894 | mFrontEndDisplayInfos.get(layer->getLayerStack()) |
| 3895 | .transform([](const frontend::DisplayInfo& info) { |
| 3896 | return Layer::InputDisplayArgs{&info.transform, info.isSecure}; |
| 3897 | }); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3898 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3899 | outWindowInfos.push_back(layer->fillInputInfo(opt.value_or(Layer::InputDisplayArgs{}))); |
| 3900 | }); |
| 3901 | } |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 3902 | |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3903 | sNumWindowInfos = outWindowInfos.size(); |
| 3904 | |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 3905 | outDisplayInfos.reserve(mFrontEndDisplayInfos.size()); |
| 3906 | for (const auto& [_, info] : mFrontEndDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3907 | outDisplayInfos.push_back(info.info); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 3908 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 3909 | } |
| 3910 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3911 | void SurfaceFlinger::updateCursorAsync() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3912 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3913 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3914 | if (HalDisplayId::tryCast(display->getId())) { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3915 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 3916 | } |
| 3917 | } |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 3918 | |
| 3919 | constexpr bool kCursorOnly = true; |
| 3920 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3921 | mCompositionEngine->updateCursorAsync(refreshArgs); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3922 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 3925 | void SurfaceFlinger::requestHardwareVsync(PhysicalDisplayId displayId, bool enable) { |
| 3926 | getHwComposer().setVsyncEnabled(displayId, enable ? hal::Vsync::ENABLE : hal::Vsync::DISABLE); |
| 3927 | } |
| 3928 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3929 | void SurfaceFlinger::requestDisplayModes(std::vector<display::DisplayModeRequest> modeRequests) { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 3930 | if (mBootStage != BootStage::FINISHED) { |
| 3931 | ALOGV("Currently in the boot stage, skipping display mode changes"); |
| 3932 | return; |
| 3933 | } |
| 3934 | |
| 3935 | ATRACE_CALL(); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3936 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 3937 | // If this is called from the main thread mStateLock must be locked before |
| 3938 | // Currently the only way to call this function from the main thread is from |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 3939 | // Scheduler::chooseRefreshRateForContent |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 3940 | |
| 3941 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
Marin Shalamanov | a63f9ae | 2021-11-03 15:05:16 +0100 | [diff] [blame] | 3942 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3943 | for (auto& request : modeRequests) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3944 | const auto& modePtr = request.mode.modePtr; |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 3945 | |
| 3946 | const auto displayId = modePtr->getPhysicalDisplayId(); |
| 3947 | const auto display = getDisplayDeviceLocked(displayId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3948 | |
| 3949 | if (!display) continue; |
| 3950 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3951 | if (!display->isPoweredOn()) { |
| 3952 | ALOGV("%s(%s): Display is powered off", __func__, to_string(displayId).c_str()); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 3953 | continue; |
| 3954 | } |
| 3955 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3956 | if (display->refreshRateSelector().isModeAllowed(request.mode)) { |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3957 | setDesiredActiveMode(std::move(request)); |
| 3958 | } else { |
| 3959 | ALOGV("%s: Mode %d is disallowed for display %s", __func__, modePtr->getId().value(), |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3960 | to_string(displayId).c_str()); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3961 | } |
| 3962 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 3963 | } |
| 3964 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 3965 | void SurfaceFlinger::triggerOnFrameRateOverridesChanged() { |
| 3966 | PhysicalDisplayId displayId = [&]() { |
| 3967 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 3968 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 3969 | }(); |
| 3970 | |
| 3971 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
| 3972 | } |
| 3973 | |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 3974 | void SurfaceFlinger::notifyCpuLoadUp() { |
| 3975 | mPowerAdvisor->notifyCpuLoadUp(); |
| 3976 | } |
| 3977 | |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 3978 | void SurfaceFlinger::onChoreographerAttached() { |
| 3979 | ATRACE_CALL(); |
| 3980 | if (mLayerLifecycleManagerEnabled) { |
| 3981 | mUpdateAttachedChoreographer = true; |
| 3982 | scheduleCommit(FrameHint::kNone); |
| 3983 | } |
| 3984 | } |
| 3985 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3986 | void SurfaceFlinger::initScheduler(const sp<const DisplayDevice>& display) { |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3987 | using namespace scheduler; |
| 3988 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3989 | LOG_ALWAYS_FATAL_IF(mScheduler); |
| 3990 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3991 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 3992 | const Fps activeRefreshRate = activeMode.fps; |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 3993 | mRefreshRateStats = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3994 | std::make_unique<RefreshRateStats>(*mTimeStats, activeRefreshRate, hal::PowerMode::OFF); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3995 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 3996 | mVsyncConfiguration = getFactory().createVsyncConfiguration(activeRefreshRate); |
Ady Abraham | 9e16a48 | 2019-12-03 17:19:41 -0800 | [diff] [blame] | 3997 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3998 | FeatureFlags features; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 3999 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4000 | if (sysprop::use_content_detection_for_refresh_rate(false)) { |
| 4001 | features |= Feature::kContentDetection; |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 4002 | if (base::GetBoolProperty("debug.sf.enable_small_dirty_detection"s, false)) { |
| 4003 | features |= Feature::kSmallDirtyContentDetection; |
| 4004 | } |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4005 | } |
| 4006 | if (base::GetBoolProperty("debug.sf.show_predicted_vsync"s, false)) { |
| 4007 | features |= Feature::kTracePredictedVsync; |
| 4008 | } |
| 4009 | if (!base::GetBoolProperty("debug.sf.vsync_reactor_ignore_present_fences"s, false) && |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 4010 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4011 | features |= Feature::kPresentFences; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4012 | } |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4013 | if (display->refreshRateSelector().kernelIdleTimerController()) { |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4014 | features |= Feature::kKernelIdleTimer; |
| 4015 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4016 | if (mBackpressureGpuComposition) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4017 | features |= Feature::kBackpressureGpuComposition; |
| 4018 | } |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4019 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4020 | auto modulatorPtr = sp<VsyncModulator>::make(mVsyncConfiguration->getCurrentConfigs()); |
| 4021 | |
| 4022 | mScheduler = std::make_unique<Scheduler>(static_cast<ICompositor&>(*this), |
| 4023 | static_cast<ISchedulerCallback&>(*this), features, |
| 4024 | std::move(modulatorPtr)); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4025 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector()); |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4026 | mScheduler->startTimers(); |
| 4027 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 4028 | const auto configs = mVsyncConfiguration->getCurrentConfigs(); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4029 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4030 | mAppConnectionHandle = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4031 | mScheduler->createEventThread(Scheduler::Cycle::Render, |
| 4032 | mFrameTimeline->getTokenManager(), |
| 4033 | /* workDuration */ configs.late.appWorkDuration, |
| 4034 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4035 | mSfConnectionHandle = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4036 | mScheduler->createEventThread(Scheduler::Cycle::LastComposite, |
| 4037 | mFrameTimeline->getTokenManager(), |
| 4038 | /* workDuration */ activeRefreshRate.getPeriod(), |
| 4039 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4040 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4041 | mScheduler->initVsync(mScheduler->getVsyncSchedule()->getDispatch(), |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 4042 | *mFrameTimeline->getTokenManager(), configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4043 | |
| 4044 | mRegionSamplingThread = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4045 | sp<RegionSamplingThread>::make(*this, |
| 4046 | RegionSamplingThread::EnvironmentTimingTunables()); |
| 4047 | mFpsReporter = sp<FpsReporter>::make(*mFrameTimeline, *this); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4048 | } |
| 4049 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4050 | void SurfaceFlinger::updatePhaseConfiguration(Fps refreshRate) { |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 4051 | mVsyncConfiguration->setRefreshRateFps(refreshRate); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4052 | mScheduler->setVsyncConfigSet(mVsyncConfiguration->getCurrentConfigs(), |
| 4053 | refreshRate.getPeriod()); |
Dominik Laskowski | 08d05c2 | 2020-07-22 00:05:08 -0700 | [diff] [blame] | 4054 | } |
| 4055 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4056 | void SurfaceFlinger::doCommitTransactions() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 4057 | ATRACE_CALL(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4058 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4059 | if (!mLayersPendingRemoval.isEmpty()) { |
| 4060 | // Notify removed layers now that they can't be drawn from |
| 4061 | for (const auto& l : mLayersPendingRemoval) { |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4062 | // Ensure any buffers set to display on any children are released. |
| 4063 | if (l->isRemovedFromCurrentState()) { |
| 4064 | l->latchAndReleaseBuffer(); |
| 4065 | } |
| 4066 | |
chaviw | 6852bff | 2022-04-19 17:35:11 -0500 | [diff] [blame] | 4067 | // If a layer has a parent, we allow it to out-live it's handle |
| 4068 | // with the idea that the parent holds a reference and will eventually |
| 4069 | // be cleaned up. However no one cleans up the top-level so we do so |
| 4070 | // here. |
| 4071 | if (l->isAtRoot()) { |
| 4072 | l->setIsAtRoot(false); |
| 4073 | mCurrentState.layersSortedByZ.remove(l); |
| 4074 | } |
| 4075 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4076 | // If the layer has been removed and has no parent, then it will not be reachable |
| 4077 | // when traversing layers on screen. Add the layer to the offscreenLayers set to |
| 4078 | // ensure we can copy its current to drawing state. |
| 4079 | if (!l->getParent()) { |
| 4080 | mOffscreenLayers.emplace(l.get()); |
| 4081 | } |
| 4082 | } |
| 4083 | mLayersPendingRemoval.clear(); |
| 4084 | } |
| 4085 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4086 | mDrawingState = mCurrentState; |
| 4087 | // clear the "changed" flags in current state |
| 4088 | mCurrentState.colorMatrixChanged = false; |
| 4089 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4090 | if (mVisibleRegionsDirty) { |
| 4091 | for (const auto& rootLayer : mDrawingState.layersSortedByZ) { |
| 4092 | rootLayer->commitChildList(); |
| 4093 | } |
Andrei Stanciu | dadac5a | 2020-08-05 17:02:34 +0300 | [diff] [blame] | 4094 | } |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4095 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4096 | commitOffscreenLayers(); |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4097 | if (mLayerMirrorRoots.size() > 0) { |
| 4098 | std::deque<Layer*> pendingUpdates; |
| 4099 | pendingUpdates.insert(pendingUpdates.end(), mLayerMirrorRoots.begin(), |
| 4100 | mLayerMirrorRoots.end()); |
| 4101 | std::vector<Layer*> needsUpdating; |
| 4102 | for (Layer* cloneRoot : mLayerMirrorRoots) { |
| 4103 | pendingUpdates.pop_front(); |
| 4104 | if (cloneRoot->isRemovedFromCurrentState()) { |
| 4105 | continue; |
| 4106 | } |
| 4107 | if (cloneRoot->updateMirrorInfo(pendingUpdates)) { |
| 4108 | } else { |
| 4109 | needsUpdating.push_back(cloneRoot); |
| 4110 | } |
| 4111 | } |
| 4112 | for (Layer* cloneRoot : needsUpdating) { |
| 4113 | cloneRoot->updateMirrorInfo({}); |
| 4114 | } |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4115 | } |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4116 | } |
| 4117 | |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4118 | void SurfaceFlinger::commitOffscreenLayers() { |
| 4119 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4120 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, [](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4121 | if (layer->clearTransactionFlags(eTransactionNeeded)) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4122 | layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4123 | layer->commitChildList(); |
| 4124 | } |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4125 | }); |
| 4126 | } |
| 4127 | } |
| 4128 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4129 | void SurfaceFlinger::invalidateLayerStack(const ui::LayerFilter& layerFilter, const Region& dirty) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4130 | for (const auto& [token, displayDevice] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4131 | auto display = displayDevice->getCompositionDisplay(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4132 | if (display->includesLayer(layerFilter)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4133 | display->editState().dirtyRegion.orSelf(dirty); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 4134 | } |
| 4135 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 4136 | } |
| 4137 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4138 | bool SurfaceFlinger::latchBuffers() { |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 4139 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 4140 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4141 | const nsecs_t latchTime = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4142 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4143 | bool visibleRegions = false; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4144 | bool frameQueued = false; |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4145 | bool newDataLatched = false; |
Eric Penner | 51c59cd | 2014-07-28 19:51:58 -0700 | [diff] [blame] | 4146 | |
| 4147 | // Store the set of layers that need updates. This set must not change as |
| 4148 | // buffers are being latched, as this could result in a deadlock. |
| 4149 | // Example: Two producers share the same command stream and: |
| 4150 | // 1.) Layer 0 is latched |
| 4151 | // 2.) Layer 0 gets a new frame |
| 4152 | // 2.) Layer 1 gets a new frame |
| 4153 | // 3.) Layer 1 is latched. |
| 4154 | // Display is now waiting on Layer 1's frame, which is behind layer 0's |
| 4155 | // second frame. But layer 0's second frame could be waiting on display. |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4156 | mDrawingState.traverse([&](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4157 | if (layer->clearTransactionFlags(eTransactionNeeded) || mForceTransactionDisplayChange) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4158 | const uint32_t flags = layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4159 | if (flags & Layer::eVisibleRegion) { |
| 4160 | mVisibleRegionsDirty = true; |
| 4161 | } |
| 4162 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4163 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4164 | if (layer->hasReadyFrame() || layer->willReleaseBufferOnLatch()) { |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4165 | frameQueued = true; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4166 | mLayersWithQueuedFrames.emplace(sp<Layer>::fromExisting(layer)); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4167 | } else { |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 4168 | layer->useEmptyDamage(); |
Vishnu Nair | c09c023 | 2023-03-02 03:22:35 +0000 | [diff] [blame] | 4169 | if (!layer->hasBuffer()) { |
| 4170 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 4171 | // instead of a missed frame. This is used to identify scenarios where we |
| 4172 | // could not latch a buffer or apply a transaction due to backpressure. |
| 4173 | // We only update the latch time for buffer less layers here, the latch time |
| 4174 | // is updated for buffer layers when the buffer is latched. |
| 4175 | layer->updateLastLatchTime(latchTime); |
| 4176 | } |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4177 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4178 | }); |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4179 | mForceTransactionDisplayChange = false; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4180 | |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4181 | // The client can continue submitting buffers for offscreen layers, but they will not |
| 4182 | // be shown on screen. Therefore, we need to latch and release buffers of offscreen |
| 4183 | // layers to ensure dequeueBuffer doesn't block indefinitely. |
| 4184 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4185 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4186 | [&](Layer* l) { l->latchAndReleaseBuffer(); }); |
| 4187 | } |
| 4188 | |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4189 | if (!mLayersWithQueuedFrames.empty()) { |
| 4190 | // mStateLock is needed for latchBuffer as LayerRejecter::reject() |
| 4191 | // writes to Layer current state. See also b/119481871 |
| 4192 | Mutex::Autolock lock(mStateLock); |
| 4193 | |
Alec Mouri | 2f7d9ae | 2020-11-30 19:32:33 -0800 | [diff] [blame] | 4194 | for (const auto& layer : mLayersWithQueuedFrames) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4195 | if (layer->willReleaseBufferOnLatch()) { |
| 4196 | mLayersWithBuffersRemoved.emplace(layer); |
| 4197 | } |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 4198 | if (layer->latchBuffer(visibleRegions, latchTime)) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4199 | mLayersPendingRefresh.push_back(layer); |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4200 | newDataLatched = true; |
| 4201 | } |
Vishnu Nair | 1b70019 | 2022-02-04 10:09:47 -0800 | [diff] [blame] | 4202 | layer->useSurfaceDamage(); |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4203 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4204 | } |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 4205 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 4206 | mVisibleRegionsDirty |= visibleRegions; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4207 | |
| 4208 | // If we will need to wake up at some time in the future to deal with a |
| 4209 | // queued frame that shouldn't be displayed during this vsync period, wake |
| 4210 | // up during the next vsync period to check again. |
Chia-I Wu | a36bf92 | 2017-06-30 12:51:05 -0700 | [diff] [blame] | 4211 | if (frameQueued && (mLayersWithQueuedFrames.empty() || !newDataLatched)) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4212 | scheduleCommit(FrameHint::kNone); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4213 | } |
| 4214 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 4215 | // enter boot animation on first buffer latch |
| 4216 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 4217 | ALOGI("Enter boot animation"); |
| 4218 | mBootStage = BootStage::BOOTANIMATION; |
| 4219 | } |
| 4220 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4221 | if (mLayerMirrorRoots.size() > 0) { |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4222 | mDrawingState.traverse([&](Layer* layer) { layer->updateCloneBufferInfo(); }); |
| 4223 | } |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 4224 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4225 | // Only continue with the refresh if there is actually new work to do |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4226 | return !mLayersWithQueuedFrames.empty() && newDataLatched; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4227 | } |
| 4228 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4229 | status_t SurfaceFlinger::addClientLayer(LayerCreationArgs& args, const sp<IBinder>& handle, |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4230 | const sp<Layer>& layer, const wp<Layer>& parent, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4231 | uint32_t* outTransformHint) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4232 | if (mNumLayers >= MAX_LAYERS) { |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4233 | ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(), |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4234 | MAX_LAYERS); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4235 | static_cast<void>(mScheduler->schedule([=] { |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4236 | ALOGE("Dumping layer keeping > 20 children alive:"); |
| 4237 | bool leakingParentLayerFound = false; |
| 4238 | mDrawingState.traverse([&](Layer* layer) { |
| 4239 | if (leakingParentLayerFound) { |
| 4240 | return; |
| 4241 | } |
| 4242 | if (layer->getChildrenCount() > 20) { |
| 4243 | leakingParentLayerFound = true; |
| 4244 | sp<Layer> parent = sp<Layer>::fromExisting(layer); |
| 4245 | while (parent) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4246 | ALOGE("Parent Layer: %s%s", parent->getName().c_str(), |
| 4247 | (parent->isHandleAlive() ? "handleAlive" : "")); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4248 | parent = parent->getParent(); |
| 4249 | } |
| 4250 | // Sample up to 100 layers |
| 4251 | ALOGE("Dumping random sampling of child layers total(%zu): ", |
| 4252 | layer->getChildrenCount()); |
| 4253 | int sampleSize = (layer->getChildrenCount() / 100) + 1; |
| 4254 | layer->traverseChildren([&](Layer* layer) { |
| 4255 | if (rand() % sampleSize == 0) { |
| 4256 | ALOGE("Child Layer: %s", layer->getName().c_str()); |
| 4257 | } |
| 4258 | }); |
| 4259 | } |
| 4260 | }); |
| 4261 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4262 | int numLayers = 0; |
| 4263 | mDrawingState.traverse([&](Layer* layer) { numLayers++; }); |
| 4264 | |
| 4265 | ALOGE("Dumping random sampling of on-screen layers total(%u):", numLayers); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4266 | mDrawingState.traverse([&](Layer* layer) { |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4267 | // Aim to dump about 200 layers to avoid totally trashing |
| 4268 | // logcat. On the other hand, if there really are 4096 layers |
| 4269 | // something has gone totally wrong its probably the most |
| 4270 | // useful information in logcat. |
| 4271 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4272 | ALOGE("Layer: %s%s", layer->getName().c_str(), |
| 4273 | (layer->isHandleAlive() ? "handleAlive" : "")); |
| 4274 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4275 | } |
| 4276 | }); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4277 | ALOGE("Dumping random sampling of off-screen layers total(%zu): ", |
| 4278 | mOffscreenLayers.size()); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4279 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 4280 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4281 | ALOGE("Offscreen-layer: %s%s", offscreenLayer->getName().c_str(), |
| 4282 | (offscreenLayer->isHandleAlive() ? "handleAlive" : "")); |
| 4283 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4284 | } |
| 4285 | } |
| 4286 | })); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4287 | return NO_MEMORY; |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4288 | } |
| 4289 | |
Vishnu Nair | 86e1190 | 2022-09-06 16:03:27 +0000 | [diff] [blame] | 4290 | layer->updateTransformHint(mActiveDisplayTransformHint); |
| 4291 | if (outTransformHint) { |
| 4292 | *outTransformHint = mActiveDisplayTransformHint; |
| 4293 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4294 | args.parentId = LayerHandle::getLayerId(args.parentHandle.promote()); |
| 4295 | args.layerIdToMirror = LayerHandle::getLayerId(args.mirrorLayerHandle.promote()); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4296 | { |
| 4297 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4298 | mCreatedLayers.emplace_back(layer, parent, args.addToRoot); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4299 | mNewLayers.emplace_back(std::make_unique<frontend::RequestedLayerState>(args)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 4300 | args.mirrorLayerHandle.clear(); |
| 4301 | args.parentHandle.clear(); |
| 4302 | mNewLayerArgs.emplace_back(std::move(args)); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4303 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4304 | |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4305 | setTransactionFlags(eTransactionNeeded); |
| 4306 | return NO_ERROR; |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 4307 | } |
| 4308 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4309 | uint32_t SurfaceFlinger::getTransactionFlags() const { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 4310 | return mTransactionFlags; |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 4311 | } |
| 4312 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4313 | uint32_t SurfaceFlinger::clearTransactionFlags(uint32_t mask) { |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4314 | uint32_t transactionFlags = mTransactionFlags.fetch_and(~mask); |
| 4315 | ATRACE_INT("mTransactionFlags", transactionFlags); |
| 4316 | return transactionFlags & mask; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4317 | } |
| 4318 | |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4319 | void SurfaceFlinger::setTransactionFlags(uint32_t mask, TransactionSchedule schedule, |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4320 | const sp<IBinder>& applyToken, FrameHint frameHint) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4321 | mScheduler->modulateVsync({}, &VsyncModulator::setTransactionSchedule, schedule, applyToken); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4322 | uint32_t transactionFlags = mTransactionFlags.fetch_or(mask); |
| 4323 | ATRACE_INT("mTransactionFlags", transactionFlags); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4324 | |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4325 | if (const bool scheduled = transactionFlags & mask; !scheduled) { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4326 | scheduleCommit(frameHint); |
Ady Abraham | 27bcb55 | 2023-01-21 04:34:22 +0000 | [diff] [blame] | 4327 | } else if (frameHint == FrameHint::kActive) { |
| 4328 | // Even if the next frame is already scheduled, we should reset the idle timer |
| 4329 | // as a new activity just happened. |
| 4330 | mScheduler->resetIdleTimer(); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4331 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4332 | } |
| 4333 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4334 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyTimelineCheck( |
| 4335 | const TransactionHandler::TransactionFlushState& flushState) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 4336 | const auto& transaction = *flushState.transaction; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4337 | |
| 4338 | const TimePoint desiredPresentTime = TimePoint::fromNs(transaction.desiredPresentTime); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 4339 | const TimePoint expectedPresentTime = mScheduler->expectedPresentTimeForPacesetter(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4340 | |
| 4341 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4342 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4343 | // Do not present if the desiredPresentTime has not passed unless it is more than |
| 4344 | // one second in the future. We ignore timestamps more than 1 second in the future |
| 4345 | // for stability reasons. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4346 | if (!transaction.isAutoTimestamp && desiredPresentTime >= expectedPresentTime && |
| 4347 | desiredPresentTime < expectedPresentTime + 1s) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4348 | ATRACE_FORMAT("not current desiredPresentTime: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4349 | desiredPresentTime, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4350 | return TransactionReadiness::NotReady; |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4351 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4352 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4353 | if (!mScheduler->isVsyncValid(expectedPresentTime, transaction.originUid)) { |
| 4354 | ATRACE_FORMAT("!isVsyncValid expectedPresentTime: %" PRId64 " uid: %d", expectedPresentTime, |
| 4355 | transaction.originUid); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4356 | return TransactionReadiness::NotReady; |
| 4357 | } |
| 4358 | |
| 4359 | // If the client didn't specify desiredPresentTime, use the vsyncId to determine the |
| 4360 | // expected present time of this transaction. |
| 4361 | if (transaction.isAutoTimestamp && |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4362 | frameIsEarly(expectedPresentTime, VsyncId{transaction.frameTimelineInfo.vsyncId})) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4363 | ATRACE_FORMAT("frameIsEarly vsyncId: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4364 | transaction.frameTimelineInfo.vsyncId, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4365 | return TransactionReadiness::NotReady; |
| 4366 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4367 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4368 | return TransactionReadiness::Ready; |
| 4369 | } |
| 4370 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4371 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheckLegacy( |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4372 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4373 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4374 | auto ready = TransactionReadiness::Ready; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4375 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const ResolvedComposerState& |
| 4376 | resolvedState) -> bool { |
| 4377 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 4378 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4379 | const auto& transaction = *flushState.transaction; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4380 | const auto& s = resolvedState.state; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4381 | // check for barrier frames |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4382 | if (s.bufferData->hasBarrier) { |
| 4383 | // The current producerId is already a newer producer than the buffer that has a |
| 4384 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4385 | // don't wait on the barrier since we know that's stale information. |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 4386 | if (layer->getDrawingState().barrierProducerId > s.bufferData->producerId) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4387 | layer->callReleaseBufferCallback(s.bufferData->releaseBufferListener, |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4388 | resolvedState.externalTexture->getBuffer(), |
Chavi Weingarten | c8bcb68 | 2023-03-06 22:20:42 +0000 | [diff] [blame] | 4389 | s.bufferData->frameNumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4390 | s.bufferData->acquireFence); |
| 4391 | // Delete the entire state at this point and not just release the buffer because |
| 4392 | // everything associated with the Layer in this Transaction is now out of date. |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4393 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", |
| 4394 | layer->getDebugName(), layer->getDrawingState().barrierProducerId, |
| 4395 | s.bufferData->producerId); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4396 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4397 | } |
| 4398 | |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 4399 | if (layer->getDrawingState().barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4400 | const bool willApplyBarrierFrame = |
| 4401 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4402 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4403 | s.bufferData->barrierFrameNumber)); |
| 4404 | if (!willApplyBarrierFrame) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4405 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4406 | layer->getDebugName(), |
| 4407 | layer->getDrawingState().barrierFrameNumber, |
| 4408 | s.bufferData->barrierFrameNumber); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4409 | ready = TransactionReadiness::NotReadyBarrier; |
| 4410 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4411 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4412 | } |
| 4413 | } |
| 4414 | |
| 4415 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4416 | // the transaction in the queue. |
| 4417 | const bool hasPendingBuffer = |
| 4418 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4419 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4420 | ATRACE_FORMAT("hasPendingBuffer %s", layer->getDebugName()); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4421 | ready = TransactionReadiness::NotReady; |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4422 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4423 | } |
| 4424 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4425 | const bool acquireFenceAvailable = s.bufferData && |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4426 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4427 | s.bufferData->acquireFence; |
Ying Wei | 1fd9bfc | 2023-06-29 16:47:00 +0000 | [diff] [blame] | 4428 | const bool fenceSignaled = !acquireFenceAvailable || |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4429 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4430 | if (!fenceSignaled) { |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4431 | // check fence status |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4432 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(s, transaction.states.size(), |
| 4433 | flushState.firstTransaction) && |
| 4434 | layer->isSimpleBufferUpdate(s); |
| 4435 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4436 | if (allowLatchUnsignaled) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4437 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", |
| 4438 | layer->getDebugName()); |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4439 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4440 | } else { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4441 | ready = TransactionReadiness::NotReady; |
| 4442 | auto& listener = s.bufferData->releaseBufferListener; |
| 4443 | if (listener && |
| 4444 | (flushState.queueProcessTime - transaction.postTime) > |
| 4445 | std::chrono::nanoseconds(4s).count()) { |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 4446 | mTransactionHandler |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 4447 | .onTransactionQueueStalled(transaction.id, |
| 4448 | {.pid = layer->getOwnerPid(), |
| 4449 | .layerId = static_cast<uint32_t>( |
| 4450 | layer->getSequence()), |
| 4451 | .layerName = layer->getDebugName(), |
| 4452 | .bufferId = s.bufferData->getId(), |
| 4453 | .frameNumber = s.bufferData->frameNumber}); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4454 | } |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4455 | ATRACE_FORMAT("fence unsignaled %s", layer->getDebugName()); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4456 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4457 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4458 | } |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4459 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4460 | }); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4461 | return ready; |
| 4462 | } |
| 4463 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4464 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheck( |
| 4465 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4466 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4467 | auto ready = TransactionReadiness::Ready; |
| 4468 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const ResolvedComposerState& |
| 4469 | resolvedState) -> bool { |
| 4470 | const frontend::RequestedLayerState* layer = |
| 4471 | mLayerLifecycleManager.getLayerFromId(resolvedState.layerId); |
| 4472 | const auto& transaction = *flushState.transaction; |
| 4473 | const auto& s = resolvedState.state; |
| 4474 | // check for barrier frames |
| 4475 | if (s.bufferData->hasBarrier) { |
| 4476 | // The current producerId is already a newer producer than the buffer that has a |
| 4477 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4478 | // don't wait on the barrier since we know that's stale information. |
| 4479 | if (layer->barrierProducerId > s.bufferData->producerId) { |
| 4480 | if (s.bufferData->releaseBufferListener) { |
| 4481 | uint32_t currentMaxAcquiredBufferCount = |
| 4482 | getMaxAcquiredBufferCountForCurrentRefreshRate(layer->ownerUid.val()); |
| 4483 | ATRACE_FORMAT_INSTANT("callReleaseBufferCallback %s - %" PRIu64, |
| 4484 | layer->name.c_str(), s.bufferData->frameNumber); |
| 4485 | s.bufferData->releaseBufferListener |
| 4486 | ->onReleaseBuffer({resolvedState.externalTexture->getBuffer()->getId(), |
| 4487 | s.bufferData->frameNumber}, |
| 4488 | s.bufferData->acquireFence |
| 4489 | ? s.bufferData->acquireFence |
| 4490 | : Fence::NO_FENCE, |
| 4491 | currentMaxAcquiredBufferCount); |
| 4492 | } |
| 4493 | |
| 4494 | // Delete the entire state at this point and not just release the buffer because |
| 4495 | // everything associated with the Layer in this Transaction is now out of date. |
| 4496 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", layer->name.c_str(), |
| 4497 | layer->barrierProducerId, s.bufferData->producerId); |
| 4498 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4499 | } |
| 4500 | |
| 4501 | if (layer->barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
| 4502 | const bool willApplyBarrierFrame = |
| 4503 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4504 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4505 | s.bufferData->barrierFrameNumber)); |
| 4506 | if (!willApplyBarrierFrame) { |
| 4507 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4508 | layer->name.c_str(), layer->barrierFrameNumber, |
| 4509 | s.bufferData->barrierFrameNumber); |
| 4510 | ready = TransactionReadiness::NotReadyBarrier; |
| 4511 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4512 | } |
| 4513 | } |
| 4514 | } |
| 4515 | |
| 4516 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4517 | // the transaction in the queue. |
| 4518 | const bool hasPendingBuffer = |
| 4519 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4520 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
| 4521 | ATRACE_FORMAT("hasPendingBuffer %s", layer->name.c_str()); |
| 4522 | ready = TransactionReadiness::NotReady; |
| 4523 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4524 | } |
| 4525 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4526 | const bool acquireFenceAvailable = s.bufferData && |
| 4527 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4528 | s.bufferData->acquireFence; |
Ying Wei | 1fd9bfc | 2023-06-29 16:47:00 +0000 | [diff] [blame] | 4529 | const bool fenceSignaled = !acquireFenceAvailable || |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4530 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
| 4531 | if (!fenceSignaled) { |
| 4532 | // check fence status |
| 4533 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(s, transaction.states.size(), |
| 4534 | flushState.firstTransaction) && |
| 4535 | layer->isSimpleBufferUpdate(s); |
| 4536 | if (allowLatchUnsignaled) { |
| 4537 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", layer->name.c_str()); |
| 4538 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4539 | } else { |
| 4540 | ready = TransactionReadiness::NotReady; |
| 4541 | auto& listener = s.bufferData->releaseBufferListener; |
| 4542 | if (listener && |
| 4543 | (flushState.queueProcessTime - transaction.postTime) > |
| 4544 | std::chrono::nanoseconds(4s).count()) { |
| 4545 | mTransactionHandler |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 4546 | .onTransactionQueueStalled(transaction.id, |
| 4547 | {.pid = layer->ownerPid.val(), |
| 4548 | .layerId = layer->id, |
| 4549 | .layerName = layer->name, |
| 4550 | .bufferId = s.bufferData->getId(), |
| 4551 | .frameNumber = s.bufferData->frameNumber}); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4552 | } |
| 4553 | ATRACE_FORMAT("fence unsignaled %s", layer->name.c_str()); |
| 4554 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4555 | } |
| 4556 | } |
| 4557 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
| 4558 | }); |
| 4559 | return ready; |
| 4560 | } |
| 4561 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4562 | void SurfaceFlinger::addTransactionReadyFilters() { |
| 4563 | mTransactionHandler.addTransactionReadyFilter( |
| 4564 | std::bind(&SurfaceFlinger::transactionReadyTimelineCheck, this, std::placeholders::_1)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4565 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4566 | mTransactionHandler.addTransactionReadyFilter( |
| 4567 | std::bind(&SurfaceFlinger::transactionReadyBufferCheck, this, |
| 4568 | std::placeholders::_1)); |
| 4569 | } else { |
| 4570 | mTransactionHandler.addTransactionReadyFilter( |
| 4571 | std::bind(&SurfaceFlinger::transactionReadyBufferCheckLegacy, this, |
| 4572 | std::placeholders::_1)); |
| 4573 | } |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4574 | } |
| 4575 | |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4576 | // For tests only |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4577 | bool SurfaceFlinger::flushTransactionQueues(VsyncId vsyncId) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4578 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4579 | std::vector<TransactionState> transactions = mTransactionHandler.flushTransactions(); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4580 | return applyTransactions(transactions, vsyncId); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4583 | bool SurfaceFlinger::applyTransactions(std::vector<TransactionState>& transactions, |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4584 | VsyncId vsyncId) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 4585 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4586 | return applyTransactionsLocked(transactions, vsyncId); |
| 4587 | } |
| 4588 | |
| 4589 | bool SurfaceFlinger::applyTransactionsLocked(std::vector<TransactionState>& transactions, |
| 4590 | VsyncId vsyncId) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4591 | bool needsTraversal = false; |
| 4592 | // Now apply all transactions. |
Robert Carr | ff7663b | 2022-02-08 12:46:49 -0800 | [diff] [blame] | 4593 | for (auto& transaction : transactions) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4594 | needsTraversal |= |
| 4595 | applyTransactionState(transaction.frameTimelineInfo, transaction.states, |
| 4596 | transaction.displays, transaction.flags, |
| 4597 | transaction.inputWindowCommands, |
| 4598 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4599 | std::move(transaction.uncacheBufferIds), transaction.postTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4600 | transaction.hasListenerCallbacks, |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4601 | transaction.listenerCallbacks, transaction.originPid, |
| 4602 | transaction.originUid, transaction.id); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4603 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4604 | return needsTraversal; |
Marissa Wall | e6e3c0d | 2019-03-29 10:28:30 -0700 | [diff] [blame] | 4605 | } |
| 4606 | |
| 4607 | bool SurfaceFlinger::transactionFlushNeeded() { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4608 | return mTransactionHandler.hasPendingTransactions(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4609 | } |
| 4610 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4611 | bool SurfaceFlinger::frameIsEarly(TimePoint expectedPresentTime, VsyncId vsyncId) const { |
| 4612 | const auto prediction = |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 4613 | mFrameTimeline->getTokenManager()->getPredictionsForToken(ftl::to_underlying(vsyncId)); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4614 | if (!prediction) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4615 | return false; |
| 4616 | } |
| 4617 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4618 | const auto predictedPresentTime = TimePoint::fromNs(prediction->presentTime); |
| 4619 | |
Rachel Lee | 0655a91 | 2023-04-20 19:54:18 -0700 | [diff] [blame] | 4620 | if (std::chrono::abs(predictedPresentTime - expectedPresentTime) >= |
| 4621 | scheduler::VsyncConfig::kEarlyLatchMaxThreshold) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4622 | return false; |
| 4623 | } |
| 4624 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4625 | const Duration earlyLatchVsyncThreshold = mScheduler->getVsyncSchedule()->period() / 2; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4626 | |
| 4627 | return predictedPresentTime >= expectedPresentTime && |
| 4628 | predictedPresentTime - expectedPresentTime >= earlyLatchVsyncThreshold; |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4629 | } |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4630 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4631 | bool SurfaceFlinger::shouldLatchUnsignaled(const layer_state_t& state, size_t numStates, |
| 4632 | bool firstTransaction) const { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4633 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Disabled) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4634 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::Disabled)", __func__); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4635 | return false; |
| 4636 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4637 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4638 | // We only want to latch unsignaled when a single layer is updated in this |
| 4639 | // transaction (i.e. not a blast sync transaction). |
| 4640 | if (numStates != 1) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4641 | ATRACE_FORMAT_INSTANT("%s: false (numStates=%zu)", __func__, numStates); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4642 | return false; |
| 4643 | } |
| 4644 | |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4645 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::AutoSingleLayer) { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4646 | if (!firstTransaction) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4647 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; not first " |
| 4648 | "transaction)", |
| 4649 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4650 | return false; |
| 4651 | } |
| 4652 | |
| 4653 | // We don't want to latch unsignaled if are in early / client composition |
| 4654 | // as it leads to jank due to RenderEngine waiting for unsignaled buffer |
| 4655 | // or window animations being slow. |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 4656 | if (mScheduler->vsyncModulator().isVsyncConfigEarly()) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4657 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; " |
| 4658 | "isVsyncConfigEarly)", |
| 4659 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4660 | return false; |
| 4661 | } |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4662 | } |
| 4663 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4664 | return true; |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4665 | } |
| 4666 | |
chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 4667 | status_t SurfaceFlinger::setTransactionState( |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4668 | const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 4669 | const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4670 | InputWindowCommands inputWindowCommands, int64_t desiredPresentTime, bool isAutoTimestamp, |
| 4671 | const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 4672 | const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId, |
| 4673 | const std::vector<uint64_t>& mergedTransactionIds) { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 4674 | ATRACE_CALL(); |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 4675 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4676 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4677 | const int originPid = ipc->getCallingPid(); |
| 4678 | const int originUid = ipc->getCallingUid(); |
| 4679 | uint32_t permissions = LayerStatePermissions::getTransactionPermissions(originPid, originUid); |
| 4680 | for (auto composerState : states) { |
| 4681 | composerState.state.sanitize(permissions); |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4682 | } |
| 4683 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4684 | for (DisplayState display : displays) { |
| 4685 | display.sanitize(permissions); |
| 4686 | } |
| 4687 | |
| 4688 | if (!inputWindowCommands.empty() && |
| 4689 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) == 0) { |
| 4690 | ALOGE("Only privileged callers are allowed to send input commands."); |
| 4691 | inputWindowCommands.clear(); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 4692 | } |
| 4693 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 4694 | if (flags & (eEarlyWakeupStart | eEarlyWakeupEnd)) { |
| 4695 | const bool hasPermission = |
| 4696 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) || |
| 4697 | callingThreadHasPermission(sWakeupSurfaceFlinger); |
| 4698 | if (!hasPermission) { |
| 4699 | ALOGE("Caller needs permission android.permission.WAKEUP_SURFACE_FLINGER to use " |
| 4700 | "eEarlyWakeup[Start|End] flags"); |
| 4701 | flags &= ~(eEarlyWakeupStart | eEarlyWakeupEnd); |
| 4702 | } |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 4703 | } |
| 4704 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4705 | const int64_t postTime = systemTime(); |
| 4706 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4707 | std::vector<uint64_t> uncacheBufferIds; |
| 4708 | uncacheBufferIds.reserve(uncacheBuffers.size()); |
| 4709 | for (const auto& uncacheBuffer : uncacheBuffers) { |
| 4710 | sp<GraphicBuffer> buffer = ClientCache::getInstance().erase(uncacheBuffer); |
| 4711 | if (buffer != nullptr) { |
| 4712 | uncacheBufferIds.push_back(buffer->getId()); |
| 4713 | } |
| 4714 | } |
| 4715 | |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4716 | std::vector<ResolvedComposerState> resolvedStates; |
| 4717 | resolvedStates.reserve(states.size()); |
| 4718 | for (auto& state : states) { |
| 4719 | resolvedStates.emplace_back(std::move(state)); |
| 4720 | auto& resolvedState = resolvedStates.back(); |
| 4721 | if (resolvedState.state.hasBufferChanges() && resolvedState.state.hasValidBuffer() && |
| 4722 | resolvedState.state.surface) { |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 4723 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 4724 | std::string layerName = (layer) ? |
| 4725 | layer->getDebugName() : std::to_string(resolvedState.state.layerId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4726 | resolvedState.externalTexture = |
| 4727 | getExternalTextureFromBufferData(*resolvedState.state.bufferData, |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 4728 | layerName.c_str(), transactionId); |
Patrick Williams | 38d920e | 2023-08-31 17:31:18 -0500 | [diff] [blame] | 4729 | if (resolvedState.externalTexture) { |
| 4730 | resolvedState.state.bufferData->buffer = resolvedState.externalTexture->getBuffer(); |
| 4731 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4732 | mBufferCountTracker.increment(resolvedState.state.surface->localBinder()); |
| 4733 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4734 | resolvedState.layerId = LayerHandle::getLayerId(resolvedState.state.surface); |
| 4735 | if (resolvedState.state.what & layer_state_t::eReparent) { |
| 4736 | resolvedState.parentId = |
| 4737 | getLayerIdFromSurfaceControl(resolvedState.state.parentSurfaceControlForChild); |
| 4738 | } |
| 4739 | if (resolvedState.state.what & layer_state_t::eRelativeLayerChanged) { |
| 4740 | resolvedState.relativeParentId = |
| 4741 | getLayerIdFromSurfaceControl(resolvedState.state.relativeLayerSurfaceControl); |
| 4742 | } |
| 4743 | if (resolvedState.state.what & layer_state_t::eInputInfoChanged) { |
| 4744 | wp<IBinder>& touchableRegionCropHandle = |
| 4745 | resolvedState.state.windowInfoHandle->editInfo()->touchableRegionCropHandle; |
| 4746 | resolvedState.touchCropId = |
| 4747 | LayerHandle::getLayerId(touchableRegionCropHandle.promote()); |
| 4748 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4749 | } |
| 4750 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4751 | TransactionState state{frameTimelineInfo, |
| 4752 | resolvedStates, |
| 4753 | displays, |
| 4754 | flags, |
| 4755 | applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4756 | std::move(inputWindowCommands), |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4757 | desiredPresentTime, |
| 4758 | isAutoTimestamp, |
| 4759 | std::move(uncacheBufferIds), |
| 4760 | postTime, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4761 | hasListenerCallbacks, |
| 4762 | listenerCallbacks, |
| 4763 | originPid, |
| 4764 | originUid, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 4765 | transactionId, |
| 4766 | mergedTransactionIds}; |
Vishnu Nair | 83df034 | 2021-03-30 11:50:44 -0700 | [diff] [blame] | 4767 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 4768 | if (mTransactionTracing) { |
| 4769 | mTransactionTracing->addQueuedTransaction(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4770 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4771 | |
| 4772 | const auto schedule = [](uint32_t flags) { |
| 4773 | if (flags & eEarlyWakeupEnd) return TransactionSchedule::EarlyEnd; |
| 4774 | if (flags & eEarlyWakeupStart) return TransactionSchedule::EarlyStart; |
| 4775 | return TransactionSchedule::Late; |
| 4776 | }(state.flags); |
| 4777 | |
| 4778 | const auto frameHint = state.isFrameActive() ? FrameHint::kActive : FrameHint::kNone; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4779 | mTransactionHandler.queueTransaction(std::move(state)); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4780 | setTransactionFlags(eTransactionFlushNeeded, schedule, applyToken, frameHint); |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 4781 | return NO_ERROR; |
| 4782 | } |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4783 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4784 | bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4785 | std::vector<ResolvedComposerState>& states, |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 4786 | Vector<DisplayState>& displays, uint32_t flags, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4787 | const InputWindowCommands& inputWindowCommands, |
| 4788 | const int64_t desiredPresentTime, bool isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4789 | const std::vector<uint64_t>& uncacheBufferIds, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4790 | const int64_t postTime, bool hasListenerCallbacks, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4791 | const std::vector<ListenerCallbacks>& listenerCallbacks, |
| 4792 | int originPid, int originUid, uint64_t transactionId) { |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 4793 | uint32_t transactionFlags = 0; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4794 | if (!mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4795 | for (DisplayState& display : displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4796 | transactionFlags |= setDisplayStateLocked(display); |
| 4797 | } |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 4798 | } |
| 4799 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4800 | // start and end registration for listeners w/ no surface so they can get their callback. Note |
| 4801 | // that listeners with SurfaceControls will start registration during setClientStateLocked |
| 4802 | // below. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4803 | for (const auto& listener : listenerCallbacks) { |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4804 | mTransactionCallbackInvoker.addEmptyTransaction(listener); |
Marissa Wall | d600d57 | 2019-03-26 15:38:50 -0700 | [diff] [blame] | 4805 | } |
| 4806 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 4807 | uint32_t clientStateFlags = 0; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4808 | for (auto& resolvedState : states) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4809 | if (mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4810 | clientStateFlags |= |
| 4811 | setClientStateLocked(frameTimelineInfo, resolvedState, desiredPresentTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4812 | isAutoTimestamp, postTime, transactionId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4813 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4814 | } else /*mLayerLifecycleManagerEnabled*/ { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4815 | clientStateFlags |= updateLayerCallbacksAndStats(frameTimelineInfo, resolvedState, |
| 4816 | desiredPresentTime, isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4817 | postTime, transactionId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4818 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4819 | if ((flags & eAnimation) && resolvedState.state.surface) { |
| 4820 | if (const auto layer = LayerHandle::getLayer(resolvedState.state.surface)) { |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 4821 | const auto layerProps = scheduler::LayerProps{ |
| 4822 | .visible = layer->isVisible(), |
| 4823 | .bounds = layer->getBounds(), |
| 4824 | .transform = layer->getTransform(), |
| 4825 | .setFrameRateVote = layer->getFrameRateForLayerTree(), |
| 4826 | .frameRateSelectionPriority = layer->getFrameRateSelectionPriority(), |
| 4827 | }; |
| 4828 | layer->recordLayerHistoryAnimationTx(layerProps); |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 4829 | } |
| 4830 | } |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 4831 | } |
| 4832 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 4833 | transactionFlags |= clientStateFlags; |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4834 | transactionFlags |= addInputWindowCommands(inputWindowCommands); |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 4835 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4836 | for (uint64_t uncacheBufferId : uncacheBufferIds) { |
| 4837 | mBufferIdsToUncache.push_back(uncacheBufferId); |
Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 4838 | } |
| 4839 | |
Jorim Jaggi | bdcf09c | 2017-08-08 15:22:08 +0200 | [diff] [blame] | 4840 | // If a synchronous transaction is explicitly requested without any changes, force a transaction |
| 4841 | // anyway. This can be used as a flush mechanism for previous async transactions. |
| 4842 | // Empty animation transaction can be used to simulate back-pressure, so also force a |
| 4843 | // transaction for empty animation transactions. |
Vishnu Nair | 1523dad | 2022-09-29 16:05:18 -0700 | [diff] [blame] | 4844 | if (transactionFlags == 0 && (flags & eAnimation)) { |
Robert Carr | 2a7dbb4 | 2016-05-24 11:41:28 -0700 | [diff] [blame] | 4845 | transactionFlags = eTransactionNeeded; |
| 4846 | } |
| 4847 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4848 | bool needsTraversal = false; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 4849 | if (transactionFlags) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4850 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 4851 | // 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] | 4852 | if (transactionFlags & eTraversalNeeded) { |
| 4853 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4854 | needsTraversal = true; |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 4855 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4856 | if (transactionFlags) { |
| 4857 | setTransactionFlags(transactionFlags); |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 4858 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4859 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4860 | |
| 4861 | return needsTraversal; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4862 | } |
| 4863 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4864 | bool SurfaceFlinger::applyAndCommitDisplayTransactionStates( |
| 4865 | std::vector<TransactionState>& transactions) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 4866 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4867 | bool needsTraversal = false; |
| 4868 | uint32_t transactionFlags = 0; |
| 4869 | for (auto& transaction : transactions) { |
| 4870 | for (DisplayState& display : transaction.displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4871 | transactionFlags |= setDisplayStateLocked(display); |
| 4872 | } |
| 4873 | } |
| 4874 | |
| 4875 | if (transactionFlags) { |
| 4876 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 4877 | // so we don't have to wake up again next frame to perform an unnecessary traversal. |
| 4878 | if (transactionFlags & eTraversalNeeded) { |
| 4879 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
| 4880 | needsTraversal = true; |
| 4881 | } |
| 4882 | if (transactionFlags) { |
| 4883 | setTransactionFlags(transactionFlags); |
| 4884 | } |
| 4885 | } |
| 4886 | |
| 4887 | mFrontEndDisplayInfosChanged = mTransactionFlags & eDisplayTransactionNeeded; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4888 | if (mFrontEndDisplayInfosChanged && !mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4889 | processDisplayChangesLocked(); |
| 4890 | mFrontEndDisplayInfos.clear(); |
| 4891 | for (const auto& [_, display] : mDisplays) { |
| 4892 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 4893 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 4894 | needsTraversal = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | return needsTraversal; |
| 4898 | } |
| 4899 | |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4900 | uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s) { |
| 4901 | const ssize_t index = mCurrentState.displays.indexOfKey(s.token); |
| 4902 | if (index < 0) return 0; |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 4903 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4904 | uint32_t flags = 0; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4905 | DisplayDeviceState& state = mCurrentState.displays.editValueAt(index); |
| 4906 | |
| 4907 | const uint32_t what = s.what; |
| 4908 | if (what & DisplayState::eSurfaceChanged) { |
| 4909 | if (IInterface::asBinder(state.surface) != IInterface::asBinder(s.surface)) { |
| 4910 | state.surface = s.surface; |
| 4911 | flags |= eDisplayTransactionNeeded; |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 4912 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4913 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4914 | if (what & DisplayState::eLayerStackChanged) { |
| 4915 | if (state.layerStack != s.layerStack) { |
| 4916 | state.layerStack = s.layerStack; |
| 4917 | flags |= eDisplayTransactionNeeded; |
| 4918 | } |
| 4919 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 4920 | if (what & DisplayState::eFlagsChanged) { |
| 4921 | if (state.flags != s.flags) { |
| 4922 | state.flags = s.flags; |
| 4923 | flags |= eDisplayTransactionNeeded; |
| 4924 | } |
| 4925 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4926 | if (what & DisplayState::eDisplayProjectionChanged) { |
| 4927 | if (state.orientation != s.orientation) { |
| 4928 | state.orientation = s.orientation; |
| 4929 | flags |= eDisplayTransactionNeeded; |
| 4930 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 4931 | if (state.orientedDisplaySpaceRect != s.orientedDisplaySpaceRect) { |
| 4932 | state.orientedDisplaySpaceRect = s.orientedDisplaySpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4933 | flags |= eDisplayTransactionNeeded; |
| 4934 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 4935 | if (state.layerStackSpaceRect != s.layerStackSpaceRect) { |
| 4936 | state.layerStackSpaceRect = s.layerStackSpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4937 | flags |= eDisplayTransactionNeeded; |
| 4938 | } |
| 4939 | } |
| 4940 | if (what & DisplayState::eDisplaySizeChanged) { |
| 4941 | if (state.width != s.width) { |
| 4942 | state.width = s.width; |
| 4943 | flags |= eDisplayTransactionNeeded; |
| 4944 | } |
| 4945 | if (state.height != s.height) { |
| 4946 | state.height = s.height; |
| 4947 | flags |= eDisplayTransactionNeeded; |
| 4948 | } |
| 4949 | } |
| 4950 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4951 | return flags; |
| 4952 | } |
| 4953 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 4954 | bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4955 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4956 | const int pid = ipc->getCallingPid(); |
| 4957 | const int uid = ipc->getCallingUid(); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4958 | if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) && |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 4959 | (usePermissionCache ? !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid) |
| 4960 | : !checkPermission(sAccessSurfaceFlinger, pid, uid))) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4961 | return false; |
| 4962 | } |
| 4963 | return true; |
| 4964 | } |
| 4965 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4966 | uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4967 | ResolvedComposerState& composerState, |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4968 | int64_t desiredPresentTime, bool isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4969 | int64_t postTime, uint64_t transactionId) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4970 | layer_state_t& s = composerState.state; |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4971 | |
| 4972 | std::vector<ListenerCallbacks> filteredListeners; |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4973 | for (auto& listener : s.listeners) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4974 | // Starts a registration but separates the callback ids according to callback type. This |
| 4975 | // allows the callback invoker to send on latch callbacks earlier. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4976 | // note that startRegistration will not re-register if the listener has |
| 4977 | // already be registered for a prior surface control |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4978 | |
| 4979 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 4980 | if (!onCommitCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4981 | filteredListeners.push_back(onCommitCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4982 | } |
| 4983 | |
| 4984 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 4985 | if (!onCompleteCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4986 | filteredListeners.push_back(onCompleteCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4987 | } |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4988 | } |
| 4989 | |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4990 | const uint64_t what = s.what; |
| 4991 | uint32_t flags = 0; |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 4992 | sp<Layer> layer = nullptr; |
| 4993 | if (s.surface) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 4994 | layer = LayerHandle::getLayer(s.surface); |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 4995 | } else { |
| 4996 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 4997 | ALOGW("Attempt to set client state with a null layer handle"); |
| 4998 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4999 | if (layer == nullptr) { |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5000 | for (auto& [listener, callbackIds] : s.listeners) { |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 5001 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5002 | callbackIds, |
| 5003 | s.surface), |
| 5004 | std::vector<JankData>()); |
Marissa Wall | 88e2048 | 2019-06-24 10:49:42 -0700 | [diff] [blame] | 5005 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5006 | return 0; |
| 5007 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 5008 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5009 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 5010 | ui::LayerStack oldLayerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5011 | |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 5012 | // Only set by BLAST adapter layers |
| 5013 | if (what & layer_state_t::eProducerDisconnect) { |
| 5014 | layer->onDisconnect(); |
| 5015 | } |
| 5016 | |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5017 | if (what & layer_state_t::ePositionChanged) { |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 5018 | if (layer->setPosition(s.x, s.y)) { |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5019 | flags |= eTraversalNeeded; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5020 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5021 | } |
| 5022 | if (what & layer_state_t::eLayerChanged) { |
| 5023 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5024 | const auto& p = layer->getParent(); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5025 | if (p == nullptr) { |
chaviw | 64f7b42 | 2017-07-12 10:31:58 -0700 | [diff] [blame] | 5026 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5027 | if (layer->setLayer(s.z) && idx >= 0) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5028 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5029 | mCurrentState.layersSortedByZ.add(layer); |
| 5030 | // we need traversal (state changed) |
| 5031 | // AND transaction (list changed) |
| 5032 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5033 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5034 | } else { |
| 5035 | if (p->setChildLayer(layer, s.z)) { |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 5036 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5037 | } |
| 5038 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5039 | } |
| 5040 | if (what & layer_state_t::eRelativeLayerChanged) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5041 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5042 | const auto& p = layer->getParent(); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5043 | const auto& relativeHandle = s.relativeLayerSurfaceControl ? |
| 5044 | s.relativeLayerSurfaceControl->getHandle() : nullptr; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5045 | if (p == nullptr) { |
| 5046 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5047 | if (layer->setRelativeLayer(relativeHandle, s.z) && |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5048 | idx >= 0) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5049 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5050 | mCurrentState.layersSortedByZ.add(layer); |
| 5051 | // we need traversal (state changed) |
| 5052 | // AND transaction (list changed) |
| 5053 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5054 | } |
| 5055 | } else { |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5056 | if (p->setChildRelativeLayer(layer, relativeHandle, s.z)) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5057 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5058 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5059 | } |
| 5060 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5061 | if (what & layer_state_t::eAlphaChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5062 | if (layer->setAlpha(s.color.a)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5063 | } |
| 5064 | if (what & layer_state_t::eColorChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5065 | if (layer->setColor(s.color.rgb)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5066 | } |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 5067 | if (what & layer_state_t::eColorTransformChanged) { |
| 5068 | if (layer->setColorTransform(s.colorTransform)) { |
| 5069 | flags |= eTraversalNeeded; |
| 5070 | } |
| 5071 | } |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5072 | if (what & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5073 | if (layer->setBackgroundColor(s.bgColor.rgb, s.bgColor.a, s.bgColorDataspace)) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5074 | flags |= eTraversalNeeded; |
| 5075 | } |
| 5076 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5077 | if (what & layer_state_t::eMatrixChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5078 | if (layer->setMatrix(s.matrix)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5079 | } |
| 5080 | if (what & layer_state_t::eTransparentRegionChanged) { |
| 5081 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 5082 | flags |= eTraversalNeeded; |
| 5083 | } |
| 5084 | if (what & layer_state_t::eFlagsChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5085 | if (layer->setFlags(s.flags, s.mask)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5086 | } |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 5087 | if (what & layer_state_t::eCornerRadiusChanged) { |
| 5088 | if (layer->setCornerRadius(s.cornerRadius)) |
| 5089 | flags |= eTraversalNeeded; |
| 5090 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5091 | if (what & layer_state_t::eBackgroundBlurRadiusChanged && mSupportsBlur) { |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5092 | if (layer->setBackgroundBlurRadius(s.backgroundBlurRadius)) flags |= eTraversalNeeded; |
| 5093 | } |
Galia Peycheva | e11d575 | 2021-01-22 13:50:16 +0000 | [diff] [blame] | 5094 | if (what & layer_state_t::eBlurRegionsChanged) { |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5095 | if (layer->setBlurRegions(s.blurRegions)) flags |= eTraversalNeeded; |
| 5096 | } |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 5097 | if (what & layer_state_t::eRenderBorderChanged) { |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 5098 | if (layer->enableBorder(s.borderEnabled, s.borderWidth, s.borderColor)) { |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 5099 | flags |= eTraversalNeeded; |
| 5100 | } |
| 5101 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5102 | if (what & layer_state_t::eLayerStackChanged) { |
| 5103 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 5104 | // We only allow setting layer stacks for top level layers, |
| 5105 | // everything else inherits layer stack from its parent. |
| 5106 | if (layer->hasParent()) { |
| 5107 | ALOGE("Attempt to set layer stack on layer with parent (%s) is invalid", |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5108 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5109 | } else if (idx < 0) { |
| 5110 | ALOGE("Attempt to set layer stack on layer without parent (%s) that " |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5111 | "that also does not appear in the top level layer list. Something" |
| 5112 | " has gone wrong.", |
| 5113 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5114 | } else if (layer->setLayerStack(s.layerStack)) { |
| 5115 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5116 | mCurrentState.layersSortedByZ.add(layer); |
| 5117 | // we need traversal (state changed) |
| 5118 | // AND transaction (list changed) |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5119 | flags |= eTransactionNeeded | eTraversalNeeded | eTransformHintUpdateNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5120 | } |
| 5121 | } |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5122 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5123 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5124 | } |
| 5125 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5126 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5127 | flags |= eTraversalNeeded; |
| 5128 | } |
| 5129 | if (what & layer_state_t::eCropChanged) { |
| 5130 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5131 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5132 | if (what & layer_state_t::eDataspaceChanged) { |
| 5133 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5134 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5135 | if (what & layer_state_t::eSurfaceDamageRegionChanged) { |
| 5136 | if (layer->setSurfaceDamageRegion(s.surfaceDamageRegion)) flags |= eTraversalNeeded; |
| 5137 | } |
| 5138 | if (what & layer_state_t::eApiChanged) { |
| 5139 | if (layer->setApi(s.api)) flags |= eTraversalNeeded; |
| 5140 | } |
| 5141 | if (what & layer_state_t::eSidebandStreamChanged) { |
| 5142 | if (layer->setSidebandStream(s.sidebandStream)) flags |= eTraversalNeeded; |
| 5143 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5144 | if (what & layer_state_t::eInputInfoChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5145 | layer->setInputInfo(*s.windowInfoHandle->getInfo()); |
| 5146 | flags |= eTraversalNeeded; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5147 | } |
Vishnu Nair | adf632b | 2021-01-07 14:05:08 -0800 | [diff] [blame] | 5148 | std::optional<nsecs_t> dequeueBufferTimestamp; |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5149 | if (what & layer_state_t::eMetadataChanged) { |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5150 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5151 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5152 | if (const int32_t gameMode = s.metadata.getInt32(gui::METADATA_GAME_MODE, -1); |
| 5153 | gameMode != -1) { |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5154 | // The transaction will be received on the Task layer and needs to be applied to all |
| 5155 | // child layers. Child layers that are added at a later point will obtain the game mode |
| 5156 | // info through addChild(). |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5157 | layer->setGameModeForTree(static_cast<GameMode>(gameMode)); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5158 | } |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5159 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 5160 | if (layer->setMetadata(s.metadata)) { |
| 5161 | flags |= eTraversalNeeded; |
| 5162 | mLayerMetadataSnapshotNeeded = true; |
| 5163 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5164 | } |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 5165 | if (what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 5166 | if (layer->setColorSpaceAgnostic(s.colorSpaceAgnostic)) { |
| 5167 | flags |= eTraversalNeeded; |
| 5168 | } |
| 5169 | } |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 5170 | if (what & layer_state_t::eShadowRadiusChanged) { |
| 5171 | if (layer->setShadowRadius(s.shadowRadius)) flags |= eTraversalNeeded; |
| 5172 | } |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 5173 | if (what & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 5174 | const auto compatibility = |
| 5175 | Layer::FrameRate::convertCompatibility(s.defaultFrameRateCompatibility); |
| 5176 | |
| 5177 | if (layer->setDefaultFrameRateCompatibility(compatibility)) { |
| 5178 | flags |= eTraversalNeeded; |
| 5179 | } |
| 5180 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5181 | if (what & layer_state_t::eFrameRateSelectionPriority) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5182 | if (layer->setFrameRateSelectionPriority(s.frameRateSelectionPriority)) { |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5183 | flags |= eTraversalNeeded; |
| 5184 | } |
| 5185 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5186 | if (what & layer_state_t::eFrameRateChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5187 | const auto compatibility = |
| 5188 | Layer::FrameRate::convertCompatibility(s.frameRateCompatibility); |
| 5189 | const auto strategy = |
| 5190 | Layer::FrameRate::convertChangeFrameRateStrategy(s.changeFrameRateStrategy); |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 5191 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 5192 | if (layer->setFrameRate(Layer::FrameRate::FrameRateVote(Fps::fromValue(s.frameRate), |
| 5193 | compatibility, strategy))) { |
| 5194 | flags |= eTraversalNeeded; |
| 5195 | } |
| 5196 | } |
| 5197 | if (what & layer_state_t::eFrameRateCategoryChanged) { |
| 5198 | const FrameRateCategory category = Layer::FrameRate::convertCategory(s.frameRateCategory); |
| 5199 | if (layer->setFrameRateCategory(category)) { |
| 5200 | flags |= eTraversalNeeded; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 5201 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5202 | } |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5203 | if (what & layer_state_t::eFixedTransformHintChanged) { |
| 5204 | if (layer->setFixedTransformHint(s.fixedTransformHint)) { |
| 5205 | flags |= eTraversalNeeded | eTransformHintUpdateNeeded; |
| 5206 | } |
| 5207 | } |
Vishnu Nair | cf26a0a | 2020-11-13 12:56:20 -0800 | [diff] [blame] | 5208 | if (what & layer_state_t::eAutoRefreshChanged) { |
| 5209 | layer->setAutoRefresh(s.autoRefresh); |
| 5210 | } |
Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 5211 | if (what & layer_state_t::eDimmingEnabledChanged) { |
| 5212 | if (layer->setDimmingEnabled(s.dimmingEnabled)) flags |= eTraversalNeeded; |
| 5213 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5214 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 5215 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5216 | flags |= eTraversalNeeded; |
| 5217 | } |
| 5218 | } |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 5219 | if (what & layer_state_t::eCachingHintChanged) { |
| 5220 | if (layer->setCachingHint(s.cachingHint)) { |
| 5221 | flags |= eTraversalNeeded; |
| 5222 | } |
| 5223 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5224 | if (what & layer_state_t::eHdrMetadataChanged) { |
| 5225 | if (layer->setHdrMetadata(s.hdrMetadata)) flags |= eTraversalNeeded; |
| 5226 | } |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5227 | if (what & layer_state_t::eTrustedOverlayChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5228 | if (layer->setTrustedOverlay(s.isTrustedOverlay)) { |
| 5229 | flags |= eTraversalNeeded; |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5230 | } |
| 5231 | } |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 5232 | if (what & layer_state_t::eStretchChanged) { |
| 5233 | if (layer->setStretchEffect(s.stretchEffect)) { |
| 5234 | flags |= eTraversalNeeded; |
| 5235 | } |
| 5236 | } |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 5237 | if (what & layer_state_t::eBufferCropChanged) { |
| 5238 | if (layer->setBufferCrop(s.bufferCrop)) { |
| 5239 | flags |= eTraversalNeeded; |
| 5240 | } |
| 5241 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 5242 | if (what & layer_state_t::eDestinationFrameChanged) { |
| 5243 | if (layer->setDestinationFrame(s.destinationFrame)) { |
| 5244 | flags |= eTraversalNeeded; |
| 5245 | } |
| 5246 | } |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5247 | if (what & layer_state_t::eDropInputModeChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5248 | if (layer->setDropInputMode(s.dropInputMode)) { |
| 5249 | flags |= eTraversalNeeded; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 5250 | mUpdateInputInfo = true; |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5251 | } |
| 5252 | } |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5253 | // This has to happen after we reparent children because when we reparent to null we remove |
| 5254 | // child layers from current state and remove its relative z. If the children are reparented in |
| 5255 | // the same transaction, then we have to make sure we reparent the children first so we do not |
| 5256 | // lose its relative z order. |
| 5257 | if (what & layer_state_t::eReparent) { |
| 5258 | bool hadParent = layer->hasParent(); |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5259 | auto parentHandle = (s.parentSurfaceControlForChild) |
| 5260 | ? s.parentSurfaceControlForChild->getHandle() |
| 5261 | : nullptr; |
| 5262 | if (layer->reparent(parentHandle)) { |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5263 | if (!hadParent) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 5264 | layer->setIsAtRoot(false); |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5265 | mCurrentState.layersSortedByZ.remove(layer); |
| 5266 | } |
| 5267 | flags |= eTransactionNeeded | eTraversalNeeded; |
| 5268 | } |
| 5269 | } |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5270 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5271 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5272 | for (auto& [listener, callbackIds] : filteredListeners) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 5273 | callbackHandles.emplace_back( |
| 5274 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5275 | } |
| 5276 | } |
Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 5277 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5278 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5279 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5280 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 5281 | frameTimelineInfo)) { |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5282 | flags |= eTraversalNeeded; |
| 5283 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5284 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5285 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 5286 | } |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 5287 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5288 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5289 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5290 | } |
| 5291 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5292 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5293 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5294 | s.trustedPresentationListener)) { |
| 5295 | flags |= eTraversalNeeded; |
| 5296 | } |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5297 | } |
| 5298 | |
Pascal Muetschard | b39918f | 2023-01-27 11:36:11 +0100 | [diff] [blame] | 5299 | if (what & layer_state_t::eFlushJankData) { |
| 5300 | // Do nothing. Processing the transaction completed listeners currently cause the flush. |
| 5301 | } |
| 5302 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5303 | if (layer->setTransactionCompletedListeners(callbackHandles, |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5304 | layer->willPresentCurrentTransaction() || |
| 5305 | layer->willReleaseBufferOnLatch())) { |
Vishnu Nair | d691322 | 2023-02-01 22:56:21 +0000 | [diff] [blame] | 5306 | flags |= eTraversalNeeded; |
| 5307 | } |
| 5308 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5309 | // Do not put anything that updates layer state or modifies flags after |
| 5310 | // setTransactionCompletedListener |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5311 | |
| 5312 | // if the layer has been parented on to a new display, update its transform hint. |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 5313 | if (((flags & eTransformHintUpdateNeeded) == 0) && |
| 5314 | oldLayerStack != layer->getLayerStack(LayerVector::StateSet::Current)) { |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5315 | flags |= eTransformHintUpdateNeeded; |
| 5316 | } |
| 5317 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5318 | return flags; |
| 5319 | } |
| 5320 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5321 | uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& frameTimelineInfo, |
| 5322 | ResolvedComposerState& composerState, |
| 5323 | int64_t desiredPresentTime, |
| 5324 | bool isAutoTimestamp, int64_t postTime, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5325 | uint64_t transactionId) { |
| 5326 | layer_state_t& s = composerState.state; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5327 | |
| 5328 | std::vector<ListenerCallbacks> filteredListeners; |
| 5329 | for (auto& listener : s.listeners) { |
| 5330 | // Starts a registration but separates the callback ids according to callback type. This |
| 5331 | // allows the callback invoker to send on latch callbacks earlier. |
| 5332 | // note that startRegistration will not re-register if the listener has |
| 5333 | // already be registered for a prior surface control |
| 5334 | |
| 5335 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5336 | if (!onCommitCallbacks.callbackIds.empty()) { |
| 5337 | filteredListeners.push_back(onCommitCallbacks); |
| 5338 | } |
| 5339 | |
| 5340 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5341 | if (!onCompleteCallbacks.callbackIds.empty()) { |
| 5342 | filteredListeners.push_back(onCompleteCallbacks); |
| 5343 | } |
| 5344 | } |
| 5345 | |
| 5346 | const uint64_t what = s.what; |
| 5347 | uint32_t flags = 0; |
| 5348 | sp<Layer> layer = nullptr; |
| 5349 | if (s.surface) { |
| 5350 | layer = LayerHandle::getLayer(s.surface); |
| 5351 | } else { |
| 5352 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5353 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5354 | } |
| 5355 | if (layer == nullptr) { |
| 5356 | for (auto& [listener, callbackIds] : s.listeners) { |
| 5357 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5358 | callbackIds, |
| 5359 | s.surface), |
| 5360 | std::vector<JankData>()); |
| 5361 | } |
| 5362 | return 0; |
| 5363 | } |
| 5364 | if (what & layer_state_t::eProducerDisconnect) { |
| 5365 | layer->onDisconnect(); |
| 5366 | } |
| 5367 | std::optional<nsecs_t> dequeueBufferTimestamp; |
| 5368 | if (what & layer_state_t::eMetadataChanged) { |
| 5369 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
| 5370 | } |
| 5371 | |
| 5372 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5373 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5374 | for (auto& [listener, callbackIds] : filteredListeners) { |
| 5375 | callbackHandles.emplace_back( |
| 5376 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
| 5377 | } |
| 5378 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5379 | // TODO(b/238781169) remove after screenshot refactor, currently screenshots |
| 5380 | // requires to read drawing state from binder thread. So we need to fix that |
| 5381 | // before removing this. |
Vishnu Nair | aeaf9d7 | 2023-09-12 15:47:41 -0700 | [diff] [blame^] | 5382 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5383 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
| 5384 | } |
| 5385 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5386 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5387 | flags |= eTraversalNeeded; |
| 5388 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5389 | if (what & layer_state_t::eCropChanged) { |
| 5390 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5391 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5392 | if (what & layer_state_t::eSidebandStreamChanged) { |
| 5393 | if (layer->setSidebandStream(s.sidebandStream)) flags |= eTraversalNeeded; |
| 5394 | } |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 5395 | if (what & layer_state_t::eDataspaceChanged) { |
| 5396 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5397 | } |
Vishnu Nair | c5e3416 | 2023-08-22 13:21:20 -0700 | [diff] [blame] | 5398 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
| 5399 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
| 5400 | flags |= eTraversalNeeded; |
| 5401 | } |
| 5402 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5403 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 5404 | std::optional<ui::Transform::RotationFlags> transformHint = std::nullopt; |
| 5405 | frontend::LayerSnapshot* snapshot = mLayerSnapshotBuilder.getSnapshot(layer->sequence); |
| 5406 | if (snapshot) { |
| 5407 | transformHint = snapshot->transformHint; |
| 5408 | } |
| 5409 | layer->setTransformHint(transformHint); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5410 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5411 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
| 5412 | frameTimelineInfo)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5413 | flags |= eTraversalNeeded; |
| 5414 | } |
| 5415 | mLayersWithQueuedFrames.emplace(layer); |
| 5416 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5417 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
| 5418 | } |
| 5419 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5420 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5421 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5422 | } |
| 5423 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5424 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5425 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5426 | s.trustedPresentationListener)) { |
| 5427 | flags |= eTraversalNeeded; |
| 5428 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5429 | } |
| 5430 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5431 | const auto& requestedLayerState = mLayerLifecycleManager.getLayerFromId(layer->getSequence()); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5432 | bool willPresentCurrentTransaction = requestedLayerState && |
| 5433 | (requestedLayerState->hasReadyFrame() || |
| 5434 | requestedLayerState->willReleaseBufferOnLatch()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5435 | if (layer->setTransactionCompletedListeners(callbackHandles, willPresentCurrentTransaction)) |
| 5436 | flags |= eTraversalNeeded; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5437 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5438 | return flags; |
| 5439 | } |
| 5440 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5441 | uint32_t SurfaceFlinger::addInputWindowCommands(const InputWindowCommands& inputWindowCommands) { |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5442 | bool hasChanges = mInputWindowCommands.merge(inputWindowCommands); |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 5443 | return hasChanges ? eTraversalNeeded : 0; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5444 | } |
| 5445 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5446 | status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5447 | const sp<IBinder>& mirrorFromHandle, |
| 5448 | gui::CreateSurfaceResult& outResult) { |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5449 | if (!mirrorFromHandle) { |
| 5450 | return NAME_NOT_FOUND; |
| 5451 | } |
| 5452 | |
| 5453 | sp<Layer> mirrorLayer; |
| 5454 | sp<Layer> mirrorFrom; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5455 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5456 | { |
| 5457 | Mutex::Autolock _l(mStateLock); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5458 | mirrorFrom = LayerHandle::getLayer(mirrorFromHandle); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5459 | if (!mirrorFrom) { |
| 5460 | return NAME_NOT_FOUND; |
| 5461 | } |
Vishnu Nair | b21272e | 2022-07-01 22:47:33 +0000 | [diff] [blame] | 5462 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5463 | mirrorArgs.mirrorLayerHandle = mirrorFromHandle; |
| 5464 | mirrorArgs.addToRoot = false; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5465 | status_t result = createEffectLayer(mirrorArgs, &outResult.handle, &mirrorLayer); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5466 | if (result != NO_ERROR) { |
| 5467 | return result; |
| 5468 | } |
| 5469 | |
Vishnu Nair | de17725 | 2023-04-21 12:44:10 -0700 | [diff] [blame] | 5470 | mirrorLayer->setClonedChild(mirrorFrom->createClone(mirrorLayer->getSequence())); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5471 | } |
| 5472 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5473 | outResult.layerId = mirrorLayer->sequence; |
| 5474 | outResult.layerName = String16(mirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5475 | return addClientLayer(mirrorArgs, outResult.handle, mirrorLayer /* layer */, |
| 5476 | nullptr /* parent */, nullptr /* outTransformHint */); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5477 | } |
| 5478 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5479 | status_t SurfaceFlinger::mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5480 | gui::CreateSurfaceResult& outResult) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5481 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5482 | const int uid = ipc->getCallingUid(); |
| 5483 | if (uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM && uid != AID_SHELL) { |
| 5484 | ALOGE("Permission denied when trying to mirror display"); |
| 5485 | return PERMISSION_DENIED; |
| 5486 | } |
| 5487 | |
| 5488 | ui::LayerStack layerStack; |
| 5489 | sp<Layer> rootMirrorLayer; |
| 5490 | status_t result = 0; |
| 5491 | |
| 5492 | { |
| 5493 | Mutex::Autolock lock(mStateLock); |
| 5494 | |
| 5495 | const auto display = getDisplayDeviceLocked(displayId); |
| 5496 | if (!display) { |
| 5497 | return NAME_NOT_FOUND; |
| 5498 | } |
| 5499 | |
| 5500 | layerStack = display->getLayerStack(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5501 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5502 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5503 | mirrorArgs.addToRoot = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5504 | mirrorArgs.layerStackToMirror = layerStack; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5505 | result = createEffectLayer(mirrorArgs, &outResult.handle, &rootMirrorLayer); |
| 5506 | outResult.layerId = rootMirrorLayer->sequence; |
| 5507 | outResult.layerName = String16(rootMirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5508 | result |= addClientLayer(mirrorArgs, outResult.handle, rootMirrorLayer /* layer */, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5509 | nullptr /* parent */, nullptr /* outTransformHint */); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5510 | } |
| 5511 | |
| 5512 | if (result != NO_ERROR) { |
| 5513 | return result; |
| 5514 | } |
| 5515 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5516 | if (mLegacyFrontEndEnabled) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5517 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5518 | mMirrorDisplays.emplace_back(layerStack, outResult.handle, args.client); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5519 | } |
| 5520 | |
| 5521 | setTransactionFlags(eTransactionFlushNeeded); |
| 5522 | return NO_ERROR; |
| 5523 | } |
| 5524 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5525 | status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, gui::CreateSurfaceResult& outResult) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5526 | status_t result = NO_ERROR; |
| 5527 | |
| 5528 | sp<Layer> layer; |
| 5529 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5530 | switch (args.flags & ISurfaceComposerClient::eFXSurfaceMask) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5531 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 5532 | case ISurfaceComposerClient::eFXSurfaceContainer: |
| 5533 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 5534 | args.flags |= ISurfaceComposerClient::eNoColorFill; |
| 5535 | FMT_FALLTHROUGH; |
| 5536 | case ISurfaceComposerClient::eFXSurfaceEffect: { |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5537 | result = createBufferStateLayer(args, &outResult.handle, &layer); |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5538 | std::atomic<int32_t>* pendingBufferCounter = layer->getPendingBufferCounter(); |
| 5539 | if (pendingBufferCounter) { |
| 5540 | std::string counterName = layer->getPendingBufferCounterName(); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5541 | mBufferCountTracker.add(outResult.handle->localBinder(), counterName, |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5542 | pendingBufferCounter); |
| 5543 | } |
| 5544 | } break; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5545 | default: |
| 5546 | result = BAD_VALUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5547 | break; |
| 5548 | } |
| 5549 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5550 | if (result != NO_ERROR) { |
| 5551 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5552 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5553 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5554 | args.addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess(); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5555 | // We can safely promote the parent layer in binder thread because we have a strong reference |
| 5556 | // to the layer's handle inside this scope. |
| 5557 | sp<Layer> parent = LayerHandle::getLayer(args.parentHandle.promote()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5558 | if (args.parentHandle != nullptr && parent == nullptr) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5559 | ALOGE("Invalid parent handle %p", args.parentHandle.promote().get()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5560 | args.addToRoot = false; |
Garfield Tan | dbc93d7 | 2021-10-26 18:28:57 -0700 | [diff] [blame] | 5561 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5562 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5563 | uint32_t outTransformHint; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5564 | result = addClientLayer(args, outResult.handle, layer, parent, &outTransformHint); |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 5565 | if (result != NO_ERROR) { |
| 5566 | return result; |
| 5567 | } |
| 5568 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5569 | outResult.transformHint = static_cast<int32_t>(outTransformHint); |
| 5570 | outResult.layerId = layer->sequence; |
| 5571 | outResult.layerName = String16(layer->getDebugName()); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5572 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5573 | } |
| 5574 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5575 | status_t SurfaceFlinger::createBufferStateLayer(LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5576 | sp<Layer>* outLayer) { |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5577 | *outLayer = getFactory().createBufferStateLayer(args); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5578 | *handle = (*outLayer)->getHandle(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5579 | return NO_ERROR; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 5580 | } |
| 5581 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5582 | status_t SurfaceFlinger::createEffectLayer(const LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5583 | sp<Layer>* outLayer) { |
| 5584 | *outLayer = getFactory().createEffectLayer(args); |
| 5585 | *handle = (*outLayer)->getHandle(); |
| 5586 | return NO_ERROR; |
| 5587 | } |
| 5588 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5589 | void SurfaceFlinger::markLayerPendingRemovalLocked(const sp<Layer>& layer) { |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5590 | mLayersPendingRemoval.add(layer); |
| 5591 | mLayersRemoved = true; |
| 5592 | setTransactionFlags(eTransactionNeeded); |
| 5593 | } |
| 5594 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5595 | void SurfaceFlinger::onHandleDestroyed(BBinder* handle, sp<Layer>& layer, uint32_t layerId) { |
| 5596 | { |
| 5597 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | 606d9d0 | 2023-08-19 14:20:18 -0700 | [diff] [blame] | 5598 | mDestroyedHandles.emplace_back(layerId, layer->getDebugName()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5599 | } |
| 5600 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 5601 | mTransactionHandler.onLayerDestroyed(layerId); |
| 5602 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5603 | Mutex::Autolock lock(mStateLock); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5604 | markLayerPendingRemovalLocked(layer); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 5605 | layer->onHandleDestroyed(); |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 5606 | mBufferCountTracker.remove(handle); |
Robert Carr | 695d528 | 2018-12-18 15:27:58 -0800 | [diff] [blame] | 5607 | layer.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5608 | |
| 5609 | setTransactionFlags(eTransactionFlushNeeded); |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 5610 | } |
| 5611 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 5612 | void SurfaceFlinger::initializeDisplays() { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5613 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 5614 | if (!display) return; |
| 5615 | |
| 5616 | const sp<IBinder> token = display->getDisplayToken().promote(); |
| 5617 | LOG_ALWAYS_FATAL_IF(token == nullptr); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 5618 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5619 | TransactionState state; |
| 5620 | state.inputWindowCommands = mInputWindowCommands; |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5621 | const nsecs_t now = systemTime(); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5622 | state.desiredPresentTime = now; |
| 5623 | state.postTime = now; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5624 | state.originPid = mPid; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5625 | state.originUid = static_cast<int>(getuid()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5626 | const uint64_t transactionId = (static_cast<uint64_t>(mPid) << 32) | mUniqueTransactionId++; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5627 | state.id = transactionId; |
| 5628 | |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 5629 | // reset screen orientation and use primary layer stack |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 5630 | Vector<DisplayState> displays; |
| 5631 | DisplayState d; |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 5632 | d.what = DisplayState::eDisplayProjectionChanged | |
| 5633 | DisplayState::eLayerStackChanged; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 5634 | d.token = token; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 5635 | d.layerStack = ui::DEFAULT_LAYER_STACK; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 5636 | d.orientation = ui::ROTATION_0; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5637 | d.orientedDisplaySpaceRect.makeInvalid(); |
| 5638 | d.layerStackSpaceRect.makeInvalid(); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 5639 | d.width = 0; |
| 5640 | d.height = 0; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5641 | state.displays.add(d); |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5642 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5643 | std::vector<TransactionState> transactions; |
| 5644 | transactions.emplace_back(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5645 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5646 | if (mLegacyFrontEndEnabled) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5647 | applyTransactions(transactions, VsyncId{0}); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5648 | } else { |
| 5649 | applyAndCommitDisplayTransactionStates(transactions); |
| 5650 | } |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 5651 | |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5652 | { |
| 5653 | ftl::FakeGuard guard(mStateLock); |
| 5654 | setPowerModeInternal(display, hal::PowerMode::ON); |
| 5655 | } |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 5656 | } |
| 5657 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5658 | void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 5659 | if (display->isVirtual()) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 5660 | ALOGE("%s: Invalid operation on virtual display", __func__); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5661 | return; |
| 5662 | } |
| 5663 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5664 | const auto displayId = display->getPhysicalId(); |
| 5665 | 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] | 5666 | |
Dominik Laskowski | b4ff7d9 | 2022-11-22 13:59:53 -0500 | [diff] [blame] | 5667 | const auto currentModeOpt = display->getPowerMode(); |
| 5668 | if (currentModeOpt == mode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5669 | return; |
| 5670 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5671 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5672 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 5673 | .transform(&PhysicalDisplay::isInternal) |
| 5674 | .value_or(false); |
| 5675 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 5676 | const auto activeDisplay = getDisplayDeviceLocked(mActiveDisplayId); |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 5677 | |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5678 | ALOGW_IF(display != activeDisplay && isInternalDisplay && activeDisplay && |
| 5679 | activeDisplay->isPoweredOn(), |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 5680 | "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] | 5681 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5682 | display->setPowerMode(mode); |
| 5683 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 5684 | const auto refreshRate = display->refreshRateSelector().getActiveMode().modePtr->getFps(); |
Dominik Laskowski | b4ff7d9 | 2022-11-22 13:59:53 -0500 | [diff] [blame] | 5685 | if (!currentModeOpt || *currentModeOpt == hal::PowerMode::OFF) { |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 5686 | // Turn on the display |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5687 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 5688 | // Activate the display (which involves a modeset to the active mode) when the inner or |
| 5689 | // outer display of a foldable is powered on. This condition relies on the above |
| 5690 | // DisplayDevice::setPowerMode. If `display` and `activeDisplay` are the same display, |
| 5691 | // then the `activeDisplay->isPoweredOn()` below is true, such that the display is not |
| 5692 | // activated every time it is powered on. |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5693 | // |
| 5694 | // TODO(b/255635821): Remove the concept of active display. |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 5695 | if (isInternalDisplay && (!activeDisplay || !activeDisplay->isPoweredOn())) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 5696 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 5697 | } |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5698 | |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5699 | if (displayId == mActiveDisplayId) { |
| 5700 | // TODO(b/281692563): Merge the syscalls. For now, keep uclamp in a separate syscall and |
| 5701 | // set it before SCHED_FIFO due to b/190237315. |
| 5702 | if (setSchedAttr(true) != NO_ERROR) { |
| 5703 | ALOGW("Failed to set uclamp.min after powering on active display: %s", |
| 5704 | strerror(errno)); |
| 5705 | } |
| 5706 | if (setSchedFifo(true) != NO_ERROR) { |
| 5707 | ALOGW("Failed to set SCHED_FIFO after powering on active display: %s", |
| 5708 | strerror(errno)); |
| 5709 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 5710 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5711 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5712 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5713 | if (displayId == mActiveDisplayId && mode != hal::PowerMode::DOZE_SUSPEND) { |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5714 | const bool enable = |
| 5715 | mScheduler->getVsyncSchedule(displayId)->getPendingHardwareVsyncState(); |
| 5716 | requestHardwareVsync(displayId, enable); |
| 5717 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5718 | mScheduler->enableSyntheticVsync(false); |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5719 | |
| 5720 | constexpr bool kAllowToEnable = true; |
| 5721 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, refreshRate); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5722 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5723 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5724 | mVisibleRegionsDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 5725 | scheduleComposite(FrameHint::kActive); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5726 | } else if (mode == hal::PowerMode::OFF) { |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 5727 | // Turn off the display |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5728 | |
| 5729 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 5730 | if (const auto display = getActivatableDisplay()) { |
| 5731 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
| 5732 | } else { |
| 5733 | if (setSchedFifo(false) != NO_ERROR) { |
| 5734 | ALOGW("Failed to set SCHED_OTHER after powering off active display: %s", |
| 5735 | strerror(errno)); |
| 5736 | } |
| 5737 | if (setSchedAttr(false) != NO_ERROR) { |
| 5738 | ALOGW("Failed set uclamp.min after powering off active display: %s", |
| 5739 | strerror(errno)); |
| 5740 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5741 | |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 5742 | if (*currentModeOpt != hal::PowerMode::DOZE_SUSPEND) { |
| 5743 | mScheduler->disableHardwareVsync(displayId, true); |
| 5744 | mScheduler->enableSyntheticVsync(); |
| 5745 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5746 | } |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 5747 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5748 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5749 | // Disable VSYNC before turning off the display. |
| 5750 | requestHardwareVsync(displayId, false); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5751 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5752 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5753 | mVisibleRegionsDirty = true; |
| 5754 | // from this point on, SF will stop drawing on this display |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5755 | } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5756 | // Update display while dozing |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5757 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5758 | if (displayId == mActiveDisplayId && *currentModeOpt == hal::PowerMode::DOZE_SUSPEND) { |
Yifei Zhang | f0bd62e | 2021-06-16 15:27:05 -0700 | [diff] [blame] | 5759 | ALOGI("Force repainting for DOZE_SUSPEND -> DOZE or ON."); |
| 5760 | mVisibleRegionsDirty = true; |
| 5761 | scheduleRepaint(); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5762 | mScheduler->enableSyntheticVsync(false); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5763 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, refreshRate); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5764 | } |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5765 | } else if (mode == hal::PowerMode::DOZE_SUSPEND) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5766 | // Leave display going to doze |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5767 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5768 | mScheduler->disableHardwareVsync(displayId, true); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5769 | mScheduler->enableSyntheticVsync(); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5770 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5771 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5772 | } else { |
Matthew Bouyack | 38d4961 | 2017-05-12 12:49:32 -0700 | [diff] [blame] | 5773 | ALOGE("Attempting to set unknown power mode: %d\n", mode); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5774 | getHwComposer().setPowerMode(displayId, mode); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5775 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5776 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5777 | if (displayId == mActiveDisplayId) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 5778 | mTimeStats->setPowerMode(mode); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 5779 | mRefreshRateStats->setPowerMode(mode); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 5780 | } |
| 5781 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5782 | mScheduler->setDisplayPowerMode(displayId, mode); |
| 5783 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5784 | 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] | 5785 | } |
| 5786 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5787 | void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) { |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 5788 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
| 5789 | kMainThreadContext) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 5790 | const auto display = getDisplayDeviceLocked(displayToken); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5791 | if (!display) { |
| 5792 | ALOGE("Attempt to set power mode %d for invalid display token %p", mode, |
| 5793 | displayToken.get()); |
| 5794 | } else if (display->isVirtual()) { |
| 5795 | ALOGW("Attempt to set power mode %d for virtual display", mode); |
| 5796 | } else { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5797 | setPowerModeInternal(display, static_cast<hal::PowerMode>(mode)); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5798 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5799 | }); |
| 5800 | |
| 5801 | future.wait(); |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 5802 | } |
| 5803 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5804 | status_t SurfaceFlinger::doDump(int fd, const DumpArgs& args, bool asProto) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5805 | std::string result; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 5806 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 5807 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5808 | const int pid = ipc->getCallingPid(); |
| 5809 | const int uid = ipc->getCallingUid(); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 5810 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 5811 | if ((uid != AID_SHELL) && |
| 5812 | !PermissionCache::checkPermission(sDump, pid, uid)) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5813 | StringAppendF(&result, "Permission Denial: can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 5814 | pid, uid); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5815 | } else { |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5816 | static const std::unordered_map<std::string, Dumper> dumpers = { |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5817 | {"--comp-displays"s, dumper(&SurfaceFlinger::dumpCompositionDisplays)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5818 | {"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)}, |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5819 | {"--displays"s, dumper(&SurfaceFlinger::dumpDisplays)}, |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5820 | {"--edid"s, argsDumper(&SurfaceFlinger::dumpRawDisplayIdentificationData)}, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5821 | {"--events"s, dumper(&SurfaceFlinger::dumpEvents)}, |
| 5822 | {"--frametimeline"s, argsDumper(&SurfaceFlinger::dumpFrameTimeline)}, |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 5823 | {"--hdrinfo"s, dumper(&SurfaceFlinger::dumpHdrInfo)}, |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 5824 | {"--hwclayers"s, dumper(&SurfaceFlinger::dumpHwcLayersMinidumpLockedLegacy)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5825 | {"--latency"s, argsDumper(&SurfaceFlinger::dumpStatsLocked)}, |
| 5826 | {"--latency-clear"s, argsDumper(&SurfaceFlinger::clearStatsLocked)}, |
| 5827 | {"--list"s, dumper(&SurfaceFlinger::listLayersLocked)}, |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 5828 | {"--planner"s, argsDumper(&SurfaceFlinger::dumpPlannerInfo)}, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5829 | {"--scheduler"s, dumper(&SurfaceFlinger::dumpScheduler)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5830 | {"--timestats"s, protoDumper(&SurfaceFlinger::dumpTimeStats)}, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5831 | {"--vsync"s, dumper(&SurfaceFlinger::dumpVsync)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5832 | {"--wide-color"s, dumper(&SurfaceFlinger::dumpWideColorInfo)}, |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 5833 | {"--frontend"s, dumper(&SurfaceFlinger::dumpFrontEnd)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5834 | }; |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5835 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5836 | const auto flag = args.empty() ? ""s : std::string(String8(args[0])); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5837 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5838 | // Traversal of drawing state must happen on the main thread. |
| 5839 | // Otherwise, SortedVector may have shared ownership during concurrent |
| 5840 | // traversals, which can result in use-after-frees. |
| 5841 | std::string compositionLayers; |
| 5842 | mScheduler |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 5843 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 5844 | if (!mLayerLifecycleManagerEnabled) { |
| 5845 | StringAppendF(&compositionLayers, "Composition layers\n"); |
| 5846 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 5847 | auto* compositionState = layer->getCompositionState(); |
| 5848 | if (!compositionState || !compositionState->isVisible) return; |
| 5849 | android::base::StringAppendF(&compositionLayers, "* Layer %p (%s)\n", |
| 5850 | layer, |
| 5851 | layer->getDebugName() |
| 5852 | ? layer->getDebugName() |
| 5853 | : "<unknown>"); |
| 5854 | compositionState->dump(compositionLayers); |
| 5855 | }); |
| 5856 | } else { |
| 5857 | std::ostringstream out; |
| 5858 | out << "\nComposition list\n"; |
| 5859 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 5860 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 5861 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 5862 | if (snapshot->hasSomethingToDraw()) { |
| 5863 | if (lastPrintedLayerStackHeader != |
| 5864 | snapshot->outputFilter.layerStack) { |
| 5865 | lastPrintedLayerStackHeader = |
| 5866 | snapshot->outputFilter.layerStack; |
| 5867 | out << "LayerStack=" << lastPrintedLayerStackHeader.id |
| 5868 | << "\n"; |
| 5869 | } |
| 5870 | out << " " << *snapshot << "\n"; |
| 5871 | } |
| 5872 | }); |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5873 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 5874 | out << "\nInput list\n"; |
| 5875 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 5876 | mLayerSnapshotBuilder.forEachInputSnapshot( |
| 5877 | [&](const frontend::LayerSnapshot& snapshot) { |
| 5878 | if (lastPrintedLayerStackHeader != |
| 5879 | snapshot.outputFilter.layerStack) { |
| 5880 | lastPrintedLayerStackHeader = |
| 5881 | snapshot.outputFilter.layerStack; |
| 5882 | out << "LayerStack=" << lastPrintedLayerStackHeader.id |
| 5883 | << "\n"; |
| 5884 | } |
| 5885 | out << " " << snapshot << "\n"; |
| 5886 | }); |
| 5887 | |
| 5888 | out << "\nLayer Hierarchy\n" |
| 5889 | << mLayerHierarchyBuilder.getHierarchy() << "\n\n"; |
| 5890 | compositionLayers = out.str(); |
| 5891 | dumpHwcLayersMinidump(compositionLayers); |
| 5892 | } |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5893 | }) |
| 5894 | .get(); |
| 5895 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5896 | bool dumpLayers = true; |
| 5897 | { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 5898 | TimedLock lock(mStateLock, s2ns(1), __func__); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5899 | if (!lock.locked()) { |
| 5900 | StringAppendF(&result, "Dumping without lock after timeout: %s (%d)\n", |
| 5901 | strerror(-lock.status), lock.status); |
| 5902 | } |
| 5903 | |
| 5904 | if (const auto it = dumpers.find(flag); it != dumpers.end()) { |
| 5905 | (it->second)(args, asProto, result); |
| 5906 | dumpLayers = false; |
| 5907 | } else if (!asProto) { |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5908 | dumpAllLocked(args, compositionLayers, result); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5909 | } |
Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 5910 | } |
| 5911 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5912 | if (dumpLayers) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 5913 | perfetto::protos::LayersTraceFileProto traceFileProto = |
| 5914 | mLayerTracing.createTraceFileProto(); |
| 5915 | perfetto::protos::LayersSnapshotProto* layersTrace = traceFileProto.add_entry(); |
| 5916 | perfetto::protos::LayersProto layersProto = dumpProtoFromMainThread(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5917 | layersTrace->mutable_layers()->Swap(&layersProto); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5918 | auto displayProtos = dumpDisplayProto(); |
| 5919 | layersTrace->mutable_displays()->Swap(&displayProtos); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5920 | |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5921 | if (asProto) { |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5922 | result.append(traceFileProto.SerializeAsString()); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5923 | } else { |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5924 | // Dump info that we need to access from the main thread |
chaviw | a2b9fab | 2021-09-08 14:46:30 -0500 | [diff] [blame] | 5925 | const auto layerTree = LayerProtoParser::generateLayerTree(layersTrace->layers()); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5926 | result.append(LayerProtoParser::layerTreeToString(layerTree)); |
| 5927 | result.append("\n"); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5928 | dumpOffscreenLayers(result); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5929 | } |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 5930 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5931 | } |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 5932 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5933 | write(fd, result.c_str(), result.size()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5934 | return NO_ERROR; |
| 5935 | } |
| 5936 | |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 5937 | status_t SurfaceFlinger::dumpCritical(int fd, const DumpArgs&, bool asProto) { |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 5938 | return doDump(fd, DumpArgs(), asProto); |
| 5939 | } |
| 5940 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5941 | void SurfaceFlinger::listLayersLocked(std::string& result) const { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5942 | mCurrentState.traverseInZOrder( |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5943 | [&](Layer* layer) { StringAppendF(&result, "%s\n", layer->getDebugName()); }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5944 | } |
| 5945 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5946 | void SurfaceFlinger::dumpStatsLocked(const DumpArgs& args, std::string& result) const { |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 5947 | StringAppendF(&result, "%" PRId64 "\n", getVsyncPeriodFromHWC()); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5948 | if (args.size() < 2) return; |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 5949 | |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5950 | const auto name = String8(args[1]); |
| 5951 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 5952 | if (layer->getName() == name.c_str()) { |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5953 | layer->dumpFrameStats(result); |
| 5954 | } |
| 5955 | }); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5956 | } |
| 5957 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5958 | void SurfaceFlinger::clearStatsLocked(const DumpArgs& args, std::string&) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5959 | const bool clearAll = args.size() < 2; |
| 5960 | const auto name = clearAll ? String8() : String8(args[1]); |
| 5961 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 5962 | mCurrentState.traverse([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 5963 | if (clearAll || layer->getName() == name.c_str()) { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 5964 | layer->clearFrameStats(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5965 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 5966 | }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5967 | } |
| 5968 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5969 | void SurfaceFlinger::dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const { |
| 5970 | mTimeStats->parseArgs(asProto, args, result); |
| 5971 | } |
| 5972 | |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 5973 | void SurfaceFlinger::dumpFrameTimeline(const DumpArgs& args, std::string& result) const { |
| 5974 | mFrameTimeline->parseArgs(args, result); |
| 5975 | } |
| 5976 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 5977 | void SurfaceFlinger::logFrameStats(TimePoint now) { |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 5978 | static TimePoint sTimestamp = now; |
| 5979 | if (now - sTimestamp < 30min) return; |
| 5980 | sTimestamp = now; |
| 5981 | |
| 5982 | ATRACE_CALL(); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5983 | mDrawingState.traverse([&](Layer* layer) { layer->logFrameStats(); }); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 5984 | } |
| 5985 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5986 | void SurfaceFlinger::appendSfConfigString(std::string& result) const { |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 5987 | result.append(" [sf"); |
Fabien Sanglard | c93afd5 | 2017-03-13 13:02:42 -0700 | [diff] [blame] | 5988 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5989 | StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); |
| 5990 | StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 5991 | StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%zu", |
| 5992 | getHwComposer().getMaxVirtualDisplayDimension()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5993 | StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5994 | StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5995 | maxFrameBufferAcquiredBuffers); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 5996 | result.append("]"); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5997 | } |
| 5998 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5999 | void SurfaceFlinger::dumpScheduler(std::string& result) const { |
| 6000 | utils::Dumper dumper{result}; |
| 6001 | |
| 6002 | mScheduler->dump(dumper); |
| 6003 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6004 | // TODO(b/241285876): Move to DisplayModeController. |
| 6005 | dumper.dump("debugDisplayModeSetByBackdoor"sv, mDebugDisplayModeSetByBackdoor); |
| 6006 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6007 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 6008 | mRefreshRateStats->dump(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6009 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6010 | |
Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 6011 | mVsyncConfiguration->dump(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6012 | StringAppendF(&result, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6013 | " present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64 |
| 6014 | " ns\n\n", |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6015 | dispSyncPresentTimeOffset, getVsyncPeriodFromHWC()); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6016 | } |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6017 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6018 | void SurfaceFlinger::dumpEvents(std::string& result) const { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 6019 | mScheduler->dump(mAppConnectionHandle, result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | void SurfaceFlinger::dumpVsync(std::string& result) const { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 6023 | mScheduler->dumpVsync(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6024 | } |
| 6025 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 6026 | void SurfaceFlinger::dumpPlannerInfo(const DumpArgs& args, std::string& result) const { |
| 6027 | for (const auto& [token, display] : mDisplays) { |
| 6028 | const auto compositionDisplay = display->getCompositionDisplay(); |
| 6029 | compositionDisplay->dumpPlannerInfo(args, result); |
| 6030 | } |
| 6031 | } |
| 6032 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6033 | void SurfaceFlinger::dumpCompositionDisplays(std::string& result) const { |
| 6034 | for (const auto& [token, display] : mDisplays) { |
| 6035 | display->getCompositionDisplay()->dump(result); |
| 6036 | result += '\n'; |
| 6037 | } |
| 6038 | } |
| 6039 | |
| 6040 | void SurfaceFlinger::dumpDisplays(std::string& result) const { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6041 | utils::Dumper dumper{result}; |
| 6042 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6043 | for (const auto& [id, display] : mPhysicalDisplays) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6044 | utils::Dumper::Section section(dumper, ftl::Concat("Display ", id.value).str()); |
| 6045 | |
| 6046 | display.snapshot().dump(dumper); |
| 6047 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6048 | if (const auto device = getDisplayDeviceLocked(id)) { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6049 | device->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6050 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6051 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6052 | |
| 6053 | for (const auto& [token, display] : mDisplays) { |
| 6054 | if (display->isVirtual()) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6055 | const auto displayId = display->getId(); |
| 6056 | utils::Dumper::Section section(dumper, |
| 6057 | ftl::Concat("Virtual Display ", displayId.value).str()); |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6058 | display->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6059 | } |
| 6060 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6061 | } |
| 6062 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6063 | void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 6064 | for (const auto& [token, display] : mDisplays) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6065 | const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6066 | if (!displayId) { |
| 6067 | continue; |
| 6068 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6069 | const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId); |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6070 | if (!hwcDisplayId) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6071 | continue; |
| 6072 | } |
| 6073 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6074 | StringAppendF(&result, |
| 6075 | "Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), |
| 6076 | *hwcDisplayId); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6077 | uint8_t port; |
| 6078 | DisplayIdentificationData data; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6079 | if (!getHwComposer().getDisplayIdentificationData(*hwcDisplayId, &port, &data)) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6080 | result.append("no identification data\n"); |
| 6081 | continue; |
| 6082 | } |
| 6083 | |
| 6084 | if (!isEdid(data)) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6085 | result.append("unknown identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6086 | continue; |
| 6087 | } |
| 6088 | |
| 6089 | const auto edid = parseEdid(data); |
| 6090 | if (!edid) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6091 | result.append("invalid EDID\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6092 | continue; |
| 6093 | } |
| 6094 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6095 | StringAppendF(&result, "port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6096 | result.append(edid->displayName.data(), edid->displayName.length()); |
| 6097 | result.append("\"\n"); |
| 6098 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6099 | } |
| 6100 | |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6101 | void SurfaceFlinger::dumpRawDisplayIdentificationData(const DumpArgs& args, |
| 6102 | std::string& result) const { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 6103 | hal::HWDisplayId hwcDisplayId; |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6104 | uint8_t port; |
| 6105 | DisplayIdentificationData data; |
| 6106 | |
| 6107 | if (args.size() > 1 && base::ParseUint(String8(args[1]), &hwcDisplayId) && |
| 6108 | getHwComposer().getDisplayIdentificationData(hwcDisplayId, &port, &data)) { |
| 6109 | result.append(reinterpret_cast<const char*>(data.data()), data.size()); |
| 6110 | } |
| 6111 | } |
| 6112 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6113 | void SurfaceFlinger::dumpWideColorInfo(std::string& result) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6114 | StringAppendF(&result, "Device supports wide color: %d\n", mSupportsWideColor); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6115 | StringAppendF(&result, "DisplayColorSetting: %s\n", |
| 6116 | decodeDisplayColorSetting(mDisplayColorSetting).c_str()); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6117 | |
| 6118 | // TODO: print out if wide-color mode is active or not |
| 6119 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6120 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6121 | StringAppendF(&result, "Display %s color modes:\n", to_string(id).c_str()); |
| 6122 | for (const auto mode : display.snapshot().colorModes()) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6123 | StringAppendF(&result, " %s (%d)\n", decodeColorMode(mode).c_str(), mode); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6124 | } |
| 6125 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6126 | if (const auto display = getDisplayDeviceLocked(id)) { |
| 6127 | ui::ColorMode currentMode = display->getCompositionDisplay()->getState().colorMode; |
| 6128 | StringAppendF(&result, " Current color mode: %s (%d)\n", |
| 6129 | decodeColorMode(currentMode).c_str(), currentMode); |
| 6130 | } |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6131 | } |
| 6132 | result.append("\n"); |
| 6133 | } |
| 6134 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6135 | void SurfaceFlinger::dumpHdrInfo(std::string& result) const { |
| 6136 | for (const auto& [displayId, listener] : mHdrLayerInfoListeners) { |
| 6137 | StringAppendF(&result, "HDR events for display %" PRIu64 "\n", displayId.value); |
| 6138 | listener->dump(result); |
| 6139 | result.append("\n"); |
| 6140 | } |
| 6141 | } |
| 6142 | |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6143 | void SurfaceFlinger::dumpFrontEnd(std::string& result) { |
| 6144 | mScheduler |
| 6145 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 6146 | std::ostringstream out; |
| 6147 | out << "\nComposition list\n"; |
| 6148 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6149 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 6150 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 6151 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 6152 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6153 | } |
| 6154 | out << " " << *snapshot << "\n"; |
| 6155 | } |
| 6156 | |
| 6157 | out << "\nInput list\n"; |
| 6158 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6159 | mLayerSnapshotBuilder.forEachInputSnapshot( |
| 6160 | [&](const frontend::LayerSnapshot& snapshot) { |
| 6161 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 6162 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 6163 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6164 | } |
| 6165 | out << " " << snapshot << "\n"; |
| 6166 | }); |
| 6167 | |
| 6168 | out << "\nLayer Hierarchy\n" |
| 6169 | << mLayerHierarchyBuilder.getHierarchy().dump() << "\n\n"; |
| 6170 | result.append(out.str()); |
| 6171 | }) |
| 6172 | .get(); |
| 6173 | } |
| 6174 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6175 | perfetto::protos::LayersProto SurfaceFlinger::dumpDrawingStateProto(uint32_t traceFlags) const { |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 6176 | std::unordered_set<uint64_t> stackIdsToSkip; |
| 6177 | |
| 6178 | // Determine if virtual layers display should be skipped |
| 6179 | if ((traceFlags & LayerTracing::TRACE_VIRTUAL_DISPLAYS) == 0) { |
| 6180 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 6181 | if (display->isVirtual()) { |
| 6182 | stackIdsToSkip.insert(display->getLayerStack().id); |
| 6183 | } |
| 6184 | } |
| 6185 | } |
| 6186 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6187 | if (mLegacyFrontEndEnabled) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6188 | perfetto::protos::LayersProto layersProto; |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 6189 | for (const sp<Layer>& layer : mDrawingState.layersSortedByZ) { |
| 6190 | if (stackIdsToSkip.find(layer->getLayerStack().id) != stackIdsToSkip.end()) { |
| 6191 | continue; |
| 6192 | } |
| 6193 | layer->writeToProto(layersProto, traceFlags); |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 6194 | } |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 6195 | return layersProto; |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 6196 | } |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 6197 | |
Vishnu Nair | 22be349 | 2023-04-20 10:08:21 -0700 | [diff] [blame] | 6198 | return LayerProtoFromSnapshotGenerator(mLayerSnapshotBuilder, mFrontEndDisplayInfos, |
| 6199 | mLegacyLayers, traceFlags) |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 6200 | .generate(mLayerHierarchyBuilder.getHierarchy()); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6201 | } |
| 6202 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6203 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> |
| 6204 | SurfaceFlinger::dumpDisplayProto() const { |
| 6205 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> displays; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6206 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6207 | perfetto::protos::DisplayProto* displayProto = displays.Add(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6208 | displayProto->set_id(display->getId().value); |
| 6209 | displayProto->set_name(display->getDisplayName()); |
| 6210 | displayProto->set_layer_stack(display->getLayerStack().id); |
DoÄŸancan Emek | fc4b6ed | 2023-07-26 15:24:04 +0000 | [diff] [blame] | 6211 | |
| 6212 | if (!display->isVirtual()) { |
| 6213 | const auto dpi = display->refreshRateSelector().getActiveMode().modePtr->getDpi(); |
| 6214 | displayProto->set_dpi_x(dpi.x); |
| 6215 | displayProto->set_dpi_y(dpi.y); |
| 6216 | } |
| 6217 | |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6218 | LayerProtoHelper::writeSizeToProto(display->getWidth(), display->getHeight(), |
| 6219 | [&]() { return displayProto->mutable_size(); }); |
| 6220 | LayerProtoHelper::writeToProto(display->getLayerStackSpaceRect(), [&]() { |
| 6221 | return displayProto->mutable_layer_stack_space_rect(); |
| 6222 | }); |
| 6223 | LayerProtoHelper::writeTransformToProto(display->getTransform(), |
| 6224 | displayProto->mutable_transform()); |
Vishnu Nair | 791d48a | 2021-12-02 16:55:13 -0800 | [diff] [blame] | 6225 | displayProto->set_is_virtual(display->isVirtual()); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6226 | } |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 6227 | return displays; |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6228 | } |
| 6229 | |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 6230 | void SurfaceFlinger::dumpHwc(std::string& result) const { |
| 6231 | getHwComposer().dump(result); |
| 6232 | } |
| 6233 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6234 | void SurfaceFlinger::dumpOffscreenLayersProto(perfetto::protos::LayersProto& layersProto, |
| 6235 | uint32_t traceFlags) const { |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6236 | // Add a fake invisible root layer to the proto output and parent all the offscreen layers to |
| 6237 | // it. |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6238 | perfetto::protos::LayerProto* rootProto = layersProto.add_layers(); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6239 | const int32_t offscreenRootLayerId = INT32_MAX - 2; |
| 6240 | rootProto->set_id(offscreenRootLayerId); |
| 6241 | rootProto->set_name("Offscreen Root"); |
Vishnu Nair | d5aeb61 | 2019-09-20 14:39:39 -0700 | [diff] [blame] | 6242 | rootProto->set_parent(-1); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6243 | |
| 6244 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6245 | // Add layer as child of the fake root |
| 6246 | rootProto->add_children(offscreenLayer->sequence); |
| 6247 | |
| 6248 | // Add layer |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6249 | auto* layerProto = offscreenLayer->writeToProto(layersProto, traceFlags); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6250 | layerProto->set_parent(offscreenRootLayerId); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6251 | } |
| 6252 | } |
| 6253 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6254 | perfetto::protos::LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6255 | return mScheduler->schedule([=] { return dumpDrawingStateProto(traceFlags); }).get(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 6256 | } |
| 6257 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6258 | void SurfaceFlinger::dumpOffscreenLayers(std::string& result) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6259 | auto future = mScheduler->schedule([this] { |
| 6260 | std::string result; |
| 6261 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6262 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
Vishnu Nair | 76554eb | 2022-12-09 03:38:36 +0000 | [diff] [blame] | 6263 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6264 | } |
| 6265 | return result; |
| 6266 | }); |
| 6267 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6268 | result.append("Offscreen Layers:\n"); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6269 | result.append(future.get()); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6270 | } |
| 6271 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6272 | void SurfaceFlinger::dumpHwcLayersMinidumpLockedLegacy(std::string& result) const { |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6273 | for (const auto& [token, display] : mDisplays) { |
| 6274 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6275 | if (!displayId) { |
| 6276 | continue; |
| 6277 | } |
| 6278 | |
| 6279 | StringAppendF(&result, "Display %s (%s) HWC layers:\n", to_string(*displayId).c_str(), |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 6280 | displayId == mActiveDisplayId ? "active" : "inactive"); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6281 | Layer::miniDumpHeader(result); |
| 6282 | |
| 6283 | const DisplayDevice& ref = *display; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6284 | mDrawingState.traverseInZOrder([&](Layer* layer) { layer->miniDumpLegacy(result, ref); }); |
| 6285 | result.append("\n"); |
| 6286 | } |
| 6287 | } |
| 6288 | |
| 6289 | void SurfaceFlinger::dumpHwcLayersMinidump(std::string& result) const { |
| 6290 | for (const auto& [token, display] : mDisplays) { |
| 6291 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6292 | if (!displayId) { |
| 6293 | continue; |
| 6294 | } |
| 6295 | |
| 6296 | StringAppendF(&result, "Display %s (%s) HWC layers:\n", to_string(*displayId).c_str(), |
| 6297 | displayId == mActiveDisplayId ? "active" : "inactive"); |
| 6298 | Layer::miniDumpHeader(result); |
| 6299 | |
| 6300 | const DisplayDevice& ref = *display; |
| 6301 | mLayerSnapshotBuilder.forEachVisibleSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6302 | if (!snapshot.hasSomethingToDraw() || |
| 6303 | ref.getLayerStack() != snapshot.outputFilter.layerStack) { |
| 6304 | return; |
| 6305 | } |
| 6306 | auto it = mLegacyLayers.find(snapshot.sequence); |
| 6307 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), "Couldnt find layer object for %s", |
| 6308 | snapshot.getDebugString().c_str()); |
| 6309 | it->second->miniDump(result, snapshot, ref); |
| 6310 | }); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6311 | result.append("\n"); |
| 6312 | } |
| 6313 | } |
| 6314 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 6315 | void SurfaceFlinger::dumpAllLocked(const DumpArgs& args, const std::string& compositionLayers, |
| 6316 | std::string& result) const { |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6317 | const bool colorize = !args.empty() && args[0] == String16("--color"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6318 | Colorizer colorizer(colorize); |
| 6319 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6320 | // figure out if we're stuck somewhere |
| 6321 | const nsecs_t now = systemTime(); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6322 | const nsecs_t inTransaction(mDebugInTransaction); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6323 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 6324 | |
| 6325 | /* |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6326 | * Dump library configuration. |
| 6327 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6328 | |
| 6329 | colorizer.bold(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6330 | result.append("Build configuration:"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6331 | colorizer.reset(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6332 | appendSfConfigString(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6333 | result.append("\n"); |
| 6334 | |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6335 | result.append("\nDisplay identification data:\n"); |
| 6336 | dumpDisplayIdentificationData(result); |
| 6337 | |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6338 | result.append("\nWide-Color information:\n"); |
| 6339 | dumpWideColorInfo(result); |
| 6340 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6341 | dumpHdrInfo(result); |
| 6342 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6343 | colorizer.bold(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6344 | result.append("Sync configuration: "); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6345 | colorizer.reset(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6346 | result.append(SyncFeatures::getInstance().toString()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6347 | result.append("\n\n"); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6348 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6349 | colorizer.bold(result); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6350 | result.append("Scheduler:\n"); |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6351 | colorizer.reset(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6352 | dumpScheduler(result); |
| 6353 | dumpEvents(result); |
| 6354 | dumpVsync(result); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 6355 | result.append("\n"); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6356 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6357 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6358 | * Dump the visible layer list |
| 6359 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6360 | colorizer.bold(result); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6361 | StringAppendF(&result, "SurfaceFlinger New Frontend Enabled:%s\n", |
| 6362 | mLayerLifecycleManagerEnabled ? "true" : "false"); |
| 6363 | StringAppendF(&result, "Active Layers - layers with client handles (count = %zu)\n", |
| 6364 | mNumLayers.load()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6365 | colorizer.reset(result); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6366 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 6367 | result.append(compositionLayers); |
Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 6368 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6369 | colorizer.bold(result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6370 | StringAppendF(&result, "Displays (%zu entries)\n", mDisplays.size()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6371 | colorizer.reset(result); |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6372 | dumpDisplays(result); |
| 6373 | dumpCompositionDisplays(result); |
| 6374 | result.push_back('\n'); |
Lloyd Pique | c3cb729 | 2019-05-17 15:25:14 -0700 | [diff] [blame] | 6375 | |
| 6376 | mCompositionEngine->dump(result); |
| 6377 | |
| 6378 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6379 | * Dump SurfaceFlinger global state |
| 6380 | */ |
| 6381 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6382 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6383 | result.append("SurfaceFlinger global state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6384 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6385 | |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 6386 | StringAppendF(&result, "MiscFlagValue: %s\n", mMiscFlagValue ? "true" : "false"); |
Brian Johnson | c99f638 | 2023-09-07 10:52:30 -0700 | [diff] [blame] | 6387 | StringAppendF(&result, "ConnectedDisplayFlagValue: %s\n", |
| 6388 | mConnectedDisplayFlagValue ? "true" : "false"); |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 6389 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 6390 | getRenderEngine().dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6391 | |
Robert Carr | beba6f0 | 2021-02-10 21:06:27 -0800 | [diff] [blame] | 6392 | result.append("ClientCache state:\n"); |
| 6393 | ClientCache::getInstance().dump(result); |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 6394 | DebugEGLImageTracker::getInstance()->dump(result); |
| 6395 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6396 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 6397 | display->getCompositionDisplay()->getState().undefinedRegion.dump(result, |
| 6398 | "undefinedRegion"); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 6399 | StringAppendF(&result, " orientation=%s, isPoweredOn=%d\n", |
| 6400 | toCString(display->getOrientation()), display->isPoweredOn()); |
Lloyd Pique | 2ae2b3b | 2017-12-14 17:18:17 -0800 | [diff] [blame] | 6401 | } |
Carlos Martinez Romero | 779dc1f | 2022-10-27 23:23:30 +0000 | [diff] [blame] | 6402 | StringAppendF(&result, " transaction-flags : %08x\n", mTransactionFlags.load()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6403 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 6404 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6405 | std::string fps, xDpi, yDpi; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 6406 | if (const auto activeModePtr = |
| 6407 | display->refreshRateSelector().getActiveMode().modePtr.get()) { |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6408 | fps = to_string(activeModePtr->getFps()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6409 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6410 | const auto dpi = activeModePtr->getDpi(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6411 | xDpi = base::StringPrintf("%.2f", dpi.x); |
| 6412 | yDpi = base::StringPrintf("%.2f", dpi.y); |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6413 | } else { |
| 6414 | fps = "unknown"; |
| 6415 | xDpi = "unknown"; |
| 6416 | yDpi = "unknown"; |
| 6417 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6418 | StringAppendF(&result, |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6419 | " refresh-rate : %s\n" |
| 6420 | " x-dpi : %s\n" |
| 6421 | " y-dpi : %s\n", |
| 6422 | fps.c_str(), xDpi.c_str(), yDpi.c_str()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6423 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6424 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6425 | StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6426 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6427 | result.append("\nTransaction tracing: "); |
| 6428 | if (mTransactionTracing) { |
| 6429 | result.append("enabled\n"); |
| 6430 | mTransactionTracing->dump(result); |
| 6431 | } else { |
| 6432 | result.append("disabled\n"); |
| 6433 | } |
| 6434 | result.push_back('\n'); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6435 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6436 | if (mLegacyFrontEndEnabled) { |
| 6437 | dumpHwcLayersMinidumpLockedLegacy(result); |
| 6438 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6439 | |
Ady Abraham | 2790e9f | 2021-04-28 13:14:20 -0700 | [diff] [blame] | 6440 | { |
| 6441 | DumpArgs plannerArgs; |
| 6442 | plannerArgs.add(); // first argument is ignored |
| 6443 | plannerArgs.add(String16("--layers")); |
| 6444 | dumpPlannerInfo(plannerArgs, result); |
| 6445 | } |
| 6446 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6447 | /* |
| 6448 | * Dump HWComposer state |
| 6449 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6450 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6451 | result.append("h/w composer state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6452 | colorizer.reset(result); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6453 | const bool hwcDisabled = mDebugDisableHWC || mDebugFlashDelay; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6454 | StringAppendF(&result, " h/w composer %s\n", hwcDisabled ? "disabled" : "enabled"); |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 6455 | dumpHwc(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6456 | |
| 6457 | /* |
| 6458 | * Dump gralloc state |
| 6459 | */ |
| 6460 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 6461 | alloc.dump(result); |
Karthik Ravi Shankar | 171155a | 2017-06-28 15:40:24 -0700 | [diff] [blame] | 6462 | |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6463 | /* |
| 6464 | * Dump flag/property manager state |
| 6465 | */ |
Robert Carr | 9b623c3 | 2022-03-21 15:55:22 -0700 | [diff] [blame] | 6466 | mFlagManager.dump(result); |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6467 | |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 6468 | result.append(mTimeStats->miniDump()); |
| 6469 | result.append("\n"); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 6470 | |
| 6471 | result.append("Window Infos:\n"); |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 6472 | auto windowInfosDebug = mWindowInfosListenerInvoker->getDebugInfo(); |
| 6473 | StringAppendF(&result, " max send vsync id: %" PRId64 "\n", |
| 6474 | ftl::to_underlying(windowInfosDebug.maxSendDelayVsyncId)); |
| 6475 | StringAppendF(&result, " max send delay (ns): %" PRId64 " ns\n", |
| 6476 | windowInfosDebug.maxSendDelayDuration); |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 6477 | StringAppendF(&result, " unsent messages: %zu\n", windowInfosDebug.pendingMessageCount); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 6478 | result.append("\n"); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6479 | } |
| 6480 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6481 | mat4 SurfaceFlinger::calculateColorMatrix(float saturation) { |
| 6482 | if (saturation == 1) { |
| 6483 | return mat4(); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6484 | } |
| 6485 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6486 | float3 luminance{0.213f, 0.715f, 0.072f}; |
| 6487 | luminance *= 1.0f - saturation; |
| 6488 | mat4 saturationMatrix = mat4(vec4{luminance.r + saturation, luminance.r, luminance.r, 0.0f}, |
| 6489 | vec4{luminance.g, luminance.g + saturation, luminance.g, 0.0f}, |
| 6490 | vec4{luminance.b, luminance.b, luminance.b + saturation, 0.0f}, |
| 6491 | vec4{0.0f, 0.0f, 0.0f, 1.0f}); |
| 6492 | return saturationMatrix; |
| 6493 | } |
| 6494 | |
| 6495 | void SurfaceFlinger::updateColorMatrixLocked() { |
| 6496 | mat4 colorMatrix = |
| 6497 | mClientColorMatrix * calculateColorMatrix(mGlobalSaturationFactor) * mDaltonizer(); |
| 6498 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6499 | if (mCurrentState.colorMatrix != colorMatrix) { |
| 6500 | mCurrentState.colorMatrix = colorMatrix; |
| 6501 | mCurrentState.colorMatrixChanged = true; |
| 6502 | setTransactionFlags(eTransactionNeeded); |
| 6503 | } |
| 6504 | } |
| 6505 | |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6506 | status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6507 | #pragma clang diagnostic push |
| 6508 | #pragma clang diagnostic error "-Wswitch-enum" |
| 6509 | switch (static_cast<ISurfaceComposerTag>(code)) { |
| 6510 | // These methods should at minimum make sure that the client requested |
| 6511 | // access to SF. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6512 | case GET_HDR_CAPABILITIES: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6513 | case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6514 | case GET_GAME_CONTENT_TYPE_SUPPORT: |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6515 | case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6516 | // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary |
| 6517 | // permission dynamically. Don't use the permission cache for this check. |
| 6518 | bool usePermissionCache = code != OVERRIDE_HDR_TYPES; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6519 | if (!callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 6520 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6521 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", |
| 6522 | ipc->getCallingPid(), ipc->getCallingUid()); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6523 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6524 | } |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 6525 | return OK; |
| 6526 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6527 | // The following calls are currently used by clients that do not |
| 6528 | // request necessary permissions. However, they do not expose any secret |
| 6529 | // information, so it is OK to pass them. |
Peiyong Lin | d1fedb4 | 2019-03-11 17:48:41 -0700 | [diff] [blame] | 6530 | case GET_ACTIVE_COLOR_MODE: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6531 | case GET_ACTIVE_DISPLAY_MODE: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6532 | case GET_DISPLAY_COLOR_MODES: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6533 | case GET_DISPLAY_MODES: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6534 | // Calling setTransactionState is safe, because you need to have been |
| 6535 | // granted a reference to Client* and Handle* to do anything with it. |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6536 | case SET_TRANSACTION_STATE: { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 6537 | // This is not sensitive information, so should not require permission control. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6538 | return OK; |
| 6539 | } |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 6540 | case BOOT_FINISHED: |
| 6541 | // Used by apps to hook Choreographer to SurfaceFlinger. |
| 6542 | case CREATE_DISPLAY_EVENT_CONNECTION: |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6543 | case CREATE_CONNECTION: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6544 | case CREATE_DISPLAY: |
| 6545 | case DESTROY_DISPLAY: |
| 6546 | case GET_PRIMARY_PHYSICAL_DISPLAY_ID: |
| 6547 | case GET_PHYSICAL_DISPLAY_IDS: |
| 6548 | case GET_PHYSICAL_DISPLAY_TOKEN: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6549 | case AUTHENTICATE_SURFACE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6550 | case SET_POWER_MODE: |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 6551 | case GET_SUPPORTED_FRAME_TIMESTAMPS: |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6552 | case GET_DISPLAY_STATE: |
| 6553 | case GET_DISPLAY_STATS: |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 6554 | case GET_STATIC_DISPLAY_INFO: |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 6555 | case GET_DYNAMIC_DISPLAY_INFO: |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 6556 | case GET_DISPLAY_NATIVE_PRIMARIES: |
| 6557 | case SET_ACTIVE_COLOR_MODE: |
| 6558 | case SET_BOOT_DISPLAY_MODE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6559 | case CLEAR_BOOT_DISPLAY_MODE: |
| 6560 | case GET_BOOT_DISPLAY_MODE_SUPPORT: |
| 6561 | case SET_AUTO_LOW_LATENCY_MODE: |
| 6562 | case SET_GAME_CONTENT_TYPE: |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6563 | case CAPTURE_LAYERS: |
| 6564 | case CAPTURE_DISPLAY: |
| 6565 | case CAPTURE_DISPLAY_BY_ID: |
Huihong Luo | 4ed1c91 | 2022-02-22 14:30:01 -0800 | [diff] [blame] | 6566 | case CLEAR_ANIMATION_FRAME_STATS: |
| 6567 | case GET_ANIMATION_FRAME_STATS: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6568 | case OVERRIDE_HDR_TYPES: |
| 6569 | case ON_PULL_ATOM: |
| 6570 | case ENABLE_VSYNC_INJECTIONS: |
| 6571 | case INJECT_VSYNC: |
| 6572 | case GET_LAYER_DEBUG_INFO: |
| 6573 | case GET_COLOR_MANAGEMENT: |
| 6574 | case GET_COMPOSITION_PREFERENCE: |
| 6575 | case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: |
| 6576 | case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6577 | case GET_DISPLAYED_CONTENT_SAMPLE: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6578 | case GET_PROTECTED_CONTENT_SUPPORT: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6579 | case IS_WIDE_COLOR_DISPLAY: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6580 | case ADD_REGION_SAMPLING_LISTENER: |
| 6581 | case REMOVE_REGION_SAMPLING_LISTENER: |
| 6582 | case ADD_FPS_LISTENER: |
| 6583 | case REMOVE_FPS_LISTENER: |
| 6584 | case ADD_TUNNEL_MODE_ENABLED_LISTENER: |
| 6585 | case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: |
| 6586 | case ADD_WINDOW_INFOS_LISTENER: |
| 6587 | case REMOVE_WINDOW_INFOS_LISTENER: |
| 6588 | case SET_DESIRED_DISPLAY_MODE_SPECS: |
| 6589 | case GET_DESIRED_DISPLAY_MODE_SPECS: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6590 | case GET_DISPLAY_BRIGHTNESS_SUPPORT: |
| 6591 | case SET_DISPLAY_BRIGHTNESS: |
| 6592 | case ADD_HDR_LAYER_INFO_LISTENER: |
| 6593 | case REMOVE_HDR_LAYER_INFO_LISTENER: |
| 6594 | case NOTIFY_POWER_BOOST: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6595 | case SET_GLOBAL_SHADOW_SETTINGS: |
| 6596 | case GET_DISPLAY_DECORATION_SUPPORT: |
| 6597 | case SET_FRAME_RATE: |
| 6598 | case SET_OVERRIDE_FRAME_RATE: |
| 6599 | case SET_FRAME_TIMELINE_INFO: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6600 | case ADD_TRANSACTION_TRACE_LISTENER: |
| 6601 | case GET_GPU_CONTEXT_PRIORITY: |
| 6602 | case GET_MAX_ACQUIRED_BUFFER_COUNT: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6603 | LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6604 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6605 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6606 | |
| 6607 | // These codes are used for the IBinder protocol to either interrogate the recipient |
| 6608 | // side of the transaction for its canonical interface descriptor or to dump its state. |
| 6609 | // We let them pass by default. |
| 6610 | if (code == IBinder::INTERFACE_TRANSACTION || code == IBinder::DUMP_TRANSACTION || |
| 6611 | code == IBinder::PING_TRANSACTION || code == IBinder::SHELL_COMMAND_TRANSACTION || |
| 6612 | code == IBinder::SYSPROPS_TRANSACTION) { |
| 6613 | return OK; |
| 6614 | } |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 6615 | // Numbers from 1000 to 1044 are currently used for backdoors. The code |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6616 | // in onTransact verifies that the user is root, and has access to use SF. |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 6617 | if (code >= 1000 && code <= 1044) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6618 | ALOGV("Accessing SurfaceFlinger through backdoor code: %u", code); |
| 6619 | return OK; |
| 6620 | } |
| 6621 | ALOGE("Permission Denial: SurfaceFlinger did not recognize request code: %u", code); |
| 6622 | return PERMISSION_DENIED; |
| 6623 | #pragma clang diagnostic pop |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6624 | } |
| 6625 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6626 | status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 6627 | uint32_t flags) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6628 | if (const status_t error = CheckTransactCodeCredentials(code); error != OK) { |
| 6629 | return error; |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6630 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 6631 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6632 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 6633 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 6634 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Romain Guy | 8c6bbd6 | 2017-06-05 13:51:43 -0700 | [diff] [blame] | 6635 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6636 | const int uid = ipc->getCallingUid(); |
| 6637 | if (CC_UNLIKELY(uid != AID_SYSTEM |
| 6638 | && !PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6639 | const int pid = ipc->getCallingPid(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 6640 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6641 | "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] | 6642 | return PERMISSION_DENIED; |
| 6643 | } |
| 6644 | int n; |
| 6645 | switch (code) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6646 | case 1000: // Unused. |
| 6647 | case 1001: |
| 6648 | return NAME_NOT_FOUND; |
| 6649 | case 1002: // Toggle flashing on surface damage. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6650 | sfdo_setDebugFlash(data.readInt32()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6651 | return NO_ERROR; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6652 | case 1004: // Force composite ahead of next VSYNC. |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 6653 | case 1006: |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6654 | sfdo_scheduleComposite(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6655 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6656 | case 1005: { // Force commit ahead of next VSYNC. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6657 | sfdo_scheduleCommit(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 6658 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6659 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6660 | case 1007: // Unused. |
| 6661 | return NAME_NOT_FOUND; |
| 6662 | case 1008: // Toggle forced GPU composition. |
| 6663 | mDebugDisableHWC = data.readInt32() != 0; |
| 6664 | scheduleRepaint(); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 6665 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6666 | case 1009: // Toggle use of transform hint. |
| 6667 | mDebugDisableTransformHint = data.readInt32() != 0; |
| 6668 | scheduleRepaint(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 6669 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6670 | case 1010: // Interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 6671 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6672 | reply->writeInt32(0); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6673 | reply->writeInt32(mDebugFlashDelay); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 6674 | reply->writeInt32(0); |
Dianne Hackborn | 12839be | 2012-02-06 21:21:05 -0800 | [diff] [blame] | 6675 | reply->writeInt32(mDebugDisableHWC); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6676 | return NO_ERROR; |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6677 | case 1013: // Unused. |
| 6678 | return NAME_NOT_FOUND; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6679 | case 1014: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6680 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6681 | // daltonize |
| 6682 | n = data.readInt32(); |
| 6683 | switch (n % 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6684 | case 1: |
| 6685 | mDaltonizer.setType(ColorBlindnessType::Protanomaly); |
| 6686 | break; |
| 6687 | case 2: |
| 6688 | mDaltonizer.setType(ColorBlindnessType::Deuteranomaly); |
| 6689 | break; |
| 6690 | case 3: |
| 6691 | mDaltonizer.setType(ColorBlindnessType::Tritanomaly); |
| 6692 | break; |
| 6693 | default: |
| 6694 | mDaltonizer.setType(ColorBlindnessType::None); |
| 6695 | break; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6696 | } |
| 6697 | if (n >= 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6698 | mDaltonizer.setMode(ColorBlindnessMode::Correction); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6699 | } else { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6700 | mDaltonizer.setMode(ColorBlindnessMode::Simulation); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6701 | } |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6702 | |
| 6703 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6704 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6705 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6706 | case 1015: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6707 | Mutex::Autolock _l(mStateLock); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6708 | // apply a color matrix |
| 6709 | n = data.readInt32(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6710 | if (n) { |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6711 | // color matrix is sent as a column-major mat4 matrix |
Alan Viverette | 794c5ba | 2013-10-03 16:40:52 -0700 | [diff] [blame] | 6712 | for (size_t i = 0 ; i < 4; i++) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6713 | for (size_t j = 0; j < 4; j++) { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6714 | mClientColorMatrix[i][j] = data.readFloat(); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6715 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6716 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6717 | } else { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6718 | mClientColorMatrix = mat4(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6719 | } |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 6720 | |
| 6721 | // Check that supplied matrix's last row is {0,0,0,1} so we can avoid |
| 6722 | // the division by w in the fragment shader |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6723 | float4 lastRow(transpose(mClientColorMatrix)[3]); |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 6724 | if (any(greaterThan(abs(lastRow - float4{0, 0, 0, 1}), float4{1e-4f}))) { |
| 6725 | ALOGE("The color transform's last row must be (0, 0, 0, 1)"); |
| 6726 | } |
| 6727 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6728 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6729 | return NO_ERROR; |
| 6730 | } |
Dominik Laskowski | 8d32ddc | 2019-08-07 11:25:35 -0700 | [diff] [blame] | 6731 | case 1016: { // Unused. |
| 6732 | return NAME_NOT_FOUND; |
Ruchi Kandoi | f52b3c8 | 2014-04-24 16:42:35 -0700 | [diff] [blame] | 6733 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 6734 | case 1017: { |
| 6735 | n = data.readInt32(); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 6736 | mForceFullDamage = n != 0; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 6737 | return NO_ERROR; |
| 6738 | } |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6739 | case 1018: { // Modify Choreographer's duration |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6740 | n = data.readInt32(); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6741 | mScheduler->setDuration(mAppConnectionHandle, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6742 | return NO_ERROR; |
| 6743 | } |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6744 | case 1019: { // Modify SurfaceFlinger's duration |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6745 | n = data.readInt32(); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6746 | mScheduler->setDuration(mSfConnectionHandle, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6747 | return NO_ERROR; |
| 6748 | } |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 6749 | case 1020: { // Unused |
| 6750 | return NAME_NOT_FOUND; |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 6751 | } |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 6752 | case 1021: { // Disable HWC virtual displays |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 6753 | const bool enable = data.readInt32() != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6754 | static_cast<void>( |
| 6755 | mScheduler->schedule([this, enable] { enableHalVirtualDisplays(enable); })); |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 6756 | return NO_ERROR; |
| 6757 | } |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6758 | case 1022: { // Set saturation boost |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6759 | Mutex::Autolock _l(mStateLock); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6760 | mGlobalSaturationFactor = std::max(0.0f, std::min(data.readFloat(), 2.0f)); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6761 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6762 | updateColorMatrixLocked(); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6763 | return NO_ERROR; |
| 6764 | } |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6765 | case 1023: { // Set color mode. |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6766 | mDisplayColorSetting = static_cast<DisplayColorSetting>(data.readInt32()); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6767 | |
| 6768 | if (int32_t colorMode; data.readInt32(&colorMode) == NO_ERROR) { |
| 6769 | mForceColorMode = static_cast<ui::ColorMode>(colorMode); |
Daniel Solomon | 7c7ede2 | 2019-07-11 16:35:40 -0700 | [diff] [blame] | 6770 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6771 | scheduleRepaint(); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 6772 | return NO_ERROR; |
| 6773 | } |
Peiyong Lin | 4bac91c | 2018-10-25 09:48:33 -0700 | [diff] [blame] | 6774 | // Deprecate, use 1030 to check whether the device is color managed. |
| 6775 | case 1024: { |
| 6776 | return NAME_NOT_FOUND; |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 6777 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 6778 | // Deprecated, use perfetto to start/stop the layer tracing |
| 6779 | case 1025: { |
| 6780 | return NAME_NOT_FOUND; |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 6781 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 6782 | // Deprecated, execute "adb shell perfetto --query" to see the ongoing tracing sessions |
| 6783 | case 1026: { |
| 6784 | return NAME_NOT_FOUND; |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 6785 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6786 | // Is a DisplayColorSetting supported? |
| 6787 | case 1027: { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6788 | const auto display = getDefaultDisplayDevice(); |
| 6789 | if (!display) { |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6790 | return NAME_NOT_FOUND; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6791 | } |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6792 | |
| 6793 | DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32()); |
| 6794 | switch (setting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6795 | case DisplayColorSetting::kManaged: |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6796 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6797 | reply->writeBool(true); |
| 6798 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6799 | case DisplayColorSetting::kEnhanced: |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6800 | reply->writeBool(display->hasRenderIntent(RenderIntent::ENHANCE)); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6801 | break; |
| 6802 | default: // vendor display color setting |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6803 | reply->writeBool( |
| 6804 | display->hasRenderIntent(static_cast<RenderIntent>(setting))); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6805 | break; |
| 6806 | } |
| 6807 | return NO_ERROR; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6808 | } |
Alec Mouri | 9c58bcd | 2020-09-09 18:57:07 -0700 | [diff] [blame] | 6809 | case 1028: { // Unused. |
| 6810 | return NAME_NOT_FOUND; |
Steven Thomas | 97f1f4c | 2018-06-01 12:04:16 -0700 | [diff] [blame] | 6811 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 6812 | // Deprecated, use perfetto to set the active layer tracing buffer size |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 6813 | case 1029: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 6814 | return NAME_NOT_FOUND; |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 6815 | } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 6816 | // Is device color managed? |
| 6817 | case 1030: { |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 6818 | // ColorDisplayManager stil calls this |
| 6819 | reply->writeBool(true); |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 6820 | return NO_ERROR; |
| 6821 | } |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 6822 | // Override default composition data space |
| 6823 | // adb shell service call SurfaceFlinger 1031 i32 1 DATASPACE_NUMBER DATASPACE_NUMBER \ |
| 6824 | // && adb shell stop zygote && adb shell start zygote |
| 6825 | // to restore: adb shell service call SurfaceFlinger 1031 i32 0 && \ |
| 6826 | // adb shell stop zygote && adb shell start zygote |
| 6827 | case 1031: { |
| 6828 | Mutex::Autolock _l(mStateLock); |
| 6829 | n = data.readInt32(); |
| 6830 | if (n) { |
| 6831 | n = data.readInt32(); |
| 6832 | if (n) { |
| 6833 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 6834 | if (!validateCompositionDataspace(dataspace)) { |
| 6835 | return BAD_VALUE; |
| 6836 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6837 | mDefaultCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 6838 | } |
| 6839 | n = data.readInt32(); |
| 6840 | if (n) { |
| 6841 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 6842 | if (!validateCompositionDataspace(dataspace)) { |
| 6843 | return BAD_VALUE; |
| 6844 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6845 | mWideColorGamutCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 6846 | } |
| 6847 | } else { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6848 | // restore composition data space. |
| 6849 | mDefaultCompositionDataspace = defaultCompositionDataspace; |
| 6850 | mWideColorGamutCompositionDataspace = wideColorGamutCompositionDataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 6851 | } |
| 6852 | return NO_ERROR; |
| 6853 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 6854 | // Deprecated, use perfetto to set layer trace flags |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 6855 | case 1033: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 6856 | return NAME_NOT_FOUND; |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 6857 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 6858 | case 1034: { |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6859 | n = data.readInt32(); |
| 6860 | if (n == 0 || n == 1) { |
| 6861 | sfdo_enableRefreshRateOverlay(static_cast<bool>(n)); |
| 6862 | } else { |
| 6863 | Mutex::Autolock lock(mStateLock); |
| 6864 | reply->writeBool(isRefreshRateOverlayEnabled()); |
| 6865 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 6866 | return NO_ERROR; |
| 6867 | } |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 6868 | case 1035: { |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 6869 | const int modeId = data.readInt32(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 6870 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6871 | const auto display = [&]() -> sp<IBinder> { |
| 6872 | uint64_t value; |
| 6873 | if (data.readUint64(&value) != NO_ERROR) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 6874 | return getDefaultDisplayDevice()->getDisplayToken().promote(); |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 6875 | } |
| 6876 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6877 | if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(value)) { |
| 6878 | return getPhysicalDisplayToken(*id); |
| 6879 | } |
| 6880 | |
| 6881 | ALOGE("Invalid physical display ID"); |
| 6882 | return nullptr; |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 6883 | }(); |
| 6884 | |
Shiyong Li | 2bcece9 | 2021-08-30 20:38:50 +0000 | [diff] [blame] | 6885 | mDebugDisplayModeSetByBackdoor = false; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6886 | const status_t result = setActiveModeFromBackdoor(display, DisplayModeId{modeId}); |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6887 | mDebugDisplayModeSetByBackdoor = result == NO_ERROR; |
| 6888 | return result; |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 6889 | } |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6890 | // Turn on/off frame rate flexibility mode. When turned on it overrides the display |
| 6891 | // manager frame rate policy a new policy which allows switching between all refresh |
| 6892 | // rates. |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6893 | case 1036: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6894 | if (data.readInt32() > 0) { // turn on |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6895 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6896 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6897 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6898 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6899 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6900 | // This is a little racy, but not in a way that hurts anything. As |
| 6901 | // we grab the defaultMode from the display manager policy, we could |
| 6902 | // be setting a new display manager policy, leaving us using a stale |
| 6903 | // defaultMode. The defaultMode doesn't matter for the override |
| 6904 | // policy though, since we set allowGroupSwitching to true, so it's |
| 6905 | // not a problem. |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6906 | scheduler::RefreshRateSelector::OverridePolicy overridePolicy; |
| 6907 | overridePolicy.defaultMode = display->refreshRateSelector() |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6908 | .getDisplayManagerPolicy() |
| 6909 | .defaultMode; |
| 6910 | overridePolicy.allowGroupSwitching = true; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6911 | return setDesiredDisplayModeSpecsInternal(display, overridePolicy); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6912 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6913 | .get(); |
| 6914 | } else { // turn off |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6915 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6916 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6917 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6918 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6919 | return setDesiredDisplayModeSpecsInternal( |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6920 | display, |
| 6921 | scheduler::RefreshRateSelector::NoOverridePolicy{}); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6922 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6923 | .get(); |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6924 | } |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6925 | } |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 6926 | // Inject a hotplug connected event for the primary display. This will deallocate and |
| 6927 | // reallocate the display state including framebuffers. |
| 6928 | case 1037: { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 6929 | const hal::HWDisplayId hwcId = |
| 6930 | (Mutex::Autolock(mStateLock), getHwComposer().getPrimaryHwcDisplayId()); |
| 6931 | |
| 6932 | onComposerHalHotplug(hwcId, hal::Connection::CONNECTED); |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 6933 | return NO_ERROR; |
| 6934 | } |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 6935 | // Modify the max number of display frames stored within FrameTimeline |
| 6936 | case 1038: { |
| 6937 | n = data.readInt32(); |
| 6938 | if (n < 0 || n > MAX_ALLOWED_DISPLAY_FRAMES) { |
| 6939 | ALOGW("Invalid max size. Maximum allowed is %d", MAX_ALLOWED_DISPLAY_FRAMES); |
| 6940 | return BAD_VALUE; |
| 6941 | } |
| 6942 | if (n == 0) { |
| 6943 | // restore to default |
| 6944 | mFrameTimeline->reset(); |
| 6945 | return NO_ERROR; |
| 6946 | } |
| 6947 | mFrameTimeline->setMaxDisplayFrames(n); |
| 6948 | return NO_ERROR; |
| 6949 | } |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 6950 | case 1039: { |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 6951 | PhysicalDisplayId displayId = [&]() { |
| 6952 | Mutex::Autolock lock(mStateLock); |
| 6953 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 6954 | }(); |
| 6955 | |
| 6956 | auto inUid = static_cast<uid_t>(data.readInt32()); |
| 6957 | const auto refreshRate = data.readFloat(); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 6958 | mScheduler->setPreferredRefreshRateForUid(FrameRateOverride{inUid, refreshRate}); |
| 6959 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 6960 | return NO_ERROR; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 6961 | } |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6962 | // Toggle caching feature |
| 6963 | // First argument is an int32 - nonzero enables caching and zero disables caching |
| 6964 | // Second argument is an optional uint64 - if present, then limits enabling/disabling |
| 6965 | // caching to a particular physical display |
| 6966 | case 1040: { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6967 | auto future = mScheduler->schedule([&] { |
| 6968 | n = data.readInt32(); |
| 6969 | std::optional<PhysicalDisplayId> inputId = std::nullopt; |
| 6970 | if (uint64_t inputDisplayId; data.readUint64(&inputDisplayId) == NO_ERROR) { |
| 6971 | inputId = DisplayId::fromValue<PhysicalDisplayId>(inputDisplayId); |
| 6972 | if (!inputId || getPhysicalDisplayToken(*inputId)) { |
| 6973 | ALOGE("No display with id: %" PRIu64, inputDisplayId); |
| 6974 | return NAME_NOT_FOUND; |
| 6975 | } |
| 6976 | } |
| 6977 | { |
| 6978 | Mutex::Autolock lock(mStateLock); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6979 | mLayerCachingEnabled = n != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6980 | for (const auto& [_, display] : mDisplays) { |
| 6981 | if (!inputId || *inputId == display->getPhysicalId()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6982 | display->enableLayerCaching(mLayerCachingEnabled); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6983 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6984 | } |
| 6985 | } |
| 6986 | return OK; |
| 6987 | }); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6988 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6989 | if (const status_t error = future.get(); error != OK) { |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6990 | return error; |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6991 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6992 | scheduleRepaint(); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6993 | return NO_ERROR; |
| 6994 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 6995 | case 1041: { // Transaction tracing |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6996 | if (mTransactionTracing) { |
| 6997 | if (data.readInt32()) { |
| 6998 | // Transaction tracing is always running but allow the user to temporarily |
| 6999 | // increase the buffer when actively debugging. |
| 7000 | mTransactionTracing->setBufferSize( |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 7001 | TransactionTracing::LEGACY_ACTIVE_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7002 | } else { |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 7003 | TransactionTraceWriter::getInstance().invoke("", /* overwrite= */ true); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7004 | mTransactionTracing->setBufferSize( |
| 7005 | TransactionTracing::CONTINUOUS_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7006 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 7007 | } |
| 7008 | reply->writeInt32(NO_ERROR); |
| 7009 | return NO_ERROR; |
| 7010 | } |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 7011 | case 1042: { // Write transaction trace to file |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7012 | if (mTransactionTracing) { |
| 7013 | mTransactionTracing->writeToFile(); |
| 7014 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7015 | reply->writeInt32(NO_ERROR); |
| 7016 | return NO_ERROR; |
| 7017 | } |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 7018 | // hdr sdr ratio overlay |
| 7019 | case 1043: { |
| 7020 | auto future = mScheduler->schedule( |
| 7021 | [&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 7022 | n = data.readInt32(); |
| 7023 | mHdrSdrRatioOverlay = n != 0; |
| 7024 | switch (n) { |
| 7025 | case 0: |
| 7026 | case 1: |
| 7027 | enableHdrSdrRatioOverlay(mHdrSdrRatioOverlay); |
| 7028 | break; |
| 7029 | default: |
| 7030 | reply->writeBool(isHdrSdrRatioOverlayEnabled()); |
| 7031 | } |
| 7032 | }); |
| 7033 | future.wait(); |
| 7034 | return NO_ERROR; |
| 7035 | } |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 7036 | |
| 7037 | case 1044: { // Enable/Disable mirroring from one display to another |
| 7038 | /* |
| 7039 | * Mirror one display onto another. |
| 7040 | * Ensure the source and destination displays are on. |
| 7041 | * Commands: |
| 7042 | * 0: Mirror one display to another |
| 7043 | * 1: Disable mirroring to a previously mirrored display |
| 7044 | * 2: Disable mirroring on previously mirrored displays |
| 7045 | * |
| 7046 | * Ex: |
| 7047 | * Get the display ids: |
| 7048 | * adb shell dumpsys SurfaceFlinger --display-id |
| 7049 | * Mirror first display to the second: |
| 7050 | * adb shell service call SurfaceFlinger 1044 i64 0 i64 4619827677550801152 i64 |
| 7051 | * 4619827677550801153 |
| 7052 | * Stop mirroring: |
| 7053 | * adb shell service call SurfaceFlinger 1044 i64 1 |
| 7054 | */ |
| 7055 | |
| 7056 | int64_t arg0 = data.readInt64(); |
| 7057 | |
| 7058 | switch (arg0) { |
| 7059 | case 0: { |
| 7060 | // Mirror arg1 to arg2 |
| 7061 | int64_t arg1 = data.readInt64(); |
| 7062 | int64_t arg2 = data.readInt64(); |
| 7063 | // Enable mirroring for one display |
| 7064 | const auto display1id = DisplayId::fromValue(arg1); |
| 7065 | auto mirrorRoot = SurfaceComposerClient::getDefault()->mirrorDisplay( |
| 7066 | display1id.value()); |
| 7067 | auto id2 = DisplayId::fromValue<PhysicalDisplayId>(arg2); |
| 7068 | const auto token2 = getPhysicalDisplayToken(*id2); |
| 7069 | ui::LayerStack layerStack; |
| 7070 | { |
| 7071 | Mutex::Autolock lock(mStateLock); |
| 7072 | sp<DisplayDevice> display = getDisplayDeviceLocked(token2); |
| 7073 | layerStack = display->getLayerStack(); |
| 7074 | } |
| 7075 | SurfaceComposerClient::Transaction t; |
| 7076 | t.setDisplayLayerStack(token2, layerStack); |
| 7077 | t.setLayer(mirrorRoot, INT_MAX); // Top-most layer |
| 7078 | t.setLayerStack(mirrorRoot, layerStack); |
| 7079 | t.apply(); |
| 7080 | |
| 7081 | mMirrorMapForDebug.emplace_or_replace(arg2, mirrorRoot); |
| 7082 | break; |
| 7083 | } |
| 7084 | |
| 7085 | case 1: { |
| 7086 | // Disable mirroring for arg1 |
| 7087 | int64_t arg1 = data.readInt64(); |
| 7088 | mMirrorMapForDebug.erase(arg1); |
| 7089 | break; |
| 7090 | } |
| 7091 | |
| 7092 | case 2: { |
| 7093 | // Disable mirroring for all displays |
| 7094 | mMirrorMapForDebug.clear(); |
| 7095 | break; |
| 7096 | } |
| 7097 | |
| 7098 | default: |
| 7099 | return BAD_VALUE; |
| 7100 | } |
| 7101 | return NO_ERROR; |
| 7102 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7103 | } |
| 7104 | } |
| 7105 | return err; |
| 7106 | } |
| 7107 | |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7108 | void SurfaceFlinger::kernelTimerChanged(bool expired) { |
| 7109 | static bool updateOverlay = |
| 7110 | property_get_bool("debug.sf.kernel_idle_timer_update_overlay", true); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7111 | if (!updateOverlay) return; |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7112 | |
| 7113 | // Update the overlay on the main thread to avoid race conditions with |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7114 | // RefreshRateSelector::getActiveMode |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7115 | static_cast<void>(mScheduler->schedule([=] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7116 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7117 | if (!display) { |
| 7118 | ALOGW("%s: default display is null", __func__); |
| 7119 | return; |
| 7120 | } |
Adrian Salido | a942af8 | 2022-02-17 19:22:31 -0800 | [diff] [blame] | 7121 | if (!display->isRefreshRateOverlayEnabled()) return; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7122 | |
| 7123 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
| 7124 | const std::optional<DisplayModeId> desiredModeId = desiredActiveMode |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7125 | ? std::make_optional(desiredActiveMode->modeOpt->modePtr->getId()) |
| 7126 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7127 | : std::nullopt; |
| 7128 | |
| 7129 | const bool timerExpired = mKernelIdleTimerEnabled && expired; |
| 7130 | |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 7131 | if (display->onKernelTimerChanged(desiredModeId, timerExpired)) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 7132 | mScheduler->scheduleFrame(); |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7133 | } |
| 7134 | })); |
| 7135 | } |
| 7136 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7137 | std::pair<std::optional<KernelIdleTimerController>, std::chrono::milliseconds> |
| 7138 | SurfaceFlinger::getKernelIdleTimerProperties(DisplayId displayId) { |
| 7139 | const bool isKernelIdleTimerHwcSupported = getHwComposer().getComposer()->isSupported( |
| 7140 | android::Hwc2::Composer::OptionalFeature::KernelIdleTimer); |
| 7141 | const auto timeout = getIdleTimerTimeout(displayId); |
| 7142 | if (isKernelIdleTimerHwcSupported) { |
| 7143 | if (const auto id = PhysicalDisplayId::tryCast(displayId); |
| 7144 | getHwComposer().hasDisplayIdleTimerCapability(*id)) { |
| 7145 | // In order to decide if we can use the HWC api for idle timer |
| 7146 | // we query DisplayCapability::DISPLAY_IDLE_TIMER directly on the composer |
| 7147 | // without relying on hasDisplayCapability. |
| 7148 | // hasDisplayCapability relies on DisplayCapabilities |
| 7149 | // which are updated after we set the PowerMode::ON. |
| 7150 | // DISPLAY_IDLE_TIMER is a display driver property |
| 7151 | // and is available before the PowerMode::ON |
| 7152 | return {KernelIdleTimerController::HwcApi, timeout}; |
| 7153 | } |
| 7154 | return {std::nullopt, timeout}; |
| 7155 | } |
| 7156 | if (getKernelIdleTimerSyspropConfig(displayId)) { |
| 7157 | return {KernelIdleTimerController::Sysprop, timeout}; |
| 7158 | } |
| 7159 | |
| 7160 | return {std::nullopt, timeout}; |
| 7161 | } |
| 7162 | |
| 7163 | void SurfaceFlinger::updateKernelIdleTimer(std::chrono::milliseconds timeout, |
| 7164 | KernelIdleTimerController controller, |
| 7165 | PhysicalDisplayId displayId) { |
| 7166 | switch (controller) { |
| 7167 | case KernelIdleTimerController::HwcApi: { |
| 7168 | getHwComposer().setIdleTimerEnabled(displayId, timeout); |
| 7169 | break; |
| 7170 | } |
| 7171 | case KernelIdleTimerController::Sysprop: { |
| 7172 | base::SetProperty(KERNEL_IDLE_TIMER_PROP, timeout > 0ms ? "true" : "false"); |
| 7173 | break; |
| 7174 | } |
| 7175 | } |
| 7176 | } |
| 7177 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7178 | void SurfaceFlinger::toggleKernelIdleTimer() { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7179 | using KernelIdleTimerAction = scheduler::RefreshRateSelector::KernelIdleTimerAction; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7180 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7181 | const auto display = getDefaultDisplayDeviceLocked(); |
| 7182 | if (!display) { |
| 7183 | ALOGW("%s: default display is null", __func__); |
| 7184 | return; |
| 7185 | } |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7186 | |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7187 | // If the support for kernel idle timer is disabled for the active display, |
| 7188 | // don't do anything. |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7189 | const std::optional<KernelIdleTimerController> kernelIdleTimerController = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7190 | display->refreshRateSelector().kernelIdleTimerController(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7191 | if (!kernelIdleTimerController.has_value()) { |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7192 | return; |
| 7193 | } |
| 7194 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7195 | const KernelIdleTimerAction action = display->refreshRateSelector().getIdleTimerAction(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7196 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7197 | switch (action) { |
| 7198 | case KernelIdleTimerAction::TurnOff: |
| 7199 | if (mKernelIdleTimerEnabled) { |
| 7200 | ATRACE_INT("KernelIdleTimer", 0); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7201 | std::chrono::milliseconds constexpr kTimerDisabledTimeout = 0ms; |
| 7202 | updateKernelIdleTimer(kTimerDisabledTimeout, kernelIdleTimerController.value(), |
| 7203 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7204 | mKernelIdleTimerEnabled = false; |
| 7205 | } |
| 7206 | break; |
| 7207 | case KernelIdleTimerAction::TurnOn: |
| 7208 | if (!mKernelIdleTimerEnabled) { |
| 7209 | ATRACE_INT("KernelIdleTimer", 1); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7210 | const std::chrono::milliseconds timeout = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7211 | display->refreshRateSelector().getIdleTimerTimeout(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7212 | updateKernelIdleTimer(timeout, kernelIdleTimerController.value(), |
| 7213 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7214 | mKernelIdleTimerEnabled = true; |
| 7215 | } |
| 7216 | break; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7217 | } |
| 7218 | } |
| 7219 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7220 | // A simple RAII class to disconnect from an ANativeWindow* when it goes out of scope |
| 7221 | class WindowDisconnector { |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7222 | public: |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7223 | WindowDisconnector(ANativeWindow* window, int api) : mWindow(window), mApi(api) {} |
| 7224 | ~WindowDisconnector() { |
| 7225 | native_window_api_disconnect(mWindow, mApi); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7226 | } |
| 7227 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7228 | private: |
| 7229 | ANativeWindow* mWindow; |
| 7230 | const int mApi; |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7231 | }; |
| 7232 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7233 | static bool hasCaptureBlackoutContentPermission() { |
| 7234 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7235 | const int pid = ipc->getCallingPid(); |
| 7236 | const int uid = ipc->getCallingUid(); |
| 7237 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 7238 | PermissionCache::checkPermission(sCaptureBlackoutContent, pid, uid); |
| 7239 | } |
| 7240 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7241 | static status_t validateScreenshotPermissions(const CaptureArgs& captureArgs) { |
| 7242 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7243 | const int pid = ipc->getCallingPid(); |
| 7244 | const int uid = ipc->getCallingUid(); |
| 7245 | if (uid == AID_GRAPHICS || PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 7246 | return OK; |
| 7247 | } |
| 7248 | |
| 7249 | // If the caller doesn't have the correct permissions but is only attempting to screenshot |
| 7250 | // itself, we allow it to continue. |
| 7251 | if (captureArgs.uid == uid) { |
| 7252 | return OK; |
| 7253 | } |
| 7254 | |
| 7255 | ALOGE("Permission Denial: can't take screenshot pid=%d, uid=%d", pid, uid); |
| 7256 | return PERMISSION_DENIED; |
| 7257 | } |
| 7258 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7259 | status_t SurfaceFlinger::setSchedFifo(bool enabled) { |
| 7260 | static constexpr int kFifoPriority = 2; |
| 7261 | static constexpr int kOtherPriority = 0; |
| 7262 | |
| 7263 | struct sched_param param = {0}; |
| 7264 | int sched_policy; |
| 7265 | if (enabled) { |
| 7266 | sched_policy = SCHED_FIFO; |
| 7267 | param.sched_priority = kFifoPriority; |
| 7268 | } else { |
| 7269 | sched_policy = SCHED_OTHER; |
| 7270 | param.sched_priority = kOtherPriority; |
| 7271 | } |
| 7272 | |
| 7273 | if (sched_setscheduler(0, sched_policy, ¶m) != 0) { |
| 7274 | return -errno; |
| 7275 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7276 | |
| 7277 | return NO_ERROR; |
| 7278 | } |
| 7279 | |
| 7280 | status_t SurfaceFlinger::setSchedAttr(bool enabled) { |
| 7281 | static const unsigned int kUclampMin = |
| 7282 | base::GetUintProperty<unsigned int>("ro.surface_flinger.uclamp.min", 0U); |
| 7283 | |
| 7284 | if (!kUclampMin) { |
| 7285 | // uclamp.min set to 0 (default), skip setting |
| 7286 | return NO_ERROR; |
| 7287 | } |
| 7288 | |
| 7289 | // Currently, there is no wrapper in bionic: b/183240349. |
| 7290 | struct sched_attr { |
| 7291 | uint32_t size; |
| 7292 | uint32_t sched_policy; |
| 7293 | uint64_t sched_flags; |
| 7294 | int32_t sched_nice; |
| 7295 | uint32_t sched_priority; |
| 7296 | uint64_t sched_runtime; |
| 7297 | uint64_t sched_deadline; |
| 7298 | uint64_t sched_period; |
| 7299 | uint32_t sched_util_min; |
| 7300 | uint32_t sched_util_max; |
| 7301 | }; |
| 7302 | |
| 7303 | sched_attr attr = {}; |
| 7304 | attr.size = sizeof(attr); |
| 7305 | |
| 7306 | attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP); |
| 7307 | attr.sched_util_min = enabled ? kUclampMin : 0; |
| 7308 | attr.sched_util_max = 1024; |
| 7309 | |
| 7310 | if (syscall(__NR_sched_setattr, 0, &attr, 0)) { |
| 7311 | return -errno; |
| 7312 | } |
| 7313 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7314 | return NO_ERROR; |
| 7315 | } |
| 7316 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7317 | namespace { |
| 7318 | |
| 7319 | ui::Dataspace pickBestDataspace(ui::Dataspace requestedDataspace, const DisplayDevice* display, |
| 7320 | bool capturingHdrLayers, bool hintForSeamlessTransition) { |
| 7321 | if (requestedDataspace != ui::Dataspace::UNKNOWN || display == nullptr) { |
| 7322 | return requestedDataspace; |
| 7323 | } |
| 7324 | |
| 7325 | const auto& state = display->getCompositionDisplay()->getState(); |
| 7326 | |
| 7327 | const auto dataspaceForColorMode = ui::pickDataspaceFor(state.colorMode); |
| 7328 | |
Alec Mouri | 2964072 | 2023-05-16 23:22:41 +0000 | [diff] [blame] | 7329 | // TODO: Enable once HDR screenshots are ready. |
| 7330 | if constexpr (/* DISABLES CODE */ (false)) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7331 | // For now since we only support 8-bit screenshots, just use HLG and |
| 7332 | // assume that 1.0 >= display max luminance. This isn't quite as future |
| 7333 | // proof as PQ is, but is good enough. |
| 7334 | // Consider using PQ once we support 16-bit screenshots and we're able |
| 7335 | // to consistently supply metadata to image encoders. |
| 7336 | return ui::Dataspace::BT2020_HLG; |
| 7337 | } |
| 7338 | |
| 7339 | return dataspaceForColorMode; |
| 7340 | } |
| 7341 | |
| 7342 | } // namespace |
| 7343 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7344 | static void invokeScreenCaptureError(const status_t status, |
| 7345 | const sp<IScreenCaptureListener>& captureListener) { |
| 7346 | ScreenCaptureResults captureResults; |
| 7347 | captureResults.fenceResult = base::unexpected(status); |
| 7348 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7349 | } |
| 7350 | |
| 7351 | void SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, |
| 7352 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7353 | ATRACE_CALL(); |
| 7354 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7355 | status_t validate = validateScreenshotPermissions(args); |
| 7356 | if (validate != OK) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7357 | invokeScreenCaptureError(validate, captureListener); |
| 7358 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7359 | } |
| 7360 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7361 | if (!args.displayToken) { |
| 7362 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7363 | return; |
| 7364 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7365 | |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7366 | wp<const DisplayDevice> displayWeak; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7367 | ui::LayerStack layerStack; |
| 7368 | ui::Size reqSize(args.width, args.height); |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7369 | std::unordered_set<uint32_t> excludeLayerIds; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7370 | { |
| 7371 | Mutex::Autolock lock(mStateLock); |
| 7372 | sp<DisplayDevice> display = getDisplayDeviceLocked(args.displayToken); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7373 | if (!display) { |
| 7374 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7375 | return; |
| 7376 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7377 | displayWeak = display; |
| 7378 | layerStack = display->getLayerStack(); |
| 7379 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7380 | // 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] | 7381 | if (args.width == 0 || args.height == 0) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7382 | reqSize = display->getLayerStackSpaceRect().getSize(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7383 | } |
| 7384 | |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7385 | for (const auto& handle : args.excludeHandles) { |
| 7386 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7387 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7388 | excludeLayerIds.emplace(excludeLayer); |
| 7389 | } else { |
| 7390 | ALOGW("Invalid layer handle passed as excludeLayer to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7391 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7392 | return; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7393 | } |
| 7394 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7395 | } |
| 7396 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7397 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
Alec Mouri | c44a1ff | 2023-05-19 23:49:05 +0000 | [diff] [blame] | 7398 | return DisplayRenderArea::create(displayWeak, args.sourceCrop, reqSize, args.dataspace, |
| 7399 | args.useIdentityTransform, args.hintForSeamlessTransition, |
| 7400 | args.captureSecureLayers); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7401 | }); |
| 7402 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7403 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7404 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7405 | getLayerSnapshots = |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7406 | getLayerSnapshotsForScreenshots(layerStack, args.uid, std::move(excludeLayerIds)); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7407 | } else { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7408 | auto traverseLayers = [this, args, excludeLayerIds, |
| 7409 | layerStack](const LayerVector::Visitor& visitor) { |
| 7410 | traverseLayersInLayerStack(layerStack, args.uid, std::move(excludeLayerIds), visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7411 | }; |
| 7412 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7413 | } |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 7414 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7415 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, args.pixelFormat, |
| 7416 | args.allowProtected, args.grayscale, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7417 | } |
| 7418 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7419 | void SurfaceFlinger::captureDisplay(DisplayId displayId, |
| 7420 | const sp<IScreenCaptureListener>& captureListener) { |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7421 | ui::LayerStack layerStack; |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7422 | wp<const DisplayDevice> displayWeak; |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7423 | ui::Size size; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7424 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7425 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7426 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7427 | const auto display = getDisplayDeviceLocked(displayId); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7428 | if (!display) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7429 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7430 | return; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7431 | } |
| 7432 | |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7433 | displayWeak = display; |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7434 | layerStack = display->getLayerStack(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7435 | size = display->getLayerStackSpaceRect().getSize(); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7436 | } |
| 7437 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7438 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7439 | return DisplayRenderArea::create(displayWeak, Rect(), size, ui::Dataspace::UNKNOWN, |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 7440 | false /* useIdentityTransform */, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7441 | false /* hintForSeamlessTransition */, |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7442 | false /* captureSecureLayers */); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7443 | }); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7444 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7445 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7446 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7447 | getLayerSnapshots = getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID, |
| 7448 | /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7449 | } else { |
| 7450 | auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7451 | traverseLayersInLayerStack(layerStack, CaptureArgs::UNSET_UID, {}, visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7452 | }; |
| 7453 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7454 | } |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7455 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7456 | if (captureListener == nullptr) { |
| 7457 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7458 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7459 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7460 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7461 | |
| 7462 | constexpr bool kAllowProtected = false; |
| 7463 | constexpr bool kGrayscale = false; |
| 7464 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7465 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, size, |
| 7466 | ui::PixelFormat::RGBA_8888, kAllowProtected, kGrayscale, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7467 | } |
| 7468 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7469 | void SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, |
| 7470 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7471 | ATRACE_CALL(); |
| 7472 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7473 | status_t validate = validateScreenshotPermissions(args); |
| 7474 | if (validate != OK) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7475 | invokeScreenCaptureError(validate, captureListener); |
| 7476 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7477 | } |
| 7478 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7479 | ui::Size reqSize; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7480 | sp<Layer> parent; |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7481 | Rect crop(args.sourceCrop); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7482 | std::unordered_set<uint32_t> excludeLayerIds; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7483 | ui::Dataspace dataspace = args.dataspace; |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7484 | |
| 7485 | // Call this before holding mStateLock to avoid any deadlocking. |
| 7486 | bool canCaptureBlackoutContent = hasCaptureBlackoutContentPermission(); |
| 7487 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7488 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7489 | Mutex::Autolock lock(mStateLock); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7490 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 7491 | parent = LayerHandle::getLayer(args.layerHandle); |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7492 | if (parent == nullptr) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7493 | ALOGE("captureLayers called with an invalid or removed parent"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7494 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7495 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7496 | } |
| 7497 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7498 | if (!canCaptureBlackoutContent && |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 7499 | parent->getDrawingState().flags & layer_state_t::eLayerSecure) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7500 | ALOGW("Attempting to capture secure layer: PERMISSION_DENIED"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7501 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 7502 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7503 | } |
| 7504 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 7505 | Rect parentSourceBounds = parent->getCroppedBufferSize(parent->getDrawingState()); |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7506 | if (args.sourceCrop.width() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7507 | crop.left = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7508 | crop.right = parentSourceBounds.getWidth(); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7509 | } |
| 7510 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7511 | if (args.sourceCrop.height() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7512 | crop.top = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7513 | crop.bottom = parentSourceBounds.getHeight(); |
| 7514 | } |
| 7515 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7516 | if (crop.isEmpty() || args.frameScaleX <= 0.0f || args.frameScaleY <= 0.0f) { |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7517 | // Error out if the layer has no source bounds (i.e. they are boundless) and a source |
| 7518 | // crop was not specified, or an invalid frame scale was provided. |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7519 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7520 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7521 | } |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7522 | reqSize = ui::Size(crop.width() * args.frameScaleX, crop.height() * args.frameScaleY); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7523 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7524 | for (const auto& handle : args.excludeHandles) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7525 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7526 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7527 | excludeLayerIds.emplace(excludeLayer); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7528 | } else { |
| 7529 | ALOGW("Invalid layer handle passed as excludeLayer to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7530 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7531 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7532 | } |
| 7533 | } |
| 7534 | } // mStateLock |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7535 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7536 | // really small crop or frameScale |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7537 | if (reqSize.width <= 0 || reqSize.height <= 0) { |
| 7538 | ALOGW("Failed to captureLayes: crop or scale too small"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7539 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7540 | return; |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7541 | } |
| 7542 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7543 | bool childrenOnly = args.childrenOnly; |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7544 | RenderAreaFuture renderAreaFuture = ftl::defer([=]() -> std::unique_ptr<RenderArea> { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7545 | ui::Transform layerTransform; |
| 7546 | Rect layerBufferSize; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7547 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7548 | frontend::LayerSnapshot* snapshot = |
| 7549 | mLayerSnapshotBuilder.getSnapshot(parent->getSequence()); |
| 7550 | if (!snapshot) { |
| 7551 | ALOGW("Couldn't find layer snapshot for %d", parent->getSequence()); |
| 7552 | } else { |
| 7553 | layerTransform = snapshot->localTransform; |
| 7554 | layerBufferSize = snapshot->bufferSize; |
| 7555 | } |
| 7556 | } else { |
| 7557 | layerTransform = parent->getTransform(); |
| 7558 | layerBufferSize = parent->getBufferSize(parent->getDrawingState()); |
| 7559 | } |
| 7560 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7561 | return std::make_unique<LayerRenderArea>(*this, parent, crop, reqSize, dataspace, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7562 | childrenOnly, args.captureSecureLayers, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7563 | layerTransform, layerBufferSize, |
| 7564 | args.hintForSeamlessTransition); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7565 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7566 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7567 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7568 | std::optional<FloatRect> parentCrop = std::nullopt; |
| 7569 | if (args.childrenOnly) { |
| 7570 | parentCrop = crop.isEmpty() ? FloatRect(0, 0, reqSize.width, reqSize.height) |
| 7571 | : crop.toFloatRect(); |
| 7572 | } |
| 7573 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7574 | getLayerSnapshots = getLayerSnapshotsForScreenshots(parent->sequence, args.uid, |
| 7575 | std::move(excludeLayerIds), |
| 7576 | args.childrenOnly, parentCrop); |
| 7577 | } else { |
| 7578 | auto traverseLayers = [parent, args, excludeLayerIds](const LayerVector::Visitor& visitor) { |
| 7579 | parent->traverseChildrenInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
| 7580 | if (!layer->isVisible()) { |
| 7581 | return; |
| 7582 | } else if (args.childrenOnly && layer == parent.get()) { |
| 7583 | return; |
| 7584 | } else if (args.uid != CaptureArgs::UNSET_UID && args.uid != layer->getOwnerUid()) { |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 7585 | return; |
| 7586 | } |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 7587 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7588 | auto p = sp<Layer>::fromExisting(layer); |
| 7589 | while (p != nullptr) { |
| 7590 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 7591 | return; |
| 7592 | } |
| 7593 | p = p->getParent(); |
| 7594 | } |
| 7595 | |
| 7596 | visitor(layer); |
| 7597 | }); |
| 7598 | }; |
| 7599 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7600 | } |
Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 7601 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7602 | if (captureListener == nullptr) { |
| 7603 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7604 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7605 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7606 | } |
| 7607 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7608 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, args.pixelFormat, |
| 7609 | args.allowProtected, args.grayscale, captureListener); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7610 | } |
| 7611 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7612 | void SurfaceFlinger::captureScreenCommon(RenderAreaFuture renderAreaFuture, |
| 7613 | GetLayerSnapshotsFunction getLayerSnapshots, |
| 7614 | ui::Size bufferSize, ui::PixelFormat reqPixelFormat, |
| 7615 | bool allowProtected, bool grayscale, |
| 7616 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7617 | ATRACE_CALL(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 7618 | |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 7619 | if (exceedsMaxRenderTargetSize(bufferSize.getWidth(), bufferSize.getHeight())) { |
| 7620 | ALOGE("Attempted to capture screen with size (%" PRId32 ", %" PRId32 |
| 7621 | ") that exceeds render target size limit.", |
| 7622 | bufferSize.getWidth(), bufferSize.getHeight()); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7623 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7624 | return; |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 7625 | } |
| 7626 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7627 | // Loop over all visible layers to see whether there's any protected layer. A protected layer is |
| 7628 | // typically a layer with DRM contents, or have the GRALLOC_USAGE_PROTECTED set on the buffer. |
| 7629 | // A protected layer has no implication on whether it's secure, which is explicitly set by |
| 7630 | // application to avoid being screenshot or drawn via unsecure display. |
| 7631 | const bool supportsProtected = getRenderEngine().supportsProtectedContent(); |
| 7632 | bool hasProtectedLayer = false; |
| 7633 | if (allowProtected && supportsProtected) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7634 | hasProtectedLayer = mScheduler |
| 7635 | ->schedule([=]() { |
| 7636 | bool protectedLayerFound = false; |
| 7637 | auto layers = getLayerSnapshots(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7638 | for (auto& [_, layerFe] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7639 | protectedLayerFound |= |
| 7640 | (layerFe->mSnapshot->isVisible && |
| 7641 | layerFe->mSnapshot->hasProtectedContent); |
| 7642 | } |
| 7643 | return protectedLayerFound; |
| 7644 | }) |
| 7645 | .get(); |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7646 | } |
| 7647 | |
Richard Liu | cbcb895 | 2020-04-08 10:51:55 +0000 | [diff] [blame] | 7648 | const uint32_t usage = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER | |
| 7649 | GRALLOC_USAGE_HW_TEXTURE | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7650 | (hasProtectedLayer && allowProtected && supportsProtected |
| 7651 | ? GRALLOC_USAGE_PROTECTED |
| 7652 | : GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7653 | sp<GraphicBuffer> buffer = |
| 7654 | getFactory().createGraphicBuffer(bufferSize.getWidth(), bufferSize.getHeight(), |
| 7655 | static_cast<android_pixel_format>(reqPixelFormat), |
| 7656 | 1 /* layerCount */, usage, "screenshot"); |
Alec Mouri | 7013b6f | 2021-02-12 11:16:54 -0800 | [diff] [blame] | 7657 | |
| 7658 | const status_t bufferStatus = buffer->initCheck(); |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 7659 | if (bufferStatus != OK) { |
| 7660 | // Animations may end up being really janky, but don't crash here. |
| 7661 | // Otherwise an irreponsible process may cause an SF crash by allocating |
| 7662 | // too much. |
| 7663 | ALOGE("%s: Buffer failed to allocate: %d", __func__, bufferStatus); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7664 | invokeScreenCaptureError(bufferStatus, captureListener); |
| 7665 | return; |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 7666 | } |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 7667 | const std::shared_ptr<renderengine::ExternalTexture> texture = std::make_shared< |
| 7668 | renderengine::impl::ExternalTexture>(buffer, getRenderEngine(), |
| 7669 | renderengine::impl::ExternalTexture::Usage:: |
| 7670 | WRITEABLE); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7671 | auto fence = captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, texture, |
| 7672 | false /* regionSampling */, grayscale, captureListener); |
| 7673 | fence.get(); |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 7674 | } |
| 7675 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7676 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenCommon( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7677 | RenderAreaFuture renderAreaFuture, GetLayerSnapshotsFunction getLayerSnapshots, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 7678 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
| 7679 | bool grayscale, const sp<IScreenCaptureListener>& captureListener) { |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 7680 | ATRACE_CALL(); |
| 7681 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7682 | bool canCaptureBlackoutContent = hasCaptureBlackoutContentPermission(); |
Robert Carr | 03480e2 | 2018-01-04 16:02:06 -0800 | [diff] [blame] | 7683 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7684 | auto future = mScheduler->schedule( |
| 7685 | [=, renderAreaFuture = std::move(renderAreaFuture)]() FTL_FAKE_GUARD( |
| 7686 | kMainThreadContext) mutable -> ftl::SharedFuture<FenceResult> { |
| 7687 | ScreenCaptureResults captureResults; |
Patrick Williams | 3190813 | 2023-01-09 13:38:48 -0600 | [diff] [blame] | 7688 | std::shared_ptr<RenderArea> renderArea = renderAreaFuture.get(); |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7689 | if (!renderArea) { |
| 7690 | ALOGW("Skipping screen capture because of invalid render area."); |
Nolan Scobie | 1d2deb2 | 2022-11-18 12:57:47 -0500 | [diff] [blame] | 7691 | if (captureListener) { |
| 7692 | captureResults.fenceResult = base::unexpected(NO_MEMORY); |
| 7693 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7694 | } |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7695 | return ftl::yield<FenceResult>(base::unexpected(NO_ERROR)).share(); |
| 7696 | } |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7697 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7698 | ftl::SharedFuture<FenceResult> renderFuture; |
| 7699 | renderArea->render([&]() FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7700 | renderFuture = renderScreenImpl(renderArea, getLayerSnapshots, buffer, |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7701 | canCaptureBlackoutContent, regionSampling, |
| 7702 | grayscale, captureResults); |
| 7703 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7704 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7705 | if (captureListener) { |
| 7706 | // Defer blocking on renderFuture back to the Binder thread. |
| 7707 | return ftl::Future(std::move(renderFuture)) |
| 7708 | .then([captureListener, captureResults = std::move(captureResults)]( |
| 7709 | FenceResult fenceResult) mutable -> FenceResult { |
| 7710 | captureResults.fenceResult = std::move(fenceResult); |
| 7711 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7712 | return base::unexpected(NO_ERROR); |
| 7713 | }) |
| 7714 | .share(); |
| 7715 | } |
| 7716 | return renderFuture; |
| 7717 | }); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7718 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7719 | // Flatten nested futures. |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7720 | auto chain = ftl::Future(std::move(future)).then([](ftl::SharedFuture<FenceResult> future) { |
| 7721 | return future; |
| 7722 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7723 | |
| 7724 | return chain.share(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 7725 | } |
| 7726 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7727 | ftl::SharedFuture<FenceResult> SurfaceFlinger::renderScreenImpl( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7728 | std::shared_ptr<const RenderArea> renderArea, GetLayerSnapshotsFunction getLayerSnapshots, |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7729 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, |
| 7730 | bool canCaptureBlackoutContent, bool regionSampling, bool grayscale, |
| 7731 | ScreenCaptureResults& captureResults) { |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 7732 | ATRACE_CALL(); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7733 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7734 | auto layers = getLayerSnapshots(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7735 | for (auto& [_, layerFE] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7736 | frontend::LayerSnapshot* snapshot = layerFE->mSnapshot.get(); |
| 7737 | captureResults.capturedSecureLayers |= (snapshot->isVisible && snapshot->isSecure); |
| 7738 | captureResults.capturedHdrLayers |= isHdrLayer(*snapshot); |
| 7739 | layerFE->mSnapshot->geomLayerTransform = |
| 7740 | renderArea->getTransform() * layerFE->mSnapshot->geomLayerTransform; |
Patrick Williams | c6e0cce | 2023-02-28 23:04:45 -0600 | [diff] [blame] | 7741 | layerFE->mSnapshot->geomInverseLayerTransform = |
| 7742 | layerFE->mSnapshot->geomLayerTransform.inverse(); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7743 | } |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7744 | |
| 7745 | // We allow the system server to take screenshots of secure layers for |
| 7746 | // use in situations like the Screen-rotation animation and place |
| 7747 | // the impetus on WindowManager to not persist them. |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7748 | if (captureResults.capturedSecureLayers && !canCaptureBlackoutContent) { |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7749 | ALOGW("FB is protected: PERMISSION_DENIED"); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7750 | return ftl::yield<FenceResult>(base::unexpected(PERMISSION_DENIED)).share(); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7751 | } |
| 7752 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7753 | auto capturedBuffer = buffer; |
| 7754 | |
| 7755 | auto requestedDataspace = renderArea->getReqDataSpace(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7756 | auto parent = renderArea->getParentLayer(); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 7757 | auto renderIntent = RenderIntent::TONE_MAP_COLORIMETRIC; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 7758 | auto sdrWhitePointNits = DisplayDevice::sDefaultMaxLumiance; |
| 7759 | auto displayBrightnessNits = DisplayDevice::sDefaultMaxLumiance; |
| 7760 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7761 | captureResults.capturedDataspace = requestedDataspace; |
| 7762 | |
| 7763 | { |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 7764 | Mutex::Autolock lock(mStateLock); |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7765 | const DisplayDevice* display = nullptr; |
| 7766 | if (parent) { |
| 7767 | display = findDisplay([layerStack = parent->getLayerStack()](const auto& display) { |
| 7768 | return display.getLayerStack() == layerStack; |
| 7769 | }).get(); |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 7770 | } |
| 7771 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7772 | if (display == nullptr) { |
| 7773 | display = renderArea->getDisplayDevice().get(); |
| 7774 | } |
| 7775 | |
| 7776 | if (display == nullptr) { |
| 7777 | display = getDefaultDisplayDeviceLocked().get(); |
| 7778 | } |
| 7779 | |
| 7780 | if (display != nullptr) { |
| 7781 | const auto& state = display->getCompositionDisplay()->getState(); |
| 7782 | captureResults.capturedDataspace = |
| 7783 | pickBestDataspace(requestedDataspace, display, captureResults.capturedHdrLayers, |
| 7784 | renderArea->getHintForSeamlessTransition()); |
| 7785 | sdrWhitePointNits = state.sdrWhitePointNits; |
| 7786 | displayBrightnessNits = state.displayBrightnessNits; |
John Reck | 1dadaa6 | 2023-07-11 14:07:00 -0400 | [diff] [blame] | 7787 | // Only clamp the display brightness if this is not a seamless transition. Otherwise |
| 7788 | // for seamless transitions it's important to match the current display state as the |
| 7789 | // buffer will be shown under these same conditions, and we want to avoid any flickers |
| 7790 | if (sdrWhitePointNits > 1.0f && !renderArea->getHintForSeamlessTransition()) { |
John Reck | 5b02fc4 | 2023-06-14 14:41:10 -0400 | [diff] [blame] | 7791 | // Restrict the amount of HDR "headroom" in the screenshot to avoid over-dimming |
| 7792 | // the SDR portion. 2.0 chosen by experimentation |
| 7793 | constexpr float kMaxScreenshotHeadroom = 2.0f; |
| 7794 | displayBrightnessNits = |
| 7795 | std::min(sdrWhitePointNits * kMaxScreenshotHeadroom, displayBrightnessNits); |
| 7796 | } |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7797 | |
| 7798 | if (requestedDataspace == ui::Dataspace::UNKNOWN) { |
| 7799 | renderIntent = state.renderIntent; |
| 7800 | } |
| 7801 | } |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 7802 | } |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7803 | |
| 7804 | captureResults.buffer = capturedBuffer->getBuffer(); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7805 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7806 | ui::LayerStack layerStack{ui::DEFAULT_LAYER_STACK}; |
| 7807 | if (!layers.empty()) { |
| 7808 | const sp<LayerFE>& layerFE = layers.back().second; |
| 7809 | layerStack = layerFE->getCompositionState()->outputFilter.layerStack; |
Yichi Chen | 40773d9 | 2020-04-01 10:10:18 +0800 | [diff] [blame] | 7810 | } |
Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 7811 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7812 | auto copyLayerFEs = [&layers]() { |
| 7813 | std::vector<sp<compositionengine::LayerFE>> layerFEs; |
| 7814 | layerFEs.reserve(layers.size()); |
| 7815 | for (const auto& [_, layerFE] : layers) { |
| 7816 | layerFEs.push_back(layerFE); |
| 7817 | } |
| 7818 | return layerFEs; |
| 7819 | }; |
| 7820 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7821 | auto present = [this, buffer = capturedBuffer, dataspace = captureResults.capturedDataspace, |
| 7822 | sdrWhitePointNits, displayBrightnessNits, grayscale, layerFEs = copyLayerFEs(), |
| 7823 | layerStack, regionSampling, renderArea = std::move(renderArea), |
Patrick Williams | 278a88f | 2023-01-27 16:52:40 -0600 | [diff] [blame] | 7824 | renderIntent]() -> FenceResult { |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7825 | std::unique_ptr<compositionengine::CompositionEngine> compositionEngine = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7826 | mFactory.createCompositionEngine(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7827 | compositionEngine->setRenderEngine(mRenderEngine.get()); |
| 7828 | |
| 7829 | compositionengine::Output::ColorProfile colorProfile{.dataspace = dataspace, |
| 7830 | .renderIntent = renderIntent}; |
| 7831 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7832 | float targetBrightness = 1.0f; |
| 7833 | if (dataspace == ui::Dataspace::BT2020_HLG) { |
| 7834 | const float maxBrightnessNits = displayBrightnessNits / sdrWhitePointNits * 203; |
| 7835 | // With a low dimming ratio, don't fit the entire curve. Otherwise mixed content |
| 7836 | // will appear way too bright. |
| 7837 | if (maxBrightnessNits < 1000.f) { |
| 7838 | targetBrightness = 1000.f / maxBrightnessNits; |
| 7839 | } |
| 7840 | } |
| 7841 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7842 | std::shared_ptr<ScreenCaptureOutput> output = createScreenCaptureOutput( |
| 7843 | ScreenCaptureOutputArgs{.compositionEngine = *compositionEngine, |
| 7844 | .colorProfile = colorProfile, |
| 7845 | .renderArea = *renderArea, |
| 7846 | .layerStack = layerStack, |
| 7847 | .buffer = std::move(buffer), |
| 7848 | .sdrWhitePointNits = sdrWhitePointNits, |
| 7849 | .displayBrightnessNits = displayBrightnessNits, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7850 | .targetBrightness = targetBrightness, |
Alec Mouri | 7dae9c1 | 2023-07-13 19:40:53 +0000 | [diff] [blame] | 7851 | .regionSampling = regionSampling, |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 7852 | .treat170mAsSrgb = mTreat170mAsSrgb, |
| 7853 | .dimInGammaSpaceForEnhancedScreenshots = |
| 7854 | mDimInGammaSpaceForEnhancedScreenshots}); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7855 | |
| 7856 | const float colorSaturation = grayscale ? 0 : 1; |
| 7857 | compositionengine::CompositionRefreshArgs refreshArgs{ |
| 7858 | .outputs = {output}, |
| 7859 | .layers = std::move(layerFEs), |
| 7860 | .updatingOutputGeometryThisFrame = true, |
| 7861 | .updatingGeometryThisFrame = true, |
| 7862 | .colorTransformMatrix = calculateColorMatrix(colorSaturation), |
| 7863 | }; |
| 7864 | compositionEngine->present(refreshArgs); |
| 7865 | |
| 7866 | return output->getRenderSurface()->getClientTargetAcquireFence(); |
| 7867 | }; |
| 7868 | |
| 7869 | // If RenderEngine is threaded, we can safely call CompositionEngine::present off the main |
| 7870 | // thread as the RenderEngine::drawLayers call will run on RenderEngine's thread. Otherwise, |
| 7871 | // we need RenderEngine to run on the main thread so we call CompositionEngine::present |
| 7872 | // immediately. |
| 7873 | // |
| 7874 | // TODO(b/196334700) Once we use RenderEngineThreaded everywhere we can always defer the call |
| 7875 | // to CompositionEngine::present. |
| 7876 | const bool renderEngineIsThreaded = [&]() { |
| 7877 | using Type = renderengine::RenderEngine::RenderEngineType; |
| 7878 | const auto type = mRenderEngine->getRenderEngineType(); |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 7879 | return type == Type::SKIA_GL_THREADED; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7880 | }(); |
| 7881 | auto presentFuture = renderEngineIsThreaded ? ftl::defer(std::move(present)).share() |
| 7882 | : ftl::yield(present()).share(); |
| 7883 | |
| 7884 | for (auto& [layer, layerFE] : layers) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 7885 | layer->onLayerDisplayed(ftl::Future(presentFuture) |
| 7886 | .then([layerFE = std::move(layerFE)](FenceResult) { |
| 7887 | return layerFE->stealCompositionResult() |
| 7888 | .releaseFences.back() |
| 7889 | .first.get(); |
| 7890 | }) |
| 7891 | .share(), |
| 7892 | ui::INVALID_LAYER_STACK); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7893 | } |
| 7894 | |
| 7895 | return presentFuture; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 7896 | } |
| 7897 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7898 | void SurfaceFlinger::traverseLegacyLayers(const LayerVector::Visitor& visitor) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7899 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7900 | for (auto& layer : mLegacyLayers) { |
| 7901 | visitor(layer.second.get()); |
| 7902 | } |
| 7903 | } else { |
| 7904 | mDrawingState.traverse(visitor); |
| 7905 | } |
| 7906 | } |
| 7907 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 7908 | // --------------------------------------------------------------------------- |
| 7909 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 7910 | void SurfaceFlinger::State::traverse(const LayerVector::Visitor& visitor) const { |
| 7911 | layersSortedByZ.traverse(visitor); |
| 7912 | } |
| 7913 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 7914 | void SurfaceFlinger::State::traverseInZOrder(const LayerVector::Visitor& visitor) const { |
| 7915 | layersSortedByZ.traverseInZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 7916 | } |
| 7917 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 7918 | void SurfaceFlinger::State::traverseInReverseZOrder(const LayerVector::Visitor& visitor) const { |
| 7919 | layersSortedByZ.traverseInReverseZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 7920 | } |
| 7921 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7922 | void SurfaceFlinger::traverseLayersInLayerStack(ui::LayerStack layerStack, const int32_t uid, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7923 | std::unordered_set<uint32_t> excludeLayerIds, |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7924 | const LayerVector::Visitor& visitor) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7925 | // We loop through the first level of layers without traversing, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 7926 | // as we need to determine which layers belong to the requested display. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7927 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 7928 | if (layer->getLayerStack() != layerStack) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7929 | continue; |
| 7930 | } |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 7931 | // relative layers are traversed in Layer::traverseInZOrder |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7932 | layer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 7933 | if (layer->isInternalDisplayOverlay()) { |
Adrian Roos | 8acf5a0 | 2018-01-17 21:28:19 +0100 | [diff] [blame] | 7934 | return; |
| 7935 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7936 | if (!layer->isVisible()) { |
| 7937 | return; |
| 7938 | } |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7939 | if (uid != CaptureArgs::UNSET_UID && layer->getOwnerUid() != uid) { |
| 7940 | return; |
| 7941 | } |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7942 | |
| 7943 | if (!excludeLayerIds.empty()) { |
| 7944 | auto p = sp<Layer>::fromExisting(layer); |
| 7945 | while (p != nullptr) { |
| 7946 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 7947 | return; |
| 7948 | } |
| 7949 | p = p->getParent(); |
| 7950 | } |
| 7951 | } |
| 7952 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7953 | visitor(layer); |
| 7954 | }); |
| 7955 | } |
| 7956 | } |
| 7957 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7958 | ftl::Optional<scheduler::FrameRateMode> SurfaceFlinger::getPreferredDisplayMode( |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7959 | PhysicalDisplayId displayId, DisplayModeId defaultModeId) const { |
| 7960 | if (const auto schedulerMode = mScheduler->getPreferredDisplayMode(); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7961 | schedulerMode.modePtr->getPhysicalDisplayId() == displayId) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7962 | return schedulerMode; |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7963 | } |
| 7964 | |
| 7965 | return mPhysicalDisplays.get(displayId) |
| 7966 | .transform(&PhysicalDisplay::snapshotRef) |
| 7967 | .and_then([&](const display::DisplaySnapshot& snapshot) { |
| 7968 | return snapshot.displayModes().get(defaultModeId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 7969 | }) |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7970 | .transform([](const DisplayModePtr& modePtr) { |
| 7971 | return scheduler::FrameRateMode{modePtr->getFps(), ftl::as_non_null(modePtr)}; |
| 7972 | }); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7973 | } |
| 7974 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7975 | status_t SurfaceFlinger::setDesiredDisplayModeSpecsInternal( |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 7976 | const sp<DisplayDevice>& display, |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7977 | const scheduler::RefreshRateSelector::PolicyVariant& policy) { |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 7978 | const auto displayId = display->getPhysicalId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 7979 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 7980 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 7981 | Mutex::Autolock lock(mStateLock); |
| 7982 | |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7983 | if (mDebugDisplayModeSetByBackdoor) { |
| 7984 | // ignore this request as mode is overridden by backdoor |
| 7985 | return NO_ERROR; |
| 7986 | } |
| 7987 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7988 | auto& selector = display->refreshRateSelector(); |
| 7989 | using SetPolicyResult = scheduler::RefreshRateSelector::SetPolicyResult; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7990 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7991 | switch (selector.setPolicy(policy)) { |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7992 | case SetPolicyResult::Invalid: |
| 7993 | return BAD_VALUE; |
| 7994 | case SetPolicyResult::Unchanged: |
| 7995 | return NO_ERROR; |
| 7996 | case SetPolicyResult::Changed: |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7997 | break; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7998 | } |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7999 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8000 | // TODO(b/255635711): Apply the policy once the display is powered on, which is currently only |
| 8001 | // done for the internal display that becomes active on fold/unfold. For now, assume that DM |
| 8002 | // always powers on the secondary (internal or external) display before setting its policy. |
| 8003 | if (!display->isPoweredOn()) { |
| 8004 | ALOGV("%s(%s): Display is powered off", __func__, to_string(displayId).c_str()); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8005 | return NO_ERROR; |
| 8006 | } |
| 8007 | |
| 8008 | return applyRefreshRateSelectorPolicy(displayId, selector); |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8009 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8010 | |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8011 | status_t SurfaceFlinger::applyRefreshRateSelectorPolicy( |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8012 | PhysicalDisplayId displayId, const scheduler::RefreshRateSelector& selector, bool force) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8013 | const scheduler::RefreshRateSelector::Policy currentPolicy = selector.getCurrentPolicy(); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8014 | ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str()); |
Adrian Salido | ab6ef6c | 2019-08-28 10:02:49 -0700 | [diff] [blame] | 8015 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 8016 | // TODO(b/140204874): Leave the event in until we do proper testing with all apps that might |
| 8017 | // be depending in this callback. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8018 | if (const auto activeMode = selector.getActiveMode(); displayId == mActiveDisplayId) { |
| 8019 | mScheduler->onPrimaryDisplayModeChanged(mAppConnectionHandle, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8020 | toggleKernelIdleTimer(); |
| 8021 | } else { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8022 | mScheduler->onNonPrimaryDisplayModeChanged(mAppConnectionHandle, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8023 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 8024 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8025 | auto preferredModeOpt = getPreferredDisplayMode(displayId, currentPolicy.defaultMode); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8026 | if (!preferredModeOpt) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8027 | ALOGE("%s: Preferred mode is unknown", __func__); |
| 8028 | return NAME_NOT_FOUND; |
| 8029 | } |
| 8030 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8031 | auto preferredMode = std::move(*preferredModeOpt); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8032 | const auto preferredModeId = preferredMode.modePtr->getId(); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 8033 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8034 | ALOGV("Switching to Scheduler preferred mode %d (%s)", preferredModeId.value(), |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8035 | to_string(preferredMode.fps).c_str()); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8036 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8037 | if (!selector.isModeAllowed(preferredMode)) { |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8038 | ALOGE("%s: Preferred mode %d is disallowed", __func__, preferredModeId.value()); |
| 8039 | return INVALID_OPERATION; |
Dominik Laskowski | 4f1dd8c | 2019-04-17 15:54:30 -0700 | [diff] [blame] | 8040 | } |
| 8041 | |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 8042 | setDesiredActiveMode({preferredMode, .emitEvent = true}, force); |
| 8043 | |
| 8044 | // Update the frameRateOverride list as the display render rate might have changed |
| 8045 | if (mScheduler->updateFrameRateOverrides(/*consideredSignals*/ {}, preferredMode.fps)) { |
| 8046 | triggerOnFrameRateOverridesChanged(); |
| 8047 | } |
| 8048 | |
Ady Abraham | d9b3ea6 | 2019-02-26 14:08:03 -0800 | [diff] [blame] | 8049 | return NO_ERROR; |
| 8050 | } |
| 8051 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8052 | namespace { |
| 8053 | FpsRange translate(const gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange& aidlRange) { |
| 8054 | return FpsRange{Fps::fromValue(aidlRange.min), Fps::fromValue(aidlRange.max)}; |
| 8055 | } |
| 8056 | |
| 8057 | FpsRanges translate(const gui::DisplayModeSpecs::RefreshRateRanges& aidlRanges) { |
| 8058 | return FpsRanges{translate(aidlRanges.physical), translate(aidlRanges.render)}; |
| 8059 | } |
| 8060 | |
| 8061 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange translate(const FpsRange& range) { |
| 8062 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange aidlRange; |
| 8063 | aidlRange.min = range.min.getValue(); |
| 8064 | aidlRange.max = range.max.getValue(); |
| 8065 | return aidlRange; |
| 8066 | } |
| 8067 | |
| 8068 | gui::DisplayModeSpecs::RefreshRateRanges translate(const FpsRanges& ranges) { |
| 8069 | gui::DisplayModeSpecs::RefreshRateRanges aidlRanges; |
| 8070 | aidlRanges.physical = translate(ranges.physical); |
| 8071 | aidlRanges.render = translate(ranges.render); |
| 8072 | return aidlRanges; |
| 8073 | } |
| 8074 | |
| 8075 | } // namespace |
| 8076 | |
| 8077 | status_t SurfaceFlinger::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 8078 | const gui::DisplayModeSpecs& specs) { |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8079 | ATRACE_CALL(); |
| 8080 | |
| 8081 | if (!displayToken) { |
| 8082 | return BAD_VALUE; |
| 8083 | } |
| 8084 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8085 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8086 | const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayToken)); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8087 | if (!display) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8088 | ALOGE("Attempt to set desired display modes for invalid display token %p", |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8089 | displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8090 | return NAME_NOT_FOUND; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8091 | } else if (display->isVirtual()) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8092 | ALOGW("Attempt to set desired display modes for virtual display"); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8093 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8094 | } else { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8095 | using Policy = scheduler::RefreshRateSelector::DisplayManagerPolicy; |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8096 | const Policy policy{DisplayModeId(specs.defaultMode), translate(specs.primaryRanges), |
| 8097 | translate(specs.appRequestRanges), specs.allowGroupSwitching}; |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 8098 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8099 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8100 | } |
| 8101 | }); |
| 8102 | |
| 8103 | return future.get(); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8104 | } |
| 8105 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 8106 | status_t SurfaceFlinger::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8107 | gui::DisplayModeSpecs* outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8108 | ATRACE_CALL(); |
| 8109 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8110 | if (!displayToken || !outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8111 | return BAD_VALUE; |
| 8112 | } |
| 8113 | |
| 8114 | Mutex::Autolock lock(mStateLock); |
| 8115 | const auto display = getDisplayDeviceLocked(displayToken); |
| 8116 | if (!display) { |
| 8117 | return NAME_NOT_FOUND; |
| 8118 | } |
| 8119 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8120 | if (display->isVirtual()) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 8121 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8122 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8123 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8124 | scheduler::RefreshRateSelector::Policy policy = |
| 8125 | display->refreshRateSelector().getDisplayManagerPolicy(); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8126 | outSpecs->defaultMode = policy.defaultMode.value(); |
| 8127 | outSpecs->allowGroupSwitching = policy.allowGroupSwitching; |
| 8128 | outSpecs->primaryRanges = translate(policy.primaryRanges); |
| 8129 | outSpecs->appRequestRanges = translate(policy.appRequestRanges); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8130 | return NO_ERROR; |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8131 | } |
| 8132 | |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 8133 | void SurfaceFlinger::onLayerFirstRef(Layer* layer) { |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8134 | mNumLayers++; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8135 | if (!layer->isRemovedFromCurrentState()) { |
| 8136 | mScheduler->registerLayer(layer); |
| 8137 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8138 | } |
| 8139 | |
| 8140 | void SurfaceFlinger::onLayerDestroyed(Layer* layer) { |
| 8141 | mNumLayers--; |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8142 | removeHierarchyFromOffscreenLayers(layer); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8143 | if (!layer->isRemovedFromCurrentState()) { |
| 8144 | mScheduler->deregisterLayer(layer); |
| 8145 | } |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 8146 | if (mTransactionTracing) { |
| 8147 | mTransactionTracing->onLayerRemoved(layer->getSequence()); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 8148 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 8149 | mScheduler->onLayerDestroyed(layer); |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8150 | } |
| 8151 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8152 | void SurfaceFlinger::onLayerUpdate() { |
| 8153 | scheduleCommit(FrameHint::kActive); |
| 8154 | } |
| 8155 | |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8156 | // WARNING: ONLY CALL THIS FROM LAYER DTOR |
| 8157 | // Here we add children in the current state to offscreen layers and remove the |
| 8158 | // layer itself from the offscreen layer list. Since |
| 8159 | // this is the dtor, it is safe to access the current state. This keeps us |
| 8160 | // from dangling children layers such that they are not reachable from the |
| 8161 | // Drawing state nor the offscreen layer list |
| 8162 | // See b/141111965 |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8163 | void SurfaceFlinger::removeHierarchyFromOffscreenLayers(Layer* layer) { |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8164 | for (auto& child : layer->getCurrentChildren()) { |
| 8165 | mOffscreenLayers.emplace(child.get()); |
| 8166 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8167 | mOffscreenLayers.erase(layer); |
| 8168 | } |
| 8169 | |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8170 | void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) { |
| 8171 | mOffscreenLayers.erase(layer); |
| 8172 | } |
| 8173 | |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 8174 | status_t SurfaceFlinger::setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, |
| 8175 | float lightPosY, float lightPosZ, |
| 8176 | float lightRadius) { |
| 8177 | Mutex::Autolock _l(mStateLock); |
| 8178 | mCurrentState.globalShadowSettings.ambientColor = vec4(ambientColor); |
| 8179 | mCurrentState.globalShadowSettings.spotColor = vec4(spotColor); |
| 8180 | mCurrentState.globalShadowSettings.lightPos.y = lightPosY; |
| 8181 | mCurrentState.globalShadowSettings.lightPos.z = lightPosZ; |
| 8182 | mCurrentState.globalShadowSettings.lightRadius = lightRadius; |
| 8183 | |
| 8184 | // these values are overridden when calculating the shadow settings for a layer. |
| 8185 | mCurrentState.globalShadowSettings.lightPos.x = 0.f; |
| 8186 | mCurrentState.globalShadowSettings.length = 0.f; |
Vishnu Nair | b13bb95 | 2019-11-15 10:24:08 -0800 | [diff] [blame] | 8187 | return NO_ERROR; |
| 8188 | } |
| 8189 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8190 | const std::unordered_map<std::string, uint32_t>& SurfaceFlinger::getGenericLayerMetadataKeyMap() |
| 8191 | const { |
| 8192 | // TODO(b/149500060): Remove this fixed/static mapping. Please prefer taking |
| 8193 | // on the work to remove the table in that bug rather than adding more to |
| 8194 | // it. |
| 8195 | static const std::unordered_map<std::string, uint32_t> genericLayerMetadataKeyMap{ |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8196 | {"org.chromium.arc.V1_0.TaskId", gui::METADATA_TASK_ID}, |
| 8197 | {"org.chromium.arc.V1_0.CursorInfo", gui::METADATA_MOUSE_CURSOR}, |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8198 | }; |
| 8199 | return genericLayerMetadataKeyMap; |
| 8200 | } |
| 8201 | |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 8202 | status_t SurfaceFlinger::setOverrideFrameRate(uid_t uid, float frameRate) { |
| 8203 | PhysicalDisplayId displayId = [&]() { |
| 8204 | Mutex::Autolock lock(mStateLock); |
| 8205 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 8206 | }(); |
| 8207 | |
| 8208 | mScheduler->setGameModeRefreshRateForUid(FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
| 8209 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
| 8210 | return NO_ERROR; |
| 8211 | } |
| 8212 | |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8213 | status_t SurfaceFlinger::updateSmallAreaDetection( |
| 8214 | std::vector<std::pair<uid_t, float>>& uidThresholdMappings) { |
| 8215 | mScheduler->updateSmallAreaDetection(uidThresholdMappings); |
| 8216 | return NO_ERROR; |
| 8217 | } |
| 8218 | |
| 8219 | status_t SurfaceFlinger::setSmallAreaDetectionThreshold(uid_t uid, float threshold) { |
| 8220 | mScheduler->setSmallAreaDetectionThreshold(uid, threshold); |
| 8221 | return NO_ERROR; |
| 8222 | } |
| 8223 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8224 | void SurfaceFlinger::enableRefreshRateOverlay(bool enable) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 8225 | bool setByHwc = getHwComposer().hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8226 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 8227 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal) { |
| 8228 | if (const auto device = getDisplayDeviceLocked(id)) { |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 8229 | const auto enableOverlay = [&](const bool setByHwc) FTL_FAKE_GUARD( |
| 8230 | kMainThreadContext) { |
| 8231 | device->enableRefreshRateOverlay(enable, setByHwc, mRefreshRateOverlaySpinner, |
| 8232 | mRefreshRateOverlayRenderRate, |
| 8233 | mRefreshRateOverlayShowInMiddle); |
| 8234 | }; |
| 8235 | enableOverlay(setByHwc); |
| 8236 | if (setByHwc) { |
| 8237 | const auto status = |
| 8238 | getHwComposer().setRefreshRateChangedCallbackDebugEnabled(id, enable); |
| 8239 | if (status != NO_ERROR) { |
| 8240 | ALOGE("Error updating the refresh rate changed callback debug enabled"); |
| 8241 | enableOverlay(/*setByHwc*/ false); |
| 8242 | } |
| 8243 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8244 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8245 | } |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 8246 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8247 | } |
| 8248 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 8249 | void SurfaceFlinger::enableHdrSdrRatioOverlay(bool enable) { |
| 8250 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 8251 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal) { |
| 8252 | if (const auto device = getDisplayDeviceLocked(id)) { |
| 8253 | device->enableHdrSdrRatioOverlay(enable); |
| 8254 | } |
| 8255 | } |
| 8256 | } |
| 8257 | } |
| 8258 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8259 | int SurfaceFlinger::getGpuContextPriority() { |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 8260 | return getRenderEngine().getContextPriority(); |
Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 8261 | } |
| 8262 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8263 | int SurfaceFlinger::calculateMaxAcquiredBufferCount(Fps refreshRate, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8264 | std::chrono::nanoseconds presentLatency) { |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8265 | auto pipelineDepth = presentLatency.count() / refreshRate.getPeriodNsecs(); |
| 8266 | if (presentLatency.count() % refreshRate.getPeriodNsecs()) { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8267 | pipelineDepth++; |
| 8268 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8269 | return std::max(minAcquiredBuffers, static_cast<int64_t>(pipelineDepth - 1)); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8270 | } |
| 8271 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8272 | status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 8273 | Fps maxRefreshRate = 60_Hz; |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8274 | |
| 8275 | if (!getHwComposer().isHeadless()) { |
| 8276 | if (const auto display = getDefaultDisplayDevice()) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8277 | maxRefreshRate = display->refreshRateSelector().getSupportedRefreshRateRange().max; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8278 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8279 | } |
| 8280 | |
| 8281 | *buffers = getMaxAcquiredBufferCountForRefreshRate(maxRefreshRate); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8282 | return NO_ERROR; |
| 8283 | } |
| 8284 | |
rnlee | ed20fa4 | 2021-08-10 18:00:03 -0700 | [diff] [blame] | 8285 | uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 8286 | Fps refreshRate = 60_Hz; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8287 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8288 | if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) { |
| 8289 | refreshRate = *frameRateOverride; |
| 8290 | } else if (!getHwComposer().isHeadless()) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8291 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked())) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8292 | refreshRate = display->refreshRateSelector().getActiveMode().fps; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8293 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8294 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8295 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8296 | return getMaxAcquiredBufferCountForRefreshRate(refreshRate); |
| 8297 | } |
| 8298 | |
| 8299 | int SurfaceFlinger::getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const { |
| 8300 | const auto vsyncConfig = mVsyncConfiguration->getConfigsForRefreshRate(refreshRate).late; |
| 8301 | const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration; |
| 8302 | return calculateMaxAcquiredBufferCount(refreshRate, presentLatency); |
| 8303 | } |
| 8304 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 8305 | void SurfaceFlinger::handleLayerCreatedLocked(const LayerCreatedState& state, VsyncId vsyncId) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8306 | sp<Layer> layer = state.layer.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8307 | if (!layer) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8308 | ALOGD("Layer was destroyed soon after creation %p", state.layer.unsafe_get()); |
| 8309 | return; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8310 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 8311 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8312 | |
| 8313 | sp<Layer> parent; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8314 | bool addToRoot = state.addToRoot; |
| 8315 | if (state.initialParent != nullptr) { |
| 8316 | parent = state.initialParent.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8317 | if (parent == nullptr) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8318 | ALOGD("Parent was destroyed soon after creation %p", state.initialParent.unsafe_get()); |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 8319 | addToRoot = false; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8320 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8321 | } |
| 8322 | |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 8323 | if (parent == nullptr && addToRoot) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 8324 | layer->setIsAtRoot(true); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8325 | mCurrentState.layersSortedByZ.add(layer); |
| 8326 | } else if (parent == nullptr) { |
| 8327 | layer->onRemovedFromCurrentState(); |
| 8328 | } else if (parent->isRemovedFromCurrentState()) { |
| 8329 | parent->addChild(layer); |
| 8330 | layer->onRemovedFromCurrentState(); |
| 8331 | } else { |
| 8332 | parent->addChild(layer); |
| 8333 | } |
| 8334 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 8335 | ui::LayerStack layerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 8336 | sp<const DisplayDevice> hintDisplay; |
| 8337 | // Find the display that includes the layer. |
| 8338 | for (const auto& [token, display] : mDisplays) { |
| 8339 | if (display->getLayerStack() == layerStack) { |
| 8340 | hintDisplay = display; |
| 8341 | break; |
| 8342 | } |
| 8343 | } |
| 8344 | |
| 8345 | if (hintDisplay) { |
| 8346 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
| 8347 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8348 | } |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8349 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8350 | void SurfaceFlinger::sample() { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8351 | if (!mLumaSampling || !mRegionSamplingThread) { |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8352 | return; |
| 8353 | } |
| 8354 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 8355 | mRegionSamplingThread->onCompositionComplete(mScheduler->getScheduledFrameTime()); |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8356 | } |
| 8357 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8358 | void SurfaceFlinger::onActiveDisplaySizeChanged(const DisplayDevice& activeDisplay) { |
| 8359 | mScheduler->onActiveDisplayAreaChanged(activeDisplay.getWidth() * activeDisplay.getHeight()); |
| 8360 | getRenderEngine().onActiveDisplaySizeChanged(activeDisplay.getSize()); |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 8361 | |
| 8362 | // Notify layers to update small dirty flag. |
| 8363 | if (mScheduler->supportSmallDirtyDetection()) { |
| 8364 | mCurrentState.traverse([&](Layer* layer) { |
| 8365 | if (layer->getLayerStack() == activeDisplay.getLayerStack()) { |
| 8366 | layer->setIsSmallDirty(); |
| 8367 | } |
| 8368 | }); |
| 8369 | } |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8370 | } |
| 8371 | |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 8372 | sp<DisplayDevice> SurfaceFlinger::getActivatableDisplay() const { |
| 8373 | if (mPhysicalDisplays.size() == 1) return nullptr; |
| 8374 | |
| 8375 | // TODO(b/255635821): Choose the pacesetter display, considering both internal and external |
| 8376 | // displays. For now, pick the other internal display, assuming a dual-display foldable. |
| 8377 | return findDisplay([this](const DisplayDevice& display) REQUIRES(mStateLock) { |
| 8378 | const auto idOpt = PhysicalDisplayId::tryCast(display.getId()); |
| 8379 | return idOpt && *idOpt != mActiveDisplayId && display.isPoweredOn() && |
| 8380 | mPhysicalDisplays.get(*idOpt) |
| 8381 | .transform(&PhysicalDisplay::isInternal) |
| 8382 | .value_or(false); |
| 8383 | }); |
| 8384 | } |
| 8385 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8386 | void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveDisplayPtr, |
| 8387 | const DisplayDevice& activeDisplay) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8388 | ATRACE_CALL(); |
| 8389 | |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 8390 | // For the first display activated during boot, there is no need to force setDesiredActiveMode, |
| 8391 | // because DM is about to send its policy via setDesiredDisplayModeSpecs. |
| 8392 | bool forceApplyPolicy = false; |
| 8393 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8394 | if (inactiveDisplayPtr) { |
| 8395 | inactiveDisplayPtr->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false); |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 8396 | forceApplyPolicy = true; |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 8397 | } |
| 8398 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8399 | mActiveDisplayId = activeDisplay.getPhysicalId(); |
| 8400 | activeDisplay.getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 8401 | |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 8402 | resetPhaseConfiguration(activeDisplay.getActiveMode().fps); |
| 8403 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8404 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8405 | mScheduler->setModeChangePending(false); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8406 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 8407 | mScheduler->setPacesetterDisplay(mActiveDisplayId); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 8408 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8409 | onActiveDisplaySizeChanged(activeDisplay); |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8410 | mActiveDisplayTransformHint = activeDisplay.getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 8411 | sActiveDisplayRotationFlags = ui::Transform::toRotationFlags(activeDisplay.getOrientation()); |
Ady Abraham | 85d692d | 2021-09-28 14:08:54 -0700 | [diff] [blame] | 8412 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 8413 | // The policy of the new active/pacesetter display may have changed while it was inactive. In |
| 8414 | // that case, its preferred mode has not been propagated to HWC (via setDesiredActiveMode). In |
| 8415 | // either case, the Scheduler's cachedModeChangedParams must be initialized to the newly active |
| 8416 | // mode, and the kernel idle timer of the newly active display must be toggled. |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 8417 | applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay.refreshRateSelector(), |
| 8418 | forceApplyPolicy); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8419 | } |
| 8420 | |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 8421 | status_t SurfaceFlinger::addWindowInfosListener(const sp<IWindowInfosListener>& windowInfosListener, |
| 8422 | gui::WindowInfosListenerInfo* outInfo) { |
| 8423 | mWindowInfosListenerInvoker->addWindowInfosListener(windowInfosListener, outInfo); |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 8424 | setTransactionFlags(eInputInfoUpdateNeeded); |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 8425 | return NO_ERROR; |
| 8426 | } |
| 8427 | |
| 8428 | status_t SurfaceFlinger::removeWindowInfosListener( |
| 8429 | const sp<IWindowInfosListener>& windowInfosListener) const { |
| 8430 | mWindowInfosListenerInvoker->removeWindowInfosListener(windowInfosListener); |
| 8431 | return NO_ERROR; |
| 8432 | } |
| 8433 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 8434 | status_t SurfaceFlinger::getStalledTransactionInfo( |
| 8435 | int pid, std::optional<TransactionHandler::StalledTransactionInfo>& result) { |
| 8436 | result = mTransactionHandler.getStalledTransactionInfo(pid); |
| 8437 | return NO_ERROR; |
| 8438 | } |
| 8439 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8440 | std::shared_ptr<renderengine::ExternalTexture> SurfaceFlinger::getExternalTextureFromBufferData( |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8441 | BufferData& bufferData, const char* layerName, uint64_t transactionId) { |
| 8442 | if (bufferData.buffer && |
| 8443 | exceedsMaxRenderTargetSize(bufferData.buffer->getWidth(), bufferData.buffer->getHeight())) { |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 8444 | std::string errorMessage = |
| 8445 | base::StringPrintf("Attempted to create an ExternalTexture with size (%u, %u) for " |
| 8446 | "layer %s that exceeds render target size limit of %u.", |
| 8447 | bufferData.buffer->getWidth(), bufferData.buffer->getHeight(), |
| 8448 | layerName, static_cast<uint32_t>(mMaxRenderTargetSize)); |
| 8449 | ALOGD("%s", errorMessage.c_str()); |
| 8450 | if (bufferData.releaseBufferListener) { |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 8451 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
| 8452 | String8(errorMessage.c_str())); |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 8453 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8454 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8455 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8456 | |
| 8457 | bool cachedBufferChanged = |
| 8458 | bufferData.flags.test(BufferData::BufferDataChange::cachedBufferChanged); |
| 8459 | if (cachedBufferChanged && bufferData.buffer) { |
| 8460 | auto result = ClientCache::getInstance().add(bufferData.cachedBuffer, bufferData.buffer); |
| 8461 | if (result.ok()) { |
| 8462 | return result.value(); |
| 8463 | } |
| 8464 | |
| 8465 | if (result.error() == ClientCache::AddError::CacheFull) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 8466 | ALOGE("Attempted to create an ExternalTexture for layer %s but CacheFull", layerName); |
| 8467 | |
| 8468 | if (bufferData.releaseBufferListener) { |
| 8469 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 8470 | String8("Buffer processing hung due to full buffer cache")); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 8471 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8472 | } |
| 8473 | |
| 8474 | return nullptr; |
| 8475 | } |
| 8476 | |
| 8477 | if (cachedBufferChanged) { |
| 8478 | return ClientCache::getInstance().get(bufferData.cachedBuffer); |
| 8479 | } |
| 8480 | |
| 8481 | if (bufferData.buffer) { |
| 8482 | return std::make_shared< |
| 8483 | renderengine::impl::ExternalTexture>(bufferData.buffer, getRenderEngine(), |
| 8484 | renderengine::impl::ExternalTexture::Usage:: |
| 8485 | READABLE); |
| 8486 | } |
| 8487 | |
| 8488 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8489 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8490 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 8491 | bool SurfaceFlinger::commitMirrorDisplays(VsyncId vsyncId) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 8492 | std::vector<MirrorDisplayState> mirrorDisplays; |
| 8493 | { |
| 8494 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
| 8495 | mirrorDisplays = std::move(mMirrorDisplays); |
| 8496 | mMirrorDisplays.clear(); |
| 8497 | if (mirrorDisplays.size() == 0) { |
| 8498 | return false; |
| 8499 | } |
| 8500 | } |
| 8501 | |
| 8502 | sp<IBinder> unused; |
| 8503 | for (const auto& mirrorDisplay : mirrorDisplays) { |
| 8504 | // Set mirror layer's default layer stack to -1 so it doesn't end up rendered on a display |
| 8505 | // accidentally. |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 8506 | sp<Layer> rootMirrorLayer = LayerHandle::getLayer(mirrorDisplay.rootHandle); |
Qi Jing | b8e4c13 | 2023-08-25 23:01:47 +0000 | [diff] [blame] | 8507 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(rootMirrorLayer); |
| 8508 | bool ret = rootMirrorLayer->setLayerStack(ui::LayerStack::fromValue(-1)); |
| 8509 | if (idx >= 0 && ret) { |
| 8510 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 8511 | mCurrentState.layersSortedByZ.add(rootMirrorLayer); |
| 8512 | } |
| 8513 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 8514 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 8515 | if (layer->getLayerStack() != mirrorDisplay.layerStack || |
| 8516 | layer->isInternalDisplayOverlay()) { |
| 8517 | continue; |
| 8518 | } |
| 8519 | |
| 8520 | LayerCreationArgs mirrorArgs(this, mirrorDisplay.client, "MirrorLayerParent", |
| 8521 | ISurfaceComposerClient::eNoColorFill, |
| 8522 | gui::LayerMetadata()); |
| 8523 | sp<Layer> childMirror; |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 8524 | { |
| 8525 | Mutex::Autolock lock(mStateLock); |
| 8526 | createEffectLayer(mirrorArgs, &unused, &childMirror); |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 8527 | MUTEX_ALIAS(mStateLock, childMirror->mFlinger->mStateLock); |
Vishnu Nair | de17725 | 2023-04-21 12:44:10 -0700 | [diff] [blame] | 8528 | childMirror->setClonedChild(layer->createClone(childMirror->getSequence())); |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 8529 | childMirror->reparent(mirrorDisplay.rootHandle); |
| 8530 | } |
| 8531 | // lock on mStateLock needs to be released before binder handle gets destroyed |
| 8532 | unused.clear(); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 8533 | } |
| 8534 | } |
| 8535 | return true; |
| 8536 | } |
| 8537 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8538 | bool SurfaceFlinger::commitCreatedLayers(VsyncId vsyncId, |
| 8539 | std::vector<LayerCreatedState>& createdLayers) { |
| 8540 | if (createdLayers.size() == 0) { |
| 8541 | return false; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8542 | } |
| 8543 | |
| 8544 | Mutex::Autolock _l(mStateLock); |
| 8545 | for (const auto& createdLayer : createdLayers) { |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 8546 | handleLayerCreatedLocked(createdLayer, vsyncId); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8547 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8548 | mLayersAdded = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8549 | return mLayersAdded; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8550 | } |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8551 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 8552 | void SurfaceFlinger::updateLayerMetadataSnapshot() { |
| 8553 | LayerMetadata parentMetadata; |
| 8554 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 8555 | layer->updateMetadataSnapshot(parentMetadata); |
| 8556 | } |
| 8557 | |
| 8558 | std::unordered_set<Layer*> visited; |
| 8559 | mDrawingState.traverse([&visited](Layer* layer) { |
| 8560 | if (visited.find(layer) != visited.end()) { |
| 8561 | return; |
| 8562 | } |
| 8563 | |
| 8564 | // If the layer isRelativeOf, then either it's relative metadata will be set |
| 8565 | // recursively when updateRelativeMetadataSnapshot is called on its relative parent or |
| 8566 | // it's relative parent has been deleted. Clear the layer's relativeLayerMetadata to ensure |
| 8567 | // that layers with deleted relative parents don't hold stale relativeLayerMetadata. |
| 8568 | if (layer->getDrawingState().isRelativeOf) { |
| 8569 | layer->editLayerSnapshot()->relativeLayerMetadata = {}; |
| 8570 | return; |
| 8571 | } |
| 8572 | |
| 8573 | layer->updateRelativeMetadataSnapshot({}, visited); |
| 8574 | }); |
| 8575 | } |
| 8576 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8577 | void SurfaceFlinger::moveSnapshotsFromCompositionArgs( |
| 8578 | compositionengine::CompositionRefreshArgs& refreshArgs, |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 8579 | const std::vector<std::pair<Layer*, LayerFE*>>& layers) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8580 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8581 | std::vector<std::unique_ptr<frontend::LayerSnapshot>>& snapshots = |
| 8582 | mLayerSnapshotBuilder.getSnapshots(); |
| 8583 | for (auto [_, layerFE] : layers) { |
| 8584 | auto i = layerFE->mSnapshot->globalZ; |
| 8585 | snapshots[i] = std::move(layerFE->mSnapshot); |
| 8586 | } |
| 8587 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8588 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8589 | for (auto [layer, layerFE] : layers) { |
| 8590 | layer->updateLayerSnapshot(std::move(layerFE->mSnapshot)); |
| 8591 | } |
| 8592 | } |
| 8593 | } |
| 8594 | |
| 8595 | std::vector<std::pair<Layer*, LayerFE*>> SurfaceFlinger::moveSnapshotsToCompositionArgs( |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 8596 | compositionengine::CompositionRefreshArgs& refreshArgs, bool cursorOnly) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8597 | std::vector<std::pair<Layer*, LayerFE*>> layers; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8598 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 8599 | nsecs_t currentTime = systemTime(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8600 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 8601 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 8602 | if (cursorOnly && |
| 8603 | snapshot->compositionType != |
| 8604 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) { |
| 8605 | return; |
| 8606 | } |
| 8607 | |
| 8608 | if (!snapshot->hasSomethingToDraw()) { |
| 8609 | return; |
| 8610 | } |
| 8611 | |
| 8612 | auto it = mLegacyLayers.find(snapshot->sequence); |
| 8613 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), |
| 8614 | "Couldnt find layer object for %s", |
| 8615 | snapshot->getDebugString().c_str()); |
| 8616 | auto& legacyLayer = it->second; |
| 8617 | sp<LayerFE> layerFE = legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 8618 | snapshot->fps = getLayerFramerate(currentTime, snapshot->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8619 | layerFE->mSnapshot = std::move(snapshot); |
| 8620 | refreshArgs.layers.push_back(layerFE); |
| 8621 | layers.emplace_back(legacyLayer.get(), layerFE.get()); |
| 8622 | }); |
| 8623 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8624 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 8625 | auto moveSnapshots = [&layers, &refreshArgs, cursorOnly](Layer* layer) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8626 | if (const auto& layerFE = layer->getCompositionEngineLayerFE()) { |
| 8627 | if (cursorOnly && |
| 8628 | layer->getLayerSnapshot()->compositionType != |
| 8629 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) |
| 8630 | return; |
| 8631 | layer->updateSnapshot(refreshArgs.updatingGeometryThisFrame); |
| 8632 | layerFE->mSnapshot = layer->stealLayerSnapshot(); |
| 8633 | refreshArgs.layers.push_back(layerFE); |
| 8634 | layers.emplace_back(layer, layerFE.get()); |
| 8635 | } |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 8636 | }; |
| 8637 | |
| 8638 | if (cursorOnly || !mVisibleRegionsDirty) { |
| 8639 | // for hot path avoid traversals by walking though the previous composition list |
| 8640 | for (sp<Layer> layer : mPreviouslyComposedLayers) { |
| 8641 | moveSnapshots(layer.get()); |
| 8642 | } |
| 8643 | } else { |
| 8644 | mPreviouslyComposedLayers.clear(); |
| 8645 | mDrawingState.traverseInZOrder( |
| 8646 | [&moveSnapshots](Layer* layer) { moveSnapshots(layer); }); |
| 8647 | mPreviouslyComposedLayers.reserve(layers.size()); |
| 8648 | for (auto [layer, _] : layers) { |
| 8649 | mPreviouslyComposedLayers.push_back(sp<Layer>::fromExisting(layer)); |
| 8650 | } |
| 8651 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8652 | } |
| 8653 | |
| 8654 | return layers; |
| 8655 | } |
| 8656 | |
| 8657 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8658 | SurfaceFlinger::getLayerSnapshotsForScreenshots( |
| 8659 | std::optional<ui::LayerStack> layerStack, uint32_t uid, |
| 8660 | std::function<bool(const frontend::LayerSnapshot&, bool& outStopTraversal)> |
| 8661 | snapshotFilterFn) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8662 | return [&, layerStack, uid]() { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8663 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers; |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8664 | bool stopTraversal = false; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8665 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 8666 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8667 | if (stopTraversal) { |
| 8668 | return; |
| 8669 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8670 | if (layerStack && snapshot->outputFilter.layerStack != *layerStack) { |
| 8671 | return; |
| 8672 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 8673 | if (uid != CaptureArgs::UNSET_UID && snapshot->uid != gui::Uid(uid)) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8674 | return; |
| 8675 | } |
| 8676 | if (!snapshot->hasSomethingToDraw()) { |
| 8677 | return; |
| 8678 | } |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8679 | if (snapshotFilterFn && !snapshotFilterFn(*snapshot, stopTraversal)) { |
| 8680 | return; |
| 8681 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8682 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8683 | auto it = mLegacyLayers.find(snapshot->sequence); |
| 8684 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), |
| 8685 | "Couldnt find layer object for %s", |
| 8686 | snapshot->getDebugString().c_str()); |
| 8687 | Layer* legacyLayer = (it == mLegacyLayers.end()) ? nullptr : it->second.get(); |
| 8688 | sp<LayerFE> layerFE = getFactory().createLayerFE(snapshot->name); |
| 8689 | layerFE->mSnapshot = std::make_unique<frontend::LayerSnapshot>(*snapshot); |
| 8690 | layers.emplace_back(legacyLayer, std::move(layerFE)); |
| 8691 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8692 | |
| 8693 | return layers; |
| 8694 | }; |
| 8695 | } |
| 8696 | |
| 8697 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8698 | SurfaceFlinger::getLayerSnapshotsForScreenshots(std::optional<ui::LayerStack> layerStack, |
| 8699 | uint32_t uid, |
| 8700 | std::unordered_set<uint32_t> excludeLayerIds) { |
| 8701 | return [&, layerStack, uid, excludeLayerIds = std::move(excludeLayerIds)]() { |
| 8702 | if (excludeLayerIds.empty()) { |
| 8703 | auto getLayerSnapshotsFn = |
| 8704 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 8705 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 8706 | return layers; |
| 8707 | } |
| 8708 | |
| 8709 | frontend::LayerSnapshotBuilder::Args |
| 8710 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 8711 | .layerLifecycleManager = mLayerLifecycleManager, |
| 8712 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
| 8713 | .displays = mFrontEndDisplayInfos, |
| 8714 | .displayChanges = true, |
| 8715 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8716 | .supportsBlur = mSupportsBlur, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8717 | .forceFullDamage = mForceFullDamage, |
| 8718 | .excludeLayerIds = std::move(excludeLayerIds), |
| 8719 | .supportedLayerGenericMetadata = |
| 8720 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 8721 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 8722 | .skipRoundCornersWhenProtected = |
| 8723 | !getRenderEngine().supportsProtectedContent()}; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8724 | mLayerSnapshotBuilder.update(args); |
| 8725 | |
| 8726 | auto getLayerSnapshotsFn = |
| 8727 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 8728 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 8729 | |
| 8730 | args.excludeLayerIds.clear(); |
| 8731 | mLayerSnapshotBuilder.update(args); |
| 8732 | |
| 8733 | return layers; |
| 8734 | }; |
| 8735 | } |
| 8736 | |
| 8737 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8738 | SurfaceFlinger::getLayerSnapshotsForScreenshots(uint32_t rootLayerId, uint32_t uid, |
| 8739 | std::unordered_set<uint32_t> excludeLayerIds, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8740 | bool childrenOnly, |
| 8741 | const std::optional<FloatRect>& parentCrop) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8742 | return [&, rootLayerId, uid, excludeLayerIds = std::move(excludeLayerIds), childrenOnly, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8743 | parentCrop]() { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8744 | auto root = mLayerHierarchyBuilder.getPartialHierarchy(rootLayerId, childrenOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8745 | frontend::LayerSnapshotBuilder::Args |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8746 | args{.root = root, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8747 | .layerLifecycleManager = mLayerLifecycleManager, |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8748 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8749 | .displays = mFrontEndDisplayInfos, |
| 8750 | .displayChanges = true, |
| 8751 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8752 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8753 | .forceFullDamage = mForceFullDamage, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8754 | .parentCrop = parentCrop, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 8755 | .excludeLayerIds = std::move(excludeLayerIds), |
| 8756 | .supportedLayerGenericMetadata = |
| 8757 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 8758 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 8759 | .skipRoundCornersWhenProtected = |
| 8760 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8761 | mLayerSnapshotBuilder.update(args); |
| 8762 | |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8763 | auto getLayerSnapshotsFn = |
| 8764 | getLayerSnapshotsForScreenshots({}, uid, /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8765 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 8766 | args.root = mLayerHierarchyBuilder.getHierarchy(); |
| 8767 | args.parentCrop.reset(); |
| 8768 | args.excludeLayerIds.clear(); |
| 8769 | mLayerSnapshotBuilder.update(args); |
| 8770 | return layers; |
| 8771 | }; |
| 8772 | } |
| 8773 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8774 | frontend::Update SurfaceFlinger::flushLifecycleUpdates() { |
| 8775 | frontend::Update update; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8776 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 8777 | // Locking: |
| 8778 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 8779 | // we must keep a copy of the transactions (specifically the composer |
| 8780 | // states) around outside the scope of the lock. |
| 8781 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 8782 | // transactions with layers still in the createdLayer queue, flush the transactions |
| 8783 | // before committing the created layers. |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 8784 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8785 | update.transactions = mTransactionHandler.flushTransactions(); |
| 8786 | { |
| 8787 | // TODO(b/238781169) lockless queue this and keep order. |
| 8788 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 8789 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 8790 | mCreatedLayers.clear(); |
| 8791 | update.newLayers = std::move(mNewLayers); |
| 8792 | mNewLayers.clear(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8793 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 8794 | mNewLayerArgs.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8795 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 8796 | mDestroyedHandles.clear(); |
| 8797 | } |
| 8798 | return update; |
| 8799 | } |
| 8800 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 8801 | void SurfaceFlinger::doActiveLayersTracingIfNeeded(bool isCompositionComputed, |
| 8802 | bool visibleRegionDirty, TimePoint time, |
| 8803 | VsyncId vsyncId) { |
| 8804 | if (!mLayerTracing.isActiveTracingStarted()) { |
| 8805 | return; |
| 8806 | } |
| 8807 | if (isCompositionComputed != |
| 8808 | mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_COMPOSITION)) { |
| 8809 | return; |
| 8810 | } |
| 8811 | if (!visibleRegionDirty && |
| 8812 | !mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_BUFFERS)) { |
| 8813 | return; |
| 8814 | } |
| 8815 | auto snapshot = takeLayersSnapshotProto(mLayerTracing.getActiveTracingFlags(), time, vsyncId, |
| 8816 | visibleRegionDirty); |
| 8817 | mLayerTracing.addProtoSnapshotToOstream(std::move(snapshot), LayerTracing::Mode::MODE_ACTIVE); |
| 8818 | } |
| 8819 | |
| 8820 | perfetto::protos::LayersSnapshotProto SurfaceFlinger::takeLayersSnapshotProto( |
| 8821 | uint32_t traceFlags, TimePoint time, VsyncId vsyncId, bool visibleRegionDirty) { |
| 8822 | ATRACE_CALL(); |
| 8823 | perfetto::protos::LayersSnapshotProto snapshot; |
| 8824 | snapshot.set_elapsed_realtime_nanos(time.ns()); |
| 8825 | snapshot.set_vsync_id(ftl::to_underlying(vsyncId)); |
| 8826 | snapshot.set_where(visibleRegionDirty ? "visibleRegionsDirty" : "bufferLatched"); |
| 8827 | snapshot.set_excludes_composition_state((traceFlags & LayerTracing::Flag::TRACE_COMPOSITION) == |
| 8828 | 0); |
| 8829 | |
| 8830 | auto layers = dumpDrawingStateProto(traceFlags); |
| 8831 | if (traceFlags & LayerTracing::Flag::TRACE_EXTRA) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8832 | dumpOffscreenLayersProto(layers); |
| 8833 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 8834 | *snapshot.mutable_layers() = std::move(layers); |
| 8835 | |
| 8836 | if (traceFlags & LayerTracing::Flag::TRACE_HWC) { |
| 8837 | std::string hwcDump; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8838 | dumpHwc(hwcDump); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 8839 | snapshot.set_hwc_blob(std::move(hwcDump)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8840 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 8841 | |
| 8842 | *snapshot.mutable_displays() = dumpDisplayProto(); |
| 8843 | |
| 8844 | return snapshot; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8845 | } |
| 8846 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 8847 | // sfdo functions |
| 8848 | |
| 8849 | void SurfaceFlinger::sfdo_enableRefreshRateOverlay(bool active) { |
| 8850 | auto future = mScheduler->schedule( |
| 8851 | [&]() FTL_FAKE_GUARD(mStateLock) |
| 8852 | FTL_FAKE_GUARD(kMainThreadContext) { enableRefreshRateOverlay(active); }); |
| 8853 | future.wait(); |
| 8854 | } |
| 8855 | |
| 8856 | void SurfaceFlinger::sfdo_setDebugFlash(int delay) { |
| 8857 | if (delay > 0) { |
| 8858 | mDebugFlashDelay = delay; |
| 8859 | } else { |
| 8860 | mDebugFlashDelay = mDebugFlashDelay ? 0 : 1; |
| 8861 | } |
| 8862 | scheduleRepaint(); |
| 8863 | } |
| 8864 | |
| 8865 | void SurfaceFlinger::sfdo_scheduleComposite() { |
| 8866 | scheduleComposite(SurfaceFlinger::FrameHint::kActive); |
| 8867 | } |
| 8868 | |
| 8869 | void SurfaceFlinger::sfdo_scheduleCommit() { |
| 8870 | Mutex::Autolock lock(mStateLock); |
| 8871 | setTransactionFlags(eTransactionNeeded | eDisplayTransactionNeeded | eTraversalNeeded); |
| 8872 | } |
| 8873 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8874 | // gui::ISurfaceComposer |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8875 | |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8876 | binder::Status SurfaceComposerAIDL::bootFinished() { |
| 8877 | status_t status = checkAccessPermission(); |
| 8878 | if (status != OK) { |
| 8879 | return binderStatusFromStatusT(status); |
| 8880 | } |
| 8881 | mFlinger->bootFinished(); |
| 8882 | return binder::Status::ok(); |
| 8883 | } |
| 8884 | |
| 8885 | binder::Status SurfaceComposerAIDL::createDisplayEventConnection( |
| 8886 | VsyncSource vsyncSource, EventRegistration eventRegistration, |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 8887 | const sp<IBinder>& layerHandle, sp<IDisplayEventConnection>* outConnection) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8888 | sp<IDisplayEventConnection> conn = |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 8889 | mFlinger->createDisplayEventConnection(vsyncSource, eventRegistration, layerHandle); |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8890 | if (conn == nullptr) { |
| 8891 | *outConnection = nullptr; |
| 8892 | return binderStatusFromStatusT(BAD_VALUE); |
| 8893 | } else { |
| 8894 | *outConnection = conn; |
| 8895 | return binder::Status::ok(); |
| 8896 | } |
| 8897 | } |
| 8898 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8899 | binder::Status SurfaceComposerAIDL::createConnection(sp<gui::ISurfaceComposerClient>* outClient) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 8900 | const sp<Client> client = sp<Client>::make(mFlinger); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8901 | if (client->initCheck() == NO_ERROR) { |
| 8902 | *outClient = client; |
| 8903 | return binder::Status::ok(); |
| 8904 | } else { |
| 8905 | *outClient = nullptr; |
| 8906 | return binderStatusFromStatusT(BAD_VALUE); |
| 8907 | } |
| 8908 | } |
| 8909 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8910 | binder::Status SurfaceComposerAIDL::createDisplay(const std::string& displayName, bool secure, |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 8911 | float requestedRefreshRate, |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8912 | sp<IBinder>* outDisplay) { |
| 8913 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8914 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8915 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8916 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8917 | String8 displayName8 = String8::format("%s", displayName.c_str()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 8918 | *outDisplay = mFlinger->createDisplay(displayName8, secure, requestedRefreshRate); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8919 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8920 | } |
| 8921 | |
| 8922 | binder::Status SurfaceComposerAIDL::destroyDisplay(const sp<IBinder>& display) { |
| 8923 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8924 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8925 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8926 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8927 | mFlinger->destroyDisplay(display); |
| 8928 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8929 | } |
| 8930 | |
| 8931 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) { |
| 8932 | std::vector<PhysicalDisplayId> physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); |
| 8933 | std::vector<int64_t> displayIds; |
| 8934 | displayIds.reserve(physicalDisplayIds.size()); |
| 8935 | for (auto item : physicalDisplayIds) { |
| 8936 | displayIds.push_back(static_cast<int64_t>(item.value)); |
| 8937 | } |
| 8938 | *outDisplayIds = displayIds; |
| 8939 | return binder::Status::ok(); |
| 8940 | } |
| 8941 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8942 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, |
| 8943 | sp<IBinder>* outDisplay) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8944 | status_t status = checkAccessPermission(); |
| 8945 | if (status != OK) { |
| 8946 | return binderStatusFromStatusT(status); |
| 8947 | } |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8948 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 8949 | *outDisplay = mFlinger->getPhysicalDisplayToken(*id); |
| 8950 | return binder::Status::ok(); |
| 8951 | } |
| 8952 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8953 | binder::Status SurfaceComposerAIDL::setPowerMode(const sp<IBinder>& display, int mode) { |
| 8954 | status_t status = checkAccessPermission(); |
| 8955 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8956 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8957 | } |
| 8958 | mFlinger->setPowerMode(display, mode); |
| 8959 | return binder::Status::ok(); |
| 8960 | } |
| 8961 | |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 8962 | binder::Status SurfaceComposerAIDL::getSupportedFrameTimestamps( |
| 8963 | std::vector<FrameEvent>* outSupported) { |
| 8964 | status_t status; |
| 8965 | if (!outSupported) { |
| 8966 | status = UNEXPECTED_NULL; |
| 8967 | } else { |
| 8968 | outSupported->clear(); |
| 8969 | status = mFlinger->getSupportedFrameTimestamps(outSupported); |
| 8970 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8971 | return binderStatusFromStatusT(status); |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 8972 | } |
| 8973 | |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8974 | binder::Status SurfaceComposerAIDL::getDisplayStats(const sp<IBinder>& display, |
| 8975 | gui::DisplayStatInfo* outStatInfo) { |
| 8976 | DisplayStatInfo statInfo; |
| 8977 | status_t status = mFlinger->getDisplayStats(display, &statInfo); |
| 8978 | if (status == NO_ERROR) { |
| 8979 | outStatInfo->vsyncTime = static_cast<long>(statInfo.vsyncTime); |
| 8980 | outStatInfo->vsyncPeriod = static_cast<long>(statInfo.vsyncPeriod); |
| 8981 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8982 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8983 | } |
| 8984 | |
| 8985 | binder::Status SurfaceComposerAIDL::getDisplayState(const sp<IBinder>& display, |
| 8986 | gui::DisplayState* outState) { |
| 8987 | ui::DisplayState state; |
| 8988 | status_t status = mFlinger->getDisplayState(display, &state); |
| 8989 | if (status == NO_ERROR) { |
| 8990 | outState->layerStack = state.layerStack.id; |
| 8991 | outState->orientation = static_cast<gui::Rotation>(state.orientation); |
| 8992 | outState->layerStackSpaceRect.width = state.layerStackSpaceRect.width; |
| 8993 | outState->layerStackSpaceRect.height = state.layerStackSpaceRect.height; |
| 8994 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8995 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8996 | } |
| 8997 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8998 | binder::Status SurfaceComposerAIDL::getStaticDisplayInfo(int64_t displayId, |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8999 | gui::StaticDisplayInfo* outInfo) { |
| 9000 | using Tag = gui::DeviceProductInfo::ManufactureOrModelDate::Tag; |
| 9001 | ui::StaticDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9002 | |
| 9003 | status_t status = mFlinger->getStaticDisplayInfo(displayId, &info); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9004 | if (status == NO_ERROR) { |
| 9005 | // convert ui::StaticDisplayInfo to gui::StaticDisplayInfo |
| 9006 | outInfo->connectionType = static_cast<gui::DisplayConnectionType>(info.connectionType); |
| 9007 | outInfo->density = info.density; |
| 9008 | outInfo->secure = info.secure; |
| 9009 | outInfo->installOrientation = static_cast<gui::Rotation>(info.installOrientation); |
| 9010 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9011 | if (const std::optional<DeviceProductInfo> dpi = info.deviceProductInfo) { |
| 9012 | gui::DeviceProductInfo dinfo; |
| 9013 | dinfo.name = std::move(dpi->name); |
| 9014 | dinfo.manufacturerPnpId = std::vector<uint8_t>(dpi->manufacturerPnpId.begin(), |
| 9015 | dpi->manufacturerPnpId.end()); |
| 9016 | dinfo.productId = dpi->productId; |
| 9017 | dinfo.relativeAddress = |
| 9018 | std::vector<uint8_t>(dpi->relativeAddress.begin(), dpi->relativeAddress.end()); |
| 9019 | if (const auto* model = |
| 9020 | std::get_if<DeviceProductInfo::ModelYear>(&dpi->manufactureOrModelDate)) { |
| 9021 | gui::DeviceProductInfo::ModelYear modelYear; |
| 9022 | modelYear.year = model->year; |
| 9023 | dinfo.manufactureOrModelDate.set<Tag::modelYear>(modelYear); |
| 9024 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureYear>( |
| 9025 | &dpi->manufactureOrModelDate)) { |
| 9026 | gui::DeviceProductInfo::ManufactureYear date; |
| 9027 | date.modelYear.year = manufacture->year; |
| 9028 | dinfo.manufactureOrModelDate.set<Tag::manufactureYear>(date); |
| 9029 | } else if (const auto* manufacture = |
| 9030 | std::get_if<DeviceProductInfo::ManufactureWeekAndYear>( |
| 9031 | &dpi->manufactureOrModelDate)) { |
| 9032 | gui::DeviceProductInfo::ManufactureWeekAndYear date; |
| 9033 | date.manufactureYear.modelYear.year = manufacture->year; |
| 9034 | date.week = manufacture->week; |
| 9035 | dinfo.manufactureOrModelDate.set<Tag::manufactureWeekAndYear>(date); |
| 9036 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9037 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9038 | outInfo->deviceProductInfo = dinfo; |
| 9039 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9040 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9041 | return binderStatusFromStatusT(status); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9042 | } |
| 9043 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9044 | void SurfaceComposerAIDL::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo& info, |
| 9045 | gui::DynamicDisplayInfo*& outInfo) { |
| 9046 | // convert ui::DynamicDisplayInfo to gui::DynamicDisplayInfo |
| 9047 | outInfo->supportedDisplayModes.clear(); |
| 9048 | outInfo->supportedDisplayModes.reserve(info.supportedDisplayModes.size()); |
| 9049 | for (const auto& mode : info.supportedDisplayModes) { |
| 9050 | gui::DisplayMode outMode; |
| 9051 | outMode.id = mode.id; |
| 9052 | outMode.resolution.width = mode.resolution.width; |
| 9053 | outMode.resolution.height = mode.resolution.height; |
| 9054 | outMode.xDpi = mode.xDpi; |
| 9055 | outMode.yDpi = mode.yDpi; |
| 9056 | outMode.refreshRate = mode.refreshRate; |
| 9057 | outMode.appVsyncOffset = mode.appVsyncOffset; |
| 9058 | outMode.sfVsyncOffset = mode.sfVsyncOffset; |
| 9059 | outMode.presentationDeadline = mode.presentationDeadline; |
| 9060 | outMode.group = mode.group; |
| 9061 | std::transform(mode.supportedHdrTypes.begin(), mode.supportedHdrTypes.end(), |
| 9062 | std::back_inserter(outMode.supportedHdrTypes), |
| 9063 | [](const ui::Hdr& value) { return static_cast<int32_t>(value); }); |
| 9064 | outInfo->supportedDisplayModes.push_back(outMode); |
| 9065 | } |
| 9066 | |
| 9067 | outInfo->activeDisplayModeId = info.activeDisplayModeId; |
| 9068 | outInfo->renderFrameRate = info.renderFrameRate; |
| 9069 | |
| 9070 | outInfo->supportedColorModes.clear(); |
| 9071 | outInfo->supportedColorModes.reserve(info.supportedColorModes.size()); |
| 9072 | for (const auto& cmode : info.supportedColorModes) { |
| 9073 | outInfo->supportedColorModes.push_back(static_cast<int32_t>(cmode)); |
| 9074 | } |
| 9075 | |
| 9076 | outInfo->activeColorMode = static_cast<int32_t>(info.activeColorMode); |
| 9077 | |
| 9078 | gui::HdrCapabilities& hdrCapabilities = outInfo->hdrCapabilities; |
| 9079 | hdrCapabilities.supportedHdrTypes.clear(); |
| 9080 | hdrCapabilities.supportedHdrTypes.reserve(info.hdrCapabilities.getSupportedHdrTypes().size()); |
| 9081 | for (const auto& hdr : info.hdrCapabilities.getSupportedHdrTypes()) { |
| 9082 | hdrCapabilities.supportedHdrTypes.push_back(static_cast<int32_t>(hdr)); |
| 9083 | } |
| 9084 | hdrCapabilities.maxLuminance = info.hdrCapabilities.getDesiredMaxLuminance(); |
| 9085 | hdrCapabilities.maxAverageLuminance = info.hdrCapabilities.getDesiredMaxAverageLuminance(); |
| 9086 | hdrCapabilities.minLuminance = info.hdrCapabilities.getDesiredMinLuminance(); |
| 9087 | |
| 9088 | outInfo->autoLowLatencyModeSupported = info.autoLowLatencyModeSupported; |
| 9089 | outInfo->gameContentTypeSupported = info.gameContentTypeSupported; |
| 9090 | outInfo->preferredBootDisplayMode = info.preferredBootDisplayMode; |
| 9091 | } |
| 9092 | |
| 9093 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromToken( |
| 9094 | const sp<IBinder>& display, gui::DynamicDisplayInfo* outInfo) { |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9095 | ui::DynamicDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9096 | status_t status = mFlinger->getDynamicDisplayInfoFromToken(display, &info); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9097 | if (status == NO_ERROR) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9098 | getDynamicDisplayInfoInternal(info, outInfo); |
| 9099 | } |
| 9100 | return binderStatusFromStatusT(status); |
| 9101 | } |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 9102 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9103 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromId(int64_t displayId, |
| 9104 | gui::DynamicDisplayInfo* outInfo) { |
| 9105 | ui::DynamicDisplayInfo info; |
| 9106 | status_t status = mFlinger->getDynamicDisplayInfoFromId(displayId, &info); |
| 9107 | if (status == NO_ERROR) { |
| 9108 | getDynamicDisplayInfoInternal(info, outInfo); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9109 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9110 | return binderStatusFromStatusT(status); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9111 | } |
| 9112 | |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9113 | binder::Status SurfaceComposerAIDL::getDisplayNativePrimaries(const sp<IBinder>& display, |
| 9114 | gui::DisplayPrimaries* outPrimaries) { |
| 9115 | ui::DisplayPrimaries primaries; |
| 9116 | status_t status = mFlinger->getDisplayNativePrimaries(display, primaries); |
| 9117 | if (status == NO_ERROR) { |
| 9118 | outPrimaries->red.X = primaries.red.X; |
| 9119 | outPrimaries->red.Y = primaries.red.Y; |
| 9120 | outPrimaries->red.Z = primaries.red.Z; |
| 9121 | |
| 9122 | outPrimaries->green.X = primaries.green.X; |
| 9123 | outPrimaries->green.Y = primaries.green.Y; |
| 9124 | outPrimaries->green.Z = primaries.green.Z; |
| 9125 | |
| 9126 | outPrimaries->blue.X = primaries.blue.X; |
| 9127 | outPrimaries->blue.Y = primaries.blue.Y; |
| 9128 | outPrimaries->blue.Z = primaries.blue.Z; |
| 9129 | |
| 9130 | outPrimaries->white.X = primaries.white.X; |
| 9131 | outPrimaries->white.Y = primaries.white.Y; |
| 9132 | outPrimaries->white.Z = primaries.white.Z; |
| 9133 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9134 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9135 | } |
| 9136 | |
| 9137 | binder::Status SurfaceComposerAIDL::setActiveColorMode(const sp<IBinder>& display, int colorMode) { |
| 9138 | status_t status = checkAccessPermission(); |
| 9139 | if (status == OK) { |
| 9140 | status = mFlinger->setActiveColorMode(display, static_cast<ui::ColorMode>(colorMode)); |
| 9141 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9142 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9143 | } |
| 9144 | |
| 9145 | binder::Status SurfaceComposerAIDL::setBootDisplayMode(const sp<IBinder>& display, |
| 9146 | int displayModeId) { |
| 9147 | status_t status = checkAccessPermission(); |
| 9148 | if (status == OK) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 9149 | status = mFlinger->setBootDisplayMode(display, DisplayModeId{displayModeId}); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9150 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9151 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9152 | } |
| 9153 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9154 | binder::Status SurfaceComposerAIDL::clearBootDisplayMode(const sp<IBinder>& display) { |
| 9155 | status_t status = checkAccessPermission(); |
| 9156 | if (status == OK) { |
| 9157 | status = mFlinger->clearBootDisplayMode(display); |
| 9158 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9159 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9160 | } |
| 9161 | |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 9162 | binder::Status SurfaceComposerAIDL::getOverlaySupport(gui::OverlayProperties* outProperties) { |
| 9163 | status_t status = checkAccessPermission(); |
| 9164 | if (status == OK) { |
| 9165 | status = mFlinger->getOverlaySupport(outProperties); |
| 9166 | } |
| 9167 | return binderStatusFromStatusT(status); |
| 9168 | } |
| 9169 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9170 | binder::Status SurfaceComposerAIDL::getBootDisplayModeSupport(bool* outMode) { |
| 9171 | status_t status = checkAccessPermission(); |
| 9172 | if (status == OK) { |
| 9173 | status = mFlinger->getBootDisplayModeSupport(outMode); |
| 9174 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9175 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9176 | } |
| 9177 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9178 | binder::Status SurfaceComposerAIDL::getHdrConversionCapabilities( |
| 9179 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) { |
| 9180 | status_t status = checkAccessPermission(); |
| 9181 | if (status == OK) { |
| 9182 | status = mFlinger->getHdrConversionCapabilities(hdrConversionCapabilities); |
| 9183 | } |
| 9184 | return binderStatusFromStatusT(status); |
| 9185 | } |
| 9186 | |
| 9187 | binder::Status SurfaceComposerAIDL::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 9188 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 9189 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9190 | status_t status = checkAccessPermission(); |
| 9191 | if (status == OK) { |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 9192 | status = mFlinger->setHdrConversionStrategy(hdrConversionStrategy, |
| 9193 | outPreferredHdrOutputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9194 | } |
| 9195 | return binderStatusFromStatusT(status); |
| 9196 | } |
| 9197 | |
| 9198 | binder::Status SurfaceComposerAIDL::getHdrOutputConversionSupport(bool* outMode) { |
| 9199 | status_t status = checkAccessPermission(); |
| 9200 | if (status == OK) { |
| 9201 | status = mFlinger->getHdrOutputConversionSupport(outMode); |
| 9202 | } |
| 9203 | return binderStatusFromStatusT(status); |
| 9204 | } |
| 9205 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9206 | binder::Status SurfaceComposerAIDL::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) { |
| 9207 | status_t status = checkAccessPermission(); |
| 9208 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9209 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9210 | } |
| 9211 | mFlinger->setAutoLowLatencyMode(display, on); |
| 9212 | return binder::Status::ok(); |
| 9213 | } |
| 9214 | |
| 9215 | binder::Status SurfaceComposerAIDL::setGameContentType(const sp<IBinder>& display, bool on) { |
| 9216 | status_t status = checkAccessPermission(); |
| 9217 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9218 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9219 | } |
| 9220 | mFlinger->setGameContentType(display, on); |
| 9221 | return binder::Status::ok(); |
| 9222 | } |
| 9223 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9224 | binder::Status SurfaceComposerAIDL::captureDisplay( |
| 9225 | const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9226 | mFlinger->captureDisplay(args, captureListener); |
| 9227 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9228 | } |
| 9229 | |
| 9230 | binder::Status SurfaceComposerAIDL::captureDisplayById( |
| 9231 | int64_t displayId, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9232 | // status_t status; |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9233 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9234 | const int uid = ipc->getCallingUid(); |
| 9235 | if (uid == AID_ROOT || uid == AID_GRAPHICS || uid == AID_SYSTEM || uid == AID_SHELL) { |
| 9236 | std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId)); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9237 | mFlinger->captureDisplay(*id, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9238 | } else { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9239 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9240 | } |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9241 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9242 | } |
| 9243 | |
| 9244 | binder::Status SurfaceComposerAIDL::captureLayers( |
| 9245 | const LayerCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9246 | mFlinger->captureLayers(args, captureListener); |
| 9247 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9248 | } |
| 9249 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9250 | binder::Status SurfaceComposerAIDL::overrideHdrTypes(const sp<IBinder>& display, |
| 9251 | const std::vector<int32_t>& hdrTypes) { |
| 9252 | // overrideHdrTypes is used by CTS tests, which acquire the necessary |
| 9253 | // permission dynamically. Don't use the permission cache for this check. |
| 9254 | status_t status = checkAccessPermission(false); |
| 9255 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9256 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9257 | } |
| 9258 | |
| 9259 | std::vector<ui::Hdr> hdrTypesVector; |
| 9260 | for (int32_t i : hdrTypes) { |
| 9261 | hdrTypesVector.push_back(static_cast<ui::Hdr>(i)); |
| 9262 | } |
| 9263 | status = mFlinger->overrideHdrTypes(display, hdrTypesVector); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9264 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9265 | } |
| 9266 | |
| 9267 | binder::Status SurfaceComposerAIDL::onPullAtom(int32_t atomId, gui::PullAtomData* outPullData) { |
| 9268 | status_t status; |
| 9269 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 9270 | if (uid != AID_SYSTEM) { |
| 9271 | status = PERMISSION_DENIED; |
| 9272 | } else { |
| 9273 | status = mFlinger->onPullAtom(atomId, &outPullData->data, &outPullData->success); |
| 9274 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9275 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9276 | } |
| 9277 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9278 | binder::Status SurfaceComposerAIDL::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
| 9279 | if (!outLayers) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9280 | return binderStatusFromStatusT(UNEXPECTED_NULL); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9281 | } |
| 9282 | |
| 9283 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9284 | const int pid = ipc->getCallingPid(); |
| 9285 | const int uid = ipc->getCallingUid(); |
| 9286 | if ((uid != AID_SHELL) && !PermissionCache::checkPermission(sDump, pid, uid)) { |
| 9287 | ALOGE("Layer debug info permission denied for pid=%d, uid=%d", pid, uid); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9288 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9289 | } |
| 9290 | status_t status = mFlinger->getLayerDebugInfo(outLayers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9291 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9292 | } |
| 9293 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9294 | binder::Status SurfaceComposerAIDL::getCompositionPreference(gui::CompositionPreference* outPref) { |
| 9295 | ui::Dataspace dataspace; |
| 9296 | ui::PixelFormat pixelFormat; |
| 9297 | ui::Dataspace wideColorGamutDataspace; |
| 9298 | ui::PixelFormat wideColorGamutPixelFormat; |
| 9299 | status_t status = |
| 9300 | mFlinger->getCompositionPreference(&dataspace, &pixelFormat, &wideColorGamutDataspace, |
| 9301 | &wideColorGamutPixelFormat); |
| 9302 | if (status == NO_ERROR) { |
| 9303 | outPref->defaultDataspace = static_cast<int32_t>(dataspace); |
| 9304 | outPref->defaultPixelFormat = static_cast<int32_t>(pixelFormat); |
| 9305 | outPref->wideColorGamutDataspace = static_cast<int32_t>(wideColorGamutDataspace); |
| 9306 | outPref->wideColorGamutPixelFormat = static_cast<int32_t>(wideColorGamutPixelFormat); |
| 9307 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9308 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9309 | } |
| 9310 | |
| 9311 | binder::Status SurfaceComposerAIDL::getDisplayedContentSamplingAttributes( |
| 9312 | const sp<IBinder>& display, gui::ContentSamplingAttributes* outAttrs) { |
| 9313 | status_t status = checkAccessPermission(); |
| 9314 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9315 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9316 | } |
| 9317 | |
| 9318 | ui::PixelFormat format; |
| 9319 | ui::Dataspace dataspace; |
| 9320 | uint8_t componentMask; |
| 9321 | status = mFlinger->getDisplayedContentSamplingAttributes(display, &format, &dataspace, |
| 9322 | &componentMask); |
| 9323 | if (status == NO_ERROR) { |
| 9324 | outAttrs->format = static_cast<int32_t>(format); |
| 9325 | outAttrs->dataspace = static_cast<int32_t>(dataspace); |
| 9326 | outAttrs->componentMask = static_cast<int8_t>(componentMask); |
| 9327 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9328 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9329 | } |
| 9330 | |
| 9331 | binder::Status SurfaceComposerAIDL::setDisplayContentSamplingEnabled(const sp<IBinder>& display, |
| 9332 | bool enable, |
| 9333 | int8_t componentMask, |
| 9334 | int64_t maxFrames) { |
| 9335 | status_t status = checkAccessPermission(); |
| 9336 | if (status == OK) { |
| 9337 | status = mFlinger->setDisplayContentSamplingEnabled(display, enable, |
| 9338 | static_cast<uint8_t>(componentMask), |
| 9339 | static_cast<uint64_t>(maxFrames)); |
| 9340 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9341 | return binderStatusFromStatusT(status); |
| 9342 | } |
| 9343 | |
| 9344 | binder::Status SurfaceComposerAIDL::getDisplayedContentSample(const sp<IBinder>& display, |
| 9345 | int64_t maxFrames, int64_t timestamp, |
| 9346 | gui::DisplayedFrameStats* outStats) { |
| 9347 | if (!outStats) { |
| 9348 | return binderStatusFromStatusT(BAD_VALUE); |
| 9349 | } |
| 9350 | |
| 9351 | status_t status = checkAccessPermission(); |
| 9352 | if (status != OK) { |
| 9353 | return binderStatusFromStatusT(status); |
| 9354 | } |
| 9355 | |
| 9356 | DisplayedFrameStats stats; |
| 9357 | status = mFlinger->getDisplayedContentSample(display, static_cast<uint64_t>(maxFrames), |
| 9358 | static_cast<uint64_t>(timestamp), &stats); |
| 9359 | if (status == NO_ERROR) { |
| 9360 | // convert from ui::DisplayedFrameStats to gui::DisplayedFrameStats |
| 9361 | outStats->numFrames = static_cast<int64_t>(stats.numFrames); |
| 9362 | outStats->component_0_sample.reserve(stats.component_0_sample.size()); |
| 9363 | for (const auto& s : stats.component_0_sample) { |
| 9364 | outStats->component_0_sample.push_back(static_cast<int64_t>(s)); |
| 9365 | } |
| 9366 | outStats->component_1_sample.reserve(stats.component_1_sample.size()); |
| 9367 | for (const auto& s : stats.component_1_sample) { |
| 9368 | outStats->component_1_sample.push_back(static_cast<int64_t>(s)); |
| 9369 | } |
| 9370 | outStats->component_2_sample.reserve(stats.component_2_sample.size()); |
| 9371 | for (const auto& s : stats.component_2_sample) { |
| 9372 | outStats->component_2_sample.push_back(static_cast<int64_t>(s)); |
| 9373 | } |
| 9374 | outStats->component_3_sample.reserve(stats.component_3_sample.size()); |
| 9375 | for (const auto& s : stats.component_3_sample) { |
| 9376 | outStats->component_3_sample.push_back(static_cast<int64_t>(s)); |
| 9377 | } |
| 9378 | } |
| 9379 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9380 | } |
| 9381 | |
| 9382 | binder::Status SurfaceComposerAIDL::getProtectedContentSupport(bool* outSupported) { |
| 9383 | status_t status = mFlinger->getProtectedContentSupport(outSupported); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9384 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9385 | } |
| 9386 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9387 | binder::Status SurfaceComposerAIDL::isWideColorDisplay(const sp<IBinder>& token, |
| 9388 | bool* outIsWideColorDisplay) { |
| 9389 | status_t status = mFlinger->isWideColorDisplay(token, outIsWideColorDisplay); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9390 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9391 | } |
| 9392 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9393 | binder::Status SurfaceComposerAIDL::addRegionSamplingListener( |
| 9394 | const gui::ARect& samplingArea, const sp<IBinder>& stopLayerHandle, |
| 9395 | const sp<gui::IRegionSamplingListener>& listener) { |
| 9396 | status_t status = checkReadFrameBufferPermission(); |
| 9397 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9398 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9399 | } |
| 9400 | android::Rect rect; |
| 9401 | rect.left = samplingArea.left; |
| 9402 | rect.top = samplingArea.top; |
| 9403 | rect.right = samplingArea.right; |
| 9404 | rect.bottom = samplingArea.bottom; |
| 9405 | status = mFlinger->addRegionSamplingListener(rect, stopLayerHandle, listener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9406 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9407 | } |
| 9408 | |
| 9409 | binder::Status SurfaceComposerAIDL::removeRegionSamplingListener( |
| 9410 | const sp<gui::IRegionSamplingListener>& listener) { |
| 9411 | status_t status = checkReadFrameBufferPermission(); |
| 9412 | if (status == OK) { |
| 9413 | status = mFlinger->removeRegionSamplingListener(listener); |
| 9414 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9415 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9416 | } |
| 9417 | |
| 9418 | binder::Status SurfaceComposerAIDL::addFpsListener(int32_t taskId, |
| 9419 | const sp<gui::IFpsListener>& listener) { |
| 9420 | status_t status = checkReadFrameBufferPermission(); |
| 9421 | if (status == OK) { |
| 9422 | status = mFlinger->addFpsListener(taskId, listener); |
| 9423 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9424 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9425 | } |
| 9426 | |
| 9427 | binder::Status SurfaceComposerAIDL::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 9428 | status_t status = checkReadFrameBufferPermission(); |
| 9429 | if (status == OK) { |
| 9430 | status = mFlinger->removeFpsListener(listener); |
| 9431 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9432 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9433 | } |
| 9434 | |
| 9435 | binder::Status SurfaceComposerAIDL::addTunnelModeEnabledListener( |
| 9436 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 9437 | status_t status = checkAccessPermission(); |
| 9438 | if (status == OK) { |
| 9439 | status = mFlinger->addTunnelModeEnabledListener(listener); |
| 9440 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9441 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9442 | } |
| 9443 | |
| 9444 | binder::Status SurfaceComposerAIDL::removeTunnelModeEnabledListener( |
| 9445 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 9446 | status_t status = checkAccessPermission(); |
| 9447 | if (status == OK) { |
| 9448 | status = mFlinger->removeTunnelModeEnabledListener(listener); |
| 9449 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9450 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9451 | } |
| 9452 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 9453 | binder::Status SurfaceComposerAIDL::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 9454 | const gui::DisplayModeSpecs& specs) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9455 | status_t status = checkAccessPermission(); |
| 9456 | if (status == OK) { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 9457 | status = mFlinger->setDesiredDisplayModeSpecs(displayToken, specs); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9458 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9459 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9460 | } |
| 9461 | |
| 9462 | binder::Status SurfaceComposerAIDL::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 9463 | gui::DisplayModeSpecs* outSpecs) { |
| 9464 | if (!outSpecs) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9465 | return binderStatusFromStatusT(BAD_VALUE); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9466 | } |
| 9467 | |
| 9468 | status_t status = checkAccessPermission(); |
| 9469 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9470 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9471 | } |
| 9472 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 9473 | status = mFlinger->getDesiredDisplayModeSpecs(displayToken, outSpecs); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9474 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9475 | } |
| 9476 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9477 | binder::Status SurfaceComposerAIDL::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 9478 | bool* outSupport) { |
| 9479 | status_t status = mFlinger->getDisplayBrightnessSupport(displayToken, outSupport); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9480 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9481 | } |
| 9482 | |
| 9483 | binder::Status SurfaceComposerAIDL::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 9484 | const gui::DisplayBrightness& brightness) { |
| 9485 | status_t status = checkControlDisplayBrightnessPermission(); |
| 9486 | if (status == OK) { |
| 9487 | status = mFlinger->setDisplayBrightness(displayToken, brightness); |
| 9488 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9489 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9490 | } |
| 9491 | |
| 9492 | binder::Status SurfaceComposerAIDL::addHdrLayerInfoListener( |
| 9493 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 9494 | status_t status = checkControlDisplayBrightnessPermission(); |
| 9495 | if (status == OK) { |
| 9496 | status = mFlinger->addHdrLayerInfoListener(displayToken, listener); |
| 9497 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9498 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9499 | } |
| 9500 | |
| 9501 | binder::Status SurfaceComposerAIDL::removeHdrLayerInfoListener( |
| 9502 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 9503 | status_t status = checkControlDisplayBrightnessPermission(); |
| 9504 | if (status == OK) { |
| 9505 | status = mFlinger->removeHdrLayerInfoListener(displayToken, listener); |
| 9506 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9507 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9508 | } |
| 9509 | |
| 9510 | binder::Status SurfaceComposerAIDL::notifyPowerBoost(int boostId) { |
| 9511 | status_t status = checkAccessPermission(); |
| 9512 | if (status == OK) { |
| 9513 | status = mFlinger->notifyPowerBoost(boostId); |
| 9514 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9515 | return binderStatusFromStatusT(status); |
| 9516 | } |
| 9517 | |
| 9518 | binder::Status SurfaceComposerAIDL::setGlobalShadowSettings(const gui::Color& ambientColor, |
| 9519 | const gui::Color& spotColor, |
| 9520 | float lightPosY, float lightPosZ, |
| 9521 | float lightRadius) { |
| 9522 | status_t status = checkAccessPermission(); |
| 9523 | if (status != OK) { |
| 9524 | return binderStatusFromStatusT(status); |
| 9525 | } |
| 9526 | |
| 9527 | half4 ambientColorHalf = {ambientColor.r, ambientColor.g, ambientColor.b, ambientColor.a}; |
| 9528 | half4 spotColorHalf = {spotColor.r, spotColor.g, spotColor.b, spotColor.a}; |
| 9529 | status = mFlinger->setGlobalShadowSettings(ambientColorHalf, spotColorHalf, lightPosY, |
| 9530 | lightPosZ, lightRadius); |
| 9531 | return binderStatusFromStatusT(status); |
| 9532 | } |
| 9533 | |
| 9534 | binder::Status SurfaceComposerAIDL::getDisplayDecorationSupport( |
| 9535 | const sp<IBinder>& displayToken, std::optional<gui::DisplayDecorationSupport>* outSupport) { |
| 9536 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport> support; |
| 9537 | status_t status = mFlinger->getDisplayDecorationSupport(displayToken, &support); |
| 9538 | if (status != NO_ERROR) { |
| 9539 | ALOGE("getDisplayDecorationSupport failed with error %d", status); |
| 9540 | return binderStatusFromStatusT(status); |
| 9541 | } |
| 9542 | |
| 9543 | if (!support || !support.has_value()) { |
| 9544 | outSupport->reset(); |
| 9545 | } else { |
| 9546 | outSupport->emplace(); |
| 9547 | outSupport->value().format = static_cast<int32_t>(support->format); |
| 9548 | outSupport->value().alphaInterpretation = |
| 9549 | static_cast<int32_t>(support->alphaInterpretation); |
| 9550 | } |
| 9551 | |
| 9552 | return binder::Status::ok(); |
| 9553 | } |
| 9554 | |
| 9555 | binder::Status SurfaceComposerAIDL::setOverrideFrameRate(int32_t uid, float frameRate) { |
| 9556 | status_t status; |
| 9557 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 9558 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 9559 | status = mFlinger->setOverrideFrameRate(uid, frameRate); |
| 9560 | } else { |
| 9561 | ALOGE("setOverrideFrameRate() permission denied for uid: %d", c_uid); |
| 9562 | status = PERMISSION_DENIED; |
| 9563 | } |
| 9564 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9565 | } |
| 9566 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 9567 | binder::Status SurfaceComposerAIDL::enableRefreshRateOverlay(bool active) { |
| 9568 | mFlinger->sfdo_enableRefreshRateOverlay(active); |
| 9569 | return binder::Status::ok(); |
| 9570 | } |
| 9571 | |
| 9572 | binder::Status SurfaceComposerAIDL::setDebugFlash(int delay) { |
| 9573 | mFlinger->sfdo_setDebugFlash(delay); |
| 9574 | return binder::Status::ok(); |
| 9575 | } |
| 9576 | |
| 9577 | binder::Status SurfaceComposerAIDL::scheduleComposite() { |
| 9578 | mFlinger->sfdo_scheduleComposite(); |
| 9579 | return binder::Status::ok(); |
| 9580 | } |
| 9581 | |
| 9582 | binder::Status SurfaceComposerAIDL::scheduleCommit() { |
| 9583 | mFlinger->sfdo_scheduleCommit(); |
| 9584 | return binder::Status::ok(); |
| 9585 | } |
| 9586 | |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9587 | binder::Status SurfaceComposerAIDL::updateSmallAreaDetection(const std::vector<int32_t>& uids, |
| 9588 | const std::vector<float>& thresholds) { |
| 9589 | status_t status; |
| 9590 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 9591 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 9592 | if (uids.size() != thresholds.size()) return binderStatusFromStatusT(BAD_VALUE); |
| 9593 | |
| 9594 | std::vector<std::pair<uid_t, float>> mappings; |
| 9595 | const size_t size = uids.size(); |
| 9596 | mappings.reserve(size); |
| 9597 | for (int i = 0; i < size; i++) { |
| 9598 | auto row = std::make_pair(static_cast<uid_t>(uids[i]), thresholds[i]); |
| 9599 | mappings.push_back(row); |
| 9600 | } |
| 9601 | status = mFlinger->updateSmallAreaDetection(mappings); |
| 9602 | } else { |
| 9603 | ALOGE("updateSmallAreaDetection() permission denied for uid: %d", c_uid); |
| 9604 | status = PERMISSION_DENIED; |
| 9605 | } |
| 9606 | return binderStatusFromStatusT(status); |
| 9607 | } |
| 9608 | |
| 9609 | binder::Status SurfaceComposerAIDL::setSmallAreaDetectionThreshold(int32_t uid, float threshold) { |
| 9610 | status_t status; |
| 9611 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 9612 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 9613 | status = mFlinger->setSmallAreaDetectionThreshold(uid, threshold); |
| 9614 | } else { |
| 9615 | ALOGE("setSmallAreaDetectionThreshold() permission denied for uid: %d", c_uid); |
| 9616 | status = PERMISSION_DENIED; |
| 9617 | } |
| 9618 | return binderStatusFromStatusT(status); |
| 9619 | } |
| 9620 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9621 | binder::Status SurfaceComposerAIDL::getGpuContextPriority(int32_t* outPriority) { |
| 9622 | *outPriority = mFlinger->getGpuContextPriority(); |
| 9623 | return binder::Status::ok(); |
| 9624 | } |
| 9625 | |
| 9626 | binder::Status SurfaceComposerAIDL::getMaxAcquiredBufferCount(int32_t* buffers) { |
| 9627 | status_t status = mFlinger->getMaxAcquiredBufferCount(buffers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9628 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9629 | } |
| 9630 | |
| 9631 | binder::Status SurfaceComposerAIDL::addWindowInfosListener( |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 9632 | const sp<gui::IWindowInfosListener>& windowInfosListener, |
| 9633 | gui::WindowInfosListenerInfo* outInfo) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9634 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9635 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9636 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9637 | // TODO(b/270566761) update permissions check so that only system_server and shell can add |
| 9638 | // WindowInfosListeners |
| 9639 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 9640 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 9641 | status = mFlinger->addWindowInfosListener(windowInfosListener, outInfo); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9642 | } else { |
| 9643 | status = PERMISSION_DENIED; |
| 9644 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9645 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9646 | } |
| 9647 | |
| 9648 | binder::Status SurfaceComposerAIDL::removeWindowInfosListener( |
| 9649 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 9650 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9651 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9652 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9653 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 9654 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9655 | status = mFlinger->removeWindowInfosListener(windowInfosListener); |
| 9656 | } else { |
| 9657 | status = PERMISSION_DENIED; |
| 9658 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9659 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9660 | } |
| 9661 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 9662 | binder::Status SurfaceComposerAIDL::getStalledTransactionInfo( |
| 9663 | int pid, std::optional<gui::StalledTransactionInfo>* outInfo) { |
| 9664 | const int callingPid = IPCThreadState::self()->getCallingPid(); |
| 9665 | const int callingUid = IPCThreadState::self()->getCallingUid(); |
| 9666 | if (!checkPermission(sAccessSurfaceFlinger, callingPid, callingUid)) { |
| 9667 | return binderStatusFromStatusT(PERMISSION_DENIED); |
| 9668 | } |
| 9669 | |
| 9670 | std::optional<TransactionHandler::StalledTransactionInfo> stalledTransactionInfo; |
| 9671 | status_t status = mFlinger->getStalledTransactionInfo(pid, stalledTransactionInfo); |
| 9672 | if (stalledTransactionInfo) { |
| 9673 | gui::StalledTransactionInfo result; |
| 9674 | result.layerName = String16{stalledTransactionInfo->layerName.c_str()}, |
| 9675 | result.bufferId = stalledTransactionInfo->bufferId, |
| 9676 | result.frameNumber = stalledTransactionInfo->frameNumber, |
| 9677 | outInfo->emplace(std::move(result)); |
| 9678 | } else { |
| 9679 | outInfo->reset(); |
| 9680 | } |
| 9681 | return binderStatusFromStatusT(status); |
| 9682 | } |
| 9683 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9684 | status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { |
| 9685 | if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
| 9686 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9687 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", ipc->getCallingPid(), |
| 9688 | ipc->getCallingUid()); |
| 9689 | return PERMISSION_DENIED; |
| 9690 | } |
| 9691 | return OK; |
| 9692 | } |
| 9693 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9694 | status_t SurfaceComposerAIDL::checkControlDisplayBrightnessPermission() { |
| 9695 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9696 | const int pid = ipc->getCallingPid(); |
| 9697 | const int uid = ipc->getCallingUid(); |
Rheygine Medel | 9e9281e | 2022-09-22 10:13:56 -0700 | [diff] [blame] | 9698 | if ((uid != AID_GRAPHICS) && (uid != AID_SYSTEM) && |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9699 | !PermissionCache::checkPermission(sControlDisplayBrightness, pid, uid)) { |
| 9700 | ALOGE("Permission Denial: can't control brightness pid=%d, uid=%d", pid, uid); |
| 9701 | return PERMISSION_DENIED; |
| 9702 | } |
| 9703 | return OK; |
| 9704 | } |
| 9705 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9706 | status_t SurfaceComposerAIDL::checkReadFrameBufferPermission() { |
| 9707 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9708 | const int pid = ipc->getCallingPid(); |
| 9709 | const int uid = ipc->getCallingUid(); |
| 9710 | if ((uid != AID_GRAPHICS) && !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 9711 | ALOGE("Permission Denial: can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 9712 | return PERMISSION_DENIED; |
| 9713 | } |
| 9714 | return OK; |
| 9715 | } |
| 9716 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 9717 | void SurfaceFlinger::forceFutureUpdate(int delayInMs) { |
| 9718 | static_cast<void>(mScheduler->scheduleDelayed([&]() { scheduleRepaint(); }, ms2ns(delayInMs))); |
| 9719 | } |
| 9720 | |
Vishnu Nair | 2f65e97 | 2023-04-04 16:36:28 +0000 | [diff] [blame] | 9721 | const DisplayDevice* SurfaceFlinger::getDisplayFromLayerStack(ui::LayerStack layerStack) { |
| 9722 | for (const auto& [_, display] : mDisplays) { |
| 9723 | if (display->getLayerStack() == layerStack) { |
| 9724 | return display.get(); |
| 9725 | } |
| 9726 | } |
| 9727 | return nullptr; |
| 9728 | } |
| 9729 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 9730 | } // namespace android |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 9731 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 9732 | #if defined(__gl_h_) |
| 9733 | #error "don't include gl/gl.h in this file" |
| 9734 | #endif |
| 9735 | |
| 9736 | #if defined(__gl2_h_) |
| 9737 | #error "don't include gl2/gl2.h in this file" |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 9738 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 9739 | |
| 9740 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 9741 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |