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 | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 19 | #include <compositionengine/RenderSurface.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 20 | #include <compositionengine/impl/Output.h> |
| 21 | #include <ui/DebugUtils.h> |
| 22 | |
| 23 | namespace android::compositionengine::impl { |
| 24 | |
| 25 | Output::Output(const CompositionEngine& compositionEngine) |
| 26 | : mCompositionEngine(compositionEngine) {} |
| 27 | |
| 28 | Output::~Output() = default; |
| 29 | |
| 30 | const CompositionEngine& Output::getCompositionEngine() const { |
| 31 | return mCompositionEngine; |
| 32 | } |
| 33 | |
| 34 | bool Output::isValid() const { |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 35 | return mRenderSurface && mRenderSurface->isValid(); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | const std::string& Output::getName() const { |
| 39 | return mName; |
| 40 | } |
| 41 | |
| 42 | void Output::setName(const std::string& name) { |
| 43 | mName = name; |
| 44 | } |
| 45 | |
| 46 | void Output::setCompositionEnabled(bool enabled) { |
| 47 | if (mState.isEnabled == enabled) { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | mState.isEnabled = enabled; |
| 52 | dirtyEntireOutput(); |
| 53 | } |
| 54 | |
| 55 | void Output::setProjection(const ui::Transform& transform, int32_t orientation, const Rect& frame, |
| 56 | const Rect& viewport, const Rect& scissor, bool needsFiltering) { |
| 57 | mState.transform = transform; |
| 58 | mState.orientation = orientation; |
| 59 | mState.scissor = scissor; |
| 60 | mState.frame = frame; |
| 61 | mState.viewport = viewport; |
| 62 | mState.needsFiltering = needsFiltering; |
| 63 | |
| 64 | dirtyEntireOutput(); |
| 65 | } |
| 66 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 67 | // TODO(lpique): Rename setSize() once more is moved. |
| 68 | void Output::setBounds(const ui::Size& size) { |
| 69 | mRenderSurface->setDisplaySize(size); |
| 70 | // TODO(lpique): Rename mState.size once more is moved. |
| 71 | mState.bounds = Rect(mRenderSurface->getSize()); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 72 | |
| 73 | dirtyEntireOutput(); |
| 74 | } |
| 75 | |
| 76 | void Output::setLayerStackFilter(bool singleLayerStack, uint32_t singleLayerStackId) { |
| 77 | mState.singleLayerStack = singleLayerStack; |
| 78 | mState.singleLayerStackId = singleLayerStackId; |
| 79 | |
| 80 | dirtyEntireOutput(); |
| 81 | } |
| 82 | |
| 83 | void Output::setColorTransform(const mat4& transform) { |
| 84 | const bool isIdentity = (transform == mat4()); |
| 85 | |
| 86 | mState.colorTransform = |
| 87 | isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX; |
| 88 | } |
| 89 | |
| 90 | void Output::setColorMode(ui::ColorMode mode, ui::Dataspace dataspace, |
| 91 | ui::RenderIntent renderIntent) { |
| 92 | mState.colorMode = mode; |
| 93 | mState.dataspace = dataspace; |
| 94 | mState.renderIntent = renderIntent; |
| 95 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 96 | mRenderSurface->setBufferDataspace(dataspace); |
| 97 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 98 | ALOGV("Set active color mode: %s (%d), active render intent: %s (%d)", |
| 99 | decodeColorMode(mode).c_str(), mode, decodeRenderIntent(renderIntent).c_str(), |
| 100 | renderIntent); |
| 101 | } |
| 102 | |
| 103 | void Output::dump(std::string& out) const { |
| 104 | using android::base::StringAppendF; |
| 105 | |
| 106 | StringAppendF(&out, " Composition Output State: [\"%s\"]", mName.c_str()); |
| 107 | |
| 108 | out.append("\n "); |
| 109 | |
| 110 | dumpBase(out); |
| 111 | } |
| 112 | |
| 113 | void Output::dumpBase(std::string& out) const { |
| 114 | mState.dump(out); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 115 | |
| 116 | if (mRenderSurface) { |
| 117 | mRenderSurface->dump(out); |
| 118 | } else { |
| 119 | out.append(" No render surface!\n"); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | compositionengine::RenderSurface* Output::getRenderSurface() const { |
| 124 | return mRenderSurface.get(); |
| 125 | } |
| 126 | |
| 127 | void Output::setRenderSurface(std::unique_ptr<compositionengine::RenderSurface> surface) { |
| 128 | mRenderSurface = std::move(surface); |
| 129 | mState.bounds = Rect(mRenderSurface->getSize()); |
| 130 | |
| 131 | dirtyEntireOutput(); |
| 132 | } |
| 133 | |
| 134 | void Output::setRenderSurfaceForTest(std::unique_ptr<compositionengine::RenderSurface> surface) { |
| 135 | mRenderSurface = std::move(surface); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | const OutputCompositionState& Output::getState() const { |
| 139 | return mState; |
| 140 | } |
| 141 | |
| 142 | OutputCompositionState& Output::editState() { |
| 143 | return mState; |
| 144 | } |
| 145 | |
| 146 | Region Output::getPhysicalSpaceDirtyRegion(bool repaintEverything) const { |
| 147 | Region dirty; |
| 148 | if (repaintEverything) { |
| 149 | dirty.set(mState.bounds); |
| 150 | } else { |
| 151 | dirty = mState.transform.transform(mState.dirtyRegion); |
| 152 | dirty.andSelf(mState.bounds); |
| 153 | } |
| 154 | return dirty; |
| 155 | } |
| 156 | |
| 157 | bool Output::belongsInOutput(uint32_t layerStackId) const { |
| 158 | return !mState.singleLayerStack || (layerStackId == mState.singleLayerStackId); |
| 159 | } |
| 160 | |
| 161 | void Output::dirtyEntireOutput() { |
| 162 | mState.dirtyRegion.set(mState.bounds); |
| 163 | } |
| 164 | |
| 165 | } // namespace android::compositionengine::impl |