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