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