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> |
| 19 | #include <compositionengine/impl/Output.h> |
| 20 | #include <ui/DebugUtils.h> |
| 21 | |
| 22 | namespace android::compositionengine::impl { |
| 23 | |
| 24 | Output::Output(const CompositionEngine& compositionEngine) |
| 25 | : mCompositionEngine(compositionEngine) {} |
| 26 | |
| 27 | Output::~Output() = default; |
| 28 | |
| 29 | const CompositionEngine& Output::getCompositionEngine() const { |
| 30 | return mCompositionEngine; |
| 31 | } |
| 32 | |
| 33 | bool Output::isValid() const { |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | const std::string& Output::getName() const { |
| 38 | return mName; |
| 39 | } |
| 40 | |
| 41 | void Output::setName(const std::string& name) { |
| 42 | mName = name; |
| 43 | } |
| 44 | |
| 45 | void Output::setCompositionEnabled(bool enabled) { |
| 46 | if (mState.isEnabled == enabled) { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | mState.isEnabled = enabled; |
| 51 | dirtyEntireOutput(); |
| 52 | } |
| 53 | |
| 54 | void Output::setProjection(const ui::Transform& transform, int32_t orientation, const Rect& frame, |
| 55 | const Rect& viewport, const Rect& scissor, bool needsFiltering) { |
| 56 | mState.transform = transform; |
| 57 | mState.orientation = orientation; |
| 58 | mState.scissor = scissor; |
| 59 | mState.frame = frame; |
| 60 | mState.viewport = viewport; |
| 61 | mState.needsFiltering = needsFiltering; |
| 62 | |
| 63 | dirtyEntireOutput(); |
| 64 | } |
| 65 | |
| 66 | void Output::setBounds(const Rect& bounds) { |
| 67 | mState.bounds = bounds; |
| 68 | |
| 69 | dirtyEntireOutput(); |
| 70 | } |
| 71 | |
| 72 | void Output::setLayerStackFilter(bool singleLayerStack, uint32_t singleLayerStackId) { |
| 73 | mState.singleLayerStack = singleLayerStack; |
| 74 | mState.singleLayerStackId = singleLayerStackId; |
| 75 | |
| 76 | dirtyEntireOutput(); |
| 77 | } |
| 78 | |
| 79 | void Output::setColorTransform(const mat4& transform) { |
| 80 | const bool isIdentity = (transform == mat4()); |
| 81 | |
| 82 | mState.colorTransform = |
| 83 | isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX; |
| 84 | } |
| 85 | |
| 86 | void Output::setColorMode(ui::ColorMode mode, ui::Dataspace dataspace, |
| 87 | ui::RenderIntent renderIntent) { |
| 88 | mState.colorMode = mode; |
| 89 | mState.dataspace = dataspace; |
| 90 | mState.renderIntent = renderIntent; |
| 91 | |
| 92 | ALOGV("Set active color mode: %s (%d), active render intent: %s (%d)", |
| 93 | decodeColorMode(mode).c_str(), mode, decodeRenderIntent(renderIntent).c_str(), |
| 94 | renderIntent); |
| 95 | } |
| 96 | |
| 97 | void Output::dump(std::string& out) const { |
| 98 | using android::base::StringAppendF; |
| 99 | |
| 100 | StringAppendF(&out, " Composition Output State: [\"%s\"]", mName.c_str()); |
| 101 | |
| 102 | out.append("\n "); |
| 103 | |
| 104 | dumpBase(out); |
| 105 | } |
| 106 | |
| 107 | void Output::dumpBase(std::string& out) const { |
| 108 | mState.dump(out); |
| 109 | } |
| 110 | |
| 111 | const OutputCompositionState& Output::getState() const { |
| 112 | return mState; |
| 113 | } |
| 114 | |
| 115 | OutputCompositionState& Output::editState() { |
| 116 | return mState; |
| 117 | } |
| 118 | |
| 119 | Region Output::getPhysicalSpaceDirtyRegion(bool repaintEverything) const { |
| 120 | Region dirty; |
| 121 | if (repaintEverything) { |
| 122 | dirty.set(mState.bounds); |
| 123 | } else { |
| 124 | dirty = mState.transform.transform(mState.dirtyRegion); |
| 125 | dirty.andSelf(mState.bounds); |
| 126 | } |
| 127 | return dirty; |
| 128 | } |
| 129 | |
| 130 | bool Output::belongsInOutput(uint32_t layerStackId) const { |
| 131 | return !mState.singleLayerStack || (layerStackId == mState.singleLayerStackId); |
| 132 | } |
| 133 | |
| 134 | void Output::dirtyEntireOutput() { |
| 135 | mState.dirtyRegion.set(mState.bounds); |
| 136 | } |
| 137 | |
| 138 | } // namespace android::compositionengine::impl |