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