blob: 2d458bfe5380a9f4bcf248eb16232ba2a346012b [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
Lloyd Piquefeb73d72018-12-04 17:23:44 -080024namespace android::compositionengine {
25
26Output::~Output() = default;
27
28namespace impl {
Lloyd Pique32cbe282018-10-19 13:09:22 -070029
30Output::Output(const CompositionEngine& compositionEngine)
31 : mCompositionEngine(compositionEngine) {}
32
33Output::~Output() = default;
34
35const CompositionEngine& Output::getCompositionEngine() const {
36 return mCompositionEngine;
37}
38
39bool Output::isValid() const {
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070040 return mDisplayColorProfile && mDisplayColorProfile->isValid() && mRenderSurface &&
41 mRenderSurface->isValid();
Lloyd Pique32cbe282018-10-19 13:09:22 -070042}
43
44const std::string& Output::getName() const {
45 return mName;
46}
47
48void Output::setName(const std::string& name) {
49 mName = name;
50}
51
52void Output::setCompositionEnabled(bool enabled) {
53 if (mState.isEnabled == enabled) {
54 return;
55 }
56
57 mState.isEnabled = enabled;
58 dirtyEntireOutput();
59}
60
61void Output::setProjection(const ui::Transform& transform, int32_t orientation, const Rect& frame,
62 const Rect& viewport, const Rect& scissor, bool needsFiltering) {
63 mState.transform = transform;
64 mState.orientation = orientation;
65 mState.scissor = scissor;
66 mState.frame = frame;
67 mState.viewport = viewport;
68 mState.needsFiltering = needsFiltering;
69
70 dirtyEntireOutput();
71}
72
Lloyd Pique31cb2942018-10-19 17:23:03 -070073// TODO(lpique): Rename setSize() once more is moved.
74void Output::setBounds(const ui::Size& size) {
75 mRenderSurface->setDisplaySize(size);
76 // TODO(lpique): Rename mState.size once more is moved.
77 mState.bounds = Rect(mRenderSurface->getSize());
Lloyd Pique32cbe282018-10-19 13:09:22 -070078
79 dirtyEntireOutput();
80}
81
Lloyd Piqueef36b002019-01-23 17:52:04 -080082void Output::setLayerStackFilter(uint32_t layerStackId, bool isInternal) {
83 mState.layerStackId = layerStackId;
84 mState.layerStackInternal = isInternal;
Lloyd Pique32cbe282018-10-19 13:09:22 -070085
86 dirtyEntireOutput();
87}
88
89void Output::setColorTransform(const mat4& transform) {
90 const bool isIdentity = (transform == mat4());
91
92 mState.colorTransform =
93 isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX;
94}
95
96void Output::setColorMode(ui::ColorMode mode, ui::Dataspace dataspace,
97 ui::RenderIntent renderIntent) {
98 mState.colorMode = mode;
99 mState.dataspace = dataspace;
100 mState.renderIntent = renderIntent;
101
Lloyd Pique31cb2942018-10-19 17:23:03 -0700102 mRenderSurface->setBufferDataspace(dataspace);
103
Lloyd Pique32cbe282018-10-19 13:09:22 -0700104 ALOGV("Set active color mode: %s (%d), active render intent: %s (%d)",
105 decodeColorMode(mode).c_str(), mode, decodeRenderIntent(renderIntent).c_str(),
106 renderIntent);
107}
108
109void Output::dump(std::string& out) const {
110 using android::base::StringAppendF;
111
112 StringAppendF(&out, " Composition Output State: [\"%s\"]", mName.c_str());
113
114 out.append("\n ");
115
116 dumpBase(out);
117}
118
119void Output::dumpBase(std::string& out) const {
120 mState.dump(out);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700121
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700122 if (mDisplayColorProfile) {
123 mDisplayColorProfile->dump(out);
124 } else {
125 out.append(" No display color profile!\n");
126 }
127
Lloyd Pique31cb2942018-10-19 17:23:03 -0700128 if (mRenderSurface) {
129 mRenderSurface->dump(out);
130 } else {
131 out.append(" No render surface!\n");
132 }
133}
134
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700135compositionengine::DisplayColorProfile* Output::getDisplayColorProfile() const {
136 return mDisplayColorProfile.get();
137}
138
139void Output::setDisplayColorProfile(std::unique_ptr<compositionengine::DisplayColorProfile> mode) {
140 mDisplayColorProfile = std::move(mode);
141}
142
143void Output::setDisplayColorProfileForTest(
144 std::unique_ptr<compositionengine::DisplayColorProfile> mode) {
145 mDisplayColorProfile = std::move(mode);
146}
147
Lloyd Pique31cb2942018-10-19 17:23:03 -0700148compositionengine::RenderSurface* Output::getRenderSurface() const {
149 return mRenderSurface.get();
150}
151
152void Output::setRenderSurface(std::unique_ptr<compositionengine::RenderSurface> surface) {
153 mRenderSurface = std::move(surface);
154 mState.bounds = Rect(mRenderSurface->getSize());
155
156 dirtyEntireOutput();
157}
158
159void Output::setRenderSurfaceForTest(std::unique_ptr<compositionengine::RenderSurface> surface) {
160 mRenderSurface = std::move(surface);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700161}
162
163const OutputCompositionState& Output::getState() const {
164 return mState;
165}
166
167OutputCompositionState& Output::editState() {
168 return mState;
169}
170
Alec Mouri0f714832018-11-12 15:31:06 -0800171Region Output::getDirtyRegion(bool repaintEverything) const {
172 Region dirty(mState.viewport);
173 if (!repaintEverything) {
174 dirty.andSelf(mState.dirtyRegion);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700175 }
176 return dirty;
177}
178
Lloyd Piqueef36b002019-01-23 17:52:04 -0800179bool Output::belongsInOutput(uint32_t layerStackId, bool internalOnly) const {
180 // The layerStackId's must match, and also the layer must not be internal
181 // only when not on an internal output.
182 return (layerStackId == mState.layerStackId) && (!internalOnly || mState.layerStackInternal);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700183}
184
185void Output::dirtyEntireOutput() {
186 mState.dirtyRegion.set(mState.bounds);
187}
188
Lloyd Piquefeb73d72018-12-04 17:23:44 -0800189} // namespace impl
190} // namespace android::compositionengine