| 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 |  | 
| Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 17 | #include <thread> | 
|  | 18 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 19 | #include <android-base/stringprintf.h> | 
|  | 20 | #include <compositionengine/CompositionEngine.h> | 
| Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 21 | #include <compositionengine/CompositionRefreshArgs.h> | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 22 | #include <compositionengine/DisplayColorProfile.h> | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 23 | #include <compositionengine/Layer.h> | 
| Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 24 | #include <compositionengine/LayerFE.h> | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 25 | #include <compositionengine/RenderSurface.h> | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 26 | #include <compositionengine/impl/LayerCompositionState.h> | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 27 | #include <compositionengine/impl/Output.h> | 
| Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 28 | #include <compositionengine/impl/OutputLayer.h> | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 29 | #include <renderengine/DisplaySettings.h> | 
|  | 30 | #include <renderengine/RenderEngine.h> | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 31 | #include <ui/DebugUtils.h> | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 32 | #include <ui/HdrCapabilities.h> | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 33 | #include <utils/Trace.h> | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 34 |  | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 35 | #include "TracedOrdinal.h" | 
|  | 36 |  | 
| Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 37 | namespace android::compositionengine { | 
|  | 38 |  | 
|  | 39 | Output::~Output() = default; | 
|  | 40 |  | 
|  | 41 | namespace impl { | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 42 |  | 
|  | 43 | Output::Output(const CompositionEngine& compositionEngine) | 
|  | 44 | : mCompositionEngine(compositionEngine) {} | 
|  | 45 |  | 
|  | 46 | Output::~Output() = default; | 
|  | 47 |  | 
|  | 48 | const CompositionEngine& Output::getCompositionEngine() const { | 
|  | 49 | return mCompositionEngine; | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | bool Output::isValid() const { | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 53 | return mDisplayColorProfile && mDisplayColorProfile->isValid() && mRenderSurface && | 
|  | 54 | mRenderSurface->isValid(); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 55 | } | 
|  | 56 |  | 
|  | 57 | const std::string& Output::getName() const { | 
|  | 58 | return mName; | 
|  | 59 | } | 
|  | 60 |  | 
|  | 61 | void Output::setName(const std::string& name) { | 
|  | 62 | mName = name; | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 | void Output::setCompositionEnabled(bool enabled) { | 
|  | 66 | if (mState.isEnabled == enabled) { | 
|  | 67 | return; | 
|  | 68 | } | 
|  | 69 |  | 
|  | 70 | mState.isEnabled = enabled; | 
|  | 71 | dirtyEntireOutput(); | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | void Output::setProjection(const ui::Transform& transform, int32_t orientation, const Rect& frame, | 
|  | 75 | const Rect& viewport, const Rect& scissor, bool needsFiltering) { | 
|  | 76 | mState.transform = transform; | 
|  | 77 | mState.orientation = orientation; | 
|  | 78 | mState.scissor = scissor; | 
|  | 79 | mState.frame = frame; | 
|  | 80 | mState.viewport = viewport; | 
|  | 81 | mState.needsFiltering = needsFiltering; | 
|  | 82 |  | 
|  | 83 | dirtyEntireOutput(); | 
|  | 84 | } | 
|  | 85 |  | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 86 | // TODO(b/121291683): Rename setSize() once more is moved. | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 87 | void Output::setBounds(const ui::Size& size) { | 
|  | 88 | mRenderSurface->setDisplaySize(size); | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 89 | // TODO(b/121291683): Rename mState.size once more is moved. | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 90 | mState.bounds = Rect(mRenderSurface->getSize()); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 91 |  | 
|  | 92 | dirtyEntireOutput(); | 
|  | 93 | } | 
|  | 94 |  | 
| Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 95 | void Output::setLayerStackFilter(uint32_t layerStackId, bool isInternal) { | 
|  | 96 | mState.layerStackId = layerStackId; | 
|  | 97 | mState.layerStackInternal = isInternal; | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 98 |  | 
|  | 99 | dirtyEntireOutput(); | 
|  | 100 | } | 
|  | 101 |  | 
| Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 102 | void Output::setColorTransform(const compositionengine::CompositionRefreshArgs& args) { | 
|  | 103 | if (!args.colorTransformMatrix || mState.colorTransformMatrix == *args.colorTransformMatrix) { | 
| Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 104 | return; | 
|  | 105 | } | 
|  | 106 |  | 
| Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 107 | mState.colorTransformMatrix = *args.colorTransformMatrix; | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 108 |  | 
|  | 109 | dirtyEntireOutput(); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 110 | } | 
|  | 111 |  | 
| Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 112 | void Output::setColorProfile(const ColorProfile& colorProfile) { | 
|  | 113 | const ui::Dataspace targetDataspace = | 
|  | 114 | getDisplayColorProfile()->getTargetDataspace(colorProfile.mode, colorProfile.dataspace, | 
|  | 115 | colorProfile.colorSpaceAgnosticDataspace); | 
| Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 116 |  | 
| Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 117 | if (mState.colorMode == colorProfile.mode && mState.dataspace == colorProfile.dataspace && | 
|  | 118 | mState.renderIntent == colorProfile.renderIntent && | 
|  | 119 | mState.targetDataspace == targetDataspace) { | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 120 | return; | 
|  | 121 | } | 
|  | 122 |  | 
| Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 123 | mState.colorMode = colorProfile.mode; | 
|  | 124 | mState.dataspace = colorProfile.dataspace; | 
|  | 125 | mState.renderIntent = colorProfile.renderIntent; | 
| Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 126 | mState.targetDataspace = targetDataspace; | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 127 |  | 
| Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 128 | mRenderSurface->setBufferDataspace(colorProfile.dataspace); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 129 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 130 | ALOGV("Set active color mode: %s (%d), active render intent: %s (%d)", | 
| Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 131 | decodeColorMode(colorProfile.mode).c_str(), colorProfile.mode, | 
|  | 132 | decodeRenderIntent(colorProfile.renderIntent).c_str(), colorProfile.renderIntent); | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 133 |  | 
|  | 134 | dirtyEntireOutput(); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 135 | } | 
|  | 136 |  | 
|  | 137 | void Output::dump(std::string& out) const { | 
|  | 138 | using android::base::StringAppendF; | 
|  | 139 |  | 
|  | 140 | StringAppendF(&out, "   Composition Output State: [\"%s\"]", mName.c_str()); | 
|  | 141 |  | 
|  | 142 | out.append("\n   "); | 
|  | 143 |  | 
|  | 144 | dumpBase(out); | 
|  | 145 | } | 
|  | 146 |  | 
|  | 147 | void Output::dumpBase(std::string& out) const { | 
|  | 148 | mState.dump(out); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 149 |  | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 150 | if (mDisplayColorProfile) { | 
|  | 151 | mDisplayColorProfile->dump(out); | 
|  | 152 | } else { | 
|  | 153 | out.append("    No display color profile!\n"); | 
|  | 154 | } | 
|  | 155 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 156 | if (mRenderSurface) { | 
|  | 157 | mRenderSurface->dump(out); | 
|  | 158 | } else { | 
|  | 159 | out.append("    No render surface!\n"); | 
|  | 160 | } | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 161 |  | 
| Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 162 | android::base::StringAppendF(&out, "\n   %zu Layers\b", mOutputLayersOrderedByZ.size()); | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 163 | for (const auto& outputLayer : mOutputLayersOrderedByZ) { | 
|  | 164 | if (!outputLayer) { | 
|  | 165 | continue; | 
|  | 166 | } | 
|  | 167 | outputLayer->dump(out); | 
|  | 168 | } | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 169 | } | 
|  | 170 |  | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 171 | compositionengine::DisplayColorProfile* Output::getDisplayColorProfile() const { | 
|  | 172 | return mDisplayColorProfile.get(); | 
|  | 173 | } | 
|  | 174 |  | 
|  | 175 | void Output::setDisplayColorProfile(std::unique_ptr<compositionengine::DisplayColorProfile> mode) { | 
|  | 176 | mDisplayColorProfile = std::move(mode); | 
|  | 177 | } | 
|  | 178 |  | 
|  | 179 | void Output::setDisplayColorProfileForTest( | 
|  | 180 | std::unique_ptr<compositionengine::DisplayColorProfile> mode) { | 
|  | 181 | mDisplayColorProfile = std::move(mode); | 
|  | 182 | } | 
|  | 183 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 184 | compositionengine::RenderSurface* Output::getRenderSurface() const { | 
|  | 185 | return mRenderSurface.get(); | 
|  | 186 | } | 
|  | 187 |  | 
|  | 188 | void Output::setRenderSurface(std::unique_ptr<compositionengine::RenderSurface> surface) { | 
|  | 189 | mRenderSurface = std::move(surface); | 
|  | 190 | mState.bounds = Rect(mRenderSurface->getSize()); | 
|  | 191 |  | 
|  | 192 | dirtyEntireOutput(); | 
|  | 193 | } | 
|  | 194 |  | 
|  | 195 | void Output::setRenderSurfaceForTest(std::unique_ptr<compositionengine::RenderSurface> surface) { | 
|  | 196 | mRenderSurface = std::move(surface); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 197 | } | 
|  | 198 |  | 
|  | 199 | const OutputCompositionState& Output::getState() const { | 
|  | 200 | return mState; | 
|  | 201 | } | 
|  | 202 |  | 
|  | 203 | OutputCompositionState& Output::editState() { | 
|  | 204 | return mState; | 
|  | 205 | } | 
|  | 206 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 207 | Region Output::getDirtyRegion(bool repaintEverything) const { | 
|  | 208 | Region dirty(mState.viewport); | 
|  | 209 | if (!repaintEverything) { | 
|  | 210 | dirty.andSelf(mState.dirtyRegion); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 211 | } | 
|  | 212 | return dirty; | 
|  | 213 | } | 
|  | 214 |  | 
| Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 215 | bool Output::belongsInOutput(std::optional<uint32_t> layerStackId, bool internalOnly) const { | 
| Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 216 | // The layerStackId's must match, and also the layer must not be internal | 
|  | 217 | // only when not on an internal output. | 
| Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 218 | return layerStackId && (*layerStackId == mState.layerStackId) && | 
|  | 219 | (!internalOnly || mState.layerStackInternal); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 220 | } | 
|  | 221 |  | 
| Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 222 | compositionengine::OutputLayer* Output::getOutputLayerForLayer( | 
|  | 223 | compositionengine::Layer* layer) const { | 
|  | 224 | for (const auto& outputLayer : mOutputLayersOrderedByZ) { | 
|  | 225 | if (outputLayer && &outputLayer->getLayer() == layer) { | 
|  | 226 | return outputLayer.get(); | 
|  | 227 | } | 
|  | 228 | } | 
|  | 229 | return nullptr; | 
|  | 230 | } | 
|  | 231 |  | 
|  | 232 | std::unique_ptr<compositionengine::OutputLayer> Output::getOrCreateOutputLayer( | 
| Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 233 | std::shared_ptr<compositionengine::Layer> layer, sp<compositionengine::LayerFE> layerFE) { | 
| Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 234 | for (auto& outputLayer : mOutputLayersOrderedByZ) { | 
|  | 235 | if (outputLayer && &outputLayer->getLayer() == layer.get()) { | 
|  | 236 | return std::move(outputLayer); | 
|  | 237 | } | 
|  | 238 | } | 
| Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 239 |  | 
|  | 240 | return createOutputLayer(layer, layerFE); | 
|  | 241 | } | 
|  | 242 |  | 
|  | 243 | std::unique_ptr<compositionengine::OutputLayer> Output::createOutputLayer( | 
|  | 244 | const std::shared_ptr<compositionengine::Layer>& layer, | 
|  | 245 | const sp<compositionengine::LayerFE>& layerFE) const { | 
|  | 246 | return impl::createOutputLayer(*this, layer, layerFE); | 
| Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 247 | } | 
|  | 248 |  | 
|  | 249 | void Output::setOutputLayersOrderedByZ(OutputLayers&& layers) { | 
|  | 250 | mOutputLayersOrderedByZ = std::move(layers); | 
|  | 251 | } | 
|  | 252 |  | 
|  | 253 | const Output::OutputLayers& Output::getOutputLayersOrderedByZ() const { | 
|  | 254 | return mOutputLayersOrderedByZ; | 
|  | 255 | } | 
|  | 256 |  | 
| Lloyd Pique | c7ef21b | 2019-01-29 18:43:00 -0800 | [diff] [blame] | 257 | void Output::setReleasedLayers(Output::ReleasedLayers&& layers) { | 
|  | 258 | mReleasedLayers = std::move(layers); | 
|  | 259 | } | 
|  | 260 |  | 
|  | 261 | Output::ReleasedLayers Output::takeReleasedLayers() { | 
|  | 262 | return std::move(mReleasedLayers); | 
|  | 263 | } | 
|  | 264 |  | 
| Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 265 | void Output::prepare(compositionengine::CompositionRefreshArgs& refreshArgs) { | 
|  | 266 | if (CC_LIKELY(!refreshArgs.updatingGeometryThisFrame)) { | 
|  | 267 | return; | 
|  | 268 | } | 
|  | 269 |  | 
|  | 270 | uint32_t zOrder = 0; | 
|  | 271 | for (auto& layer : mOutputLayersOrderedByZ) { | 
|  | 272 | // Assign a simple Z order sequence to each visible layer. | 
|  | 273 | layer->editState().z = zOrder++; | 
|  | 274 | } | 
|  | 275 | } | 
|  | 276 |  | 
| Lloyd Pique | d7b429f | 2019-03-07 21:11:02 -0800 | [diff] [blame] | 277 | void Output::present(const compositionengine::CompositionRefreshArgs& refreshArgs) { | 
| Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 278 | updateColorProfile(refreshArgs); | 
|  | 279 | updateAndWriteCompositionState(refreshArgs); | 
|  | 280 | setColorTransform(refreshArgs); | 
| Lloyd Pique | d7b429f | 2019-03-07 21:11:02 -0800 | [diff] [blame] | 281 | beginFrame(); | 
|  | 282 | prepareFrame(); | 
|  | 283 | devOptRepaintFlash(refreshArgs); | 
|  | 284 | finishFrame(refreshArgs); | 
|  | 285 | postFramebuffer(); | 
|  | 286 | } | 
|  | 287 |  | 
| Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 288 | void Output::updateLayerStateFromFE(const CompositionRefreshArgs& args) const { | 
|  | 289 | for (auto& layer : mOutputLayersOrderedByZ) { | 
|  | 290 | layer->getLayerFE().latchCompositionState(layer->getLayer().editState().frontEnd, | 
| Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 291 | args.updatingGeometryThisFrame | 
|  | 292 | ? LayerFE::StateSubset::GeometryAndContent | 
|  | 293 | : LayerFE::StateSubset::Content); | 
| Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 294 | } | 
|  | 295 | } | 
|  | 296 |  | 
|  | 297 | void Output::updateAndWriteCompositionState( | 
|  | 298 | const compositionengine::CompositionRefreshArgs& refreshArgs) { | 
|  | 299 | ATRACE_CALL(); | 
|  | 300 | ALOGV(__FUNCTION__); | 
|  | 301 |  | 
|  | 302 | for (auto& layer : mOutputLayersOrderedByZ) { | 
|  | 303 | if (refreshArgs.devOptForceClientComposition) { | 
|  | 304 | layer->editState().forceClientComposition = true; | 
|  | 305 | } | 
|  | 306 |  | 
|  | 307 | layer->updateCompositionState(refreshArgs.updatingGeometryThisFrame); | 
|  | 308 |  | 
|  | 309 | // Send the updated state to the HWC, if appropriate. | 
|  | 310 | layer->writeStateToHWC(refreshArgs.updatingGeometryThisFrame); | 
|  | 311 | } | 
|  | 312 | } | 
|  | 313 |  | 
| Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 314 | void Output::updateColorProfile(const compositionengine::CompositionRefreshArgs& refreshArgs) { | 
|  | 315 | setColorProfile(pickColorProfile(refreshArgs)); | 
|  | 316 | } | 
|  | 317 |  | 
|  | 318 | // Returns a data space that fits all visible layers.  The returned data space | 
|  | 319 | // can only be one of | 
|  | 320 | //  - Dataspace::SRGB (use legacy dataspace and let HWC saturate when colors are enhanced) | 
|  | 321 | //  - Dataspace::DISPLAY_P3 | 
|  | 322 | //  - Dataspace::DISPLAY_BT2020 | 
|  | 323 | // The returned HDR data space is one of | 
|  | 324 | //  - Dataspace::UNKNOWN | 
|  | 325 | //  - Dataspace::BT2020_HLG | 
|  | 326 | //  - Dataspace::BT2020_PQ | 
|  | 327 | ui::Dataspace Output::getBestDataspace(ui::Dataspace* outHdrDataSpace, | 
|  | 328 | bool* outIsHdrClientComposition) const { | 
|  | 329 | ui::Dataspace bestDataSpace = ui::Dataspace::V0_SRGB; | 
|  | 330 | *outHdrDataSpace = ui::Dataspace::UNKNOWN; | 
|  | 331 |  | 
|  | 332 | for (const auto& layer : mOutputLayersOrderedByZ) { | 
|  | 333 | switch (layer->getLayer().getState().frontEnd.dataspace) { | 
|  | 334 | case ui::Dataspace::V0_SCRGB: | 
|  | 335 | case ui::Dataspace::V0_SCRGB_LINEAR: | 
|  | 336 | case ui::Dataspace::BT2020: | 
|  | 337 | case ui::Dataspace::BT2020_ITU: | 
|  | 338 | case ui::Dataspace::BT2020_LINEAR: | 
|  | 339 | case ui::Dataspace::DISPLAY_BT2020: | 
|  | 340 | bestDataSpace = ui::Dataspace::DISPLAY_BT2020; | 
|  | 341 | break; | 
|  | 342 | case ui::Dataspace::DISPLAY_P3: | 
|  | 343 | bestDataSpace = ui::Dataspace::DISPLAY_P3; | 
|  | 344 | break; | 
|  | 345 | case ui::Dataspace::BT2020_PQ: | 
|  | 346 | case ui::Dataspace::BT2020_ITU_PQ: | 
|  | 347 | bestDataSpace = ui::Dataspace::DISPLAY_P3; | 
|  | 348 | *outHdrDataSpace = ui::Dataspace::BT2020_PQ; | 
|  | 349 | *outIsHdrClientComposition = | 
|  | 350 | layer->getLayer().getState().frontEnd.forceClientComposition; | 
|  | 351 | break; | 
|  | 352 | case ui::Dataspace::BT2020_HLG: | 
|  | 353 | case ui::Dataspace::BT2020_ITU_HLG: | 
|  | 354 | bestDataSpace = ui::Dataspace::DISPLAY_P3; | 
|  | 355 | // When there's mixed PQ content and HLG content, we set the HDR | 
|  | 356 | // data space to be BT2020_PQ and convert HLG to PQ. | 
|  | 357 | if (*outHdrDataSpace == ui::Dataspace::UNKNOWN) { | 
|  | 358 | *outHdrDataSpace = ui::Dataspace::BT2020_HLG; | 
|  | 359 | } | 
|  | 360 | break; | 
|  | 361 | default: | 
|  | 362 | break; | 
|  | 363 | } | 
|  | 364 | } | 
|  | 365 |  | 
|  | 366 | return bestDataSpace; | 
|  | 367 | } | 
|  | 368 |  | 
|  | 369 | compositionengine::Output::ColorProfile Output::pickColorProfile( | 
|  | 370 | const compositionengine::CompositionRefreshArgs& refreshArgs) const { | 
|  | 371 | if (refreshArgs.outputColorSetting == OutputColorSetting::kUnmanaged) { | 
|  | 372 | return ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN, | 
|  | 373 | ui::RenderIntent::COLORIMETRIC, | 
|  | 374 | refreshArgs.colorSpaceAgnosticDataspace}; | 
|  | 375 | } | 
|  | 376 |  | 
|  | 377 | ui::Dataspace hdrDataSpace; | 
|  | 378 | bool isHdrClientComposition = false; | 
|  | 379 | ui::Dataspace bestDataSpace = getBestDataspace(&hdrDataSpace, &isHdrClientComposition); | 
|  | 380 |  | 
|  | 381 | switch (refreshArgs.forceOutputColorMode) { | 
|  | 382 | case ui::ColorMode::SRGB: | 
|  | 383 | bestDataSpace = ui::Dataspace::V0_SRGB; | 
|  | 384 | break; | 
|  | 385 | case ui::ColorMode::DISPLAY_P3: | 
|  | 386 | bestDataSpace = ui::Dataspace::DISPLAY_P3; | 
|  | 387 | break; | 
|  | 388 | default: | 
|  | 389 | break; | 
|  | 390 | } | 
|  | 391 |  | 
|  | 392 | // respect hdrDataSpace only when there is no legacy HDR support | 
|  | 393 | const bool isHdr = hdrDataSpace != ui::Dataspace::UNKNOWN && | 
|  | 394 | !mDisplayColorProfile->hasLegacyHdrSupport(hdrDataSpace) && !isHdrClientComposition; | 
|  | 395 | if (isHdr) { | 
|  | 396 | bestDataSpace = hdrDataSpace; | 
|  | 397 | } | 
|  | 398 |  | 
|  | 399 | ui::RenderIntent intent; | 
|  | 400 | switch (refreshArgs.outputColorSetting) { | 
|  | 401 | case OutputColorSetting::kManaged: | 
|  | 402 | case OutputColorSetting::kUnmanaged: | 
|  | 403 | intent = isHdr ? ui::RenderIntent::TONE_MAP_COLORIMETRIC | 
|  | 404 | : ui::RenderIntent::COLORIMETRIC; | 
|  | 405 | break; | 
|  | 406 | case OutputColorSetting::kEnhanced: | 
|  | 407 | intent = isHdr ? ui::RenderIntent::TONE_MAP_ENHANCE : ui::RenderIntent::ENHANCE; | 
|  | 408 | break; | 
|  | 409 | default: // vendor display color setting | 
|  | 410 | intent = static_cast<ui::RenderIntent>(refreshArgs.outputColorSetting); | 
|  | 411 | break; | 
|  | 412 | } | 
|  | 413 |  | 
|  | 414 | ui::ColorMode outMode; | 
|  | 415 | ui::Dataspace outDataSpace; | 
|  | 416 | ui::RenderIntent outRenderIntent; | 
|  | 417 | mDisplayColorProfile->getBestColorMode(bestDataSpace, intent, &outDataSpace, &outMode, | 
|  | 418 | &outRenderIntent); | 
|  | 419 |  | 
|  | 420 | return ColorProfile{outMode, outDataSpace, outRenderIntent, | 
|  | 421 | refreshArgs.colorSpaceAgnosticDataspace}; | 
|  | 422 | } | 
|  | 423 |  | 
| Lloyd Pique | d0a92a0 | 2019-02-19 17:47:26 -0800 | [diff] [blame] | 424 | void Output::beginFrame() { | 
|  | 425 | const bool dirty = !getDirtyRegion(false).isEmpty(); | 
|  | 426 | const bool empty = mOutputLayersOrderedByZ.empty(); | 
|  | 427 | const bool wasEmpty = !mState.lastCompositionHadVisibleLayers; | 
|  | 428 |  | 
|  | 429 | // If nothing has changed (!dirty), don't recompose. | 
|  | 430 | // If something changed, but we don't currently have any visible layers, | 
|  | 431 | //   and didn't when we last did a composition, then skip it this time. | 
|  | 432 | // The second rule does two things: | 
|  | 433 | // - When all layers are removed from a display, we'll emit one black | 
|  | 434 | //   frame, then nothing more until we get new layers. | 
|  | 435 | // - When a display is created with a private layer stack, we won't | 
|  | 436 | //   emit any black frames until a layer is added to the layer stack. | 
|  | 437 | const bool mustRecompose = dirty && !(empty && wasEmpty); | 
|  | 438 |  | 
|  | 439 | const char flagPrefix[] = {'-', '+'}; | 
|  | 440 | static_cast<void>(flagPrefix); | 
|  | 441 | ALOGV_IF("%s: %s composition for %s (%cdirty %cempty %cwasEmpty)", __FUNCTION__, | 
|  | 442 | mustRecompose ? "doing" : "skipping", getName().c_str(), flagPrefix[dirty], | 
|  | 443 | flagPrefix[empty], flagPrefix[wasEmpty]); | 
|  | 444 |  | 
|  | 445 | mRenderSurface->beginFrame(mustRecompose); | 
|  | 446 |  | 
|  | 447 | if (mustRecompose) { | 
|  | 448 | mState.lastCompositionHadVisibleLayers = !empty; | 
|  | 449 | } | 
|  | 450 | } | 
|  | 451 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 452 | void Output::prepareFrame() { | 
|  | 453 | ATRACE_CALL(); | 
|  | 454 | ALOGV(__FUNCTION__); | 
|  | 455 |  | 
|  | 456 | if (!mState.isEnabled) { | 
|  | 457 | return; | 
|  | 458 | } | 
|  | 459 |  | 
|  | 460 | chooseCompositionStrategy(); | 
|  | 461 |  | 
|  | 462 | mRenderSurface->prepareFrame(mState.usesClientComposition, mState.usesDeviceComposition); | 
|  | 463 | } | 
|  | 464 |  | 
| Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 465 | void Output::devOptRepaintFlash(const compositionengine::CompositionRefreshArgs& refreshArgs) { | 
|  | 466 | if (CC_LIKELY(!refreshArgs.devOptFlashDirtyRegionsDelay)) { | 
|  | 467 | return; | 
|  | 468 | } | 
|  | 469 |  | 
|  | 470 | if (mState.isEnabled) { | 
|  | 471 | // transform the dirty region into this screen's coordinate space | 
|  | 472 | const Region dirtyRegion = getDirtyRegion(refreshArgs.repaintEverything); | 
|  | 473 | if (!dirtyRegion.isEmpty()) { | 
|  | 474 | base::unique_fd readyFence; | 
|  | 475 | // redraw the whole screen | 
| Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 476 | static_cast<void>(composeSurfaces(dirtyRegion)); | 
| Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 477 |  | 
|  | 478 | mRenderSurface->queueBuffer(std::move(readyFence)); | 
|  | 479 | } | 
|  | 480 | } | 
|  | 481 |  | 
|  | 482 | postFramebuffer(); | 
|  | 483 |  | 
|  | 484 | std::this_thread::sleep_for(*refreshArgs.devOptFlashDirtyRegionsDelay); | 
|  | 485 |  | 
|  | 486 | prepareFrame(); | 
|  | 487 | } | 
|  | 488 |  | 
| Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 489 | void Output::finishFrame(const compositionengine::CompositionRefreshArgs&) { | 
|  | 490 | ATRACE_CALL(); | 
|  | 491 | ALOGV(__FUNCTION__); | 
|  | 492 |  | 
|  | 493 | if (!mState.isEnabled) { | 
|  | 494 | return; | 
|  | 495 | } | 
|  | 496 |  | 
|  | 497 | // Repaint the framebuffer (if needed), getting the optional fence for when | 
|  | 498 | // the composition completes. | 
|  | 499 | auto optReadyFence = composeSurfaces(Region::INVALID_REGION); | 
|  | 500 | if (!optReadyFence) { | 
|  | 501 | return; | 
|  | 502 | } | 
|  | 503 |  | 
|  | 504 | // swap buffers (presentation) | 
|  | 505 | mRenderSurface->queueBuffer(std::move(*optReadyFence)); | 
|  | 506 | } | 
|  | 507 |  | 
|  | 508 | std::optional<base::unique_fd> Output::composeSurfaces(const Region& debugRegion) { | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 509 | ATRACE_CALL(); | 
|  | 510 | ALOGV(__FUNCTION__); | 
|  | 511 |  | 
|  | 512 | const TracedOrdinal<bool> hasClientComposition = {"hasClientComposition", | 
|  | 513 | mState.usesClientComposition}; | 
| Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 514 | base::unique_fd readyFence; | 
|  | 515 |  | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 516 | if (!hasClientComposition) { | 
| Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 517 | return readyFence; | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 518 | } | 
|  | 519 |  | 
|  | 520 | ALOGV("hasClientComposition"); | 
|  | 521 |  | 
|  | 522 | auto& renderEngine = mCompositionEngine.getRenderEngine(); | 
|  | 523 | const bool supportsProtectedContent = renderEngine.supportsProtectedContent(); | 
|  | 524 |  | 
|  | 525 | renderengine::DisplaySettings clientCompositionDisplay; | 
| Lloyd Pique | 810b030 | 2019-08-14 16:09:32 -0700 | [diff] [blame] | 526 | clientCompositionDisplay.physicalDisplay = mState.scissor; | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 527 | clientCompositionDisplay.clip = mState.scissor; | 
|  | 528 | clientCompositionDisplay.globalTransform = mState.transform.asMatrix4(); | 
|  | 529 | clientCompositionDisplay.orientation = mState.orientation; | 
|  | 530 | clientCompositionDisplay.outputDataspace = | 
|  | 531 | mDisplayColorProfile->hasWideColorGamut() ? mState.dataspace : ui::Dataspace::UNKNOWN; | 
|  | 532 | clientCompositionDisplay.maxLuminance = | 
|  | 533 | mDisplayColorProfile->getHdrCapabilities().getDesiredMaxLuminance(); | 
|  | 534 |  | 
|  | 535 | // Compute the global color transform matrix. | 
|  | 536 | if (!mState.usesDeviceComposition && !getSkipColorTransform()) { | 
| Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 537 | clientCompositionDisplay.colorTransform = mState.colorTransformMatrix; | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 538 | } | 
|  | 539 |  | 
|  | 540 | // Note: Updated by generateClientCompositionRequests | 
|  | 541 | clientCompositionDisplay.clearRegion = Region::INVALID_REGION; | 
|  | 542 |  | 
|  | 543 | // Generate the client composition requests for the layers on this output. | 
|  | 544 | std::vector<renderengine::LayerSettings> clientCompositionLayers = | 
|  | 545 | generateClientCompositionRequests(supportsProtectedContent, | 
|  | 546 | clientCompositionDisplay.clearRegion); | 
|  | 547 | appendRegionFlashRequests(debugRegion, clientCompositionLayers); | 
|  | 548 |  | 
|  | 549 | // If we the display is secure, protected content support is enabled, and at | 
|  | 550 | // least one layer has protected content, we need to use a secure back | 
|  | 551 | // buffer. | 
|  | 552 | if (mState.isSecure && supportsProtectedContent) { | 
|  | 553 | bool needsProtected = | 
|  | 554 | std::any_of(mOutputLayersOrderedByZ.begin(), mOutputLayersOrderedByZ.end(), | 
|  | 555 | [](auto& layer) { | 
|  | 556 | return layer->getLayer().getState().frontEnd.hasProtectedContent; | 
|  | 557 | }); | 
|  | 558 | if (needsProtected != renderEngine.isProtected()) { | 
|  | 559 | renderEngine.useProtectedContext(needsProtected); | 
|  | 560 | } | 
|  | 561 | if (needsProtected != mRenderSurface->isProtected() && | 
|  | 562 | needsProtected == renderEngine.isProtected()) { | 
|  | 563 | mRenderSurface->setProtected(needsProtected); | 
|  | 564 | } | 
|  | 565 | } | 
|  | 566 |  | 
|  | 567 | base::unique_fd fd; | 
|  | 568 | sp<GraphicBuffer> buf = mRenderSurface->dequeueBuffer(&fd); | 
|  | 569 | if (buf == nullptr) { | 
|  | 570 | ALOGW("Dequeuing buffer for display [%s] failed, bailing out of " | 
|  | 571 | "client composition for this frame", | 
|  | 572 | mName.c_str()); | 
| Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 573 | return std::nullopt; | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 574 | } | 
|  | 575 |  | 
|  | 576 | // We boost GPU frequency here because there will be color spaces conversion | 
|  | 577 | // and it's expensive. We boost the GPU frequency so that GPU composition can | 
|  | 578 | // finish in time. We must reset GPU frequency afterwards, because high frequency | 
|  | 579 | // consumes extra battery. | 
|  | 580 | const bool expensiveRenderingExpected = | 
|  | 581 | clientCompositionDisplay.outputDataspace == ui::Dataspace::DISPLAY_P3; | 
|  | 582 | if (expensiveRenderingExpected) { | 
|  | 583 | setExpensiveRenderingExpected(true); | 
|  | 584 | } | 
|  | 585 |  | 
|  | 586 | renderEngine.drawLayers(clientCompositionDisplay, clientCompositionLayers, | 
|  | 587 | buf->getNativeBuffer(), /*useFramebufferCache=*/true, std::move(fd), | 
| Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 588 | &readyFence); | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 589 |  | 
|  | 590 | if (expensiveRenderingExpected) { | 
|  | 591 | setExpensiveRenderingExpected(false); | 
|  | 592 | } | 
|  | 593 |  | 
| Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 594 | return readyFence; | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 595 | } | 
|  | 596 |  | 
|  | 597 | std::vector<renderengine::LayerSettings> Output::generateClientCompositionRequests( | 
|  | 598 | bool supportsProtectedContent, Region& clearRegion) { | 
|  | 599 | std::vector<renderengine::LayerSettings> clientCompositionLayers; | 
|  | 600 | ALOGV("Rendering client layers"); | 
|  | 601 |  | 
|  | 602 | const Region viewportRegion(mState.viewport); | 
|  | 603 | const bool useIdentityTransform = false; | 
|  | 604 | bool firstLayer = true; | 
|  | 605 | // Used when a layer clears part of the buffer. | 
|  | 606 | Region dummyRegion; | 
|  | 607 |  | 
|  | 608 | for (auto& layer : mOutputLayersOrderedByZ) { | 
|  | 609 | const auto& layerState = layer->getState(); | 
|  | 610 | const auto& layerFEState = layer->getLayer().getState().frontEnd; | 
|  | 611 | auto& layerFE = layer->getLayerFE(); | 
|  | 612 |  | 
| Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 613 | const Region clip(viewportRegion.intersect(layerState.visibleRegion)); | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 614 | ALOGV("Layer: %s", layerFE.getDebugName()); | 
|  | 615 | if (clip.isEmpty()) { | 
|  | 616 | ALOGV("  Skipping for empty clip"); | 
|  | 617 | firstLayer = false; | 
|  | 618 | continue; | 
|  | 619 | } | 
|  | 620 |  | 
|  | 621 | bool clientComposition = layer->requiresClientComposition(); | 
|  | 622 |  | 
|  | 623 | // We clear the client target for non-client composed layers if | 
|  | 624 | // requested by the HWC. We skip this if the layer is not an opaque | 
|  | 625 | // rectangle, as by definition the layer must blend with whatever is | 
|  | 626 | // underneath. We also skip the first layer as the buffer target is | 
|  | 627 | // guaranteed to start out cleared. | 
|  | 628 | bool clearClientComposition = | 
|  | 629 | layerState.clearClientTarget && layerFEState.isOpaque && !firstLayer; | 
|  | 630 |  | 
|  | 631 | ALOGV("  Composition type: client %d clear %d", clientComposition, clearClientComposition); | 
|  | 632 |  | 
|  | 633 | if (clientComposition || clearClientComposition) { | 
|  | 634 | compositionengine::LayerFE::ClientCompositionTargetSettings targetSettings{ | 
|  | 635 | clip, | 
|  | 636 | useIdentityTransform, | 
|  | 637 | layer->needsFiltering() || mState.needsFiltering, | 
|  | 638 | mState.isSecure, | 
|  | 639 | supportsProtectedContent, | 
|  | 640 | clientComposition ? clearRegion : dummyRegion, | 
|  | 641 | }; | 
|  | 642 | if (auto result = layerFE.prepareClientComposition(targetSettings)) { | 
| Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 643 | if (!clientComposition) { | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 644 | auto& layerSettings = *result; | 
|  | 645 | layerSettings.source.buffer.buffer = nullptr; | 
|  | 646 | layerSettings.source.solidColor = half3(0.0, 0.0, 0.0); | 
|  | 647 | layerSettings.alpha = half(0.0); | 
|  | 648 | layerSettings.disableBlending = true; | 
|  | 649 | } | 
|  | 650 |  | 
|  | 651 | clientCompositionLayers.push_back(*result); | 
|  | 652 | } | 
|  | 653 | } | 
|  | 654 |  | 
|  | 655 | firstLayer = false; | 
|  | 656 | } | 
|  | 657 |  | 
|  | 658 | return clientCompositionLayers; | 
|  | 659 | } | 
|  | 660 |  | 
|  | 661 | void Output::appendRegionFlashRequests( | 
|  | 662 | const Region& flashRegion, | 
|  | 663 | std::vector<renderengine::LayerSettings>& clientCompositionLayers) { | 
|  | 664 | if (flashRegion.isEmpty()) { | 
|  | 665 | return; | 
|  | 666 | } | 
|  | 667 |  | 
|  | 668 | renderengine::LayerSettings layerSettings; | 
|  | 669 | layerSettings.source.buffer.buffer = nullptr; | 
|  | 670 | layerSettings.source.solidColor = half3(1.0, 0.0, 1.0); | 
|  | 671 | layerSettings.alpha = half(1.0); | 
|  | 672 |  | 
|  | 673 | for (const auto& rect : flashRegion) { | 
|  | 674 | layerSettings.geometry.boundaries = rect.toFloatRect(); | 
|  | 675 | clientCompositionLayers.push_back(layerSettings); | 
|  | 676 | } | 
|  | 677 | } | 
|  | 678 |  | 
|  | 679 | void Output::setExpensiveRenderingExpected(bool) { | 
|  | 680 | // The base class does nothing with this call. | 
|  | 681 | } | 
|  | 682 |  | 
| Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 683 | void Output::postFramebuffer() { | 
|  | 684 | ATRACE_CALL(); | 
|  | 685 | ALOGV(__FUNCTION__); | 
|  | 686 |  | 
|  | 687 | if (!getState().isEnabled) { | 
|  | 688 | return; | 
|  | 689 | } | 
|  | 690 |  | 
| Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 691 | mState.dirtyRegion.clear(); | 
|  | 692 | mRenderSurface->flip(); | 
|  | 693 |  | 
| Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 694 | auto frame = presentAndGetFrameFences(); | 
|  | 695 |  | 
| Lloyd Pique | 7d90ba5 | 2019-08-08 11:57:53 -0700 | [diff] [blame] | 696 | mRenderSurface->onPresentDisplayCompleted(); | 
|  | 697 |  | 
| Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 698 | for (auto& layer : getOutputLayersOrderedByZ()) { | 
|  | 699 | // The layer buffer from the previous frame (if any) is released | 
|  | 700 | // by HWC only when the release fence from this frame (if any) is | 
|  | 701 | // signaled.  Always get the release fence from HWC first. | 
|  | 702 | sp<Fence> releaseFence = Fence::NO_FENCE; | 
|  | 703 |  | 
|  | 704 | if (auto hwcLayer = layer->getHwcLayer()) { | 
|  | 705 | if (auto f = frame.layerFences.find(hwcLayer); f != frame.layerFences.end()) { | 
|  | 706 | releaseFence = f->second; | 
|  | 707 | } | 
|  | 708 | } | 
|  | 709 |  | 
|  | 710 | // If the layer was client composited in the previous frame, we | 
|  | 711 | // need to merge with the previous client target acquire fence. | 
|  | 712 | // Since we do not track that, always merge with the current | 
|  | 713 | // client target acquire fence when it is available, even though | 
|  | 714 | // this is suboptimal. | 
|  | 715 | // TODO(b/121291683): Track previous frame client target acquire fence. | 
|  | 716 | if (mState.usesClientComposition) { | 
|  | 717 | releaseFence = | 
|  | 718 | Fence::merge("LayerRelease", releaseFence, frame.clientTargetAcquireFence); | 
|  | 719 | } | 
|  | 720 |  | 
|  | 721 | layer->getLayerFE().onLayerDisplayed(releaseFence); | 
|  | 722 | } | 
|  | 723 |  | 
|  | 724 | // We've got a list of layers needing fences, that are disjoint with | 
|  | 725 | // getOutputLayersOrderedByZ.  The best we can do is to | 
|  | 726 | // supply them with the present fence. | 
|  | 727 | for (auto& weakLayer : mReleasedLayers) { | 
|  | 728 | if (auto layer = weakLayer.promote(); layer != nullptr) { | 
|  | 729 | layer->onLayerDisplayed(frame.presentFence); | 
|  | 730 | } | 
|  | 731 | } | 
|  | 732 |  | 
|  | 733 | // Clear out the released layers now that we're done with them. | 
|  | 734 | mReleasedLayers.clear(); | 
|  | 735 | } | 
|  | 736 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 737 | void Output::dirtyEntireOutput() { | 
|  | 738 | mState.dirtyRegion.set(mState.bounds); | 
|  | 739 | } | 
|  | 740 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 741 | void Output::chooseCompositionStrategy() { | 
|  | 742 | // The base output implementation can only do client composition | 
|  | 743 | mState.usesClientComposition = true; | 
|  | 744 | mState.usesDeviceComposition = false; | 
|  | 745 | } | 
|  | 746 |  | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 747 | bool Output::getSkipColorTransform() const { | 
|  | 748 | return true; | 
|  | 749 | } | 
|  | 750 |  | 
| Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 751 | compositionengine::Output::FrameFences Output::presentAndGetFrameFences() { | 
|  | 752 | compositionengine::Output::FrameFences result; | 
|  | 753 | if (mState.usesClientComposition) { | 
|  | 754 | result.clientTargetAcquireFence = mRenderSurface->getClientTargetAcquireFence(); | 
|  | 755 | } | 
|  | 756 | return result; | 
|  | 757 | } | 
|  | 758 |  | 
| Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 759 | } // namespace impl | 
|  | 760 | } // namespace android::compositionengine |