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