blob: 0cd0d23f90103a3cd033c2ddaece4d21e5897671 [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 <cmath>
18
19#include <compositionengine/impl/Output.h>
20#include <compositionengine/mock/CompositionEngine.h>
21#include <gtest/gtest.h>
22#include <ui/Rect.h>
23#include <ui/Region.h>
24
25#include "RegionMatcher.h"
26#include "TransformMatcher.h"
27
28namespace android::compositionengine {
29namespace {
30
31using testing::ReturnRef;
32using testing::StrictMock;
33
34class OutputTest : public testing::Test {
35public:
36 ~OutputTest() override = default;
37
38 StrictMock<mock::CompositionEngine> mCompositionEngine;
39 impl::Output mOutput{mCompositionEngine};
40};
41
42/* ------------------------------------------------------------------------
43 * Basic construction
44 */
45
46TEST_F(OutputTest, canInstantiateOutput) {}
47
48/* ------------------------------------------------------------------------
49 * Output::setCompositionEnabled()
50 */
51
52TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) {
53 const Rect displaySize{100, 200};
54 mOutput.editState().bounds = displaySize;
55 mOutput.editState().isEnabled = true;
56
57 mOutput.setCompositionEnabled(true);
58
59 EXPECT_TRUE(mOutput.getState().isEnabled);
60 EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region()));
61}
62
63TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) {
64 const Rect displaySize{100, 200};
65 mOutput.editState().bounds = displaySize;
66 mOutput.editState().isEnabled = false;
67
68 mOutput.setCompositionEnabled(true);
69
70 EXPECT_TRUE(mOutput.getState().isEnabled);
71 EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(displaySize)));
72}
73
74TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) {
75 const Rect displaySize{100, 200};
76 mOutput.editState().bounds = displaySize;
77 mOutput.editState().isEnabled = true;
78
79 mOutput.setCompositionEnabled(false);
80
81 EXPECT_FALSE(mOutput.getState().isEnabled);
82 EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(displaySize)));
83}
84
85/* ------------------------------------------------------------------------
86 * Output::setProjection()
87 */
88
89TEST_F(OutputTest, setProjectionTriviallyWorks) {
90 const ui::Transform transform{ui::Transform::ROT_180};
91 const int32_t orientation = 123;
92 const Rect frame{1, 2, 3, 4};
93 const Rect viewport{5, 6, 7, 8};
94 const Rect scissor{9, 10, 11, 12};
95 const bool needsFiltering = true;
96
97 mOutput.setProjection(transform, orientation, frame, viewport, scissor, needsFiltering);
98
99 EXPECT_THAT(mOutput.getState().transform, TransformEq(transform));
100 EXPECT_EQ(orientation, mOutput.getState().orientation);
101 EXPECT_EQ(frame, mOutput.getState().frame);
102 EXPECT_EQ(viewport, mOutput.getState().viewport);
103 EXPECT_EQ(scissor, mOutput.getState().scissor);
104 EXPECT_EQ(needsFiltering, mOutput.getState().needsFiltering);
105}
106
107/* ------------------------------------------------------------------------
108 * Output::setBounds()
109 */
110
111TEST_F(OutputTest, setBoundsSetsSizeAndDirtiesEntireOutput) {
112 const Rect displaySize{100, 200};
113 mOutput.setBounds(displaySize);
114
115 EXPECT_EQ(displaySize, mOutput.getState().bounds);
116
117 EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(displaySize)));
118}
119
120/* ------------------------------------------------------------------------
121 * Output::setLayerStackFilter()
122 */
123
124TEST_F(OutputTest, setLayerStackFilterSetsFilterAndDirtiesEntireOutput) {
125 const Rect displaySize{100, 200};
126 mOutput.editState().bounds = displaySize;
127
128 const uint32_t layerStack = 123u;
129 mOutput.setLayerStackFilter(true, layerStack);
130
131 EXPECT_TRUE(mOutput.getState().singleLayerStack);
132 EXPECT_EQ(layerStack, mOutput.getState().singleLayerStackId);
133
134 EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(displaySize)));
135}
136
137/* ------------------------------------------------------------------------
138 * Output::setColorTransform
139 */
140
141TEST_F(OutputTest, setColorTransformSetsTransform) {
142 // Identity matrix sets an identity state value
143 const mat4 identity;
144
145 mOutput.setColorTransform(identity);
146
147 EXPECT_EQ(HAL_COLOR_TRANSFORM_IDENTITY, mOutput.getState().colorTransform);
148
149 // Non-identity matrix sets a non-identity state value
150 const mat4 nonIdentity = mat4() * 2;
151
152 mOutput.setColorTransform(nonIdentity);
153
154 EXPECT_EQ(HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX, mOutput.getState().colorTransform);
155}
156
157/* ------------------------------------------------------------------------
158 * Output::setColorMode
159 */
160
161TEST_F(OutputTest, setColorModeSetsModeUnlessNoChange) {
162 mOutput.setColorMode(ui::ColorMode::BT2100_PQ, ui::Dataspace::SRGB,
163 ui::RenderIntent::TONE_MAP_COLORIMETRIC);
164
165 EXPECT_EQ(ui::ColorMode::BT2100_PQ, mOutput.getState().colorMode);
166 EXPECT_EQ(ui::Dataspace::SRGB, mOutput.getState().dataspace);
167 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput.getState().renderIntent);
168}
169
170/* ------------------------------------------------------------------------
171 * Output::getPhysicalSpaceDirtyRegion()
172 */
173
174TEST_F(OutputTest, getPhysicalSpaceDirtyRegionWithRepaintEverythingTrue) {
175 const Rect displaySize{100, 200};
176 mOutput.editState().bounds = displaySize;
177 mOutput.editState().dirtyRegion.set(50, 300);
178
179 {
180 Region result = mOutput.getPhysicalSpaceDirtyRegion(true);
181
182 EXPECT_THAT(result, RegionEq(Region(displaySize)));
183 }
184
185 // For repaint everything == true, the returned value does not depend on the display
186 // rotation.
187 mOutput.editState().transform.set(ui::Transform::ROT_90, 0, 0);
188
189 {
190 Region result = mOutput.getPhysicalSpaceDirtyRegion(true);
191
192 EXPECT_THAT(result, RegionEq(Region(displaySize)));
193 }
194}
195
196TEST_F(OutputTest, getPhysicalSpaceDirtyRegionWithRepaintEverythingFalse) {
197 const Rect displaySize{100, 200};
198 mOutput.editState().bounds = displaySize;
199 mOutput.editState().dirtyRegion.set(50, 300);
200
201 {
202 Region result = mOutput.getPhysicalSpaceDirtyRegion(false);
203
204 // The dirtyRegion should be clipped to the display bounds.
205 EXPECT_THAT(result, RegionEq(Region(Rect(50, 200))));
206 }
207
208 mOutput.editState().transform.set(ui::Transform::ROT_90, displaySize.getWidth(),
209 displaySize.getHeight());
210
211 {
212 Region result = mOutput.getPhysicalSpaceDirtyRegion(false);
213
214 // The dirtyRegion should be rotated and clipped to the display bounds.
215 EXPECT_THAT(result, RegionEq(Region(Rect(100, 50))));
216 }
217}
218
219} // namespace
220} // namespace android::compositionengine