blob: a1c156a2303207885af58fc55ea235d53971e7b6 [file] [log] [blame]
Lloyd Piquecc01a452018-12-04 17:24:00 -08001/*
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 <compositionengine/impl/OutputLayer.h>
Lloyd Pique07e33212018-12-18 16:33:37 -080018#include <compositionengine/mock/CompositionEngine.h>
Lloyd Piquef5275482019-01-29 18:42:42 -080019#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080020#include <compositionengine/mock/Layer.h>
21#include <compositionengine/mock/LayerFE.h>
22#include <compositionengine/mock/Output.h>
23#include <gtest/gtest.h>
24
Lloyd Pique67e3d9b2019-03-22 23:09:28 +000025#include "FloatRectMatcher.h"
Lloyd Pique07e33212018-12-18 16:33:37 -080026#include "MockHWC2.h"
27#include "MockHWComposer.h"
Lloyd Piquea83776c2019-01-29 18:42:32 -080028#include "RectMatcher.h"
Lloyd Piquef5275482019-01-29 18:42:42 -080029#include "RegionMatcher.h"
Lloyd Pique07e33212018-12-18 16:33:37 -080030
Lloyd Piquecc01a452018-12-04 17:24:00 -080031namespace android::compositionengine {
32namespace {
33
Lloyd Piquea83776c2019-01-29 18:42:32 -080034using testing::_;
35using testing::Return;
36using testing::ReturnRef;
Lloyd Piquecc01a452018-12-04 17:24:00 -080037using testing::StrictMock;
38
Lloyd Piquea83776c2019-01-29 18:42:32 -080039constexpr auto TR_IDENT = 0u;
40constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H;
41constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V;
42constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
43constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V;
44constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180;
45
46const std::string kOutputName{"Test Output"};
47
Lloyd Piquef5275482019-01-29 18:42:42 -080048MATCHER_P(ColorEq, expected, "") {
49 *result_listener << "Colors are not equal\n";
50 *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " "
51 << expected.a << "\n";
52 *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n";
53
54 return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a;
55}
56
Lloyd Pique66d68602019-02-13 14:23:31 -080057struct OutputLayerTest : public testing::Test {
Lloyd Piquea83776c2019-01-29 18:42:32 -080058 OutputLayerTest() {
59 EXPECT_CALL(*mLayerFE, getDebugName()).WillRepeatedly(Return("Test LayerFE"));
60 EXPECT_CALL(mOutput, getName()).WillRepeatedly(ReturnRef(kOutputName));
61
Lloyd Pique9755fb72019-03-26 14:44:40 -070062 EXPECT_CALL(*mLayer, getFEState()).WillRepeatedly(ReturnRef(mLayerFEState));
Lloyd Piquea83776c2019-01-29 18:42:32 -080063 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
64 }
65
Lloyd Piquecc01a452018-12-04 17:24:00 -080066 compositionengine::mock::Output mOutput;
67 std::shared_ptr<compositionengine::mock::Layer> mLayer{
68 new StrictMock<compositionengine::mock::Layer>()};
69 sp<compositionengine::mock::LayerFE> mLayerFE{
70 new StrictMock<compositionengine::mock::LayerFE>()};
71 impl::OutputLayer mOutputLayer{mOutput, mLayer, mLayerFE};
Lloyd Piquea83776c2019-01-29 18:42:32 -080072
Lloyd Pique9755fb72019-03-26 14:44:40 -070073 LayerFECompositionState mLayerFEState;
Lloyd Piquea83776c2019-01-29 18:42:32 -080074 impl::OutputCompositionState mOutputState;
Lloyd Piquecc01a452018-12-04 17:24:00 -080075};
76
Lloyd Piquea83776c2019-01-29 18:42:32 -080077/*
Lloyd Piquecc01a452018-12-04 17:24:00 -080078 * Basic construction
79 */
80
81TEST_F(OutputLayerTest, canInstantiateOutputLayer) {}
82
Lloyd Piquea83776c2019-01-29 18:42:32 -080083/*
Lloyd Piquedf336d92019-03-07 21:38:42 -080084 * OutputLayer::setHwcLayer()
Lloyd Pique07e33212018-12-18 16:33:37 -080085 */
86
Lloyd Piquedf336d92019-03-07 21:38:42 -080087TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) {
Lloyd Pique07e33212018-12-18 16:33:37 -080088 StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
89
Lloyd Piquedf336d92019-03-07 21:38:42 -080090 mOutputLayer.setHwcLayer(nullptr);
Lloyd Pique07e33212018-12-18 16:33:37 -080091
92 EXPECT_FALSE(mOutputLayer.getState().hwc);
93}
94
Lloyd Piquedf336d92019-03-07 21:38:42 -080095TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) {
96 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Pique07e33212018-12-18 16:33:37 -080097
Lloyd Piquedf336d92019-03-07 21:38:42 -080098 mOutputLayer.setHwcLayer(hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -080099
Lloyd Piquea83776c2019-01-29 18:42:32 -0800100 const auto& outputLayerState = mOutputLayer.getState();
101 ASSERT_TRUE(outputLayerState.hwc);
Lloyd Pique07e33212018-12-18 16:33:37 -0800102
Lloyd Piquea83776c2019-01-29 18:42:32 -0800103 const auto& hwcState = *outputLayerState.hwc;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800104 EXPECT_EQ(hwcLayer, hwcState.hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800105}
106
Lloyd Piquea83776c2019-01-29 18:42:32 -0800107/*
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000108 * OutputLayer::calculateOutputSourceCrop()
109 */
110
111struct OutputLayerSourceCropTest : public OutputLayerTest {
112 OutputLayerSourceCropTest() {
113 // Set reasonable default values for a simple case. Each test will
114 // set one specific value to something different.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700115 mLayerFEState.geomUsesSourceCrop = true;
116 mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080};
117 mLayerFEState.transparentRegionHint = Region{};
118 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
119 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
120 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
121 mLayerFEState.geomBufferTransform = TR_IDENT;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000122
123 mOutputState.viewport = Rect{0, 0, 1920, 1080};
124 }
125
126 FloatRect calculateOutputSourceCrop() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700127 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000128
129 return mOutputLayer.calculateOutputSourceCrop();
130 }
131};
132
133TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700134 mLayerFEState.geomUsesSourceCrop = false;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000135
136 const FloatRect expected{};
137 EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected));
138}
139
140TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) {
141 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
142 EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected));
143}
144
145TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700146 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000147
148 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
149 EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected));
150}
151
152TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700153 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
154 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000155
156 const FloatRect expected{0.f, 0.f, 1080.f, 1080.f};
157 EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected));
158}
159
160TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) {
161 struct Entry {
162 uint32_t bufferInvDisplay;
163 uint32_t buffer;
164 uint32_t display;
165 FloatRect expected;
166 };
167 // Not an exhaustive list of cases, but hopefully enough.
168 const std::array<Entry, 12> testData = {
169 // clang-format off
170 // inv buffer display expected
171 /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
172 /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
173 /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
174 /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
175
176 /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
177 /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
178 /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
179 /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
180
181 /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
182 /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
183 /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
184 /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
185
186 // clang-format on
187 };
188
189 for (size_t i = 0; i < testData.size(); i++) {
190 const auto& entry = testData[i];
191
Lloyd Pique9755fb72019-03-26 14:44:40 -0700192 mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay;
193 mLayerFEState.geomBufferTransform = entry.buffer;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000194 mOutputState.orientation = entry.display;
195
196 EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(entry.expected)) << "entry " << i;
197 }
198}
199
200TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700201 mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000202
203 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
204 EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected));
205}
206
207TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) {
208 mOutputState.viewport = Rect{0, 0, 960, 540};
209
210 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
211 EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected));
212}
213
214/*
Lloyd Piquea83776c2019-01-29 18:42:32 -0800215 * OutputLayer::calculateOutputDisplayFrame()
216 */
217
218struct OutputLayerDisplayFrameTest : public OutputLayerTest {
219 OutputLayerDisplayFrameTest() {
220 // Set reasonable default values for a simple case. Each test will
221 // set one specific value to something different.
222
Lloyd Pique9755fb72019-03-26 14:44:40 -0700223 mLayerFEState.transparentRegionHint = Region{};
224 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
225 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
226 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
227 mLayerFEState.geomCrop = Rect{0, 0, 1920, 1080};
228 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800229
230 mOutputState.viewport = Rect{0, 0, 1920, 1080};
231 mOutputState.transform = ui::Transform{TR_IDENT};
232 }
233
234 Rect calculateOutputDisplayFrame() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700235 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800236
237 return mOutputLayer.calculateOutputDisplayFrame();
238 }
239};
240
241TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) {
242 const Rect expected{0, 0, 1920, 1080};
243 EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected));
244}
245
246TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700247 mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800248 const Rect expected{0, 0, 0, 0};
249 EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected));
250}
251
252TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700253 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800254 const Rect expected{100, 200, 300, 500};
255 EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected));
256}
257
258TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700259 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
260 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800261 const Rect expected{1420, 100, 1720, 300};
262 EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected));
263}
264
265TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700266 mLayerFEState.geomCrop = Rect{};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800267 const Rect expected{0, 0, 1920, 1080};
268 EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected));
269}
270
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000271TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700272 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800273 const Rect expected{0, 0, 960, 540};
274 EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected));
275}
276
277TEST_F(OutputLayerDisplayFrameTest, viewportAffectsFrame) {
278 mOutputState.viewport = Rect{0, 0, 960, 540};
279 const Rect expected{0, 0, 960, 540};
280 EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected));
281}
282
283TEST_F(OutputLayerDisplayFrameTest, outputTransformAffectsDisplayFrame) {
284 mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90};
285 const Rect expected{-1080, 0, 0, 1920};
286 EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected));
287}
288
289/*
290 * OutputLayer::calculateOutputRelativeBufferTransform()
291 */
292
293TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700294 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800295
296 struct Entry {
297 uint32_t layer;
298 uint32_t buffer;
299 uint32_t display;
300 uint32_t expected;
301 };
302 // Not an exhaustive list of cases, but hopefully enough.
303 const std::array<Entry, 24> testData = {
304 // clang-format off
305 // layer buffer display expected
306 /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
307 /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_90},
308 /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
309 /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270},
310
311 /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_IDENT},
312 /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_90},
313 /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_180},
314 /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_ROT_270},
315
316 /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V},
317 /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_180},
318 /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
319 /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_180},
320
321 /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_90},
322 /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_180},
323 /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT ^ TR_ROT_270},
324 /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_IDENT},
325
326 /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_ROT_180},
327 /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT ^ TR_ROT_270},
328 /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_IDENT},
329 /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_90},
330
331 /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_270},
332 /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_IDENT},
333 /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_90},
334 /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_180},
335 // clang-format on
336 };
337
338 for (size_t i = 0; i < testData.size(); i++) {
339 const auto& entry = testData[i];
340
Lloyd Pique9755fb72019-03-26 14:44:40 -0700341 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
342 mLayerFEState.geomBufferTransform = entry.buffer;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800343 mOutputState.orientation = entry.display;
344
345 auto actual = mOutputLayer.calculateOutputRelativeBufferTransform();
346 EXPECT_EQ(entry.expected, actual) << "entry " << i;
347 }
348}
349
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000350TEST_F(OutputLayerTest,
351 calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700352 mLayerFEState.geomBufferUsesDisplayInverseTransform = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000353
354 struct Entry {
355 uint32_t layer;
356 uint32_t buffer;
357 uint32_t display;
358 uint32_t expected;
359 };
360 // Not an exhaustive list of cases, but hopefully enough.
361 const std::array<Entry, 24> testData = {
362 // clang-format off
363 // layer buffer display expected
364 /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
365 /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT},
366 /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_IDENT},
367 /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_IDENT},
368
369 /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H},
370 /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H},
371 /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H},
372 /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H},
373
374 /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V},
375 /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_90},
376 /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_ROT_180},
377 /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_270},
378
379 /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT},
380 /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H},
381 /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT},
382 /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H},
383
384 /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H},
385 /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT},
386 /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H},
387 /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT},
388
389 /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT},
390 /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H},
391 /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H},
392 /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT},
393 // clang-format on
394 };
395
396 for (size_t i = 0; i < testData.size(); i++) {
397 const auto& entry = testData[i];
398
Lloyd Pique9755fb72019-03-26 14:44:40 -0700399 mLayerFEState.geomLayerTransform = ui::Transform{entry.layer};
400 mLayerFEState.geomBufferTransform = entry.buffer;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000401 mOutputState.orientation = entry.display;
402
403 auto actual = mOutputLayer.calculateOutputRelativeBufferTransform();
404 EXPECT_EQ(entry.expected, actual) << "entry " << i;
405 }
406}
407
408/*
409 * OutputLayer::updateCompositionState()
410 */
411
412struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer {
413 OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output,
414 std::shared_ptr<compositionengine::Layer> layer,
415 sp<compositionengine::LayerFE> layerFE)
416 : impl::OutputLayer(output, layer, layerFE) {}
417 // Mock everything called by updateCompositionState to simplify testing it.
418 MOCK_CONST_METHOD0(calculateOutputSourceCrop, FloatRect());
419 MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect());
420 MOCK_CONST_METHOD0(calculateOutputRelativeBufferTransform, uint32_t());
421};
422
423struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest {
424public:
425 OutputLayerUpdateCompositionStateTest() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700426 EXPECT_CALL(*mLayer, getFEState()).WillRepeatedly(ReturnRef(mLayerFEState));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000427 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
Lloyd Piquef5275482019-01-29 18:42:42 -0800428 EXPECT_CALL(mOutput, getDisplayColorProfile())
429 .WillRepeatedly(Return(&mDisplayColorProfile));
430 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000431 }
432
433 ~OutputLayerUpdateCompositionStateTest() = default;
434
435 void setupGeometryChildCallValues() {
436 EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop()).WillOnce(Return(kSourceCrop));
437 EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame));
438 EXPECT_CALL(mOutputLayer, calculateOutputRelativeBufferTransform())
439 .WillOnce(Return(mBufferTransform));
440 }
441
442 void validateComputedGeometryState() {
443 const auto& state = mOutputLayer.getState();
444 EXPECT_EQ(kSourceCrop, state.sourceCrop);
445 EXPECT_EQ(kDisplayFrame, state.displayFrame);
446 EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform);
447 }
448
449 const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f};
450 const Rect kDisplayFrame{11, 12, 13, 14};
451 uint32_t mBufferTransform{21};
452
453 using OutputLayer = OutputLayerPartialMockForUpdateCompositionState;
454 StrictMock<OutputLayer> mOutputLayer{mOutput, mLayer, mLayerFE};
Lloyd Piquef5275482019-01-29 18:42:42 -0800455 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000456};
457
458TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700459 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000460 mOutputState.isSecure = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700461 mOutputLayer.editState().forceClientComposition = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000462
463 setupGeometryChildCallValues();
464
465 mOutputLayer.updateCompositionState(true);
466
467 validateComputedGeometryState();
468
469 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
470}
471
472TEST_F(OutputLayerUpdateCompositionStateTest,
473 alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700474 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000475 mOutputState.isSecure = false;
476
477 setupGeometryChildCallValues();
478
479 mOutputLayer.updateCompositionState(true);
480
481 validateComputedGeometryState();
482
483 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
484}
485
486TEST_F(OutputLayerUpdateCompositionStateTest,
487 alsoSetsForceCompositionIfUnsupportedBufferTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700488 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000489 mOutputState.isSecure = true;
490
491 mBufferTransform = ui::Transform::ROT_INVALID;
492
493 setupGeometryChildCallValues();
494
495 mOutputLayer.updateCompositionState(true);
496
497 validateComputedGeometryState();
498
499 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
500}
501
Lloyd Piquef5275482019-01-29 18:42:42 -0800502TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700503 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
Lloyd Piquef5275482019-01-29 18:42:42 -0800504 mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB;
505
506 // If the layer is not colorspace agnostic, the output layer dataspace
507 // should use the layers requested colorspace.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700508 mLayerFEState.isColorspaceAgnostic = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800509
510 mOutputLayer.updateCompositionState(false);
511
512 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
513
514 // If the layer is colorspace agnostic, the output layer dataspace
515 // should use the colorspace chosen for the whole output.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700516 mLayerFEState.isColorspaceAgnostic = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800517
518 mOutputLayer.updateCompositionState(false);
519
520 EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace);
521}
522
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000523TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700524 mOutputLayer.editState().forceClientComposition = false;
525
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000526 mOutputLayer.updateCompositionState(false);
527
528 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
529}
530
Lloyd Piquefe671022019-09-24 10:43:03 -0700531TEST_F(OutputLayerUpdateCompositionStateTest,
532 doesNotClearForceClientCompositionIfNotDoingGeometry) {
533 mOutputLayer.editState().forceClientComposition = true;
534
535 mOutputLayer.updateCompositionState(false);
536
537 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
538}
539
Lloyd Piquef5275482019-01-29 18:42:42 -0800540TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700541 mLayerFEState.forceClientComposition = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700542 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800543
544 mOutputLayer.updateCompositionState(false);
545
546 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
547}
548
549TEST_F(OutputLayerUpdateCompositionStateTest,
550 clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700551 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800552 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false));
553
554 mOutputLayer.updateCompositionState(false);
555
556 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
557}
558
Lloyd Piquea83776c2019-01-29 18:42:32 -0800559/*
560 * OutputLayer::writeStateToHWC()
561 */
562
563struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
564 static constexpr HWC2::Error kError = HWC2::Error::Unsupported;
565 static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f};
566 static constexpr uint32_t kZOrder = 21u;
567 static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31);
568 static constexpr Hwc2::IComposerClient::BlendMode kBlendMode =
569 static_cast<Hwc2::IComposerClient::BlendMode>(41);
570 static constexpr float kAlpha = 51.f;
571 static constexpr uint32_t kType = 61u;
572 static constexpr uint32_t kAppId = 62u;
Lloyd Piquef5275482019-01-29 18:42:42 -0800573 static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
574 static constexpr int kSupportedPerFrameMetadata = 101;
575 static constexpr int kExpectedHwcSlot = 0;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800576
Lloyd Piquef5275482019-01-29 18:42:42 -0800577 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800578 static const Rect kDisplayFrame;
Lloyd Piquea2468662019-03-07 21:31:06 -0800579 static const Region kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800580 static const mat4 kColorTransform;
581 static const Region kSurfaceDamage;
582 static const HdrMetadata kHdrMetadata;
583 static native_handle_t* kSidebandStreamHandle;
584 static const sp<GraphicBuffer> kBuffer;
585 static const sp<Fence> kFence;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800586
587 OutputLayerWriteStateToHWCTest() {
588 auto& outputLayerState = mOutputLayer.editState();
589 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
590
591 outputLayerState.displayFrame = kDisplayFrame;
592 outputLayerState.sourceCrop = kSourceCrop;
593 outputLayerState.z = kZOrder;
594 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800595 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800596 outputLayerState.dataspace = kDataspace;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800597
Lloyd Pique9755fb72019-03-26 14:44:40 -0700598 mLayerFEState.blendMode = kBlendMode;
599 mLayerFEState.alpha = kAlpha;
600 mLayerFEState.type = kType;
601 mLayerFEState.appId = kAppId;
602 mLayerFEState.colorTransform = kColorTransform;
603 mLayerFEState.color = kColor;
604 mLayerFEState.surfaceDamage = kSurfaceDamage;
605 mLayerFEState.hdrMetadata = kHdrMetadata;
606 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
607 mLayerFEState.buffer = kBuffer;
608 mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
609 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800610
611 EXPECT_CALL(mOutput, getDisplayColorProfile())
612 .WillRepeatedly(Return(&mDisplayColorProfile));
613 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
614 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800615 }
616
Lloyd Piquef5275482019-01-29 18:42:42 -0800617 // Some tests may need to simulate unsupported HWC calls
618 enum class SimulateUnsupported { None, ColorTransform };
619
Lloyd Piquea83776c2019-01-29 18:42:32 -0800620 void expectGeometryCommonCalls() {
621 EXPECT_CALL(*mHwcLayer, setDisplayFrame(kDisplayFrame)).WillOnce(Return(kError));
622 EXPECT_CALL(*mHwcLayer, setSourceCrop(kSourceCrop)).WillOnce(Return(kError));
623 EXPECT_CALL(*mHwcLayer, setZOrder(kZOrder)).WillOnce(Return(kError));
624 EXPECT_CALL(*mHwcLayer, setTransform(static_cast<HWC2::Transform>(kBufferTransform)))
625 .WillOnce(Return(kError));
626
627 EXPECT_CALL(*mHwcLayer, setBlendMode(static_cast<HWC2::BlendMode>(kBlendMode)))
628 .WillOnce(Return(kError));
629 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(kAlpha)).WillOnce(Return(kError));
630 EXPECT_CALL(*mHwcLayer, setInfo(kType, kAppId)).WillOnce(Return(kError));
631 }
632
Lloyd Piquef5275482019-01-29 18:42:42 -0800633 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None) {
Lloyd Piquea2468662019-03-07 21:31:06 -0800634 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(kOutputSpaceVisibleRegion)))
Lloyd Piquef5275482019-01-29 18:42:42 -0800635 .WillOnce(Return(kError));
636 EXPECT_CALL(*mHwcLayer, setDataspace(kDataspace)).WillOnce(Return(kError));
637 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
638 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
639 ? HWC2::Error::Unsupported
640 : HWC2::Error::None));
641 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(kSurfaceDamage)))
642 .WillOnce(Return(kError));
643 }
644
645 void expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition compositionType) {
646 EXPECT_CALL(*mHwcLayer, setCompositionType(static_cast<HWC2::Composition>(compositionType)))
647 .WillOnce(Return(kError));
648 }
649
650 void expectNoSetCompositionTypeCall() {
651 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
652 }
653
654 void expectSetColorCall() {
655 hwc_color_t color = {static_cast<uint8_t>(std::round(kColor.r * 255)),
656 static_cast<uint8_t>(std::round(kColor.g * 255)),
657 static_cast<uint8_t>(std::round(kColor.b * 255)), 255};
658
659 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
660 }
661
662 void expectSetSidebandHandleCall() {
663 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
664 }
665
666 void expectSetHdrMetadataAndBufferCalls() {
667 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
668 EXPECT_CALL(*mHwcLayer, setBuffer(kExpectedHwcSlot, kBuffer, kFence));
669 }
670
Lloyd Piquea83776c2019-01-29 18:42:32 -0800671 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800672 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800673};
674
Lloyd Piquef5275482019-01-29 18:42:42 -0800675const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
676 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800677const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Lloyd Piquea2468662019-03-07 21:31:06 -0800678const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
679 Rect{1005, 1006, 1007, 1008}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800680const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
681 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
682 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
683};
684const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
685const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
686native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
687 reinterpret_cast<native_handle_t*>(1031);
688const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer;
689const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800690
691TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
692 mOutputLayer.editState().hwc.reset();
693
694 mOutputLayer.writeStateToHWC(true);
695}
696
697TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
698 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
699
700 mOutputLayer.writeStateToHWC(true);
701}
702
Lloyd Piquef5275482019-01-29 18:42:42 -0800703TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800704 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -0800705 expectPerFrameCommonCalls();
706
707 expectNoSetCompositionTypeCall();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800708
709 mOutputLayer.writeStateToHWC(true);
710}
711
Lloyd Piquef5275482019-01-29 18:42:42 -0800712TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700713 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800714
715 expectPerFrameCommonCalls();
716 expectSetColorCall();
717 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SOLID_COLOR);
718
719 mOutputLayer.writeStateToHWC(false);
720}
721
722TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700723 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -0800724
725 expectPerFrameCommonCalls();
726 expectSetSidebandHandleCall();
727 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SIDEBAND);
728
729 mOutputLayer.writeStateToHWC(false);
730}
731
732TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700733 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800734
735 expectPerFrameCommonCalls();
736 expectSetHdrMetadataAndBufferCalls();
737 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CURSOR);
738
739 mOutputLayer.writeStateToHWC(false);
740}
741
742TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700743 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -0800744
745 expectPerFrameCommonCalls();
746 expectSetHdrMetadataAndBufferCalls();
747 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
748
749 mOutputLayer.writeStateToHWC(false);
750}
751
752TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
753 (*mOutputLayer.editState().hwc).hwcCompositionType =
754 Hwc2::IComposerClient::Composition::SOLID_COLOR;
755
Lloyd Pique9755fb72019-03-26 14:44:40 -0700756 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800757
758 expectPerFrameCommonCalls();
759 expectSetColorCall();
760 expectNoSetCompositionTypeCall();
761
762 mOutputLayer.writeStateToHWC(false);
763}
764
765TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700766 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800767
768 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
769 expectSetColorCall();
770 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
771
772 mOutputLayer.writeStateToHWC(false);
773}
774
775TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
776 mOutputLayer.editState().forceClientComposition = true;
777
Lloyd Pique9755fb72019-03-26 14:44:40 -0700778 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800779
780 expectPerFrameCommonCalls();
781 expectSetColorCall();
782 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
783
784 mOutputLayer.writeStateToHWC(false);
785}
786
Lloyd Pique66d68602019-02-13 14:23:31 -0800787/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800788 * OutputLayer::writeCursorPositionToHWC()
789 */
790
791struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
792 static constexpr int kDefaultTransform = TR_IDENT;
793 static constexpr HWC2::Error kDefaultError = HWC2::Error::Unsupported;
794
795 static const Rect kDefaultDisplayViewport;
796 static const Rect kDefaultCursorFrame;
797
798 OutputLayerWriteCursorPositionToHWCTest() {
799 auto& outputLayerState = mOutputLayer.editState();
800 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
801
Lloyd Pique9755fb72019-03-26 14:44:40 -0700802 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800803
804 mOutputState.viewport = kDefaultDisplayViewport;
805 mOutputState.transform = ui::Transform{kDefaultTransform};
806 }
807
808 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
809};
810
811const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
812const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
813
814TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
815 mOutputLayer.editState().hwc.reset();
816
817 mOutputLayer.writeCursorPositionToHWC();
818}
819
820TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
821 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
822
823 mOutputLayer.writeCursorPositionToHWC();
824}
825
826TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700827 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800828
829 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
830
831 mOutputLayer.writeCursorPositionToHWC();
832}
833
834TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
835 mOutputState.transform = ui::Transform{TR_ROT_90};
836
837 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
838
839 mOutputLayer.writeCursorPositionToHWC();
840}
841
842/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800843 * OutputLayer::getHwcLayer()
844 */
845
846TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
847 mOutputLayer.editState().hwc.reset();
848
849 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
850}
851
852TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
853 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
854
855 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
856}
857
858TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
859 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
860 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
861
862 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
863}
864
865/*
866 * OutputLayer::requiresClientComposition()
867 */
868
869TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
870 mOutputLayer.editState().hwc.reset();
871
872 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
873}
874
875TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
876 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
877 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CLIENT;
878
879 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
880}
881
882TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
883 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
884 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
885
886 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
887}
888
889/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800890 * OutputLayer::isHardwareCursor()
891 */
892
893TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
894 mOutputLayer.editState().hwc.reset();
895
896 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
897}
898
899TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
900 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
901 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CURSOR;
902
903 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
904}
905
906TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
907 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
908 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
909
910 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
911}
912
913/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800914 * OutputLayer::applyDeviceCompositionTypeChange()
915 */
916
917TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
918 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
919 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
920
921 mOutputLayer.applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT);
922
923 ASSERT_TRUE(mOutputLayer.getState().hwc);
924 EXPECT_EQ(Hwc2::IComposerClient::Composition::CLIENT,
925 mOutputLayer.getState().hwc->hwcCompositionType);
926}
927
928/*
929 * OutputLayer::prepareForDeviceLayerRequests()
930 */
931
932TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
933 mOutputLayer.editState().clearClientTarget = true;
934
935 mOutputLayer.prepareForDeviceLayerRequests();
936
937 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
938}
939
940/*
941 * OutputLayer::applyDeviceLayerRequest()
942 */
943
944TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
945 mOutputLayer.editState().clearClientTarget = false;
946
947 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
948
949 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
950}
951
952TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
953 mOutputLayer.editState().clearClientTarget = false;
954
955 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
956
957 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
958}
959
Lloyd Pique688abd42019-02-15 15:42:24 -0800960/*
961 * OutputLayer::needsFiltering()
962 */
963
964TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
965 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
966 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
967
968 EXPECT_FALSE(mOutputLayer.needsFiltering());
969}
970
971TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
972 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
973 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
974
975 EXPECT_TRUE(mOutputLayer.needsFiltering());
976}
977
Lloyd Piquecc01a452018-12-04 17:24:00 -0800978} // namespace
979} // namespace android::compositionengine