blob: b74c5c6e8360bd26c4b759e20e37a2486bff411b [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>
Lloyd Pique31cb2942018-10-19 17:23:03 -070019#include <compositionengine/RenderSurface.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070020#include <compositionengine/impl/Output.h>
21#include <ui/DebugUtils.h>
22
23namespace android::compositionengine::impl {
24
25Output::Output(const CompositionEngine& compositionEngine)
26 : mCompositionEngine(compositionEngine) {}
27
28Output::~Output() = default;
29
30const CompositionEngine& Output::getCompositionEngine() const {
31 return mCompositionEngine;
32}
33
34bool Output::isValid() const {
Lloyd Pique31cb2942018-10-19 17:23:03 -070035 return mRenderSurface && mRenderSurface->isValid();
Lloyd Pique32cbe282018-10-19 13:09:22 -070036}
37
38const std::string& Output::getName() const {
39 return mName;
40}
41
42void Output::setName(const std::string& name) {
43 mName = name;
44}
45
46void Output::setCompositionEnabled(bool enabled) {
47 if (mState.isEnabled == enabled) {
48 return;
49 }
50
51 mState.isEnabled = enabled;
52 dirtyEntireOutput();
53}
54
55void 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 Pique31cb2942018-10-19 17:23:03 -070067// TODO(lpique): Rename setSize() once more is moved.
68void 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 Pique32cbe282018-10-19 13:09:22 -070072
73 dirtyEntireOutput();
74}
75
76void Output::setLayerStackFilter(bool singleLayerStack, uint32_t singleLayerStackId) {
77 mState.singleLayerStack = singleLayerStack;
78 mState.singleLayerStackId = singleLayerStackId;
79
80 dirtyEntireOutput();
81}
82
83void 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
90void 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 Pique31cb2942018-10-19 17:23:03 -070096 mRenderSurface->setBufferDataspace(dataspace);
97
Lloyd Pique32cbe282018-10-19 13:09:22 -070098 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
103void 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
113void Output::dumpBase(std::string& out) const {
114 mState.dump(out);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700115
116 if (mRenderSurface) {
117 mRenderSurface->dump(out);
118 } else {
119 out.append(" No render surface!\n");
120 }
121}
122
123compositionengine::RenderSurface* Output::getRenderSurface() const {
124 return mRenderSurface.get();
125}
126
127void Output::setRenderSurface(std::unique_ptr<compositionengine::RenderSurface> surface) {
128 mRenderSurface = std::move(surface);
129 mState.bounds = Rect(mRenderSurface->getSize());
130
131 dirtyEntireOutput();
132}
133
134void Output::setRenderSurfaceForTest(std::unique_ptr<compositionengine::RenderSurface> surface) {
135 mRenderSurface = std::move(surface);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700136}
137
138const OutputCompositionState& Output::getState() const {
139 return mState;
140}
141
142OutputCompositionState& Output::editState() {
143 return mState;
144}
145
146Region 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
157bool Output::belongsInOutput(uint32_t layerStackId) const {
158 return !mState.singleLayerStack || (layerStackId == mState.singleLayerStackId);
159}
160
161void Output::dirtyEntireOutput() {
162 mState.dirtyRegion.set(mState.bounds);
163}
164
165} // namespace android::compositionengine::impl