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()); |
| 93 | |
| 94 | mState.colorTransform = |
| 95 | isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX; |
| 96 | } |
| 97 | |
| 98 | void Output::setColorMode(ui::ColorMode mode, ui::Dataspace dataspace, |
| 99 | ui::RenderIntent renderIntent) { |
| 100 | mState.colorMode = mode; |
| 101 | mState.dataspace = dataspace; |
| 102 | mState.renderIntent = renderIntent; |
| 103 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 104 | mRenderSurface->setBufferDataspace(dataspace); |
| 105 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 106 | ALOGV("Set active color mode: %s (%d), active render intent: %s (%d)", |
| 107 | decodeColorMode(mode).c_str(), mode, decodeRenderIntent(renderIntent).c_str(), |
| 108 | renderIntent); |
| 109 | } |
| 110 | |
| 111 | void Output::dump(std::string& out) const { |
| 112 | using android::base::StringAppendF; |
| 113 | |
| 114 | StringAppendF(&out, " Composition Output State: [\"%s\"]", mName.c_str()); |
| 115 | |
| 116 | out.append("\n "); |
| 117 | |
| 118 | dumpBase(out); |
| 119 | } |
| 120 | |
| 121 | void Output::dumpBase(std::string& out) const { |
| 122 | mState.dump(out); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 123 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 124 | if (mDisplayColorProfile) { |
| 125 | mDisplayColorProfile->dump(out); |
| 126 | } else { |
| 127 | out.append(" No display color profile!\n"); |
| 128 | } |
| 129 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 130 | if (mRenderSurface) { |
| 131 | mRenderSurface->dump(out); |
| 132 | } else { |
| 133 | out.append(" No render surface!\n"); |
| 134 | } |
| 135 | } |
| 136 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 137 | compositionengine::DisplayColorProfile* Output::getDisplayColorProfile() const { |
| 138 | return mDisplayColorProfile.get(); |
| 139 | } |
| 140 | |
| 141 | void Output::setDisplayColorProfile(std::unique_ptr<compositionengine::DisplayColorProfile> mode) { |
| 142 | mDisplayColorProfile = std::move(mode); |
| 143 | } |
| 144 | |
| 145 | void Output::setDisplayColorProfileForTest( |
| 146 | std::unique_ptr<compositionengine::DisplayColorProfile> mode) { |
| 147 | mDisplayColorProfile = std::move(mode); |
| 148 | } |
| 149 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 150 | compositionengine::RenderSurface* Output::getRenderSurface() const { |
| 151 | return mRenderSurface.get(); |
| 152 | } |
| 153 | |
| 154 | void Output::setRenderSurface(std::unique_ptr<compositionengine::RenderSurface> surface) { |
| 155 | mRenderSurface = std::move(surface); |
| 156 | mState.bounds = Rect(mRenderSurface->getSize()); |
| 157 | |
| 158 | dirtyEntireOutput(); |
| 159 | } |
| 160 | |
| 161 | void Output::setRenderSurfaceForTest(std::unique_ptr<compositionengine::RenderSurface> surface) { |
| 162 | mRenderSurface = std::move(surface); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | const OutputCompositionState& Output::getState() const { |
| 166 | return mState; |
| 167 | } |
| 168 | |
| 169 | OutputCompositionState& Output::editState() { |
| 170 | return mState; |
| 171 | } |
| 172 | |
Alec Mouri | 0f71483 | 2018-11-12 15:31:06 -0800 | [diff] [blame] | 173 | Region Output::getDirtyRegion(bool repaintEverything) const { |
| 174 | Region dirty(mState.viewport); |
| 175 | if (!repaintEverything) { |
| 176 | dirty.andSelf(mState.dirtyRegion); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 177 | } |
| 178 | return dirty; |
| 179 | } |
| 180 | |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 181 | bool Output::belongsInOutput(uint32_t layerStackId, bool internalOnly) const { |
| 182 | // The layerStackId's must match, and also the layer must not be internal |
| 183 | // only when not on an internal output. |
| 184 | return (layerStackId == mState.layerStackId) && (!internalOnly || mState.layerStackInternal); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame^] | 187 | compositionengine::OutputLayer* Output::getOutputLayerForLayer( |
| 188 | compositionengine::Layer* layer) const { |
| 189 | for (const auto& outputLayer : mOutputLayersOrderedByZ) { |
| 190 | if (outputLayer && &outputLayer->getLayer() == layer) { |
| 191 | return outputLayer.get(); |
| 192 | } |
| 193 | } |
| 194 | return nullptr; |
| 195 | } |
| 196 | |
| 197 | std::unique_ptr<compositionengine::OutputLayer> Output::getOrCreateOutputLayer( |
| 198 | std::shared_ptr<compositionengine::Layer> layer, sp<compositionengine::LayerFE> layerFE) { |
| 199 | for (auto& outputLayer : mOutputLayersOrderedByZ) { |
| 200 | if (outputLayer && &outputLayer->getLayer() == layer.get()) { |
| 201 | return std::move(outputLayer); |
| 202 | } |
| 203 | } |
| 204 | return createOutputLayer(*this, layer, layerFE); |
| 205 | } |
| 206 | |
| 207 | void Output::setOutputLayersOrderedByZ(OutputLayers&& layers) { |
| 208 | mOutputLayersOrderedByZ = std::move(layers); |
| 209 | } |
| 210 | |
| 211 | const Output::OutputLayers& Output::getOutputLayersOrderedByZ() const { |
| 212 | return mOutputLayersOrderedByZ; |
| 213 | } |
| 214 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 215 | void Output::dirtyEntireOutput() { |
| 216 | mState.dirtyRegion.set(mState.bounds); |
| 217 | } |
| 218 | |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 219 | } // namespace impl |
| 220 | } // namespace android::compositionengine |