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 | |
| 17 | #include <android-base/stringprintf.h> |
| 18 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 19 | #include <compositionengine/DisplayColorProfile.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 20 | #include <compositionengine/LayerFE.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 21 | #include <compositionengine/RenderSurface.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 22 | #include <compositionengine/impl/Output.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 23 | #include <compositionengine/impl/OutputLayer.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 24 | #include <ui/DebugUtils.h> |
| 25 | |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 26 | namespace android::compositionengine { |
| 27 | |
| 28 | Output::~Output() = default; |
| 29 | |
| 30 | namespace impl { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 31 | |
| 32 | Output::Output(const CompositionEngine& compositionEngine) |
| 33 | : mCompositionEngine(compositionEngine) {} |
| 34 | |
| 35 | Output::~Output() = default; |
| 36 | |
| 37 | const CompositionEngine& Output::getCompositionEngine() const { |
| 38 | return mCompositionEngine; |
| 39 | } |
| 40 | |
| 41 | bool Output::isValid() const { |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 42 | return mDisplayColorProfile && mDisplayColorProfile->isValid() && mRenderSurface && |
| 43 | mRenderSurface->isValid(); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | const std::string& Output::getName() const { |
| 47 | return mName; |
| 48 | } |
| 49 | |
| 50 | void Output::setName(const std::string& name) { |
| 51 | mName = name; |
| 52 | } |
| 53 | |
| 54 | void Output::setCompositionEnabled(bool enabled) { |
| 55 | if (mState.isEnabled == enabled) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | mState.isEnabled = enabled; |
| 60 | dirtyEntireOutput(); |
| 61 | } |
| 62 | |
| 63 | void Output::setProjection(const ui::Transform& transform, int32_t orientation, const Rect& frame, |
| 64 | const Rect& viewport, const Rect& scissor, bool needsFiltering) { |
| 65 | mState.transform = transform; |
| 66 | mState.orientation = orientation; |
| 67 | mState.scissor = scissor; |
| 68 | mState.frame = frame; |
| 69 | mState.viewport = viewport; |
| 70 | mState.needsFiltering = needsFiltering; |
| 71 | |
| 72 | dirtyEntireOutput(); |
| 73 | } |
| 74 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 75 | // TODO(lpique): Rename setSize() once more is moved. |
| 76 | void Output::setBounds(const ui::Size& size) { |
| 77 | mRenderSurface->setDisplaySize(size); |
| 78 | // TODO(lpique): Rename mState.size once more is moved. |
| 79 | mState.bounds = Rect(mRenderSurface->getSize()); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 80 | |
| 81 | dirtyEntireOutput(); |
| 82 | } |
| 83 | |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 84 | void Output::setLayerStackFilter(uint32_t layerStackId, bool isInternal) { |
| 85 | mState.layerStackId = layerStackId; |
| 86 | mState.layerStackInternal = isInternal; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 87 | |
| 88 | dirtyEntireOutput(); |
| 89 | } |
| 90 | |
| 91 | void Output::setColorTransform(const mat4& transform) { |
| 92 | const bool isIdentity = (transform == mat4()); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 93 | const auto newColorTransform = |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 94 | isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX; |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 95 | |
| 96 | if (mState.colorTransform == newColorTransform) { |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | mState.colorTransform = newColorTransform; |
Alec Mouri | c7e8ce8 | 2019-04-02 12:28:05 -0700 | [diff] [blame] | 101 | mState.colorTransformMat = transform; |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 102 | |
| 103 | dirtyEntireOutput(); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | void Output::setColorMode(ui::ColorMode mode, ui::Dataspace dataspace, |
| 107 | ui::RenderIntent renderIntent) { |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 108 | if (mState.colorMode == mode && mState.dataspace == dataspace && |
| 109 | mState.renderIntent == renderIntent) { |
| 110 | return; |
| 111 | } |
| 112 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 113 | mState.colorMode = mode; |
| 114 | mState.dataspace = dataspace; |
| 115 | mState.renderIntent = renderIntent; |
| 116 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 117 | mRenderSurface->setBufferDataspace(dataspace); |
| 118 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 119 | ALOGV("Set active color mode: %s (%d), active render intent: %s (%d)", |
| 120 | decodeColorMode(mode).c_str(), mode, decodeRenderIntent(renderIntent).c_str(), |
| 121 | renderIntent); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 122 | |
| 123 | dirtyEntireOutput(); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void Output::dump(std::string& out) const { |
| 127 | using android::base::StringAppendF; |
| 128 | |
| 129 | StringAppendF(&out, " Composition Output State: [\"%s\"]", mName.c_str()); |
| 130 | |
| 131 | out.append("\n "); |
| 132 | |
| 133 | dumpBase(out); |
| 134 | } |
| 135 | |
| 136 | void Output::dumpBase(std::string& out) const { |
| 137 | mState.dump(out); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 138 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 139 | if (mDisplayColorProfile) { |
| 140 | mDisplayColorProfile->dump(out); |
| 141 | } else { |
| 142 | out.append(" No display color profile!\n"); |
| 143 | } |
| 144 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 145 | if (mRenderSurface) { |
| 146 | mRenderSurface->dump(out); |
| 147 | } else { |
| 148 | out.append(" No render surface!\n"); |
| 149 | } |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 150 | |
Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 151 | android::base::StringAppendF(&out, "\n %zu Layers\b", mOutputLayersOrderedByZ.size()); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 152 | for (const auto& outputLayer : mOutputLayersOrderedByZ) { |
| 153 | if (!outputLayer) { |
| 154 | continue; |
| 155 | } |
| 156 | outputLayer->dump(out); |
| 157 | } |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 160 | compositionengine::DisplayColorProfile* Output::getDisplayColorProfile() const { |
| 161 | return mDisplayColorProfile.get(); |
| 162 | } |
| 163 | |
| 164 | void Output::setDisplayColorProfile(std::unique_ptr<compositionengine::DisplayColorProfile> mode) { |
| 165 | mDisplayColorProfile = std::move(mode); |
| 166 | } |
| 167 | |
| 168 | void Output::setDisplayColorProfileForTest( |
| 169 | std::unique_ptr<compositionengine::DisplayColorProfile> mode) { |
| 170 | mDisplayColorProfile = std::move(mode); |
| 171 | } |
| 172 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 173 | compositionengine::RenderSurface* Output::getRenderSurface() const { |
| 174 | return mRenderSurface.get(); |
| 175 | } |
| 176 | |
| 177 | void Output::setRenderSurface(std::unique_ptr<compositionengine::RenderSurface> surface) { |
| 178 | mRenderSurface = std::move(surface); |
| 179 | mState.bounds = Rect(mRenderSurface->getSize()); |
| 180 | |
| 181 | dirtyEntireOutput(); |
| 182 | } |
| 183 | |
| 184 | void Output::setRenderSurfaceForTest(std::unique_ptr<compositionengine::RenderSurface> surface) { |
| 185 | mRenderSurface = std::move(surface); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | const OutputCompositionState& Output::getState() const { |
| 189 | return mState; |
| 190 | } |
| 191 | |
| 192 | OutputCompositionState& Output::editState() { |
| 193 | return mState; |
| 194 | } |
| 195 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 196 | Region Output::getDirtyRegion(bool repaintEverything) const { |
| 197 | Region dirty(mState.viewport); |
| 198 | if (!repaintEverything) { |
| 199 | dirty.andSelf(mState.dirtyRegion); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 200 | } |
| 201 | return dirty; |
| 202 | } |
| 203 | |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 204 | bool Output::belongsInOutput(uint32_t layerStackId, bool internalOnly) const { |
| 205 | // The layerStackId's must match, and also the layer must not be internal |
| 206 | // only when not on an internal output. |
| 207 | return (layerStackId == mState.layerStackId) && (!internalOnly || mState.layerStackInternal); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 210 | compositionengine::OutputLayer* Output::getOutputLayerForLayer( |
| 211 | compositionengine::Layer* layer) const { |
| 212 | for (const auto& outputLayer : mOutputLayersOrderedByZ) { |
| 213 | if (outputLayer && &outputLayer->getLayer() == layer) { |
| 214 | return outputLayer.get(); |
| 215 | } |
| 216 | } |
| 217 | return nullptr; |
| 218 | } |
| 219 | |
| 220 | std::unique_ptr<compositionengine::OutputLayer> Output::getOrCreateOutputLayer( |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 221 | std::optional<DisplayId> displayId, std::shared_ptr<compositionengine::Layer> layer, |
| 222 | sp<compositionengine::LayerFE> layerFE) { |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 223 | for (auto& outputLayer : mOutputLayersOrderedByZ) { |
| 224 | if (outputLayer && &outputLayer->getLayer() == layer.get()) { |
| 225 | return std::move(outputLayer); |
| 226 | } |
| 227 | } |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 228 | return createOutputLayer(mCompositionEngine, displayId, *this, layer, layerFE); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | void Output::setOutputLayersOrderedByZ(OutputLayers&& layers) { |
| 232 | mOutputLayersOrderedByZ = std::move(layers); |
| 233 | } |
| 234 | |
| 235 | const Output::OutputLayers& Output::getOutputLayersOrderedByZ() const { |
| 236 | return mOutputLayersOrderedByZ; |
| 237 | } |
| 238 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 239 | void Output::dirtyEntireOutput() { |
| 240 | mState.dirtyRegion.set(mState.bounds); |
| 241 | } |
| 242 | |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 243 | } // namespace impl |
| 244 | } // namespace android::compositionengine |