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