blob: fe12825623ddd78ba56e1988f99455aa6361aec3 [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>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070021#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070022#include <compositionengine/mock/RenderSurface.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070023#include <gtest/gtest.h>
24#include <ui/Rect.h>
25#include <ui/Region.h>
26
27#include "RegionMatcher.h"
28#include "TransformMatcher.h"
29
30namespace android::compositionengine {
31namespace {
32
Lloyd Pique31cb2942018-10-19 17:23:03 -070033using testing::Return;
Lloyd Pique32cbe282018-10-19 13:09:22 -070034using testing::ReturnRef;
35using testing::StrictMock;
36
37class OutputTest : public testing::Test {
38public:
Lloyd Pique31cb2942018-10-19 17:23:03 -070039 OutputTest() {
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070040 mOutput.setDisplayColorProfileForTest(
41 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
Lloyd Pique31cb2942018-10-19 17:23:03 -070042 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
43 }
Lloyd Pique32cbe282018-10-19 13:09:22 -070044 ~OutputTest() override = default;
45
46 StrictMock<mock::CompositionEngine> mCompositionEngine;
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070047 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Pique31cb2942018-10-19 17:23:03 -070048 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Pique32cbe282018-10-19 13:09:22 -070049 impl::Output mOutput{mCompositionEngine};
50};
51
52/* ------------------------------------------------------------------------
53 * Basic construction
54 */
55
Lloyd Pique31cb2942018-10-19 17:23:03 -070056TEST_F(OutputTest, canInstantiateOutput) {
57 // The validation check checks each required component.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070058 EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
Lloyd Pique31cb2942018-10-19 17:23:03 -070059 EXPECT_CALL(*mRenderSurface, isValid()).WillOnce(Return(true));
60
61 EXPECT_TRUE(mOutput.isValid());
62
63 // If we take away the required components, it is no longer valid.
64 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>());
65
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070066 EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
67
Lloyd Pique31cb2942018-10-19 17:23:03 -070068 EXPECT_FALSE(mOutput.isValid());
69}
Lloyd Pique32cbe282018-10-19 13:09:22 -070070
71/* ------------------------------------------------------------------------
72 * Output::setCompositionEnabled()
73 */
74
75TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) {
76 const Rect displaySize{100, 200};
77 mOutput.editState().bounds = displaySize;
78 mOutput.editState().isEnabled = true;
79
80 mOutput.setCompositionEnabled(true);
81
82 EXPECT_TRUE(mOutput.getState().isEnabled);
83 EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region()));
84}
85
86TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) {
87 const Rect displaySize{100, 200};
88 mOutput.editState().bounds = displaySize;
89 mOutput.editState().isEnabled = false;
90
91 mOutput.setCompositionEnabled(true);
92
93 EXPECT_TRUE(mOutput.getState().isEnabled);
94 EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(displaySize)));
95}
96
97TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) {
98 const Rect displaySize{100, 200};
99 mOutput.editState().bounds = displaySize;
100 mOutput.editState().isEnabled = true;
101
102 mOutput.setCompositionEnabled(false);
103
104 EXPECT_FALSE(mOutput.getState().isEnabled);
105 EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(displaySize)));
106}
107
108/* ------------------------------------------------------------------------
109 * Output::setProjection()
110 */
111
112TEST_F(OutputTest, setProjectionTriviallyWorks) {
113 const ui::Transform transform{ui::Transform::ROT_180};
114 const int32_t orientation = 123;
115 const Rect frame{1, 2, 3, 4};
116 const Rect viewport{5, 6, 7, 8};
117 const Rect scissor{9, 10, 11, 12};
118 const bool needsFiltering = true;
119
120 mOutput.setProjection(transform, orientation, frame, viewport, scissor, needsFiltering);
121
122 EXPECT_THAT(mOutput.getState().transform, TransformEq(transform));
123 EXPECT_EQ(orientation, mOutput.getState().orientation);
124 EXPECT_EQ(frame, mOutput.getState().frame);
125 EXPECT_EQ(viewport, mOutput.getState().viewport);
126 EXPECT_EQ(scissor, mOutput.getState().scissor);
127 EXPECT_EQ(needsFiltering, mOutput.getState().needsFiltering);
128}
129
130/* ------------------------------------------------------------------------
131 * Output::setBounds()
132 */
133
134TEST_F(OutputTest, setBoundsSetsSizeAndDirtiesEntireOutput) {
Lloyd Pique31cb2942018-10-19 17:23:03 -0700135 const ui::Size displaySize{100, 200};
136
137 EXPECT_CALL(*mRenderSurface, setDisplaySize(displaySize)).Times(1);
138 EXPECT_CALL(*mRenderSurface, getSize()).WillOnce(ReturnRef(displaySize));
139
Lloyd Pique32cbe282018-10-19 13:09:22 -0700140 mOutput.setBounds(displaySize);
141
Lloyd Pique31cb2942018-10-19 17:23:03 -0700142 EXPECT_EQ(Rect(displaySize), mOutput.getState().bounds);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700143
Lloyd Pique31cb2942018-10-19 17:23:03 -0700144 EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(Rect(displaySize))));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700145}
146
147/* ------------------------------------------------------------------------
148 * Output::setLayerStackFilter()
149 */
150
151TEST_F(OutputTest, setLayerStackFilterSetsFilterAndDirtiesEntireOutput) {
152 const Rect displaySize{100, 200};
153 mOutput.editState().bounds = displaySize;
154
155 const uint32_t layerStack = 123u;
Lloyd Piqueef36b002019-01-23 17:52:04 -0800156 mOutput.setLayerStackFilter(layerStack, true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700157
Lloyd Piqueef36b002019-01-23 17:52:04 -0800158 EXPECT_TRUE(mOutput.getState().layerStackInternal);
159 EXPECT_EQ(layerStack, mOutput.getState().layerStackId);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700160
161 EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(displaySize)));
162}
163
164/* ------------------------------------------------------------------------
165 * Output::setColorTransform
166 */
167
168TEST_F(OutputTest, setColorTransformSetsTransform) {
169 // Identity matrix sets an identity state value
170 const mat4 identity;
171
172 mOutput.setColorTransform(identity);
173
174 EXPECT_EQ(HAL_COLOR_TRANSFORM_IDENTITY, mOutput.getState().colorTransform);
175
176 // Non-identity matrix sets a non-identity state value
177 const mat4 nonIdentity = mat4() * 2;
178
179 mOutput.setColorTransform(nonIdentity);
180
181 EXPECT_EQ(HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX, mOutput.getState().colorTransform);
182}
183
184/* ------------------------------------------------------------------------
185 * Output::setColorMode
186 */
187
188TEST_F(OutputTest, setColorModeSetsModeUnlessNoChange) {
Lloyd Pique31cb2942018-10-19 17:23:03 -0700189 EXPECT_CALL(*mRenderSurface, setBufferDataspace(ui::Dataspace::SRGB)).Times(1);
190
Lloyd Pique32cbe282018-10-19 13:09:22 -0700191 mOutput.setColorMode(ui::ColorMode::BT2100_PQ, ui::Dataspace::SRGB,
192 ui::RenderIntent::TONE_MAP_COLORIMETRIC);
193
194 EXPECT_EQ(ui::ColorMode::BT2100_PQ, mOutput.getState().colorMode);
195 EXPECT_EQ(ui::Dataspace::SRGB, mOutput.getState().dataspace);
196 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput.getState().renderIntent);
197}
198
199/* ------------------------------------------------------------------------
Lloyd Pique31cb2942018-10-19 17:23:03 -0700200 * Output::setRenderSurface()
201 */
202
203TEST_F(OutputTest, setRenderSurfaceResetsBounds) {
204 const ui::Size newDisplaySize{640, 480};
205
206 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
207 EXPECT_CALL(*renderSurface, getSize()).WillOnce(ReturnRef(newDisplaySize));
208
209 mOutput.setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface));
210
211 EXPECT_EQ(Rect(newDisplaySize), mOutput.getState().bounds);
212}
213
214/* ------------------------------------------------------------------------
Lloyd Pique32cbe282018-10-19 13:09:22 -0700215 * Output::getPhysicalSpaceDirtyRegion()
216 */
217
218TEST_F(OutputTest, getPhysicalSpaceDirtyRegionWithRepaintEverythingTrue) {
219 const Rect displaySize{100, 200};
220 mOutput.editState().bounds = displaySize;
221 mOutput.editState().dirtyRegion.set(50, 300);
222
223 {
224 Region result = mOutput.getPhysicalSpaceDirtyRegion(true);
225
226 EXPECT_THAT(result, RegionEq(Region(displaySize)));
227 }
228
229 // For repaint everything == true, the returned value does not depend on the display
230 // rotation.
231 mOutput.editState().transform.set(ui::Transform::ROT_90, 0, 0);
232
233 {
234 Region result = mOutput.getPhysicalSpaceDirtyRegion(true);
235
236 EXPECT_THAT(result, RegionEq(Region(displaySize)));
237 }
238}
239
240TEST_F(OutputTest, getPhysicalSpaceDirtyRegionWithRepaintEverythingFalse) {
241 const Rect displaySize{100, 200};
242 mOutput.editState().bounds = displaySize;
243 mOutput.editState().dirtyRegion.set(50, 300);
244
245 {
246 Region result = mOutput.getPhysicalSpaceDirtyRegion(false);
247
248 // The dirtyRegion should be clipped to the display bounds.
249 EXPECT_THAT(result, RegionEq(Region(Rect(50, 200))));
250 }
251
252 mOutput.editState().transform.set(ui::Transform::ROT_90, displaySize.getWidth(),
253 displaySize.getHeight());
254
255 {
256 Region result = mOutput.getPhysicalSpaceDirtyRegion(false);
257
258 // The dirtyRegion should be rotated and clipped to the display bounds.
259 EXPECT_THAT(result, RegionEq(Region(Rect(100, 50))));
260 }
261}
262
Lloyd Piqueef36b002019-01-23 17:52:04 -0800263/* ------------------------------------------------------------------------
264 * Output::belongsInOutput()
265 */
266
267TEST_F(OutputTest, belongsInOutputFiltersAsExpected) {
268 const uint32_t layerStack1 = 123u;
269 const uint32_t layerStack2 = 456u;
270
271 // If the output accepts layerStack1 and internal-only layers....
272 mOutput.setLayerStackFilter(layerStack1, true);
273
274 // Any layer with layerStack1 belongs to it, internal-only or not.
275 EXPECT_TRUE(mOutput.belongsInOutput(layerStack1, false));
276 EXPECT_TRUE(mOutput.belongsInOutput(layerStack1, true));
277 EXPECT_FALSE(mOutput.belongsInOutput(layerStack2, true));
278 EXPECT_FALSE(mOutput.belongsInOutput(layerStack2, false));
279
280 // If the output accepts layerStack21 but not internal-only layers...
281 mOutput.setLayerStackFilter(layerStack1, false);
282
283 // Only non-internal layers with layerStack1 belong to it.
284 EXPECT_TRUE(mOutput.belongsInOutput(layerStack1, false));
285 EXPECT_FALSE(mOutput.belongsInOutput(layerStack1, true));
286 EXPECT_FALSE(mOutput.belongsInOutput(layerStack2, true));
287 EXPECT_FALSE(mOutput.belongsInOutput(layerStack2, false));
288}
289
Lloyd Pique32cbe282018-10-19 13:09:22 -0700290} // namespace
291} // namespace android::compositionengine