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