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