blob: 88cedfa7eaee4b18cb8f4dd92814726e4722cd4f [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;
461
462 setupGeometryChildCallValues();
463
464 mOutputLayer.updateCompositionState(true);
465
466 validateComputedGeometryState();
467
468 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
469}
470
471TEST_F(OutputLayerUpdateCompositionStateTest,
472 alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700473 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000474 mOutputState.isSecure = false;
475
476 setupGeometryChildCallValues();
477
478 mOutputLayer.updateCompositionState(true);
479
480 validateComputedGeometryState();
481
482 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
483}
484
485TEST_F(OutputLayerUpdateCompositionStateTest,
486 alsoSetsForceCompositionIfUnsupportedBufferTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700487 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000488 mOutputState.isSecure = true;
489
490 mBufferTransform = ui::Transform::ROT_INVALID;
491
492 setupGeometryChildCallValues();
493
494 mOutputLayer.updateCompositionState(true);
495
496 validateComputedGeometryState();
497
498 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
499}
500
Lloyd Piquef5275482019-01-29 18:42:42 -0800501TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700502 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
Lloyd Piquef5275482019-01-29 18:42:42 -0800503 mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB;
504
505 // If the layer is not colorspace agnostic, the output layer dataspace
506 // should use the layers requested colorspace.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700507 mLayerFEState.isColorspaceAgnostic = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800508
509 mOutputLayer.updateCompositionState(false);
510
511 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
512
513 // If the layer is colorspace agnostic, the output layer dataspace
514 // should use the colorspace chosen for the whole output.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700515 mLayerFEState.isColorspaceAgnostic = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800516
517 mOutputLayer.updateCompositionState(false);
518
519 EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace);
520}
521
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000522TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
523 mOutputLayer.updateCompositionState(false);
524
525 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
526}
527
Lloyd Piquef5275482019-01-29 18:42:42 -0800528TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700529 mLayerFEState.forceClientComposition = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800530
531 mOutputLayer.updateCompositionState(false);
532
533 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
534}
535
536TEST_F(OutputLayerUpdateCompositionStateTest,
537 clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) {
538 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false));
539
540 mOutputLayer.updateCompositionState(false);
541
542 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
543}
544
Lloyd Piquea83776c2019-01-29 18:42:32 -0800545/*
546 * OutputLayer::writeStateToHWC()
547 */
548
549struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
550 static constexpr HWC2::Error kError = HWC2::Error::Unsupported;
551 static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f};
552 static constexpr uint32_t kZOrder = 21u;
553 static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31);
554 static constexpr Hwc2::IComposerClient::BlendMode kBlendMode =
555 static_cast<Hwc2::IComposerClient::BlendMode>(41);
556 static constexpr float kAlpha = 51.f;
557 static constexpr uint32_t kType = 61u;
558 static constexpr uint32_t kAppId = 62u;
Lloyd Piquef5275482019-01-29 18:42:42 -0800559 static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
560 static constexpr int kSupportedPerFrameMetadata = 101;
561 static constexpr int kExpectedHwcSlot = 0;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800562
Lloyd Piquef5275482019-01-29 18:42:42 -0800563 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800564 static const Rect kDisplayFrame;
Lloyd Piquea2468662019-03-07 21:31:06 -0800565 static const Region kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800566 static const mat4 kColorTransform;
567 static const Region kSurfaceDamage;
568 static const HdrMetadata kHdrMetadata;
569 static native_handle_t* kSidebandStreamHandle;
570 static const sp<GraphicBuffer> kBuffer;
571 static const sp<Fence> kFence;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800572
573 OutputLayerWriteStateToHWCTest() {
574 auto& outputLayerState = mOutputLayer.editState();
575 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
576
577 outputLayerState.displayFrame = kDisplayFrame;
578 outputLayerState.sourceCrop = kSourceCrop;
579 outputLayerState.z = kZOrder;
580 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800581 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800582 outputLayerState.dataspace = kDataspace;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800583
Lloyd Pique9755fb72019-03-26 14:44:40 -0700584 mLayerFEState.blendMode = kBlendMode;
585 mLayerFEState.alpha = kAlpha;
586 mLayerFEState.type = kType;
587 mLayerFEState.appId = kAppId;
588 mLayerFEState.colorTransform = kColorTransform;
589 mLayerFEState.color = kColor;
590 mLayerFEState.surfaceDamage = kSurfaceDamage;
591 mLayerFEState.hdrMetadata = kHdrMetadata;
592 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
593 mLayerFEState.buffer = kBuffer;
594 mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
595 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800596
597 EXPECT_CALL(mOutput, getDisplayColorProfile())
598 .WillRepeatedly(Return(&mDisplayColorProfile));
599 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
600 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800601 }
602
Lloyd Piquef5275482019-01-29 18:42:42 -0800603 // Some tests may need to simulate unsupported HWC calls
604 enum class SimulateUnsupported { None, ColorTransform };
605
Lloyd Piquea83776c2019-01-29 18:42:32 -0800606 void expectGeometryCommonCalls() {
607 EXPECT_CALL(*mHwcLayer, setDisplayFrame(kDisplayFrame)).WillOnce(Return(kError));
608 EXPECT_CALL(*mHwcLayer, setSourceCrop(kSourceCrop)).WillOnce(Return(kError));
609 EXPECT_CALL(*mHwcLayer, setZOrder(kZOrder)).WillOnce(Return(kError));
610 EXPECT_CALL(*mHwcLayer, setTransform(static_cast<HWC2::Transform>(kBufferTransform)))
611 .WillOnce(Return(kError));
612
613 EXPECT_CALL(*mHwcLayer, setBlendMode(static_cast<HWC2::BlendMode>(kBlendMode)))
614 .WillOnce(Return(kError));
615 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(kAlpha)).WillOnce(Return(kError));
616 EXPECT_CALL(*mHwcLayer, setInfo(kType, kAppId)).WillOnce(Return(kError));
617 }
618
Lloyd Piquef5275482019-01-29 18:42:42 -0800619 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None) {
Lloyd Piquea2468662019-03-07 21:31:06 -0800620 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(kOutputSpaceVisibleRegion)))
Lloyd Piquef5275482019-01-29 18:42:42 -0800621 .WillOnce(Return(kError));
622 EXPECT_CALL(*mHwcLayer, setDataspace(kDataspace)).WillOnce(Return(kError));
623 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
624 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
625 ? HWC2::Error::Unsupported
626 : HWC2::Error::None));
627 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(kSurfaceDamage)))
628 .WillOnce(Return(kError));
629 }
630
631 void expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition compositionType) {
632 EXPECT_CALL(*mHwcLayer, setCompositionType(static_cast<HWC2::Composition>(compositionType)))
633 .WillOnce(Return(kError));
634 }
635
636 void expectNoSetCompositionTypeCall() {
637 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
638 }
639
640 void expectSetColorCall() {
641 hwc_color_t color = {static_cast<uint8_t>(std::round(kColor.r * 255)),
642 static_cast<uint8_t>(std::round(kColor.g * 255)),
643 static_cast<uint8_t>(std::round(kColor.b * 255)), 255};
644
645 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
646 }
647
648 void expectSetSidebandHandleCall() {
649 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
650 }
651
652 void expectSetHdrMetadataAndBufferCalls() {
653 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
654 EXPECT_CALL(*mHwcLayer, setBuffer(kExpectedHwcSlot, kBuffer, kFence));
655 }
656
Lloyd Piquea83776c2019-01-29 18:42:32 -0800657 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800658 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800659};
660
Lloyd Piquef5275482019-01-29 18:42:42 -0800661const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
662 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800663const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Lloyd Piquea2468662019-03-07 21:31:06 -0800664const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
665 Rect{1005, 1006, 1007, 1008}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800666const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
667 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
668 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
669};
670const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
671const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
672native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
673 reinterpret_cast<native_handle_t*>(1031);
674const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer;
675const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800676
677TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
678 mOutputLayer.editState().hwc.reset();
679
680 mOutputLayer.writeStateToHWC(true);
681}
682
683TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
684 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
685
686 mOutputLayer.writeStateToHWC(true);
687}
688
Lloyd Piquef5275482019-01-29 18:42:42 -0800689TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800690 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -0800691 expectPerFrameCommonCalls();
692
693 expectNoSetCompositionTypeCall();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800694
695 mOutputLayer.writeStateToHWC(true);
696}
697
Lloyd Piquef5275482019-01-29 18:42:42 -0800698TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700699 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800700
701 expectPerFrameCommonCalls();
702 expectSetColorCall();
703 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SOLID_COLOR);
704
705 mOutputLayer.writeStateToHWC(false);
706}
707
708TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700709 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -0800710
711 expectPerFrameCommonCalls();
712 expectSetSidebandHandleCall();
713 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SIDEBAND);
714
715 mOutputLayer.writeStateToHWC(false);
716}
717
718TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700719 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800720
721 expectPerFrameCommonCalls();
722 expectSetHdrMetadataAndBufferCalls();
723 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CURSOR);
724
725 mOutputLayer.writeStateToHWC(false);
726}
727
728TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700729 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -0800730
731 expectPerFrameCommonCalls();
732 expectSetHdrMetadataAndBufferCalls();
733 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
734
735 mOutputLayer.writeStateToHWC(false);
736}
737
738TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
739 (*mOutputLayer.editState().hwc).hwcCompositionType =
740 Hwc2::IComposerClient::Composition::SOLID_COLOR;
741
Lloyd Pique9755fb72019-03-26 14:44:40 -0700742 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800743
744 expectPerFrameCommonCalls();
745 expectSetColorCall();
746 expectNoSetCompositionTypeCall();
747
748 mOutputLayer.writeStateToHWC(false);
749}
750
751TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700752 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800753
754 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
755 expectSetColorCall();
756 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
757
758 mOutputLayer.writeStateToHWC(false);
759}
760
761TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
762 mOutputLayer.editState().forceClientComposition = true;
763
Lloyd Pique9755fb72019-03-26 14:44:40 -0700764 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800765
766 expectPerFrameCommonCalls();
767 expectSetColorCall();
768 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
769
770 mOutputLayer.writeStateToHWC(false);
771}
772
Lloyd Pique66d68602019-02-13 14:23:31 -0800773/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800774 * OutputLayer::writeCursorPositionToHWC()
775 */
776
777struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
778 static constexpr int kDefaultTransform = TR_IDENT;
779 static constexpr HWC2::Error kDefaultError = HWC2::Error::Unsupported;
780
781 static const Rect kDefaultDisplayViewport;
782 static const Rect kDefaultCursorFrame;
783
784 OutputLayerWriteCursorPositionToHWCTest() {
785 auto& outputLayerState = mOutputLayer.editState();
786 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
787
Lloyd Pique9755fb72019-03-26 14:44:40 -0700788 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800789
790 mOutputState.viewport = kDefaultDisplayViewport;
791 mOutputState.transform = ui::Transform{kDefaultTransform};
792 }
793
794 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
795};
796
797const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
798const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
799
800TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
801 mOutputLayer.editState().hwc.reset();
802
803 mOutputLayer.writeCursorPositionToHWC();
804}
805
806TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
807 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
808
809 mOutputLayer.writeCursorPositionToHWC();
810}
811
812TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700813 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800814
815 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
816
817 mOutputLayer.writeCursorPositionToHWC();
818}
819
820TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
821 mOutputState.transform = ui::Transform{TR_ROT_90};
822
823 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
824
825 mOutputLayer.writeCursorPositionToHWC();
826}
827
828/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800829 * OutputLayer::getHwcLayer()
830 */
831
832TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
833 mOutputLayer.editState().hwc.reset();
834
835 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
836}
837
838TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
839 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
840
841 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
842}
843
844TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
845 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
846 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
847
848 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
849}
850
851/*
852 * OutputLayer::requiresClientComposition()
853 */
854
855TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
856 mOutputLayer.editState().hwc.reset();
857
858 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
859}
860
861TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
862 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
863 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CLIENT;
864
865 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
866}
867
868TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
869 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
870 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
871
872 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
873}
874
875/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800876 * OutputLayer::isHardwareCursor()
877 */
878
879TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
880 mOutputLayer.editState().hwc.reset();
881
882 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
883}
884
885TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
886 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
887 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CURSOR;
888
889 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
890}
891
892TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
893 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
894 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
895
896 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
897}
898
899/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800900 * OutputLayer::applyDeviceCompositionTypeChange()
901 */
902
903TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
904 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
905 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
906
907 mOutputLayer.applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT);
908
909 ASSERT_TRUE(mOutputLayer.getState().hwc);
910 EXPECT_EQ(Hwc2::IComposerClient::Composition::CLIENT,
911 mOutputLayer.getState().hwc->hwcCompositionType);
912}
913
914/*
915 * OutputLayer::prepareForDeviceLayerRequests()
916 */
917
918TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
919 mOutputLayer.editState().clearClientTarget = true;
920
921 mOutputLayer.prepareForDeviceLayerRequests();
922
923 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
924}
925
926/*
927 * OutputLayer::applyDeviceLayerRequest()
928 */
929
930TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
931 mOutputLayer.editState().clearClientTarget = false;
932
933 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
934
935 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
936}
937
938TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
939 mOutputLayer.editState().clearClientTarget = false;
940
941 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
942
943 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
944}
945
Lloyd Pique688abd42019-02-15 15:42:24 -0800946/*
947 * OutputLayer::needsFiltering()
948 */
949
950TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
951 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
952 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
953
954 EXPECT_FALSE(mOutputLayer.needsFiltering());
955}
956
957TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
958 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
959 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
960
961 EXPECT_TRUE(mOutputLayer.needsFiltering());
962}
963
Lloyd Piquecc01a452018-12-04 17:24:00 -0800964} // namespace
965} // namespace android::compositionengine