blob: 8b2441f271de9a907f8505af126b35b7c7fc0621 [file] [log] [blame]
Lloyd Pique32cbe282018-10-19 13:09:22 -07001/*
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
22namespace android::compositionengine::impl {
23
24Output::Output(const CompositionEngine& compositionEngine)
25 : mCompositionEngine(compositionEngine) {}
26
27Output::~Output() = default;
28
29const CompositionEngine& Output::getCompositionEngine() const {
30 return mCompositionEngine;
31}
32
33bool Output::isValid() const {
34 return true;
35}
36
37const std::string& Output::getName() const {
38 return mName;
39}
40
41void Output::setName(const std::string& name) {
42 mName = name;
43}
44
45void Output::setCompositionEnabled(bool enabled) {
46 if (mState.isEnabled == enabled) {
47 return;
48 }
49
50 mState.isEnabled = enabled;
51 dirtyEntireOutput();
52}
53
54void 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
66void Output::setBounds(const Rect& bounds) {
67 mState.bounds = bounds;
68
69 dirtyEntireOutput();
70}
71
72void Output::setLayerStackFilter(bool singleLayerStack, uint32_t singleLayerStackId) {
73 mState.singleLayerStack = singleLayerStack;
74 mState.singleLayerStackId = singleLayerStackId;
75
76 dirtyEntireOutput();
77}
78
79void 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
86void 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
97void 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
107void Output::dumpBase(std::string& out) const {
108 mState.dump(out);
109}
110
111const OutputCompositionState& Output::getState() const {
112 return mState;
113}
114
115OutputCompositionState& Output::editState() {
116 return mState;
117}
118
119Region 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
130bool Output::belongsInOutput(uint32_t layerStackId) const {
131 return !mState.singleLayerStack || (layerStackId == mState.singleLayerStackId);
132}
133
134void Output::dirtyEntireOutput() {
135 mState.dirtyRegion.set(mState.bounds);
136}
137
138} // namespace android::compositionengine::impl