Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 17 | #include <SurfaceFlingerProperties.sysprop.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 18 | #include <android-base/stringprintf.h> |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 19 | #include <common/FlagManager.h> |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 20 | #include <common/trace.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 21 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 22 | #include <compositionengine/CompositionRefreshArgs.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 23 | #include <compositionengine/DisplayColorProfile.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 24 | #include <compositionengine/LayerFE.h> |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 25 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 26 | #include <compositionengine/RenderSurface.h> |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 27 | #include <compositionengine/impl/HwcAsyncWorker.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 28 | #include <compositionengine/impl/Output.h> |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 29 | #include <compositionengine/impl/OutputCompositionState.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 30 | #include <compositionengine/impl/OutputLayer.h> |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 31 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 32 | #include <compositionengine/impl/planner/Planner.h> |
Leon Scroggins III | 370b8b5 | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 33 | #include <ftl/algorithm.h> |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 34 | #include <ftl/future.h> |
Brian Lindahl | 1a4ffd8 | 2024-10-30 11:00:37 -0600 | [diff] [blame] | 35 | #include <ftl/optional.h> |
Leon Scroggins III | 370b8b5 | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 36 | #include <scheduler/FrameTargeter.h> |
| 37 | #include <scheduler/Time.h> |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 38 | |
Brian Lindahl | 1a4ffd8 | 2024-10-30 11:00:37 -0600 | [diff] [blame] | 39 | #include <com_android_graphics_libgui_flags.h> |
| 40 | |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 41 | #include <optional> |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 42 | #include <thread> |
| 43 | |
| 44 | #include "renderengine/ExternalTexture.h" |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 45 | |
| 46 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 47 | #pragma clang diagnostic push |
| 48 | #pragma clang diagnostic ignored "-Wconversion" |
| 49 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 50 | #include <renderengine/DisplaySettings.h> |
| 51 | #include <renderengine/RenderEngine.h> |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 52 | |
| 53 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 54 | #pragma clang diagnostic pop // ignored "-Wconversion" |
| 55 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 56 | #include <android-base/properties.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 57 | #include <ui/DebugUtils.h> |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 58 | #include <ui/HdrCapabilities.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 59 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 60 | #include "TracedOrdinal.h" |
| 61 | |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 62 | using aidl::android::hardware::graphics::composer3::Composition; |
| 63 | |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 64 | namespace android::compositionengine { |
| 65 | |
| 66 | Output::~Output() = default; |
| 67 | |
| 68 | namespace impl { |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 69 | using CompositionStrategyPredictionState = |
| 70 | OutputCompositionState::CompositionStrategyPredictionState; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 71 | namespace { |
| 72 | |
| 73 | template <typename T> |
| 74 | class Reversed { |
| 75 | public: |
| 76 | explicit Reversed(const T& container) : mContainer(container) {} |
| 77 | auto begin() { return mContainer.rbegin(); } |
| 78 | auto end() { return mContainer.rend(); } |
| 79 | |
| 80 | private: |
| 81 | const T& mContainer; |
| 82 | }; |
| 83 | |
| 84 | // Helper for enumerating over a container in reverse order |
| 85 | template <typename T> |
| 86 | Reversed<T> reversed(const T& c) { |
| 87 | return Reversed<T>(c); |
| 88 | } |
| 89 | |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 90 | struct ScaleVector { |
| 91 | float x; |
| 92 | float y; |
| 93 | }; |
| 94 | |
| 95 | // Returns a ScaleVector (x, y) such that from.scale(x, y) = to', |
| 96 | // where to' will have the same size as "to". In the case where "from" and "to" |
| 97 | // start at the origin to'=to. |
| 98 | ScaleVector getScale(const Rect& from, const Rect& to) { |
| 99 | return {.x = static_cast<float>(to.width()) / from.width(), |
| 100 | .y = static_cast<float>(to.height()) / from.height()}; |
| 101 | } |
| 102 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 103 | } // namespace |
| 104 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 105 | std::shared_ptr<Output> createOutput( |
| 106 | const compositionengine::CompositionEngine& compositionEngine) { |
| 107 | return createOutputTemplated<Output>(compositionEngine); |
| 108 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 109 | |
| 110 | Output::~Output() = default; |
| 111 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 112 | bool Output::isValid() const { |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 113 | return mDisplayColorProfile && mDisplayColorProfile->isValid() && mRenderSurface && |
| 114 | mRenderSurface->isValid(); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Brian Lindahl | 1a4ffd8 | 2024-10-30 11:00:37 -0600 | [diff] [blame] | 117 | ftl::Optional<DisplayId> Output::getDisplayId() const { |
Lloyd Pique | 6c564cf | 2019-05-17 17:31:36 -0700 | [diff] [blame] | 118 | return {}; |
| 119 | } |
| 120 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 121 | const std::string& Output::getName() const { |
| 122 | return mName; |
| 123 | } |
| 124 | |
| 125 | void Output::setName(const std::string& name) { |
| 126 | mName = name; |
Leon Scroggins III | 5a655b8 | 2022-09-07 13:17:09 -0400 | [diff] [blame] | 127 | auto displayIdOpt = getDisplayId(); |
Leon Scroggins III | c03d465 | 2023-01-05 13:03:53 -0500 | [diff] [blame] | 128 | mNamePlusId = displayIdOpt ? base::StringPrintf("%s (%s)", mName.c_str(), |
| 129 | to_string(*displayIdOpt).c_str()) |
| 130 | : mName; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | void Output::setCompositionEnabled(bool enabled) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 134 | auto& outputState = editState(); |
| 135 | if (outputState.isEnabled == enabled) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 136 | return; |
| 137 | } |
| 138 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 139 | outputState.isEnabled = enabled; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 140 | dirtyEntireOutput(); |
| 141 | } |
| 142 | |
Alec Mouri | 023c188 | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 143 | void Output::setLayerCachingEnabled(bool enabled) { |
| 144 | if (enabled == (mPlanner != nullptr)) { |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | if (enabled) { |
Alec Mouri | df6201b | 2021-06-01 16:20:42 -0700 | [diff] [blame] | 149 | mPlanner = std::make_unique<planner::Planner>(getCompositionEngine().getRenderEngine()); |
Alec Mouri | 023c188 | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 150 | if (mRenderSurface) { |
| 151 | mPlanner->setDisplaySize(mRenderSurface->getSize()); |
| 152 | } |
| 153 | } else { |
| 154 | mPlanner.reset(); |
| 155 | } |
Alec Mouri | c773472b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 156 | |
| 157 | for (auto* outputLayer : getOutputLayersOrderedByZ()) { |
| 158 | if (!outputLayer) { |
| 159 | continue; |
| 160 | } |
| 161 | |
| 162 | outputLayer->editState().overrideInfo = {}; |
| 163 | } |
Alec Mouri | 023c188 | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 166 | void Output::setLayerCachingTexturePoolEnabled(bool enabled) { |
| 167 | if (mPlanner) { |
| 168 | mPlanner->setTexturePoolEnabled(enabled); |
| 169 | } |
| 170 | } |
| 171 | |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 172 | void Output::setProjection(ui::Rotation orientation, const Rect& layerStackSpaceRect, |
| 173 | const Rect& orientedDisplaySpaceRect) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 174 | auto& outputState = editState(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 175 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 176 | outputState.displaySpace.setOrientation(orientation); |
| 177 | LOG_FATAL_IF(outputState.displaySpace.getBoundsAsRect() == Rect::INVALID_RECT, |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 178 | "The display bounds are unknown."); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 179 | |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 180 | // Compute orientedDisplaySpace |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 181 | ui::Size orientedSize = outputState.displaySpace.getBounds(); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 182 | if (orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 183 | std::swap(orientedSize.width, orientedSize.height); |
| 184 | } |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 185 | outputState.orientedDisplaySpace.setBounds(orientedSize); |
| 186 | outputState.orientedDisplaySpace.setContent(orientedDisplaySpaceRect); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 187 | |
| 188 | // Compute displaySpace.content |
| 189 | const uint32_t transformOrientationFlags = ui::Transform::toRotationFlags(orientation); |
| 190 | ui::Transform rotation; |
| 191 | if (transformOrientationFlags != ui::Transform::ROT_INVALID) { |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 192 | const auto displaySize = outputState.displaySpace.getBoundsAsRect(); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 193 | rotation.set(transformOrientationFlags, displaySize.width(), displaySize.height()); |
| 194 | } |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 195 | outputState.displaySpace.setContent(rotation.transform(orientedDisplaySpaceRect)); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 196 | |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 197 | // Compute framebufferSpace |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 198 | outputState.framebufferSpace.setOrientation(orientation); |
| 199 | LOG_FATAL_IF(outputState.framebufferSpace.getBoundsAsRect() == Rect::INVALID_RECT, |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 200 | "The framebuffer bounds are unknown."); |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 201 | const auto scale = getScale(outputState.displaySpace.getBoundsAsRect(), |
| 202 | outputState.framebufferSpace.getBoundsAsRect()); |
| 203 | outputState.framebufferSpace.setContent( |
| 204 | outputState.displaySpace.getContent().scale(scale.x, scale.y)); |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 205 | |
| 206 | // Compute layerStackSpace |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 207 | outputState.layerStackSpace.setContent(layerStackSpaceRect); |
| 208 | outputState.layerStackSpace.setBounds( |
| 209 | ui::Size(layerStackSpaceRect.getWidth(), layerStackSpaceRect.getHeight())); |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 210 | |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 211 | outputState.transform = outputState.layerStackSpace.getTransform(outputState.displaySpace); |
| 212 | outputState.needsFiltering = outputState.transform.needsBilinearFiltering(); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 213 | dirtyEntireOutput(); |
| 214 | } |
| 215 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 216 | void Output::setNextBrightness(float brightness) { |
| 217 | editState().displayBrightness = brightness; |
| 218 | } |
| 219 | |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 220 | void Output::setDisplaySize(const ui::Size& size) { |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 221 | mRenderSurface->setDisplaySize(size); |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 222 | |
| 223 | auto& state = editState(); |
| 224 | |
| 225 | // Update framebuffer space |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 226 | const ui::Size newBounds(size); |
| 227 | state.framebufferSpace.setBounds(newBounds); |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 228 | |
| 229 | // Update display space |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 230 | state.displaySpace.setBounds(newBounds); |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 231 | state.transform = state.layerStackSpace.getTransform(state.displaySpace); |
| 232 | |
| 233 | // Update oriented display space |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 234 | const auto orientation = state.displaySpace.getOrientation(); |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 235 | ui::Size orientedSize = size; |
| 236 | if (orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270) { |
| 237 | std::swap(orientedSize.width, orientedSize.height); |
| 238 | } |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 239 | const ui::Size newOrientedBounds(orientedSize); |
| 240 | state.orientedDisplaySpace.setBounds(newOrientedBounds); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 241 | |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 242 | if (mPlanner) { |
| 243 | mPlanner->setDisplaySize(size); |
| 244 | } |
| 245 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 246 | dirtyEntireOutput(); |
| 247 | } |
| 248 | |
Garfield Tan | 54edd91 | 2020-10-21 16:31:41 -0700 | [diff] [blame] | 249 | ui::Transform::RotationFlags Output::getTransformHint() const { |
| 250 | return static_cast<ui::Transform::RotationFlags>(getState().transform.getOrientation()); |
| 251 | } |
| 252 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 253 | void Output::setLayerFilter(ui::LayerFilter filter) { |
| 254 | editState().layerFilter = filter; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 255 | dirtyEntireOutput(); |
| 256 | } |
| 257 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 258 | void Output::setColorTransform(const compositionengine::CompositionRefreshArgs& args) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 259 | auto& colorTransformMatrix = editState().colorTransformMatrix; |
| 260 | if (!args.colorTransformMatrix || colorTransformMatrix == args.colorTransformMatrix) { |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 261 | return; |
| 262 | } |
| 263 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 264 | colorTransformMatrix = *args.colorTransformMatrix; |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 265 | |
| 266 | dirtyEntireOutput(); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 269 | void Output::setColorProfile(const ColorProfile& colorProfile) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 270 | auto& outputState = editState(); |
| 271 | if (outputState.colorMode == colorProfile.mode && |
| 272 | outputState.dataspace == colorProfile.dataspace && |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 273 | outputState.renderIntent == colorProfile.renderIntent) { |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 274 | return; |
| 275 | } |
| 276 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 277 | outputState.colorMode = colorProfile.mode; |
| 278 | outputState.dataspace = colorProfile.dataspace; |
| 279 | outputState.renderIntent = colorProfile.renderIntent; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 280 | |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 281 | mRenderSurface->setBufferDataspace(colorProfile.dataspace); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 282 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 283 | ALOGV("Set active color mode: %s (%d), active render intent: %s (%d)", |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 284 | decodeColorMode(colorProfile.mode).c_str(), colorProfile.mode, |
| 285 | decodeRenderIntent(colorProfile.renderIntent).c_str(), colorProfile.renderIntent); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 286 | |
| 287 | dirtyEntireOutput(); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 288 | } |
| 289 | |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 290 | void Output::setDisplayBrightness(float sdrWhitePointNits, float displayBrightnessNits) { |
| 291 | auto& outputState = editState(); |
| 292 | if (outputState.sdrWhitePointNits == sdrWhitePointNits && |
| 293 | outputState.displayBrightnessNits == displayBrightnessNits) { |
| 294 | // Nothing changed |
| 295 | return; |
| 296 | } |
| 297 | outputState.sdrWhitePointNits = sdrWhitePointNits; |
| 298 | outputState.displayBrightnessNits = displayBrightnessNits; |
| 299 | dirtyEntireOutput(); |
| 300 | } |
| 301 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 302 | void Output::dump(std::string& out) const { |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 303 | base::StringAppendF(&out, "Output \"%s\"", mName.c_str()); |
| 304 | out.append("\n Composition Output State:\n"); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 305 | |
| 306 | dumpBase(out); |
| 307 | } |
| 308 | |
| 309 | void Output::dumpBase(std::string& out) const { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 310 | dumpState(out); |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 311 | out += '\n'; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 312 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 313 | if (mDisplayColorProfile) { |
| 314 | mDisplayColorProfile->dump(out); |
| 315 | } else { |
| 316 | out.append(" No display color profile!\n"); |
| 317 | } |
| 318 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 319 | out += '\n'; |
| 320 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 321 | if (mRenderSurface) { |
| 322 | mRenderSurface->dump(out); |
| 323 | } else { |
| 324 | out.append(" No render surface!\n"); |
| 325 | } |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 326 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 327 | base::StringAppendF(&out, "\n %zu Layers\n", getOutputLayerCount()); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 328 | for (const auto* outputLayer : getOutputLayersOrderedByZ()) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 329 | if (!outputLayer) { |
| 330 | continue; |
| 331 | } |
| 332 | outputLayer->dump(out); |
| 333 | } |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 336 | void Output::dumpPlannerInfo(const Vector<String16>& args, std::string& out) const { |
| 337 | if (!mPlanner) { |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 338 | out.append("Planner is disabled\n"); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 339 | return; |
| 340 | } |
| 341 | base::StringAppendF(&out, "Planner info for display [%s]\n", mName.c_str()); |
| 342 | mPlanner->dump(args, out); |
| 343 | } |
| 344 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 345 | compositionengine::DisplayColorProfile* Output::getDisplayColorProfile() const { |
| 346 | return mDisplayColorProfile.get(); |
| 347 | } |
| 348 | |
| 349 | void Output::setDisplayColorProfile(std::unique_ptr<compositionengine::DisplayColorProfile> mode) { |
| 350 | mDisplayColorProfile = std::move(mode); |
| 351 | } |
| 352 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 353 | const Output::ReleasedLayers& Output::getReleasedLayersForTest() const { |
| 354 | return mReleasedLayers; |
| 355 | } |
| 356 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 357 | void Output::setDisplayColorProfileForTest( |
| 358 | std::unique_ptr<compositionengine::DisplayColorProfile> mode) { |
| 359 | mDisplayColorProfile = std::move(mode); |
| 360 | } |
| 361 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 362 | compositionengine::RenderSurface* Output::getRenderSurface() const { |
| 363 | return mRenderSurface.get(); |
| 364 | } |
| 365 | |
| 366 | void Output::setRenderSurface(std::unique_ptr<compositionengine::RenderSurface> surface) { |
| 367 | mRenderSurface = std::move(surface); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 368 | const auto size = mRenderSurface->getSize(); |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 369 | editState().framebufferSpace.setBounds(size); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 370 | if (mPlanner) { |
| 371 | mPlanner->setDisplaySize(size); |
| 372 | } |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 373 | dirtyEntireOutput(); |
| 374 | } |
| 375 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 376 | void Output::cacheClientCompositionRequests(uint32_t cacheSize) { |
| 377 | if (cacheSize == 0) { |
| 378 | mClientCompositionRequestCache.reset(); |
| 379 | } else { |
| 380 | mClientCompositionRequestCache = std::make_unique<ClientCompositionRequestCache>(cacheSize); |
| 381 | } |
| 382 | }; |
| 383 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 384 | void Output::setRenderSurfaceForTest(std::unique_ptr<compositionengine::RenderSurface> surface) { |
| 385 | mRenderSurface = std::move(surface); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 388 | Region Output::getDirtyRegion() const { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 389 | const auto& outputState = getState(); |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 390 | return outputState.dirtyRegion.intersect(outputState.layerStackSpace.getContent()); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 393 | bool Output::includesLayer(ui::LayerFilter filter) const { |
| 394 | return getState().layerFilter.includes(filter); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 397 | bool Output::includesLayer(const sp<LayerFE>& layerFE) const { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 398 | const auto* layerFEState = layerFE->getCompositionState(); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 399 | return layerFEState && includesLayer(layerFEState->outputFilter); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 400 | } |
| 401 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 402 | std::unique_ptr<compositionengine::OutputLayer> Output::createOutputLayer( |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 403 | const sp<LayerFE>& layerFE) const { |
| 404 | return impl::createOutputLayer(*this, layerFE); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 407 | compositionengine::OutputLayer* Output::getOutputLayerForLayer(const sp<LayerFE>& layerFE) const { |
| 408 | auto index = findCurrentOutputLayerForLayer(layerFE); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 409 | return index ? getOutputLayerOrderedByZByIndex(*index) : nullptr; |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 412 | std::optional<size_t> Output::findCurrentOutputLayerForLayer( |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 413 | const sp<compositionengine::LayerFE>& layer) const { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 414 | for (size_t i = 0; i < getOutputLayerCount(); i++) { |
| 415 | auto outputLayer = getOutputLayerOrderedByZByIndex(i); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 416 | if (outputLayer && &outputLayer->getLayerFE() == layer.get()) { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 417 | return i; |
| 418 | } |
| 419 | } |
| 420 | return std::nullopt; |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 421 | } |
| 422 | |
Lloyd Pique | c7ef21b | 2019-01-29 18:43:00 -0800 | [diff] [blame] | 423 | void Output::setReleasedLayers(Output::ReleasedLayers&& layers) { |
| 424 | mReleasedLayers = std::move(layers); |
| 425 | } |
| 426 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 427 | void Output::prepare(const compositionengine::CompositionRefreshArgs& refreshArgs, |
| 428 | LayerFESet& geomSnapshots) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 429 | SFTRACE_CALL(); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 430 | ALOGV(__FUNCTION__); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 431 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 432 | rebuildLayerStacks(refreshArgs, geomSnapshots); |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 433 | uncacheBuffers(refreshArgs.bufferIdsToUncache); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 436 | ftl::Future<std::monostate> Output::present( |
| 437 | const compositionengine::CompositionRefreshArgs& refreshArgs) { |
Leon Scroggins III | 370b8b5 | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 438 | const auto stringifyExpectedPresentTime = [this, &refreshArgs]() -> std::string { |
Brian Lindahl | 1a4ffd8 | 2024-10-30 11:00:37 -0600 | [diff] [blame] | 439 | return getDisplayId() |
Leon Scroggins III | 370b8b5 | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 440 | .and_then(PhysicalDisplayId::tryCast) |
| 441 | .and_then([&refreshArgs](PhysicalDisplayId id) { |
| 442 | return refreshArgs.frameTargets.get(id); |
| 443 | }) |
| 444 | .transform([](const auto& frameTargetPtr) { |
| 445 | return frameTargetPtr.get()->expectedPresentTime(); |
| 446 | }) |
| 447 | .transform([](TimePoint expectedPresentTime) { |
| 448 | return base::StringPrintf(" vsyncIn %.2fms", |
| 449 | ticks<std::milli, float>(expectedPresentTime - |
| 450 | TimePoint::now())); |
| 451 | }) |
| 452 | .or_else([] { |
| 453 | // There is no vsync for this output. |
| 454 | return std::make_optional(std::string()); |
| 455 | }) |
| 456 | .value(); |
| 457 | }; |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 458 | SFTRACE_FORMAT("%s for %s%s", __func__, mNamePlusId.c_str(), |
| 459 | stringifyExpectedPresentTime().c_str()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 460 | ALOGV(__FUNCTION__); |
| 461 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 462 | updateColorProfile(refreshArgs); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 463 | updateCompositionState(refreshArgs); |
| 464 | planComposition(); |
| 465 | writeCompositionState(refreshArgs); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 466 | setColorTransform(refreshArgs); |
Lloyd Pique | d7b429f | 2019-03-07 21:11:02 -0800 | [diff] [blame] | 467 | beginFrame(); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 468 | |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 469 | if (isPowerHintSessionEnabled()) { |
| 470 | // always reset the flag before the composition prediction |
| 471 | setHintSessionRequiresRenderEngine(false); |
| 472 | } |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 473 | GpuCompositionResult result; |
| 474 | const bool predictCompositionStrategy = canPredictCompositionStrategy(refreshArgs); |
| 475 | if (predictCompositionStrategy) { |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 476 | result = prepareFrameAsync(); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 477 | } else { |
| 478 | prepareFrame(); |
| 479 | } |
| 480 | |
Lloyd Pique | d7b429f | 2019-03-07 21:11:02 -0800 | [diff] [blame] | 481 | devOptRepaintFlash(refreshArgs); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 482 | finishFrame(std::move(result)); |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 483 | ftl::Future<std::monostate> future; |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 484 | const bool flushEvenWhenDisabled = !refreshArgs.bufferIdsToUncache.empty(); |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 485 | if (mOffloadPresent) { |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 486 | future = presentFrameAndReleaseLayersAsync(flushEvenWhenDisabled); |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 487 | |
| 488 | // Only offload for this frame. The next frame will determine whether it |
| 489 | // needs to be offloaded. Leave the HwcAsyncWorker in place. For one thing, |
| 490 | // it is currently presenting. Further, it may be needed next frame, and |
| 491 | // we don't want to churn. |
| 492 | mOffloadPresent = false; |
| 493 | } else { |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 494 | presentFrameAndReleaseLayers(flushEvenWhenDisabled); |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 495 | future = ftl::yield<std::monostate>({}); |
| 496 | } |
Alec Mouri | aa83158 | 2021-06-07 16:23:01 -0700 | [diff] [blame] | 497 | renderCachedSets(refreshArgs); |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 498 | return future; |
| 499 | } |
| 500 | |
| 501 | void Output::offloadPresentNextFrame() { |
| 502 | mOffloadPresent = true; |
| 503 | updateHwcAsyncWorker(); |
Lloyd Pique | d7b429f | 2019-03-07 21:11:02 -0800 | [diff] [blame] | 504 | } |
| 505 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 506 | void Output::rebuildLayerStacks(const compositionengine::CompositionRefreshArgs& refreshArgs, |
| 507 | LayerFESet& layerFESet) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 508 | auto& outputState = editState(); |
| 509 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 510 | // Do nothing if this output is not enabled or there is no need to perform this update |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 511 | if (!outputState.isEnabled || CC_LIKELY(!refreshArgs.updatingOutputGeometryThisFrame)) { |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 512 | return; |
| 513 | } |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 514 | SFTRACE_CALL(); |
Vishnu Nair | d9a640b | 2023-07-21 14:20:27 +0000 | [diff] [blame] | 515 | ALOGV(__FUNCTION__); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 516 | |
| 517 | // Process the layers to determine visibility and coverage |
| 518 | compositionengine::Output::CoverageState coverage{layerFESet}; |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 519 | coverage.aboveCoveredLayersExcludingOverlays = refreshArgs.hasTrustedPresentationListener |
| 520 | ? std::make_optional<Region>() |
| 521 | : std::nullopt; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 522 | collectVisibleLayers(refreshArgs, coverage); |
| 523 | |
| 524 | // Compute the resulting coverage for this output, and store it for later |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 525 | const ui::Transform& tr = outputState.transform; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 526 | Region undefinedRegion{outputState.displaySpace.getBoundsAsRect()}; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 527 | undefinedRegion.subtractSelf(tr.transform(coverage.aboveOpaqueLayers)); |
| 528 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 529 | outputState.undefinedRegion = undefinedRegion; |
| 530 | outputState.dirtyRegion.orSelf(coverage.dirtyRegion); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | void Output::collectVisibleLayers(const compositionengine::CompositionRefreshArgs& refreshArgs, |
| 534 | compositionengine::Output::CoverageState& coverage) { |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 535 | // Evaluate the layers from front to back to determine what is visible. This |
| 536 | // also incrementally calculates the coverage information for each layer as |
| 537 | // well as the entire output. |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 538 | for (auto layer : reversed(refreshArgs.layers)) { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 539 | // Incrementally process the coverage for each layer |
| 540 | ensureOutputLayerIfVisible(layer, coverage); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 541 | |
| 542 | // TODO(b/121291683): Stop early if the output is completely covered and |
| 543 | // no more layers could even be visible underneath the ones on top. |
| 544 | } |
| 545 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 546 | setReleasedLayers(refreshArgs); |
| 547 | |
| 548 | finalizePendingOutputLayers(); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 549 | } |
| 550 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 551 | void Output::ensureOutputLayerIfVisible(sp<compositionengine::LayerFE>& layerFE, |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 552 | compositionengine::Output::CoverageState& coverage) { |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 553 | // Ensure we have a snapshot of the basic geometry layer state. Limit the |
| 554 | // snapshots to once per frame for each candidate layer, as layers may |
| 555 | // appear on multiple outputs. |
| 556 | if (!coverage.latchedLayers.count(layerFE)) { |
| 557 | coverage.latchedLayers.insert(layerFE); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 558 | } |
| 559 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 560 | // Only consider the layers on this output |
| 561 | if (!includesLayer(layerFE)) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 562 | return; |
| 563 | } |
| 564 | |
| 565 | // Obtain a read-only pointer to the front-end layer state |
| 566 | const auto* layerFEState = layerFE->getCompositionState(); |
| 567 | if (CC_UNLIKELY(!layerFEState)) { |
| 568 | return; |
| 569 | } |
| 570 | |
| 571 | // handle hidden surfaces by setting the visible region to empty |
| 572 | if (CC_UNLIKELY(!layerFEState->isVisible)) { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 573 | return; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 574 | } |
| 575 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 576 | bool computeAboveCoveredExcludingOverlays = coverage.aboveCoveredLayersExcludingOverlays && |
| 577 | !layerFEState->outputFilter.toInternalDisplay; |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 578 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 579 | /* |
| 580 | * opaqueRegion: area of a surface that is fully opaque. |
| 581 | */ |
| 582 | Region opaqueRegion; |
| 583 | |
| 584 | /* |
| 585 | * visibleRegion: area of a surface that is visible on screen and not fully |
| 586 | * transparent. This is essentially the layer's footprint minus the opaque |
| 587 | * regions above it. Areas covered by a translucent surface are considered |
| 588 | * visible. |
| 589 | */ |
| 590 | Region visibleRegion; |
| 591 | |
| 592 | /* |
| 593 | * coveredRegion: area of a surface that is covered by all visible regions |
| 594 | * above it (which includes the translucent areas). |
| 595 | */ |
| 596 | Region coveredRegion; |
| 597 | |
| 598 | /* |
| 599 | * transparentRegion: area of a surface that is hinted to be completely |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 600 | * transparent. |
| 601 | * This is used to tell when the layer has no visible non-transparent |
| 602 | * regions and can be removed from the layer list. It does not affect the |
| 603 | * visibleRegion of this layer or any layers beneath it. The hint may not |
| 604 | * be correct if apps don't respect the SurfaceView restrictions (which, |
| 605 | * sadly, some don't). |
| 606 | * |
| 607 | * In addition, it is used on DISPLAY_DECORATION layers to specify the |
| 608 | * blockingRegion, allowing the DPU to skip it to save power. Once we have |
| 609 | * hardware that supports a blockingRegion on frames with AFBC, it may be |
| 610 | * useful to use this for other layers, too, so long as we can prevent |
| 611 | * regressions on b/7179570. |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 612 | */ |
| 613 | Region transparentRegion; |
| 614 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 615 | /* |
| 616 | * shadowRegion: Region cast by the layer's shadow. |
| 617 | */ |
| 618 | Region shadowRegion; |
| 619 | |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 620 | /** |
| 621 | * covered region above excluding internal display overlay layers |
| 622 | */ |
| 623 | std::optional<Region> coveredRegionExcludingDisplayOverlays = std::nullopt; |
| 624 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 625 | const ui::Transform& tr = layerFEState->geomLayerTransform; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 626 | |
| 627 | // Get the visible region |
| 628 | // TODO(b/121291683): Is it worth creating helper methods on LayerFEState |
| 629 | // for computations like this? |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 630 | const Rect visibleRect(tr.transform(layerFEState->geomLayerBounds)); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 631 | visibleRegion.set(visibleRect); |
| 632 | |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 633 | if (layerFEState->shadowSettings.length > 0.0f) { |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 634 | // if the layer casts a shadow, offset the layers visible region and |
| 635 | // calculate the shadow region. |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 636 | const auto inset = static_cast<int32_t>(ceilf(layerFEState->shadowSettings.length) * -1.0f); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 637 | Rect visibleRectWithShadows(visibleRect); |
| 638 | visibleRectWithShadows.inset(inset, inset, inset, inset); |
| 639 | visibleRegion.set(visibleRectWithShadows); |
| 640 | shadowRegion = visibleRegion.subtract(visibleRect); |
| 641 | } |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 642 | |
| 643 | if (visibleRegion.isEmpty()) { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 644 | return; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | // Remove the transparent area from the visible region |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 648 | if (!layerFEState->isOpaque) { |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 649 | if (tr.preserveRects()) { |
Alec Mouri | e60f0b9 | 2022-06-10 19:15:20 +0000 | [diff] [blame] | 650 | // Clip the transparent region to geomLayerBounds first |
| 651 | // The transparent region may be influenced by applications, for |
| 652 | // instance, by overriding ViewGroup#gatherTransparentRegion with a |
| 653 | // custom view. Once the layer stack -> display mapping is known, we |
| 654 | // must guard against very wrong inputs to prevent underflow or |
| 655 | // overflow errors. We do this here by constraining the transparent |
| 656 | // region to be within the pre-transform layer bounds, since the |
| 657 | // layer bounds are expected to play nicely with the full |
| 658 | // transform. |
| 659 | const Region clippedTransparentRegionHint = |
| 660 | layerFEState->transparentRegionHint.intersect( |
| 661 | Rect(layerFEState->geomLayerBounds)); |
| 662 | |
| 663 | if (clippedTransparentRegionHint.isEmpty()) { |
| 664 | if (!layerFEState->transparentRegionHint.isEmpty()) { |
| 665 | ALOGD("Layer: %s had an out of bounds transparent region", |
| 666 | layerFE->getDebugName()); |
| 667 | layerFEState->transparentRegionHint.dump("transparentRegionHint"); |
| 668 | } |
| 669 | transparentRegion.clear(); |
| 670 | } else { |
| 671 | transparentRegion = tr.transform(clippedTransparentRegionHint); |
| 672 | } |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 673 | } else { |
| 674 | // transformation too complex, can't do the |
| 675 | // transparent region optimization. |
| 676 | transparentRegion.clear(); |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | // compute the opaque region |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 681 | const auto layerOrientation = tr.getOrientation(); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 682 | if (layerFEState->isOpaque && ((layerOrientation & ui::Transform::ROT_INVALID) == 0)) { |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 683 | // If we one of the simple category of transforms (0/90/180/270 rotation |
| 684 | // + any flip), then the opaque region is the layer's footprint. |
| 685 | // Otherwise we don't try and compute the opaque region since there may |
| 686 | // be errors at the edges, and we treat the entire layer as |
| 687 | // translucent. |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 688 | opaqueRegion.set(visibleRect); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | // Clip the covered region to the visible region |
| 692 | coveredRegion = coverage.aboveCoveredLayers.intersect(visibleRegion); |
| 693 | |
| 694 | // Update accumAboveCoveredLayers for next (lower) layer |
| 695 | coverage.aboveCoveredLayers.orSelf(visibleRegion); |
| 696 | |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 697 | if (CC_UNLIKELY(computeAboveCoveredExcludingOverlays)) { |
| 698 | coveredRegionExcludingDisplayOverlays = |
| 699 | coverage.aboveCoveredLayersExcludingOverlays->intersect(visibleRegion); |
| 700 | coverage.aboveCoveredLayersExcludingOverlays->orSelf(visibleRegion); |
| 701 | } |
| 702 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 703 | // subtract the opaque region covered by the layers above us |
| 704 | visibleRegion.subtractSelf(coverage.aboveOpaqueLayers); |
| 705 | |
| 706 | if (visibleRegion.isEmpty()) { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 707 | return; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | // Get coverage information for the layer as previously displayed, |
| 711 | // also taking over ownership from mOutputLayersorderedByZ. |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 712 | auto prevOutputLayerIndex = findCurrentOutputLayerForLayer(layerFE); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 713 | auto prevOutputLayer = |
| 714 | prevOutputLayerIndex ? getOutputLayerOrderedByZByIndex(*prevOutputLayerIndex) : nullptr; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 715 | |
| 716 | // Get coverage information for the layer as previously displayed |
| 717 | // TODO(b/121291683): Define kEmptyRegion as a constant in Region.h |
| 718 | const Region kEmptyRegion; |
| 719 | const Region& oldVisibleRegion = |
| 720 | prevOutputLayer ? prevOutputLayer->getState().visibleRegion : kEmptyRegion; |
| 721 | const Region& oldCoveredRegion = |
| 722 | prevOutputLayer ? prevOutputLayer->getState().coveredRegion : kEmptyRegion; |
| 723 | |
| 724 | // compute this layer's dirty region |
| 725 | Region dirty; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 726 | if (layerFEState->contentDirty) { |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 727 | // we need to invalidate the whole region |
| 728 | dirty = visibleRegion; |
| 729 | // as well, as the old visible region |
| 730 | dirty.orSelf(oldVisibleRegion); |
| 731 | } else { |
| 732 | /* compute the exposed region: |
| 733 | * the exposed region consists of two components: |
| 734 | * 1) what's VISIBLE now and was COVERED before |
| 735 | * 2) what's EXPOSED now less what was EXPOSED before |
| 736 | * |
| 737 | * note that (1) is conservative, we start with the whole visible region |
| 738 | * but only keep what used to be covered by something -- which mean it |
| 739 | * may have been exposed. |
| 740 | * |
| 741 | * (2) handles areas that were not covered by anything but got exposed |
| 742 | * because of a resize. |
| 743 | * |
| 744 | */ |
| 745 | const Region newExposed = visibleRegion - coveredRegion; |
| 746 | const Region oldExposed = oldVisibleRegion - oldCoveredRegion; |
| 747 | dirty = (visibleRegion & oldCoveredRegion) | (newExposed - oldExposed); |
| 748 | } |
| 749 | dirty.subtractSelf(coverage.aboveOpaqueLayers); |
| 750 | |
| 751 | // accumulate to the screen dirty region |
| 752 | coverage.dirtyRegion.orSelf(dirty); |
| 753 | |
| 754 | // Update accumAboveOpaqueLayers for next (lower) layer |
| 755 | coverage.aboveOpaqueLayers.orSelf(opaqueRegion); |
| 756 | |
| 757 | // Compute the visible non-transparent region |
| 758 | Region visibleNonTransparentRegion = visibleRegion.subtract(transparentRegion); |
| 759 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 760 | // Perform the final check to see if this layer is visible on this output |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 761 | // TODO(b/121291683): Why does this not use visibleRegion? (see outputSpaceVisibleRegion below) |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 762 | const auto& outputState = getState(); |
| 763 | Region drawRegion(outputState.transform.transform(visibleNonTransparentRegion)); |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 764 | drawRegion.andSelf(outputState.displaySpace.getBoundsAsRect()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 765 | if (drawRegion.isEmpty()) { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 766 | return; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 767 | } |
| 768 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 769 | Region visibleNonShadowRegion = visibleRegion.subtract(shadowRegion); |
| 770 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 771 | // The layer is visible. Either reuse the existing outputLayer if we have |
| 772 | // one, or create a new one if we do not. |
Brian Lindahl | 1a4ffd8 | 2024-10-30 11:00:37 -0600 | [diff] [blame] | 773 | auto outputLayer = ensureOutputLayer(prevOutputLayerIndex, layerFE); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 774 | |
| 775 | // Store the layer coverage information into the layer state as some of it |
| 776 | // is useful later. |
Brian Lindahl | 1a4ffd8 | 2024-10-30 11:00:37 -0600 | [diff] [blame] | 777 | auto& outputLayerState = outputLayer->editState(); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 778 | outputLayerState.visibleRegion = visibleRegion; |
| 779 | outputLayerState.visibleNonTransparentRegion = visibleNonTransparentRegion; |
| 780 | outputLayerState.coveredRegion = coveredRegion; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 781 | outputLayerState.outputSpaceVisibleRegion = outputState.transform.transform( |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 782 | visibleNonShadowRegion.intersect(outputState.layerStackSpace.getContent())); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 783 | outputLayerState.shadowRegion = shadowRegion; |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 784 | outputLayerState.outputSpaceBlockingRegionHint = |
Leon Scroggins III | 7f7ad2c | 2022-03-17 17:06:20 -0400 | [diff] [blame] | 785 | layerFEState->compositionType == Composition::DISPLAY_DECORATION |
| 786 | ? outputState.transform.transform( |
| 787 | transparentRegion.intersect(outputState.layerStackSpace.getContent())) |
| 788 | : Region(); |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 789 | if (CC_UNLIKELY(computeAboveCoveredExcludingOverlays)) { |
| 790 | outputLayerState.coveredRegionExcludingDisplayOverlays = |
| 791 | std::move(coveredRegionExcludingDisplayOverlays); |
| 792 | } |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Brian Lindahl | 1a4ffd8 | 2024-10-30 11:00:37 -0600 | [diff] [blame] | 795 | void Output::uncacheBuffers(std::vector<uint64_t> const& bufferIdsToUncache) { |
| 796 | if (bufferIdsToUncache.empty()) { |
| 797 | return; |
| 798 | } |
| 799 | for (auto outputLayer : getOutputLayersOrderedByZ()) { |
| 800 | outputLayer->uncacheBuffers(bufferIdsToUncache); |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | void Output::commitPictureProfilesToCompositionState() { |
| 805 | if (!com_android_graphics_libgui_flags_apply_picture_profiles()) { |
| 806 | return; |
| 807 | } |
| 808 | if (!hasPictureProcessing()) { |
| 809 | return; |
| 810 | } |
| 811 | auto compare = [](const ::android::compositionengine::OutputLayer* lhs, |
| 812 | const ::android::compositionengine::OutputLayer* rhs) { |
| 813 | return lhs->getPictureProfilePriority() > rhs->getPictureProfilePriority(); |
| 814 | }; |
| 815 | std::priority_queue<::android::compositionengine::OutputLayer*, |
| 816 | std::vector<::android::compositionengine::OutputLayer*>, decltype(compare)> |
| 817 | layersWithProfiles; |
| 818 | for (auto outputLayer : getOutputLayersOrderedByZ()) { |
| 819 | if (outputLayer->getPictureProfileHandle()) { |
| 820 | layersWithProfiles.push(outputLayer); |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | // TODO(b/337330263): Use the default display picture profile from SurfaceFlinger |
| 825 | editState().pictureProfileHandle = PictureProfileHandle::NONE; |
| 826 | |
| 827 | // When layer-specific picture processing is supported, apply as many high priority profiles as |
| 828 | // possible to the layers, and ignore the low priority layers. |
| 829 | if (getMaxLayerPictureProfiles() > 0) { |
| 830 | for (int i = 0; i < getMaxLayerPictureProfiles() && !layersWithProfiles.empty(); |
| 831 | layersWithProfiles.pop(), ++i) { |
| 832 | layersWithProfiles.top()->commitPictureProfileToCompositionState(); |
| 833 | } |
| 834 | // No layer-specific picture processing, so apply the highest priority picture profile to |
| 835 | // the entire display. |
| 836 | } else if (!layersWithProfiles.empty()) { |
| 837 | editState().pictureProfileHandle = layersWithProfiles.top()->getPictureProfileHandle(); |
| 838 | } |
| 839 | } |
| 840 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 841 | void Output::setReleasedLayers(const compositionengine::CompositionRefreshArgs&) { |
| 842 | // The base class does nothing with this call. |
| 843 | } |
| 844 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 845 | void Output::updateCompositionState(const compositionengine::CompositionRefreshArgs& refreshArgs) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 846 | SFTRACE_CALL(); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 847 | ALOGV(__FUNCTION__); |
| 848 | |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 849 | if (!getState().isEnabled) { |
| 850 | return; |
| 851 | } |
| 852 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 853 | mLayerRequestingBackgroundBlur = findLayerRequestingBackgroundComposition(); |
| 854 | bool forceClientComposition = mLayerRequestingBackgroundBlur != nullptr; |
| 855 | |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 856 | auto* properties = getOverlaySupport(); |
| 857 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 858 | for (auto* layer : getOutputLayersOrderedByZ()) { |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 859 | layer->updateCompositionState(refreshArgs.updatingGeometryThisFrame, |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 860 | refreshArgs.devOptForceClientComposition || |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 861 | forceClientComposition, |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 862 | refreshArgs.internalDisplayRotationFlags, |
| 863 | properties ? properties->lutProperties : std::nullopt); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 864 | |
| 865 | if (mLayerRequestingBackgroundBlur == layer) { |
| 866 | forceClientComposition = false; |
| 867 | } |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 868 | } |
Brian Lindahl | 1a4ffd8 | 2024-10-30 11:00:37 -0600 | [diff] [blame] | 869 | commitPictureProfilesToCompositionState(); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 870 | } |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 871 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 872 | void Output::planComposition() { |
| 873 | if (!mPlanner || !getState().isEnabled) { |
| 874 | return; |
| 875 | } |
| 876 | |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 877 | SFTRACE_CALL(); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 878 | ALOGV(__FUNCTION__); |
| 879 | |
| 880 | mPlanner->plan(getOutputLayersOrderedByZ()); |
| 881 | } |
| 882 | |
| 883 | void Output::writeCompositionState(const compositionengine::CompositionRefreshArgs& refreshArgs) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 884 | SFTRACE_CALL(); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 885 | ALOGV(__FUNCTION__); |
| 886 | |
| 887 | if (!getState().isEnabled) { |
| 888 | return; |
| 889 | } |
| 890 | |
Brian Lindahl | 1a4ffd8 | 2024-10-30 11:00:37 -0600 | [diff] [blame] | 891 | if (auto frameTargetPtrOpt = getDisplayId() |
Leon Scroggins III | 370b8b5 | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 892 | .and_then(PhysicalDisplayId::tryCast) |
| 893 | .and_then([&refreshArgs](PhysicalDisplayId id) { |
| 894 | return refreshArgs.frameTargets.get(id); |
| 895 | })) { |
| 896 | editState().earliestPresentTime = frameTargetPtrOpt->get()->earliestPresentTime(); |
| 897 | editState().expectedPresentTime = frameTargetPtrOpt->get()->expectedPresentTime().ns(); |
| 898 | } |
ramindani | 4aac32c | 2023-10-30 14:13:30 -0700 | [diff] [blame] | 899 | editState().frameInterval = refreshArgs.frameInterval; |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 900 | editState().powerCallback = refreshArgs.powerCallback; |
Ady Abraham | 3645e64 | 2021-04-20 18:39:00 -0700 | [diff] [blame] | 901 | |
Brian Lindahl | 1a4ffd8 | 2024-10-30 11:00:37 -0600 | [diff] [blame] | 902 | applyPictureProfile(); |
| 903 | |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 904 | compositionengine::OutputLayer* peekThroughLayer = nullptr; |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 905 | sp<GraphicBuffer> previousOverride = nullptr; |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 906 | bool includeGeometry = refreshArgs.updatingGeometryThisFrame; |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 907 | uint32_t z = 0; |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 908 | bool overrideZ = false; |
Robert Carr | ec8ccca | 2022-05-04 09:36:14 -0700 | [diff] [blame] | 909 | uint64_t outputLayerHash = 0; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 910 | for (auto* layer : getOutputLayersOrderedByZ()) { |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 911 | if (layer == peekThroughLayer) { |
| 912 | // No longer needed, although it should not show up again, so |
| 913 | // resetting it is not truly needed either. |
| 914 | peekThroughLayer = nullptr; |
| 915 | |
| 916 | // peekThroughLayer was already drawn ahead of its z order. |
| 917 | continue; |
| 918 | } |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 919 | bool skipLayer = false; |
Leon Scroggins III | d305ef2 | 2021-04-06 09:53:26 -0400 | [diff] [blame] | 920 | const auto& overrideInfo = layer->getState().overrideInfo; |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 921 | if (overrideInfo.buffer != nullptr) { |
| 922 | if (previousOverride && overrideInfo.buffer->getBuffer() == previousOverride) { |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 923 | ALOGV("Skipping redundant buffer"); |
| 924 | skipLayer = true; |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 925 | } else { |
| 926 | // First layer with the override buffer. |
| 927 | if (overrideInfo.peekThroughLayer) { |
| 928 | peekThroughLayer = overrideInfo.peekThroughLayer; |
Leon Scroggins III | d305ef2 | 2021-04-06 09:53:26 -0400 | [diff] [blame] | 929 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 930 | // Draw peekThroughLayer first. |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 931 | overrideZ = true; |
| 932 | includeGeometry = true; |
| 933 | constexpr bool isPeekingThrough = true; |
| 934 | peekThroughLayer->writeStateToHWC(includeGeometry, false, z++, overrideZ, |
| 935 | isPeekingThrough); |
Robert Carr | ec8ccca | 2022-05-04 09:36:14 -0700 | [diff] [blame] | 936 | outputLayerHash ^= android::hashCombine( |
| 937 | reinterpret_cast<uint64_t>(&peekThroughLayer->getLayerFE()), |
| 938 | z, includeGeometry, overrideZ, isPeekingThrough, |
| 939 | peekThroughLayer->requiresClientComposition()); |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | previousOverride = overrideInfo.buffer->getBuffer(); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 943 | } |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 944 | } |
| 945 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 946 | constexpr bool isPeekingThrough = false; |
| 947 | layer->writeStateToHWC(includeGeometry, skipLayer, z++, overrideZ, isPeekingThrough); |
Robert Carr | ec8ccca | 2022-05-04 09:36:14 -0700 | [diff] [blame] | 948 | if (!skipLayer) { |
| 949 | outputLayerHash ^= android::hashCombine( |
| 950 | reinterpret_cast<uint64_t>(&layer->getLayerFE()), |
| 951 | z, includeGeometry, overrideZ, isPeekingThrough, |
| 952 | layer->requiresClientComposition()); |
| 953 | } |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 954 | } |
Robert Carr | ec8ccca | 2022-05-04 09:36:14 -0700 | [diff] [blame] | 955 | editState().outputLayerHash = outputLayerHash; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 956 | } |
| 957 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 958 | compositionengine::OutputLayer* Output::findLayerRequestingBackgroundComposition() const { |
| 959 | compositionengine::OutputLayer* layerRequestingBgComposition = nullptr; |
| 960 | for (auto* layer : getOutputLayersOrderedByZ()) { |
Leon Scroggins III | c1dbfcb | 2022-03-21 16:48:10 -0400 | [diff] [blame] | 961 | const auto* compState = layer->getLayerFE().getCompositionState(); |
Galia Peycheva | 66eaf4a | 2020-11-09 13:17:57 +0100 | [diff] [blame] | 962 | |
| 963 | // If any layer has a sideband stream, we will disable blurs. In that case, we don't |
| 964 | // want to force client composition because of the blur. |
| 965 | if (compState->sidebandStream != nullptr) { |
| 966 | return nullptr; |
| 967 | } |
Leon Scroggins III | c1dbfcb | 2022-03-21 16:48:10 -0400 | [diff] [blame] | 968 | |
| 969 | // If RenderEngine cannot render protected content, we cannot blur. |
| 970 | if (compState->hasProtectedContent && |
| 971 | !getCompositionEngine().getRenderEngine().supportsProtectedContent()) { |
| 972 | return nullptr; |
| 973 | } |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 974 | if (compState->isOpaque) { |
| 975 | continue; |
| 976 | } |
Galia Peycheva | 66eaf4a | 2020-11-09 13:17:57 +0100 | [diff] [blame] | 977 | if (compState->backgroundBlurRadius > 0 || compState->blurRegions.size() > 0) { |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 978 | layerRequestingBgComposition = layer; |
| 979 | } |
| 980 | } |
| 981 | return layerRequestingBgComposition; |
| 982 | } |
| 983 | |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 984 | void Output::updateColorProfile(const compositionengine::CompositionRefreshArgs& refreshArgs) { |
| 985 | setColorProfile(pickColorProfile(refreshArgs)); |
| 986 | } |
| 987 | |
| 988 | // Returns a data space that fits all visible layers. The returned data space |
| 989 | // can only be one of |
| 990 | // - Dataspace::SRGB (use legacy dataspace and let HWC saturate when colors are enhanced) |
| 991 | // - Dataspace::DISPLAY_P3 |
| 992 | // - Dataspace::DISPLAY_BT2020 |
| 993 | // The returned HDR data space is one of |
| 994 | // - Dataspace::UNKNOWN |
| 995 | // - Dataspace::BT2020_HLG |
| 996 | // - Dataspace::BT2020_PQ |
| 997 | ui::Dataspace Output::getBestDataspace(ui::Dataspace* outHdrDataSpace, |
| 998 | bool* outIsHdrClientComposition) const { |
| 999 | ui::Dataspace bestDataSpace = ui::Dataspace::V0_SRGB; |
| 1000 | *outHdrDataSpace = ui::Dataspace::UNKNOWN; |
| 1001 | |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 1002 | // An Output's layers may be stale when it is disabled. As a consequence, the layers returned by |
| 1003 | // getOutputLayersOrderedByZ may not be in a valid state and it is not safe to access their |
| 1004 | // properties. Return a default dataspace value in this case. |
| 1005 | if (!getState().isEnabled) { |
| 1006 | return ui::Dataspace::V0_SRGB; |
| 1007 | } |
| 1008 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1009 | for (const auto* layer : getOutputLayersOrderedByZ()) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1010 | switch (layer->getLayerFE().getCompositionState()->dataspace) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 1011 | case ui::Dataspace::V0_SCRGB: |
| 1012 | case ui::Dataspace::V0_SCRGB_LINEAR: |
| 1013 | case ui::Dataspace::BT2020: |
| 1014 | case ui::Dataspace::BT2020_ITU: |
| 1015 | case ui::Dataspace::BT2020_LINEAR: |
| 1016 | case ui::Dataspace::DISPLAY_BT2020: |
| 1017 | bestDataSpace = ui::Dataspace::DISPLAY_BT2020; |
| 1018 | break; |
| 1019 | case ui::Dataspace::DISPLAY_P3: |
| 1020 | bestDataSpace = ui::Dataspace::DISPLAY_P3; |
| 1021 | break; |
| 1022 | case ui::Dataspace::BT2020_PQ: |
| 1023 | case ui::Dataspace::BT2020_ITU_PQ: |
| 1024 | bestDataSpace = ui::Dataspace::DISPLAY_P3; |
| 1025 | *outHdrDataSpace = ui::Dataspace::BT2020_PQ; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1026 | *outIsHdrClientComposition = |
| 1027 | layer->getLayerFE().getCompositionState()->forceClientComposition; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 1028 | break; |
| 1029 | case ui::Dataspace::BT2020_HLG: |
| 1030 | case ui::Dataspace::BT2020_ITU_HLG: |
| 1031 | bestDataSpace = ui::Dataspace::DISPLAY_P3; |
| 1032 | // When there's mixed PQ content and HLG content, we set the HDR |
Sally Qi | 37d07c0 | 2023-10-05 17:32:32 +0000 | [diff] [blame] | 1033 | // data space to be BT2020_HLG and convert PQ to HLG. |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 1034 | if (*outHdrDataSpace == ui::Dataspace::UNKNOWN) { |
| 1035 | *outHdrDataSpace = ui::Dataspace::BT2020_HLG; |
| 1036 | } |
| 1037 | break; |
| 1038 | default: |
| 1039 | break; |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | return bestDataSpace; |
| 1044 | } |
| 1045 | |
| 1046 | compositionengine::Output::ColorProfile Output::pickColorProfile( |
| 1047 | const compositionengine::CompositionRefreshArgs& refreshArgs) const { |
| 1048 | if (refreshArgs.outputColorSetting == OutputColorSetting::kUnmanaged) { |
| 1049 | return ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 1050 | ui::RenderIntent::COLORIMETRIC}; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | ui::Dataspace hdrDataSpace; |
| 1054 | bool isHdrClientComposition = false; |
| 1055 | ui::Dataspace bestDataSpace = getBestDataspace(&hdrDataSpace, &isHdrClientComposition); |
| 1056 | |
| 1057 | switch (refreshArgs.forceOutputColorMode) { |
| 1058 | case ui::ColorMode::SRGB: |
| 1059 | bestDataSpace = ui::Dataspace::V0_SRGB; |
| 1060 | break; |
| 1061 | case ui::ColorMode::DISPLAY_P3: |
| 1062 | bestDataSpace = ui::Dataspace::DISPLAY_P3; |
| 1063 | break; |
| 1064 | default: |
| 1065 | break; |
| 1066 | } |
| 1067 | |
| 1068 | // respect hdrDataSpace only when there is no legacy HDR support |
| 1069 | const bool isHdr = hdrDataSpace != ui::Dataspace::UNKNOWN && |
| 1070 | !mDisplayColorProfile->hasLegacyHdrSupport(hdrDataSpace) && !isHdrClientComposition; |
| 1071 | if (isHdr) { |
| 1072 | bestDataSpace = hdrDataSpace; |
| 1073 | } |
| 1074 | |
| 1075 | ui::RenderIntent intent; |
| 1076 | switch (refreshArgs.outputColorSetting) { |
| 1077 | case OutputColorSetting::kManaged: |
| 1078 | case OutputColorSetting::kUnmanaged: |
| 1079 | intent = isHdr ? ui::RenderIntent::TONE_MAP_COLORIMETRIC |
| 1080 | : ui::RenderIntent::COLORIMETRIC; |
| 1081 | break; |
| 1082 | case OutputColorSetting::kEnhanced: |
| 1083 | intent = isHdr ? ui::RenderIntent::TONE_MAP_ENHANCE : ui::RenderIntent::ENHANCE; |
| 1084 | break; |
| 1085 | default: // vendor display color setting |
| 1086 | intent = static_cast<ui::RenderIntent>(refreshArgs.outputColorSetting); |
| 1087 | break; |
| 1088 | } |
| 1089 | |
| 1090 | ui::ColorMode outMode; |
| 1091 | ui::Dataspace outDataSpace; |
| 1092 | ui::RenderIntent outRenderIntent; |
| 1093 | mDisplayColorProfile->getBestColorMode(bestDataSpace, intent, &outDataSpace, &outMode, |
| 1094 | &outRenderIntent); |
| 1095 | |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 1096 | return ColorProfile{outMode, outDataSpace, outRenderIntent}; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 1097 | } |
| 1098 | |
Lloyd Pique | d0a92a0 | 2019-02-19 17:47:26 -0800 | [diff] [blame] | 1099 | void Output::beginFrame() { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1100 | auto& outputState = editState(); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1101 | const bool dirty = !getDirtyRegion().isEmpty(); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1102 | const bool empty = getOutputLayerCount() == 0; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1103 | const bool wasEmpty = !outputState.lastCompositionHadVisibleLayers; |
Lloyd Pique | d0a92a0 | 2019-02-19 17:47:26 -0800 | [diff] [blame] | 1104 | |
| 1105 | // If nothing has changed (!dirty), don't recompose. |
| 1106 | // If something changed, but we don't currently have any visible layers, |
| 1107 | // and didn't when we last did a composition, then skip it this time. |
| 1108 | // The second rule does two things: |
| 1109 | // - When all layers are removed from a display, we'll emit one black |
| 1110 | // frame, then nothing more until we get new layers. |
| 1111 | // - When a display is created with a private layer stack, we won't |
| 1112 | // emit any black frames until a layer is added to the layer stack. |
Chavi Weingarten | 09fa1d6 | 2022-08-17 21:57:04 +0000 | [diff] [blame] | 1113 | mMustRecompose = dirty && !(empty && wasEmpty); |
Lloyd Pique | d0a92a0 | 2019-02-19 17:47:26 -0800 | [diff] [blame] | 1114 | |
| 1115 | const char flagPrefix[] = {'-', '+'}; |
| 1116 | static_cast<void>(flagPrefix); |
Chavi Weingarten | 09fa1d6 | 2022-08-17 21:57:04 +0000 | [diff] [blame] | 1117 | ALOGV("%s: %s composition for %s (%cdirty %cempty %cwasEmpty)", __func__, |
| 1118 | mMustRecompose ? "doing" : "skipping", getName().c_str(), flagPrefix[dirty], |
| 1119 | flagPrefix[empty], flagPrefix[wasEmpty]); |
Lloyd Pique | d0a92a0 | 2019-02-19 17:47:26 -0800 | [diff] [blame] | 1120 | |
Chavi Weingarten | 09fa1d6 | 2022-08-17 21:57:04 +0000 | [diff] [blame] | 1121 | mRenderSurface->beginFrame(mMustRecompose); |
Lloyd Pique | d0a92a0 | 2019-02-19 17:47:26 -0800 | [diff] [blame] | 1122 | |
Chavi Weingarten | 09fa1d6 | 2022-08-17 21:57:04 +0000 | [diff] [blame] | 1123 | if (mMustRecompose) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1124 | outputState.lastCompositionHadVisibleLayers = !empty; |
Lloyd Pique | d0a92a0 | 2019-02-19 17:47:26 -0800 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1128 | void Output::prepareFrame() { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1129 | SFTRACE_CALL(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1130 | ALOGV(__FUNCTION__); |
| 1131 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1132 | auto& outputState = editState(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1133 | if (!outputState.isEnabled) { |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1134 | return; |
| 1135 | } |
| 1136 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1137 | std::optional<android::HWComposer::DeviceRequestedChanges> changes; |
| 1138 | bool success = chooseCompositionStrategy(&changes); |
| 1139 | resetCompositionStrategy(); |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 1140 | outputState.strategyPrediction = CompositionStrategyPredictionState::DISABLED; |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1141 | outputState.previousDeviceRequestedChanges = changes; |
| 1142 | outputState.previousDeviceRequestedSuccess = success; |
| 1143 | if (success) { |
| 1144 | applyCompositionStrategy(changes); |
| 1145 | } |
| 1146 | finishPrepareFrame(); |
| 1147 | } |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1148 | |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 1149 | ftl::Future<std::monostate> Output::presentFrameAndReleaseLayersAsync(bool flushEvenWhenDisabled) { |
Yi Kong | 9dce90f | 2024-08-14 07:06:52 +0800 | [diff] [blame] | 1150 | return ftl::Future<bool>(mHwComposerAsyncWorker->send([this, flushEvenWhenDisabled]() { |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 1151 | presentFrameAndReleaseLayers(flushEvenWhenDisabled); |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 1152 | return true; |
Yi Kong | 9dce90f | 2024-08-14 07:06:52 +0800 | [diff] [blame] | 1153 | })) |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 1154 | .then([](bool) { return std::monostate{}; }); |
| 1155 | } |
| 1156 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1157 | std::future<bool> Output::chooseCompositionStrategyAsync( |
| 1158 | std::optional<android::HWComposer::DeviceRequestedChanges>* changes) { |
| 1159 | return mHwComposerAsyncWorker->send( |
| 1160 | [&, changes]() { return chooseCompositionStrategy(changes); }); |
| 1161 | } |
| 1162 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1163 | GpuCompositionResult Output::prepareFrameAsync() { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1164 | SFTRACE_CALL(); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1165 | ALOGV(__FUNCTION__); |
| 1166 | auto& state = editState(); |
| 1167 | const auto& previousChanges = state.previousDeviceRequestedChanges; |
| 1168 | std::optional<android::HWComposer::DeviceRequestedChanges> changes; |
| 1169 | resetCompositionStrategy(); |
| 1170 | auto hwcResult = chooseCompositionStrategyAsync(&changes); |
| 1171 | if (state.previousDeviceRequestedSuccess) { |
| 1172 | applyCompositionStrategy(previousChanges); |
| 1173 | } |
| 1174 | finishPrepareFrame(); |
| 1175 | |
| 1176 | base::unique_fd bufferFence; |
| 1177 | std::shared_ptr<renderengine::ExternalTexture> buffer; |
| 1178 | updateProtectedContentState(); |
| 1179 | const bool dequeueSucceeded = dequeueRenderBuffer(&bufferFence, &buffer); |
| 1180 | GpuCompositionResult compositionResult; |
| 1181 | if (dequeueSucceeded) { |
| 1182 | std::optional<base::unique_fd> optFd = |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1183 | composeSurfaces(Region::INVALID_REGION, buffer, bufferFence); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1184 | if (optFd) { |
| 1185 | compositionResult.fence = std::move(*optFd); |
| 1186 | } |
Dan Stoza | 47437bb | 2021-01-15 16:21:07 -0800 | [diff] [blame] | 1187 | } |
| 1188 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1189 | auto chooseCompositionSuccess = hwcResult.get(); |
| 1190 | const bool predictionSucceeded = dequeueSucceeded && changes == previousChanges; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 1191 | state.strategyPrediction = predictionSucceeded ? CompositionStrategyPredictionState::SUCCESS |
| 1192 | : CompositionStrategyPredictionState::FAIL; |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1193 | if (!predictionSucceeded) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1194 | SFTRACE_NAME("CompositionStrategyPredictionMiss"); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1195 | resetCompositionStrategy(); |
| 1196 | if (chooseCompositionSuccess) { |
| 1197 | applyCompositionStrategy(changes); |
| 1198 | } |
| 1199 | finishPrepareFrame(); |
| 1200 | // Track the dequeued buffer to reuse so we don't need to dequeue another one. |
| 1201 | compositionResult.buffer = buffer; |
| 1202 | } else { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1203 | SFTRACE_NAME("CompositionStrategyPredictionHit"); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1204 | } |
| 1205 | state.previousDeviceRequestedChanges = std::move(changes); |
| 1206 | state.previousDeviceRequestedSuccess = chooseCompositionSuccess; |
| 1207 | return compositionResult; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1208 | } |
| 1209 | |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 1210 | void Output::devOptRepaintFlash(const compositionengine::CompositionRefreshArgs& refreshArgs) { |
| 1211 | if (CC_LIKELY(!refreshArgs.devOptFlashDirtyRegionsDelay)) { |
| 1212 | return; |
| 1213 | } |
| 1214 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1215 | if (getState().isEnabled) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1216 | if (const auto dirtyRegion = getDirtyRegion(); !dirtyRegion.isEmpty()) { |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1217 | base::unique_fd bufferFence; |
| 1218 | std::shared_ptr<renderengine::ExternalTexture> buffer; |
| 1219 | updateProtectedContentState(); |
| 1220 | dequeueRenderBuffer(&bufferFence, &buffer); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1221 | static_cast<void>(composeSurfaces(dirtyRegion, buffer, bufferFence)); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 1222 | mRenderSurface->queueBuffer(base::unique_fd(), getHdrSdrRatio(buffer)); |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 1223 | } |
| 1224 | } |
| 1225 | |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 1226 | constexpr bool kFlushEvenWhenDisabled = false; |
| 1227 | presentFrameAndReleaseLayers(kFlushEvenWhenDisabled); |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 1228 | |
| 1229 | std::this_thread::sleep_for(*refreshArgs.devOptFlashDirtyRegionsDelay); |
| 1230 | |
| 1231 | prepareFrame(); |
| 1232 | } |
| 1233 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1234 | void Output::finishFrame(GpuCompositionResult&& result) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1235 | SFTRACE_CALL(); |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 1236 | ALOGV(__FUNCTION__); |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 1237 | const auto& outputState = getState(); |
| 1238 | if (!outputState.isEnabled) { |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 1239 | return; |
| 1240 | } |
| 1241 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1242 | std::optional<base::unique_fd> optReadyFence; |
| 1243 | std::shared_ptr<renderengine::ExternalTexture> buffer; |
| 1244 | base::unique_fd bufferFence; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 1245 | if (outputState.strategyPrediction == CompositionStrategyPredictionState::SUCCESS) { |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1246 | optReadyFence = std::move(result.fence); |
| 1247 | } else { |
| 1248 | if (result.bufferAvailable()) { |
| 1249 | buffer = std::move(result.buffer); |
| 1250 | bufferFence = std::move(result.fence); |
| 1251 | } else { |
| 1252 | updateProtectedContentState(); |
| 1253 | if (!dequeueRenderBuffer(&bufferFence, &buffer)) { |
| 1254 | return; |
| 1255 | } |
| 1256 | } |
| 1257 | // Repaint the framebuffer (if needed), getting the optional fence for when |
| 1258 | // the composition completes. |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1259 | optReadyFence = composeSurfaces(Region::INVALID_REGION, buffer, bufferFence); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1260 | } |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 1261 | if (!optReadyFence) { |
| 1262 | return; |
| 1263 | } |
Xiang Wang | cb50bbd | 2024-04-18 16:57:54 -0700 | [diff] [blame] | 1264 | if (isPowerHintSessionEnabled() && !isPowerHintSessionGpuReportingEnabled()) { |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 1265 | // get fence end time to know when gpu is complete in display |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 1266 | setHintSessionGpuFence( |
| 1267 | std::make_unique<FenceTime>(sp<Fence>::make(dup(optReadyFence->get())))); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 1268 | } |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 1269 | // swap buffers (presentation) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 1270 | mRenderSurface->queueBuffer(std::move(*optReadyFence), getHdrSdrRatio(buffer)); |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 1271 | } |
| 1272 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1273 | void Output::updateProtectedContentState() { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1274 | const auto& outputState = getState(); |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 1275 | auto& renderEngine = getCompositionEngine().getRenderEngine(); |
| 1276 | const bool supportsProtectedContent = renderEngine.supportsProtectedContent(); |
| 1277 | |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 1278 | bool isProtected; |
| 1279 | if (FlagManager::getInstance().display_protected()) { |
| 1280 | isProtected = outputState.isProtected; |
| 1281 | } else { |
| 1282 | isProtected = outputState.isSecure; |
| 1283 | } |
| 1284 | |
| 1285 | // We need to set the render surface as protected (DRM) if all the following conditions are met: |
| 1286 | // 1. The display is protected (in legacy, check if the display is secure) |
| 1287 | // 2. Protected content is supported |
| 1288 | // 3. At least one layer has protected content. |
| 1289 | if (isProtected && supportsProtectedContent) { |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 1290 | auto layers = getOutputLayersOrderedByZ(); |
| 1291 | bool needsProtected = std::any_of(layers.begin(), layers.end(), [](auto* layer) { |
Eason Chiu | 4509966 | 2023-10-23 08:55:48 +0800 | [diff] [blame] | 1292 | return layer->getLayerFE().getCompositionState()->hasProtectedContent && |
| 1293 | (!FlagManager::getInstance().protected_if_client() || |
| 1294 | layer->requiresClientComposition()); |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 1295 | }); |
Patrick Williams | 8aed5d2 | 2022-10-31 22:18:10 +0000 | [diff] [blame] | 1296 | if (needsProtected != mRenderSurface->isProtected()) { |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 1297 | mRenderSurface->setProtected(needsProtected); |
| 1298 | } |
| 1299 | } |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1300 | } |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 1301 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1302 | bool Output::dequeueRenderBuffer(base::unique_fd* bufferFence, |
| 1303 | std::shared_ptr<renderengine::ExternalTexture>* tex) { |
| 1304 | const auto& outputState = getState(); |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 1305 | |
| 1306 | // If we aren't doing client composition on this output, but do have a |
| 1307 | // flipClientTarget request for this frame on this output, we still need to |
| 1308 | // dequeue a buffer. |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1309 | if (outputState.usesClientComposition || outputState.flipClientTarget) { |
| 1310 | *tex = mRenderSurface->dequeueBuffer(bufferFence); |
| 1311 | if (*tex == nullptr) { |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 1312 | ALOGW("Dequeuing buffer for display [%s] failed, bailing out of " |
| 1313 | "client composition for this frame", |
| 1314 | mName.c_str()); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1315 | return false; |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 1316 | } |
| 1317 | } |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1318 | return true; |
| 1319 | } |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 1320 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1321 | std::optional<base::unique_fd> Output::composeSurfaces( |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1322 | const Region& debugRegion, std::shared_ptr<renderengine::ExternalTexture> tex, |
| 1323 | base::unique_fd& fd) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1324 | SFTRACE_CALL(); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1325 | ALOGV(__FUNCTION__); |
| 1326 | |
| 1327 | const auto& outputState = getState(); |
Leon Scroggins III | 042fdba | 2023-01-04 10:53:07 -0500 | [diff] [blame] | 1328 | const TracedOrdinal<bool> hasClientComposition = { |
| 1329 | base::StringPrintf("hasClientComposition %s", mNamePlusId.c_str()), |
| 1330 | outputState.usesClientComposition}; |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1331 | if (!hasClientComposition) { |
Lloyd Pique | a76ce46 | 2020-01-14 13:06:37 -0800 | [diff] [blame] | 1332 | setExpensiveRenderingExpected(false); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 1333 | return base::unique_fd(); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1334 | } |
| 1335 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1336 | if (tex == nullptr) { |
| 1337 | ALOGW("Buffer not valid for display [%s], bailing out of " |
| 1338 | "client composition for this frame", |
| 1339 | mName.c_str()); |
| 1340 | return {}; |
| 1341 | } |
| 1342 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1343 | ALOGV("hasClientComposition"); |
| 1344 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 1345 | renderengine::DisplaySettings clientCompositionDisplay = |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 1346 | generateClientCompositionDisplaySettings(tex); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1347 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1348 | // Generate the client composition requests for the layers on this output. |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1349 | auto& renderEngine = getCompositionEngine().getRenderEngine(); |
| 1350 | const bool supportsProtectedContent = renderEngine.supportsProtectedContent(); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 1351 | std::vector<LayerFE*> clientCompositionLayersFE; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1352 | std::vector<LayerFE::LayerSettings> clientCompositionLayers = |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1353 | generateClientCompositionRequests(supportsProtectedContent, |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 1354 | clientCompositionDisplay.outputDataspace, |
| 1355 | clientCompositionLayersFE); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1356 | appendRegionFlashRequests(debugRegion, clientCompositionLayers); |
| 1357 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1358 | OutputCompositionState& outputCompositionState = editState(); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1359 | // Check if the client composition requests were rendered into the provided graphic buffer. If |
| 1360 | // so, we can reuse the buffer and avoid client composition. |
| 1361 | if (mClientCompositionRequestCache) { |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1362 | if (mClientCompositionRequestCache->exists(tex->getBuffer()->getId(), |
| 1363 | clientCompositionDisplay, |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1364 | clientCompositionLayers)) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1365 | SFTRACE_NAME("ClientCompositionCacheHit"); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1366 | outputCompositionState.reusedClientComposition = true; |
| 1367 | setExpensiveRenderingExpected(false); |
Vishnu Nair | 3a49f0a | 2022-07-29 21:52:53 +0000 | [diff] [blame] | 1368 | // b/239944175 pass the fence associated with the buffer. |
| 1369 | return base::unique_fd(std::move(fd)); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1370 | } |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1371 | SFTRACE_NAME("ClientCompositionCacheMiss"); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1372 | mClientCompositionRequestCache->add(tex->getBuffer()->getId(), clientCompositionDisplay, |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1373 | clientCompositionLayers); |
| 1374 | } |
| 1375 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1376 | // We boost GPU frequency here because there will be color spaces conversion |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1377 | // or complex GPU shaders and it's expensive. We boost the GPU frequency so that |
| 1378 | // GPU composition can finish in time. We must reset GPU frequency afterwards, |
| 1379 | // because high frequency consumes extra battery. |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1380 | const bool expensiveRenderingExpected = |
Leon Scroggins III | cf17ebc | 2022-03-03 14:54:00 -0500 | [diff] [blame] | 1381 | std::any_of(clientCompositionLayers.begin(), clientCompositionLayers.end(), |
| 1382 | [outputDataspace = |
| 1383 | clientCompositionDisplay.outputDataspace](const auto& layer) { |
| 1384 | return layer.sourceDataspace != outputDataspace; |
| 1385 | }); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1386 | if (expensiveRenderingExpected) { |
| 1387 | setExpensiveRenderingExpected(true); |
| 1388 | } |
| 1389 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1390 | std::vector<renderengine::LayerSettings> clientRenderEngineLayers; |
| 1391 | clientRenderEngineLayers.reserve(clientCompositionLayers.size()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1392 | std::transform(clientCompositionLayers.begin(), clientCompositionLayers.end(), |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1393 | std::back_inserter(clientRenderEngineLayers), |
| 1394 | [](LayerFE::LayerSettings& settings) -> renderengine::LayerSettings { |
| 1395 | return settings; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1396 | }); |
| 1397 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 1398 | const nsecs_t renderEngineStart = systemTime(); |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 1399 | auto fenceResult = renderEngine |
| 1400 | .drawLayers(clientCompositionDisplay, clientRenderEngineLayers, tex, |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 1401 | std::move(fd)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 1402 | .get(); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 1403 | |
| 1404 | if (mClientCompositionRequestCache && fenceStatus(fenceResult) != NO_ERROR) { |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1405 | // If rendering was not successful, remove the request from the cache. |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1406 | mClientCompositionRequestCache->remove(tex->getBuffer()->getId()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1407 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 1408 | const auto fence = std::move(fenceResult).value_or(Fence::NO_FENCE); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 1409 | if (isPowerHintSessionEnabled()) { |
| 1410 | if (fence != Fence::NO_FENCE && fence->isValid() && |
| 1411 | !outputCompositionState.reusedClientComposition) { |
| 1412 | setHintSessionRequiresRenderEngine(true); |
Xiang Wang | cb50bbd | 2024-04-18 16:57:54 -0700 | [diff] [blame] | 1413 | if (isPowerHintSessionGpuReportingEnabled()) { |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 1414 | // the order of the two calls here matters as we should check if the previously |
| 1415 | // tracked fence has signaled first and archive the previous start time |
| 1416 | setHintSessionGpuStart(TimePoint::now()); |
| 1417 | setHintSessionGpuFence( |
| 1418 | std::make_unique<FenceTime>(sp<Fence>::make(dup(fence->get())))); |
| 1419 | } |
| 1420 | } |
| 1421 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 1422 | |
Patrick Williams | 74c0bf6 | 2022-11-02 23:59:26 +0000 | [diff] [blame] | 1423 | if (auto timeStats = getCompositionEngine().getTimeStats()) { |
| 1424 | if (fence->isValid()) { |
| 1425 | timeStats->recordRenderEngineDuration(renderEngineStart, |
| 1426 | std::make_shared<FenceTime>(fence)); |
| 1427 | } else { |
| 1428 | timeStats->recordRenderEngineDuration(renderEngineStart, systemTime()); |
| 1429 | } |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 1430 | } |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1431 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 1432 | for (auto* clientComposedLayer : clientCompositionLayersFE) { |
| 1433 | clientComposedLayer->setWasClientComposed(fence); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 1434 | } |
| 1435 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 1436 | return base::unique_fd(fence->dup()); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1437 | } |
| 1438 | |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 1439 | renderengine::DisplaySettings Output::generateClientCompositionDisplaySettings( |
| 1440 | const std::shared_ptr<renderengine::ExternalTexture>& buffer) const { |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 1441 | const auto& outputState = getState(); |
| 1442 | |
| 1443 | renderengine::DisplaySettings clientCompositionDisplay; |
Leon Scroggins III | 5a655b8 | 2022-09-07 13:17:09 -0400 | [diff] [blame] | 1444 | clientCompositionDisplay.namePlusId = mNamePlusId; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 1445 | clientCompositionDisplay.physicalDisplay = outputState.framebufferSpace.getContent(); |
| 1446 | clientCompositionDisplay.clip = outputState.layerStackSpace.getContent(); |
| 1447 | clientCompositionDisplay.orientation = |
| 1448 | ui::Transform::toRotationFlags(outputState.displaySpace.getOrientation()); |
| 1449 | clientCompositionDisplay.outputDataspace = mDisplayColorProfile->hasWideColorGamut() |
| 1450 | ? outputState.dataspace |
| 1451 | : ui::Dataspace::UNKNOWN; |
| 1452 | |
| 1453 | // If we have a valid current display brightness use that, otherwise fall back to the |
| 1454 | // display's max desired |
| 1455 | clientCompositionDisplay.currentLuminanceNits = outputState.displayBrightnessNits > 0.f |
| 1456 | ? outputState.displayBrightnessNits |
| 1457 | : mDisplayColorProfile->getHdrCapabilities().getDesiredMaxLuminance(); |
| 1458 | clientCompositionDisplay.maxLuminance = |
| 1459 | mDisplayColorProfile->getHdrCapabilities().getDesiredMaxLuminance(); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 1460 | |
| 1461 | float hdrSdrRatioMultiplier = 1.0f / getHdrSdrRatio(buffer); |
| 1462 | clientCompositionDisplay.targetLuminanceNits = outputState.clientTargetBrightness * |
| 1463 | outputState.displayBrightnessNits * hdrSdrRatioMultiplier; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 1464 | clientCompositionDisplay.dimmingStage = outputState.clientTargetDimmingStage; |
| 1465 | clientCompositionDisplay.renderIntent = |
| 1466 | static_cast<aidl::android::hardware::graphics::composer3::RenderIntent>( |
| 1467 | outputState.renderIntent); |
| 1468 | |
| 1469 | // Compute the global color transform matrix. |
| 1470 | clientCompositionDisplay.colorTransform = outputState.colorTransformMatrix; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 1471 | clientCompositionDisplay.deviceHandlesColorTransform = |
| 1472 | outputState.usesDeviceComposition || getSkipColorTransform(); |
| 1473 | return clientCompositionDisplay; |
| 1474 | } |
| 1475 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1476 | std::vector<LayerFE::LayerSettings> Output::generateClientCompositionRequests( |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 1477 | bool supportsProtectedContent, ui::Dataspace outputDataspace, std::vector<LayerFE*>& outLayerFEs) { |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1478 | std::vector<LayerFE::LayerSettings> clientCompositionLayers; |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1479 | ALOGV("Rendering client layers"); |
| 1480 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1481 | const auto& outputState = getState(); |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1482 | const Region viewportRegion(outputState.layerStackSpace.getContent()); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1483 | bool firstLayer = true; |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1484 | |
Galia Peycheva | 66eaf4a | 2020-11-09 13:17:57 +0100 | [diff] [blame] | 1485 | bool disableBlurs = false; |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 1486 | uint64_t previousOverrideBufferId = 0; |
Galia Peycheva | 66eaf4a | 2020-11-09 13:17:57 +0100 | [diff] [blame] | 1487 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1488 | for (auto* layer : getOutputLayersOrderedByZ()) { |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1489 | const auto& layerState = layer->getState(); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1490 | const auto* layerFEState = layer->getLayerFE().getCompositionState(); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1491 | auto& layerFE = layer->getLayerFE(); |
Robert Carr | 05da008 | 2022-05-25 23:29:34 -0700 | [diff] [blame] | 1492 | layerFE.setWasClientComposed(nullptr); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1493 | |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 1494 | const Region clip(viewportRegion.intersect(layerState.visibleRegion)); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1495 | ALOGV("Layer: %s", layerFE.getDebugName()); |
| 1496 | if (clip.isEmpty()) { |
| 1497 | ALOGV(" Skipping for empty clip"); |
| 1498 | firstLayer = false; |
| 1499 | continue; |
| 1500 | } |
| 1501 | |
Galia Peycheva | 66eaf4a | 2020-11-09 13:17:57 +0100 | [diff] [blame] | 1502 | disableBlurs |= layerFEState->sidebandStream != nullptr; |
| 1503 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1504 | const bool clientComposition = layer->requiresClientComposition(); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1505 | |
| 1506 | // We clear the client target for non-client composed layers if |
| 1507 | // requested by the HWC. We skip this if the layer is not an opaque |
| 1508 | // rectangle, as by definition the layer must blend with whatever is |
| 1509 | // underneath. We also skip the first layer as the buffer target is |
| 1510 | // guaranteed to start out cleared. |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 1511 | const bool clearClientComposition = |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1512 | layerState.clearClientTarget && layerFEState->isOpaque && !firstLayer; |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1513 | |
| 1514 | ALOGV(" Composition type: client %d clear %d", clientComposition, clearClientComposition); |
| 1515 | |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 1516 | // If the layer casts a shadow but the content casting the shadow is occluded, skip |
| 1517 | // composing the non-shadow content and only draw the shadows. |
| 1518 | const bool realContentIsVisible = clientComposition && |
| 1519 | !layerState.visibleRegion.subtract(layerState.shadowRegion).isEmpty(); |
| 1520 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1521 | if (clientComposition || clearClientComposition) { |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 1522 | if (auto overrideSettings = layer->getOverrideCompositionSettings()) { |
| 1523 | if (overrideSettings->bufferId != previousOverrideBufferId) { |
| 1524 | previousOverrideBufferId = overrideSettings->bufferId; |
| 1525 | clientCompositionLayers.push_back(std::move(*overrideSettings)); |
Huihong Luo | 91ac3b5 | 2021-04-08 11:07:41 -0700 | [diff] [blame] | 1526 | ALOGV("Replacing [%s] with override in RE", layer->getLayerFE().getDebugName()); |
| 1527 | } else { |
| 1528 | ALOGV("Skipping redundant override buffer for [%s] in RE", |
| 1529 | layer->getLayerFE().getDebugName()); |
| 1530 | } |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 1531 | } else { |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 1532 | LayerFE::ClientCompositionTargetSettings::BlurSetting blurSetting = disableBlurs |
| 1533 | ? LayerFE::ClientCompositionTargetSettings::BlurSetting::Disabled |
| 1534 | : (layer->getState().overrideInfo.disableBackgroundBlur |
| 1535 | ? LayerFE::ClientCompositionTargetSettings::BlurSetting:: |
| 1536 | BlurRegionsOnly |
| 1537 | : LayerFE::ClientCompositionTargetSettings::BlurSetting:: |
| 1538 | Enabled); |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 1539 | bool isProtected = supportsProtectedContent; |
| 1540 | if (FlagManager::getInstance().display_protected()) { |
| 1541 | isProtected = outputState.isProtected && supportsProtectedContent; |
| 1542 | } |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 1543 | compositionengine::LayerFE::ClientCompositionTargetSettings |
| 1544 | targetSettings{.clip = clip, |
Patrick Williams | 278a88f | 2023-01-27 16:52:40 -0600 | [diff] [blame] | 1545 | .needsFiltering = layer->needsFiltering() || |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 1546 | outputState.needsFiltering, |
| 1547 | .isSecure = outputState.isSecure, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 1548 | .isProtected = isProtected, |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1549 | .viewport = outputState.layerStackSpace.getContent(), |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 1550 | .dataspace = outputDataspace, |
| 1551 | .realContentIsVisible = realContentIsVisible, |
| 1552 | .clearContent = !clientComposition, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1553 | .blurSetting = blurSetting, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 1554 | .whitePointNits = layerState.whitePointNits, |
| 1555 | .treat170mAsSrgb = outputState.treat170mAsSrgb}; |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 1556 | if (auto clientCompositionSettings = |
| 1557 | layerFE.prepareClientComposition(targetSettings)) { |
| 1558 | clientCompositionLayers.push_back(std::move(*clientCompositionSettings)); |
| 1559 | if (realContentIsVisible) { |
| 1560 | layer->editState().clientCompositionTimestamp = systemTime(); |
| 1561 | } |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 1562 | } |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1563 | } |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 1564 | |
Tianhua Sun | f91f140 | 2022-05-09 05:45:46 +0000 | [diff] [blame] | 1565 | if (clientComposition) { |
| 1566 | outLayerFEs.push_back(&layerFE); |
| 1567 | } |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | firstLayer = false; |
| 1571 | } |
| 1572 | |
| 1573 | return clientCompositionLayers; |
| 1574 | } |
| 1575 | |
| 1576 | void Output::appendRegionFlashRequests( |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1577 | const Region& flashRegion, std::vector<LayerFE::LayerSettings>& clientCompositionLayers) { |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1578 | if (flashRegion.isEmpty()) { |
| 1579 | return; |
| 1580 | } |
| 1581 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1582 | LayerFE::LayerSettings layerSettings; |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1583 | layerSettings.source.buffer.buffer = nullptr; |
| 1584 | layerSettings.source.solidColor = half3(1.0, 0.0, 1.0); |
| 1585 | layerSettings.alpha = half(1.0); |
| 1586 | |
| 1587 | for (const auto& rect : flashRegion) { |
| 1588 | layerSettings.geometry.boundaries = rect.toFloatRect(); |
| 1589 | clientCompositionLayers.push_back(layerSettings); |
| 1590 | } |
| 1591 | } |
| 1592 | |
| 1593 | void Output::setExpensiveRenderingExpected(bool) { |
| 1594 | // The base class does nothing with this call. |
| 1595 | } |
| 1596 | |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 1597 | void Output::setHintSessionGpuStart(TimePoint) { |
| 1598 | // The base class does nothing with this call. |
| 1599 | } |
| 1600 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 1601 | void Output::setHintSessionGpuFence(std::unique_ptr<FenceTime>&&) { |
| 1602 | // The base class does nothing with this call. |
| 1603 | } |
| 1604 | |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 1605 | void Output::setHintSessionRequiresRenderEngine(bool) { |
| 1606 | // The base class does nothing with this call. |
| 1607 | } |
| 1608 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 1609 | bool Output::isPowerHintSessionEnabled() { |
| 1610 | return false; |
| 1611 | } |
| 1612 | |
Xiang Wang | cb50bbd | 2024-04-18 16:57:54 -0700 | [diff] [blame] | 1613 | bool Output::isPowerHintSessionGpuReportingEnabled() { |
| 1614 | return false; |
| 1615 | } |
| 1616 | |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 1617 | void Output::presentFrameAndReleaseLayers(bool flushEvenWhenDisabled) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1618 | SFTRACE_FORMAT("%s for %s", __func__, mNamePlusId.c_str()); |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 1619 | ALOGV(__FUNCTION__); |
| 1620 | |
| 1621 | if (!getState().isEnabled) { |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 1622 | if (flushEvenWhenDisabled && FlagManager::getInstance().flush_buffer_slots_to_uncache()) { |
| 1623 | // Some commands, like clearing buffer slots, should still be executed |
| 1624 | // even if the display is not enabled. |
| 1625 | executeCommands(); |
| 1626 | } |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 1627 | return; |
| 1628 | } |
| 1629 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1630 | auto& outputState = editState(); |
| 1631 | outputState.dirtyRegion.clear(); |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 1632 | |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 1633 | auto frame = presentFrame(); |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 1634 | |
Lloyd Pique | 7d90ba5 | 2019-08-08 11:57:53 -0700 | [diff] [blame] | 1635 | mRenderSurface->onPresentDisplayCompleted(); |
| 1636 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1637 | for (auto* layer : getOutputLayersOrderedByZ()) { |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 1638 | // The layer buffer from the previous frame (if any) is released |
| 1639 | // by HWC only when the release fence from this frame (if any) is |
| 1640 | // signaled. Always get the release fence from HWC first. |
| 1641 | sp<Fence> releaseFence = Fence::NO_FENCE; |
| 1642 | |
| 1643 | if (auto hwcLayer = layer->getHwcLayer()) { |
| 1644 | if (auto f = frame.layerFences.find(hwcLayer); f != frame.layerFences.end()) { |
| 1645 | releaseFence = f->second; |
| 1646 | } |
| 1647 | } |
| 1648 | |
| 1649 | // If the layer was client composited in the previous frame, we |
| 1650 | // need to merge with the previous client target acquire fence. |
| 1651 | // Since we do not track that, always merge with the current |
| 1652 | // client target acquire fence when it is available, even though |
| 1653 | // this is suboptimal. |
| 1654 | // TODO(b/121291683): Track previous frame client target acquire fence. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1655 | if (outputState.usesClientComposition) { |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 1656 | releaseFence = |
| 1657 | Fence::merge("LayerRelease", releaseFence, frame.clientTargetAcquireFence); |
| 1658 | } |
Melody Hsu | 0077fde | 2024-10-17 21:42:50 +0000 | [diff] [blame] | 1659 | layer->getLayerFE().setReleaseFence(releaseFence); |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | // We've got a list of layers needing fences, that are disjoint with |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1663 | // OutputLayersOrderedByZ. The best we can do is to |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 1664 | // supply them with the present fence. |
| 1665 | for (auto& weakLayer : mReleasedLayers) { |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 1666 | if (const auto layer = weakLayer.promote()) { |
Melody Hsu | 0077fde | 2024-10-17 21:42:50 +0000 | [diff] [blame] | 1667 | layer->setReleaseFence(frame.presentFence); |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | // Clear out the released layers now that we're done with them. |
| 1672 | mReleasedLayers.clear(); |
| 1673 | } |
| 1674 | |
Alec Mouri | aa83158 | 2021-06-07 16:23:01 -0700 | [diff] [blame] | 1675 | void Output::renderCachedSets(const CompositionRefreshArgs& refreshArgs) { |
Leon Scroggins III | 43b5d52 | 2023-04-10 15:53:45 -0400 | [diff] [blame] | 1676 | const auto& outputState = getState(); |
| 1677 | if (mPlanner && outputState.isEnabled) { |
| 1678 | mPlanner->renderCachedSets(outputState, refreshArgs.scheduledFrameTime, |
| 1679 | outputState.usesDeviceComposition || getSkipColorTransform()); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 1680 | } |
| 1681 | } |
| 1682 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1683 | void Output::dirtyEntireOutput() { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1684 | auto& outputState = editState(); |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1685 | outputState.dirtyRegion.set(outputState.displaySpace.getBoundsAsRect()); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1686 | } |
| 1687 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1688 | void Output::resetCompositionStrategy() { |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1689 | // The base output implementation can only do client composition |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1690 | auto& outputState = editState(); |
| 1691 | outputState.usesClientComposition = true; |
| 1692 | outputState.usesDeviceComposition = false; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1693 | outputState.reusedClientComposition = false; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1694 | } |
| 1695 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1696 | bool Output::getSkipColorTransform() const { |
| 1697 | return true; |
| 1698 | } |
| 1699 | |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 1700 | compositionengine::Output::FrameFences Output::presentFrame() { |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 1701 | compositionengine::Output::FrameFences result; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1702 | if (getState().usesClientComposition) { |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 1703 | result.clientTargetAcquireFence = mRenderSurface->getClientTargetAcquireFence(); |
| 1704 | } |
| 1705 | return result; |
| 1706 | } |
| 1707 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1708 | void Output::setPredictCompositionStrategy(bool predict) { |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 1709 | mPredictCompositionStrategy = predict; |
| 1710 | updateHwcAsyncWorker(); |
| 1711 | } |
| 1712 | |
| 1713 | void Output::updateHwcAsyncWorker() { |
| 1714 | if (mPredictCompositionStrategy || mOffloadPresent) { |
| 1715 | if (!mHwComposerAsyncWorker) { |
| 1716 | mHwComposerAsyncWorker = std::make_unique<HwcAsyncWorker>(); |
| 1717 | } |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1718 | } else { |
| 1719 | mHwComposerAsyncWorker.reset(nullptr); |
| 1720 | } |
| 1721 | } |
| 1722 | |
Alec Mouri | dda07d9 | 2022-04-25 22:39:25 +0000 | [diff] [blame] | 1723 | void Output::setTreat170mAsSrgb(bool enable) { |
| 1724 | editState().treat170mAsSrgb = enable; |
| 1725 | } |
| 1726 | |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 1727 | const aidl::android::hardware::graphics::composer3::OverlayProperties* Output::getOverlaySupport() { |
| 1728 | return nullptr; |
| 1729 | } |
| 1730 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1731 | bool Output::canPredictCompositionStrategy(const CompositionRefreshArgs& refreshArgs) { |
Robert Carr | ec8ccca | 2022-05-04 09:36:14 -0700 | [diff] [blame] | 1732 | uint64_t lastOutputLayerHash = getState().lastOutputLayerHash; |
| 1733 | uint64_t outputLayerHash = getState().outputLayerHash; |
| 1734 | editState().lastOutputLayerHash = outputLayerHash; |
| 1735 | |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 1736 | if (!getState().isEnabled || !mPredictCompositionStrategy) { |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1737 | ALOGV("canPredictCompositionStrategy disabled"); |
| 1738 | return false; |
| 1739 | } |
| 1740 | |
| 1741 | if (!getState().previousDeviceRequestedChanges) { |
| 1742 | ALOGV("canPredictCompositionStrategy previous changes not available"); |
| 1743 | return false; |
| 1744 | } |
| 1745 | |
| 1746 | if (!mRenderSurface->supportsCompositionStrategyPrediction()) { |
| 1747 | ALOGV("canPredictCompositionStrategy surface does not support"); |
| 1748 | return false; |
| 1749 | } |
| 1750 | |
| 1751 | if (refreshArgs.devOptFlashDirtyRegionsDelay) { |
| 1752 | ALOGV("canPredictCompositionStrategy devOptFlashDirtyRegionsDelay"); |
| 1753 | return false; |
| 1754 | } |
| 1755 | |
Robert Carr | ec8ccca | 2022-05-04 09:36:14 -0700 | [diff] [blame] | 1756 | if (lastOutputLayerHash != outputLayerHash) { |
| 1757 | ALOGV("canPredictCompositionStrategy output layers changed"); |
| 1758 | return false; |
| 1759 | } |
| 1760 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1761 | // If no layer uses clientComposition, then don't predict composition strategy |
| 1762 | // because we have less work to do in parallel. |
| 1763 | if (!anyLayersRequireClientComposition()) { |
| 1764 | ALOGV("canPredictCompositionStrategy no layer uses clientComposition"); |
| 1765 | return false; |
| 1766 | } |
| 1767 | |
Robert Carr | ec8ccca | 2022-05-04 09:36:14 -0700 | [diff] [blame] | 1768 | return true; |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | bool Output::anyLayersRequireClientComposition() const { |
| 1772 | const auto layers = getOutputLayersOrderedByZ(); |
| 1773 | return std::any_of(layers.begin(), layers.end(), |
| 1774 | [](const auto& layer) { return layer->requiresClientComposition(); }); |
| 1775 | } |
| 1776 | |
| 1777 | void Output::finishPrepareFrame() { |
| 1778 | const auto& state = getState(); |
| 1779 | if (mPlanner) { |
| 1780 | mPlanner->reportFinalPlan(getOutputLayersOrderedByZ()); |
| 1781 | } |
| 1782 | mRenderSurface->prepareFrame(state.usesClientComposition, state.usesDeviceComposition); |
| 1783 | } |
| 1784 | |
Chavi Weingarten | 09fa1d6 | 2022-08-17 21:57:04 +0000 | [diff] [blame] | 1785 | bool Output::mustRecompose() const { |
| 1786 | return mMustRecompose; |
| 1787 | } |
| 1788 | |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 1789 | float Output::getHdrSdrRatio(const std::shared_ptr<renderengine::ExternalTexture>& buffer) const { |
| 1790 | if (buffer == nullptr) { |
| 1791 | return 1.0f; |
| 1792 | } |
| 1793 | |
| 1794 | if (!FlagManager::getInstance().fp16_client_target()) { |
| 1795 | return 1.0f; |
| 1796 | } |
| 1797 | |
| 1798 | if (getState().displayBrightnessNits < 0.0f || getState().sdrWhitePointNits <= 0.0f || |
| 1799 | buffer->getPixelFormat() != PIXEL_FORMAT_RGBA_FP16 || |
| 1800 | (static_cast<int32_t>(getState().dataspace) & |
| 1801 | static_cast<int32_t>(ui::Dataspace::RANGE_MASK)) != |
| 1802 | static_cast<int32_t>(ui::Dataspace::RANGE_EXTENDED)) { |
| 1803 | return 1.0f; |
| 1804 | } |
| 1805 | |
| 1806 | return getState().displayBrightnessNits / getState().sdrWhitePointNits; |
| 1807 | } |
| 1808 | |
Brian Lindahl | 1a4ffd8 | 2024-10-30 11:00:37 -0600 | [diff] [blame] | 1809 | bool Output::hasPictureProcessing() const { |
| 1810 | return false; |
| 1811 | } |
| 1812 | |
| 1813 | int32_t Output::getMaxLayerPictureProfiles() const { |
| 1814 | return 0; |
| 1815 | } |
| 1816 | |
| 1817 | void Output::applyPictureProfile() { |
| 1818 | if (!com_android_graphics_libgui_flags_apply_picture_profiles()) { |
| 1819 | return; |
| 1820 | } |
| 1821 | |
| 1822 | // TODO(b/337330263): Move this into the Display class and add a Display unit test. |
| 1823 | if (!getState().pictureProfileHandle) { |
| 1824 | return; |
| 1825 | } |
| 1826 | if (!getDisplayId()) { |
| 1827 | return; |
| 1828 | } |
| 1829 | if (auto displayId = PhysicalDisplayId::tryCast(*getDisplayId())) { |
| 1830 | auto& hwc = getCompositionEngine().getHwComposer(); |
| 1831 | const status_t error = |
| 1832 | hwc.setDisplayPictureProfileHandle(*displayId, getState().pictureProfileHandle); |
| 1833 | ALOGE_IF(error, "setDisplayPictureProfileHandle failed for %s: %d, (%s)", getName().c_str(), |
| 1834 | error, strerror(-error)); |
| 1835 | } |
| 1836 | } |
| 1837 | |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 1838 | } // namespace impl |
| 1839 | } // namespace android::compositionengine |