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