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