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