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