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