blob: dcfc162922bce18e197d02a16e50f22211a60b01 [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 Piquea38ea7e2019-04-16 18:10:26 -070018#include <compositionengine/impl/OutputLayerCompositionState.h>
Lloyd Pique07e33212018-12-18 16:33:37 -080019#include <compositionengine/mock/CompositionEngine.h>
Lloyd Piquef5275482019-01-29 18:42:42 -080020#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080021#include <compositionengine/mock/LayerFE.h>
22#include <compositionengine/mock/Output.h>
23#include <gtest/gtest.h>
Marin Shalamanov68933fb2020-09-10 17:58:12 +020024#include <log/log.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080025
Lloyd Pique07e33212018-12-18 16:33:37 -080026#include "MockHWC2.h"
27#include "MockHWComposer.h"
Lloyd Piquef5275482019-01-29 18:42:42 -080028#include "RegionMatcher.h"
Lloyd Pique07e33212018-12-18 16:33:37 -080029
Lloyd Piquecc01a452018-12-04 17:24:00 -080030namespace android::compositionengine {
31namespace {
32
Peiyong Line9d809e2020-04-14 13:10:48 -070033namespace hal = android::hardware::graphics::composer::hal;
34
Lloyd Piquea83776c2019-01-29 18:42:32 -080035using testing::_;
Lloyd Pique46b72df2019-10-29 13:19:27 -070036using testing::InSequence;
Lloyd Piquea83776c2019-01-29 18:42:32 -080037using testing::Return;
38using testing::ReturnRef;
Lloyd Piquecc01a452018-12-04 17:24:00 -080039using testing::StrictMock;
40
Lloyd Piquea83776c2019-01-29 18:42:32 -080041constexpr auto TR_IDENT = 0u;
42constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H;
43constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V;
44constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
45constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V;
46constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180;
47
48const std::string kOutputName{"Test Output"};
49
Lloyd Piquef5275482019-01-29 18:42:42 -080050MATCHER_P(ColorEq, expected, "") {
51 *result_listener << "Colors are not equal\n";
52 *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " "
53 << expected.a << "\n";
54 *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n";
55
56 return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a;
57}
58
Marin Shalamanov68933fb2020-09-10 17:58:12 +020059ui::Rotation toRotation(uint32_t rotationFlag) {
60 switch (rotationFlag) {
61 case ui::Transform::RotationFlags::ROT_0:
62 return ui::ROTATION_0;
63 case ui::Transform::RotationFlags::ROT_90:
64 return ui::ROTATION_90;
65 case ui::Transform::RotationFlags::ROT_180:
66 return ui::ROTATION_180;
67 case ui::Transform::RotationFlags::ROT_270:
68 return ui::ROTATION_270;
69 default:
70 LOG_FATAL("Unexpected rotation flag %d", rotationFlag);
71 return ui::Rotation(-1);
72 }
73}
74
Lloyd Pique66d68602019-02-13 14:23:31 -080075struct OutputLayerTest : public testing::Test {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070076 struct OutputLayer final : public impl::OutputLayer {
Lloyd Piquede196652020-01-22 17:29:58 -080077 OutputLayer(const compositionengine::Output& output, sp<compositionengine::LayerFE> layerFE)
78 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070079 ~OutputLayer() override = default;
80
81 // compositionengine::OutputLayer overrides
82 const compositionengine::Output& getOutput() const override { return mOutput; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070083 compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
84 const impl::OutputLayerCompositionState& getState() const override { return mState; }
85 impl::OutputLayerCompositionState& editState() override { return mState; }
86
87 // compositionengine::impl::OutputLayer overrides
88 void dumpState(std::string& out) const override { mState.dump(out); }
89
90 const compositionengine::Output& mOutput;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070091 sp<compositionengine::LayerFE> mLayerFE;
92 impl::OutputLayerCompositionState mState;
93 };
94
Lloyd Piquea83776c2019-01-29 18:42:32 -080095 OutputLayerTest() {
96 EXPECT_CALL(*mLayerFE, getDebugName()).WillRepeatedly(Return("Test LayerFE"));
97 EXPECT_CALL(mOutput, getName()).WillRepeatedly(ReturnRef(kOutputName));
98
Lloyd Piquede196652020-01-22 17:29:58 -080099 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800100 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
101 }
102
Lloyd Piquecc01a452018-12-04 17:24:00 -0800103 compositionengine::mock::Output mOutput;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800104 sp<compositionengine::mock::LayerFE> mLayerFE{
105 new StrictMock<compositionengine::mock::LayerFE>()};
Lloyd Piquede196652020-01-22 17:29:58 -0800106 OutputLayer mOutputLayer{mOutput, mLayerFE};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800107
Lloyd Pique9755fb72019-03-26 14:44:40 -0700108 LayerFECompositionState mLayerFEState;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800109 impl::OutputCompositionState mOutputState;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800110};
111
Lloyd Piquea83776c2019-01-29 18:42:32 -0800112/*
Lloyd Piquecc01a452018-12-04 17:24:00 -0800113 * Basic construction
114 */
115
116TEST_F(OutputLayerTest, canInstantiateOutputLayer) {}
117
Lloyd Piquea83776c2019-01-29 18:42:32 -0800118/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800119 * OutputLayer::setHwcLayer()
Lloyd Pique07e33212018-12-18 16:33:37 -0800120 */
121
Lloyd Piquedf336d92019-03-07 21:38:42 -0800122TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) {
Lloyd Pique07e33212018-12-18 16:33:37 -0800123 StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
124
Lloyd Piquedf336d92019-03-07 21:38:42 -0800125 mOutputLayer.setHwcLayer(nullptr);
Lloyd Pique07e33212018-12-18 16:33:37 -0800126
127 EXPECT_FALSE(mOutputLayer.getState().hwc);
128}
129
Lloyd Piquedf336d92019-03-07 21:38:42 -0800130TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) {
131 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Pique07e33212018-12-18 16:33:37 -0800132
Lloyd Piquedf336d92019-03-07 21:38:42 -0800133 mOutputLayer.setHwcLayer(hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800134
Lloyd Piquea83776c2019-01-29 18:42:32 -0800135 const auto& outputLayerState = mOutputLayer.getState();
136 ASSERT_TRUE(outputLayerState.hwc);
Lloyd Pique07e33212018-12-18 16:33:37 -0800137
Lloyd Piquea83776c2019-01-29 18:42:32 -0800138 const auto& hwcState = *outputLayerState.hwc;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800139 EXPECT_EQ(hwcLayer, hwcState.hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800140}
141
Lloyd Piquea83776c2019-01-29 18:42:32 -0800142/*
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000143 * OutputLayer::calculateOutputSourceCrop()
144 */
145
146struct OutputLayerSourceCropTest : public OutputLayerTest {
147 OutputLayerSourceCropTest() {
148 // Set reasonable default values for a simple case. Each test will
149 // set one specific value to something different.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700150 mLayerFEState.geomUsesSourceCrop = true;
151 mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080};
152 mLayerFEState.transparentRegionHint = Region{};
153 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
154 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
155 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
156 mLayerFEState.geomBufferTransform = TR_IDENT;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000157
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200158 mOutputState.layerStackSpace.content = Rect{0, 0, 1920, 1080};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000159 }
160
161 FloatRect calculateOutputSourceCrop() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700162 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000163
164 return mOutputLayer.calculateOutputSourceCrop();
165 }
166};
167
168TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700169 mLayerFEState.geomUsesSourceCrop = false;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000170
171 const FloatRect expected{};
Lloyd Piqueea629282019-12-03 15:57:10 -0800172 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000173}
174
175TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) {
176 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800177 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000178}
179
180TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700181 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000182
183 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800184 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000185}
186
187TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700188 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
189 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000190
191 const FloatRect expected{0.f, 0.f, 1080.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800192 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000193}
194
195TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) {
196 struct Entry {
197 uint32_t bufferInvDisplay;
198 uint32_t buffer;
199 uint32_t display;
200 FloatRect expected;
201 };
202 // Not an exhaustive list of cases, but hopefully enough.
203 const std::array<Entry, 12> testData = {
204 // clang-format off
205 // inv buffer display expected
206 /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
207 /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
208 /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
209 /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
210
211 /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
212 /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
213 /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
214 /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
215
216 /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
217 /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
218 /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
219 /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
220
221 // clang-format on
222 };
223
224 for (size_t i = 0; i < testData.size(); i++) {
225 const auto& entry = testData[i];
226
Lloyd Pique9755fb72019-03-26 14:44:40 -0700227 mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay;
228 mLayerFEState.geomBufferTransform = entry.buffer;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200229 mOutputState.displaySpace.orientation = toRotation(entry.display);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000230
Lloyd Piqueea629282019-12-03 15:57:10 -0800231 EXPECT_THAT(calculateOutputSourceCrop(), entry.expected) << "entry " << i;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000232 }
233}
234
235TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700236 mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000237
238 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800239 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000240}
241
242TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200243 mOutputState.layerStackSpace.content = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000244
245 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800246 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000247}
248
249/*
Lloyd Piquea83776c2019-01-29 18:42:32 -0800250 * OutputLayer::calculateOutputDisplayFrame()
251 */
252
253struct OutputLayerDisplayFrameTest : public OutputLayerTest {
254 OutputLayerDisplayFrameTest() {
255 // Set reasonable default values for a simple case. Each test will
256 // set one specific value to something different.
257
Lloyd Pique9755fb72019-03-26 14:44:40 -0700258 mLayerFEState.transparentRegionHint = Region{};
259 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
260 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
261 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
262 mLayerFEState.geomCrop = Rect{0, 0, 1920, 1080};
263 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800264
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200265 mOutputState.layerStackSpace.content = Rect{0, 0, 1920, 1080};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800266 mOutputState.transform = ui::Transform{TR_IDENT};
267 }
268
269 Rect calculateOutputDisplayFrame() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700270 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800271
272 return mOutputLayer.calculateOutputDisplayFrame();
273 }
274};
275
276TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) {
277 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800278 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800279}
280
281TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700282 mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800283 const Rect expected{0, 0, 0, 0};
Lloyd Piqueea629282019-12-03 15:57:10 -0800284 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800285}
286
287TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700288 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800289 const Rect expected{100, 200, 300, 500};
Lloyd Piqueea629282019-12-03 15:57:10 -0800290 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800291}
292
293TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700294 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
295 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800296 const Rect expected{1420, 100, 1720, 300};
Lloyd Piqueea629282019-12-03 15:57:10 -0800297 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800298}
299
300TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700301 mLayerFEState.geomCrop = Rect{};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800302 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800303 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800304}
305
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000306TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700307 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800308 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800309 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800310}
311
312TEST_F(OutputLayerDisplayFrameTest, viewportAffectsFrame) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200313 mOutputState.layerStackSpace.content = Rect{0, 0, 960, 540};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800314 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800315 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800316}
317
318TEST_F(OutputLayerDisplayFrameTest, outputTransformAffectsDisplayFrame) {
319 mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90};
320 const Rect expected{-1080, 0, 0, 1920};
Lloyd Piqueea629282019-12-03 15:57:10 -0800321 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800322}
323
324/*
325 * OutputLayer::calculateOutputRelativeBufferTransform()
326 */
327
328TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700329 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800330
331 struct Entry {
332 uint32_t layer;
333 uint32_t buffer;
334 uint32_t display;
335 uint32_t expected;
336 };
337 // Not an exhaustive list of cases, but hopefully enough.
338 const std::array<Entry, 24> testData = {
339 // clang-format off
340 // layer buffer display expected
341 /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
342 /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_90},
343 /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
344 /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270},
345
346 /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_IDENT},
347 /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_90},
348 /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_180},
349 /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_ROT_270},
350
351 /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V},
352 /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_180},
353 /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
354 /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_180},
355
356 /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_90},
357 /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_180},
358 /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT ^ TR_ROT_270},
359 /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_IDENT},
360
361 /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_ROT_180},
362 /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT ^ TR_ROT_270},
363 /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_IDENT},
364 /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_90},
365
366 /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_270},
367 /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_IDENT},
368 /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_90},
369 /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_180},
370 // clang-format on
371 };
372
373 for (size_t i = 0; i < testData.size(); i++) {
374 const auto& entry = testData[i];
375
Lloyd Pique9755fb72019-03-26 14:44:40 -0700376 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
377 mLayerFEState.geomBufferTransform = entry.buffer;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200378 mOutputState.displaySpace.orientation = toRotation(entry.display);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700379 mOutputState.transform = ui::Transform{entry.display};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800380
Snild Dolkow9e217d62020-04-22 15:53:42 +0200381 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.display);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800382 EXPECT_EQ(entry.expected, actual) << "entry " << i;
383 }
384}
385
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000386TEST_F(OutputLayerTest,
387 calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700388 mLayerFEState.geomBufferUsesDisplayInverseTransform = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000389
390 struct Entry {
Snild Dolkow9e217d62020-04-22 15:53:42 +0200391 uint32_t layer; /* shouldn't affect the result, so we just use arbitrary values */
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000392 uint32_t buffer;
393 uint32_t display;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200394 uint32_t internal;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000395 uint32_t expected;
396 };
Snild Dolkow9e217d62020-04-22 15:53:42 +0200397 const std::array<Entry, 64> testData = {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000398 // clang-format off
Snild Dolkow9e217d62020-04-22 15:53:42 +0200399 // layer buffer display internal expected
400 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
401 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_270},
402 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
403 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_90},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000404
Snild Dolkow9e217d62020-04-22 15:53:42 +0200405 Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT, TR_ROT_90},
406 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_90, TR_IDENT},
407 Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_180, TR_ROT_270},
408 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000409
Snild Dolkow9e217d62020-04-22 15:53:42 +0200410 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_180},
411 Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_90, TR_ROT_90},
412 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
413 Entry{TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000414
Snild Dolkow9e217d62020-04-22 15:53:42 +0200415 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270},
416 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_ROT_90, TR_ROT_180},
417 Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_180, TR_ROT_90},
418 Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000419
Snild Dolkow9e217d62020-04-22 15:53:42 +0200420 // layer buffer display internal expected
421 Entry{TR_IDENT, TR_ROT_90, TR_IDENT, TR_IDENT, TR_ROT_90},
422 Entry{TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_90, TR_IDENT},
423 Entry{TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_270},
424 Entry{TR_ROT_270, TR_ROT_90, TR_IDENT, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000425
Snild Dolkow9e217d62020-04-22 15:53:42 +0200426 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_180},
427 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90},
428 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_IDENT},
429 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270, TR_ROT_270},
430
431 Entry{TR_IDENT, TR_ROT_90, TR_ROT_180, TR_IDENT, TR_ROT_270},
432 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_180},
433 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_180, TR_ROT_90},
434 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_270, TR_IDENT},
435
436 Entry{TR_IDENT, TR_ROT_90, TR_ROT_270, TR_IDENT, TR_IDENT},
437 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270},
438 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_ROT_180, TR_ROT_180},
439 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90},
440
441 // layer buffer display internal expected
442 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_IDENT, TR_ROT_180},
443 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_90},
444 Entry{TR_ROT_180, TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT},
445 Entry{TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_270},
446
447 Entry{TR_IDENT, TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_270},
448 Entry{TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_90, TR_ROT_180},
449 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_90},
450 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_IDENT},
451
452 Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT, TR_IDENT},
453 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270},
454 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180},
455 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90},
456
457 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_IDENT, TR_ROT_90},
458 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_IDENT},
459 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_270},
460 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_270, TR_ROT_180},
461
462 // layer buffer display internal expected
463 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_IDENT, TR_ROT_270},
464 Entry{TR_ROT_90, TR_ROT_270, TR_IDENT, TR_ROT_90, TR_ROT_180},
465 Entry{TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_90},
466 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT},
467
468 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_IDENT, TR_IDENT},
469 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270},
470 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_ROT_180, TR_ROT_180},
471 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90},
472
473 Entry{TR_IDENT, TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_90},
474 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_90, TR_IDENT},
475 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270},
476 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_180},
477
478 Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180},
479 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_ROT_90},
480 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_IDENT},
481 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000482 // clang-format on
483 };
484
485 for (size_t i = 0; i < testData.size(); i++) {
486 const auto& entry = testData[i];
487
Snild Dolkow9e217d62020-04-22 15:53:42 +0200488 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
Lloyd Pique9755fb72019-03-26 14:44:40 -0700489 mLayerFEState.geomBufferTransform = entry.buffer;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200490 mOutputState.displaySpace.orientation = toRotation(entry.display);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700491 mOutputState.transform = ui::Transform{entry.display};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000492
Snild Dolkow9e217d62020-04-22 15:53:42 +0200493 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.internal);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000494 EXPECT_EQ(entry.expected, actual) << "entry " << i;
495 }
496}
497
498/*
499 * OutputLayer::updateCompositionState()
500 */
501
502struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer {
503 OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output,
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000504 sp<compositionengine::LayerFE> layerFE)
Lloyd Piquede196652020-01-22 17:29:58 -0800505 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000506 // Mock everything called by updateCompositionState to simplify testing it.
507 MOCK_CONST_METHOD0(calculateOutputSourceCrop, FloatRect());
508 MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect());
Snild Dolkow9e217d62020-04-22 15:53:42 +0200509 MOCK_CONST_METHOD1(calculateOutputRelativeBufferTransform, uint32_t(uint32_t));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700510
511 // compositionengine::OutputLayer overrides
512 const compositionengine::Output& getOutput() const override { return mOutput; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700513 compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
514 const impl::OutputLayerCompositionState& getState() const override { return mState; }
515 impl::OutputLayerCompositionState& editState() override { return mState; }
516
517 // These need implementations though are not expected to be called.
518 MOCK_CONST_METHOD1(dumpState, void(std::string&));
519
520 const compositionengine::Output& mOutput;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700521 sp<compositionengine::LayerFE> mLayerFE;
522 impl::OutputLayerCompositionState mState;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000523};
524
525struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest {
526public:
527 OutputLayerUpdateCompositionStateTest() {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000528 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
Lloyd Piquef5275482019-01-29 18:42:42 -0800529 EXPECT_CALL(mOutput, getDisplayColorProfile())
530 .WillRepeatedly(Return(&mDisplayColorProfile));
531 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000532 }
533
534 ~OutputLayerUpdateCompositionStateTest() = default;
535
Snild Dolkow9e217d62020-04-22 15:53:42 +0200536 void setupGeometryChildCallValues(ui::Transform::RotationFlags internalDisplayRotationFlags) {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000537 EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop()).WillOnce(Return(kSourceCrop));
538 EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200539 EXPECT_CALL(mOutputLayer,
540 calculateOutputRelativeBufferTransform(internalDisplayRotationFlags))
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000541 .WillOnce(Return(mBufferTransform));
542 }
543
544 void validateComputedGeometryState() {
545 const auto& state = mOutputLayer.getState();
546 EXPECT_EQ(kSourceCrop, state.sourceCrop);
547 EXPECT_EQ(kDisplayFrame, state.displayFrame);
548 EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform);
549 }
550
551 const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f};
552 const Rect kDisplayFrame{11, 12, 13, 14};
553 uint32_t mBufferTransform{21};
554
555 using OutputLayer = OutputLayerPartialMockForUpdateCompositionState;
Lloyd Piquede196652020-01-22 17:29:58 -0800556 StrictMock<OutputLayer> mOutputLayer{mOutput, mLayerFE};
Lloyd Piquef5275482019-01-29 18:42:42 -0800557 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000558};
559
Lloyd Piquede196652020-01-22 17:29:58 -0800560TEST_F(OutputLayerUpdateCompositionStateTest, doesNothingIfNoFECompositionState) {
561 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
562
Snild Dolkow9e217d62020-04-22 15:53:42 +0200563 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Piquede196652020-01-22 17:29:58 -0800564}
565
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000566TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700567 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000568 mOutputState.isSecure = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700569 mOutputLayer.editState().forceClientComposition = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000570
Snild Dolkow9e217d62020-04-22 15:53:42 +0200571 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000572
Snild Dolkow9e217d62020-04-22 15:53:42 +0200573 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000574
575 validateComputedGeometryState();
576
577 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
578}
579
580TEST_F(OutputLayerUpdateCompositionStateTest,
581 alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700582 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000583 mOutputState.isSecure = false;
584
Snild Dolkow9e217d62020-04-22 15:53:42 +0200585 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000586
Snild Dolkow9e217d62020-04-22 15:53:42 +0200587 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000588
589 validateComputedGeometryState();
590
591 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
592}
593
594TEST_F(OutputLayerUpdateCompositionStateTest,
595 alsoSetsForceCompositionIfUnsupportedBufferTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700596 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000597 mOutputState.isSecure = true;
598
599 mBufferTransform = ui::Transform::ROT_INVALID;
600
Snild Dolkow9e217d62020-04-22 15:53:42 +0200601 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000602
Snild Dolkow9e217d62020-04-22 15:53:42 +0200603 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000604
605 validateComputedGeometryState();
606
607 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
608}
609
Lloyd Piquef5275482019-01-29 18:42:42 -0800610TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700611 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
Lloyd Piquef5275482019-01-29 18:42:42 -0800612 mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB;
613
614 // If the layer is not colorspace agnostic, the output layer dataspace
615 // should use the layers requested colorspace.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700616 mLayerFEState.isColorspaceAgnostic = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800617
Snild Dolkow9e217d62020-04-22 15:53:42 +0200618 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800619
620 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
621
622 // If the layer is colorspace agnostic, the output layer dataspace
623 // should use the colorspace chosen for the whole output.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700624 mLayerFEState.isColorspaceAgnostic = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800625
Snild Dolkow9e217d62020-04-22 15:53:42 +0200626 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800627
628 EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace);
629}
630
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000631TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700632 mOutputLayer.editState().forceClientComposition = false;
633
Snild Dolkow9e217d62020-04-22 15:53:42 +0200634 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000635
636 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
637}
638
Lloyd Piquefe671022019-09-24 10:43:03 -0700639TEST_F(OutputLayerUpdateCompositionStateTest,
640 doesNotClearForceClientCompositionIfNotDoingGeometry) {
641 mOutputLayer.editState().forceClientComposition = true;
642
Snild Dolkow9e217d62020-04-22 15:53:42 +0200643 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquefe671022019-09-24 10:43:03 -0700644
645 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
646}
647
Lloyd Piquef5275482019-01-29 18:42:42 -0800648TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700649 mLayerFEState.forceClientComposition = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700650 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800651
Snild Dolkow9e217d62020-04-22 15:53:42 +0200652 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800653
654 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
655}
656
657TEST_F(OutputLayerUpdateCompositionStateTest,
658 clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700659 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800660 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false));
661
Snild Dolkow9e217d62020-04-22 15:53:42 +0200662 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700663
664 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
665}
666
667TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromArgumentFlag) {
668 mLayerFEState.forceClientComposition = false;
669 mOutputLayer.editState().forceClientComposition = false;
670
Snild Dolkow9e217d62020-04-22 15:53:42 +0200671 mOutputLayer.updateCompositionState(false, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700672
673 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
674
675 mOutputLayer.editState().forceClientComposition = false;
676
Snild Dolkow9e217d62020-04-22 15:53:42 +0200677 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700678
Snild Dolkow9e217d62020-04-22 15:53:42 +0200679 mOutputLayer.updateCompositionState(true, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800680
681 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
682}
683
Lloyd Piquea83776c2019-01-29 18:42:32 -0800684/*
685 * OutputLayer::writeStateToHWC()
686 */
687
688struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
Peiyong Line9d809e2020-04-14 13:10:48 -0700689 static constexpr hal::Error kError = hal::Error::UNSUPPORTED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800690 static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f};
691 static constexpr uint32_t kZOrder = 21u;
692 static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31);
693 static constexpr Hwc2::IComposerClient::BlendMode kBlendMode =
694 static_cast<Hwc2::IComposerClient::BlendMode>(41);
695 static constexpr float kAlpha = 51.f;
Lloyd Piquef5275482019-01-29 18:42:42 -0800696 static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
697 static constexpr int kSupportedPerFrameMetadata = 101;
698 static constexpr int kExpectedHwcSlot = 0;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800699 static constexpr bool kLayerGenericMetadata1Mandatory = true;
700 static constexpr bool kLayerGenericMetadata2Mandatory = true;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800701
Lloyd Piquef5275482019-01-29 18:42:42 -0800702 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800703 static const Rect kDisplayFrame;
Lloyd Piquea2468662019-03-07 21:31:06 -0800704 static const Region kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800705 static const mat4 kColorTransform;
706 static const Region kSurfaceDamage;
707 static const HdrMetadata kHdrMetadata;
708 static native_handle_t* kSidebandStreamHandle;
709 static const sp<GraphicBuffer> kBuffer;
710 static const sp<Fence> kFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800711 static const std::string kLayerGenericMetadata1Key;
712 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
713 static const std::string kLayerGenericMetadata2Key;
714 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800715
716 OutputLayerWriteStateToHWCTest() {
717 auto& outputLayerState = mOutputLayer.editState();
718 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
719
720 outputLayerState.displayFrame = kDisplayFrame;
721 outputLayerState.sourceCrop = kSourceCrop;
722 outputLayerState.z = kZOrder;
723 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800724 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800725 outputLayerState.dataspace = kDataspace;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800726
Lloyd Pique9755fb72019-03-26 14:44:40 -0700727 mLayerFEState.blendMode = kBlendMode;
728 mLayerFEState.alpha = kAlpha;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700729 mLayerFEState.colorTransform = kColorTransform;
730 mLayerFEState.color = kColor;
731 mLayerFEState.surfaceDamage = kSurfaceDamage;
732 mLayerFEState.hdrMetadata = kHdrMetadata;
733 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
734 mLayerFEState.buffer = kBuffer;
735 mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
736 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800737
738 EXPECT_CALL(mOutput, getDisplayColorProfile())
739 .WillRepeatedly(Return(&mDisplayColorProfile));
740 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
741 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800742 }
743
Lloyd Piquef5275482019-01-29 18:42:42 -0800744 // Some tests may need to simulate unsupported HWC calls
745 enum class SimulateUnsupported { None, ColorTransform };
746
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800747 void includeGenericLayerMetadataInState() {
748 mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory,
749 kLayerGenericMetadata1Value};
750 mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory,
751 kLayerGenericMetadata2Value};
752 }
753
Lloyd Piquea83776c2019-01-29 18:42:32 -0800754 void expectGeometryCommonCalls() {
755 EXPECT_CALL(*mHwcLayer, setDisplayFrame(kDisplayFrame)).WillOnce(Return(kError));
756 EXPECT_CALL(*mHwcLayer, setSourceCrop(kSourceCrop)).WillOnce(Return(kError));
757 EXPECT_CALL(*mHwcLayer, setZOrder(kZOrder)).WillOnce(Return(kError));
Peiyong Line9d809e2020-04-14 13:10:48 -0700758 EXPECT_CALL(*mHwcLayer, setTransform(kBufferTransform)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800759
Peiyong Line9d809e2020-04-14 13:10:48 -0700760 EXPECT_CALL(*mHwcLayer, setBlendMode(kBlendMode)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800761 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(kAlpha)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800762 }
763
Lloyd Piquef5275482019-01-29 18:42:42 -0800764 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None) {
Lloyd Piquea2468662019-03-07 21:31:06 -0800765 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(kOutputSpaceVisibleRegion)))
Lloyd Piquef5275482019-01-29 18:42:42 -0800766 .WillOnce(Return(kError));
767 EXPECT_CALL(*mHwcLayer, setDataspace(kDataspace)).WillOnce(Return(kError));
768 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
769 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700770 ? hal::Error::UNSUPPORTED
771 : hal::Error::NONE));
Lloyd Piquef5275482019-01-29 18:42:42 -0800772 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(kSurfaceDamage)))
773 .WillOnce(Return(kError));
774 }
775
776 void expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700777 EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800778 }
779
780 void expectNoSetCompositionTypeCall() {
781 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
782 }
783
784 void expectSetColorCall() {
Peiyong Lin65248e02020-04-18 21:15:07 -0700785 const hal::Color color = {static_cast<uint8_t>(std::round(kColor.r * 255)),
786 static_cast<uint8_t>(std::round(kColor.g * 255)),
787 static_cast<uint8_t>(std::round(kColor.b * 255)), 255};
Lloyd Piquef5275482019-01-29 18:42:42 -0800788
789 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
790 }
791
792 void expectSetSidebandHandleCall() {
793 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
794 }
795
796 void expectSetHdrMetadataAndBufferCalls() {
797 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
798 EXPECT_CALL(*mHwcLayer, setBuffer(kExpectedHwcSlot, kBuffer, kFence));
799 }
800
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800801 void expectGenericLayerMetadataCalls() {
802 // Note: Can be in any order.
803 EXPECT_CALL(*mHwcLayer,
804 setLayerGenericMetadata(kLayerGenericMetadata1Key,
805 kLayerGenericMetadata1Mandatory,
806 kLayerGenericMetadata1Value));
807 EXPECT_CALL(*mHwcLayer,
808 setLayerGenericMetadata(kLayerGenericMetadata2Key,
809 kLayerGenericMetadata2Mandatory,
810 kLayerGenericMetadata2Value));
811 }
812
Lloyd Piquea83776c2019-01-29 18:42:32 -0800813 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800814 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800815};
816
Lloyd Piquef5275482019-01-29 18:42:42 -0800817const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
818 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800819const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Lloyd Piquea2468662019-03-07 21:31:06 -0800820const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
821 Rect{1005, 1006, 1007, 1008}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800822const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
823 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
824 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
825};
826const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
827const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
828native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
829 reinterpret_cast<native_handle_t*>(1031);
830const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer;
831const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800832const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
833 "com.example.metadata.1";
834const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
835const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
836 "com.example.metadata.2";
837const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
838 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800839
Lloyd Piquede196652020-01-22 17:29:58 -0800840TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
841 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
842
843 mOutputLayer.writeStateToHWC(true);
844}
845
Lloyd Piquea83776c2019-01-29 18:42:32 -0800846TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
847 mOutputLayer.editState().hwc.reset();
848
849 mOutputLayer.writeStateToHWC(true);
850}
851
852TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
853 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
854
855 mOutputLayer.writeStateToHWC(true);
856}
857
Lloyd Piquef5275482019-01-29 18:42:42 -0800858TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800859 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -0800860 expectPerFrameCommonCalls();
861
862 expectNoSetCompositionTypeCall();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800863
864 mOutputLayer.writeStateToHWC(true);
865}
866
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700867TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
868 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
869 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
870 // This test simulates a scenario where displayInstallOrientation is set to
871 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
872 // DisplayDevice::setProjection).
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200873 mOutputState.displaySpace.orientation = ui::ROTATION_0;
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700874 mOutputState.transform = ui::Transform{TR_ROT_90};
875 // Buffers are pre-rotated based on the transform hint (ROT_90); their
876 // geomBufferTransform is set to the inverse transform.
877 mLayerFEState.geomBufferTransform = TR_ROT_270;
878
Snild Dolkow9e217d62020-04-22 15:53:42 +0200879 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700880}
881
Lloyd Piquef5275482019-01-29 18:42:42 -0800882TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700883 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800884
885 expectPerFrameCommonCalls();
Lloyd Pique46b72df2019-10-29 13:19:27 -0700886
887 // Setting the composition type should happen before setting the color. We
888 // check this in this test only by setting up an testing::InSeqeuence
889 // instance before setting up the two expectations.
890 InSequence s;
Lloyd Piquef5275482019-01-29 18:42:42 -0800891 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -0700892 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -0800893
894 mOutputLayer.writeStateToHWC(false);
895}
896
897TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700898 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -0800899
900 expectPerFrameCommonCalls();
901 expectSetSidebandHandleCall();
902 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SIDEBAND);
903
904 mOutputLayer.writeStateToHWC(false);
905}
906
907TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700908 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800909
910 expectPerFrameCommonCalls();
911 expectSetHdrMetadataAndBufferCalls();
912 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CURSOR);
913
914 mOutputLayer.writeStateToHWC(false);
915}
916
917TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700918 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -0800919
920 expectPerFrameCommonCalls();
921 expectSetHdrMetadataAndBufferCalls();
922 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
923
924 mOutputLayer.writeStateToHWC(false);
925}
926
927TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
928 (*mOutputLayer.editState().hwc).hwcCompositionType =
929 Hwc2::IComposerClient::Composition::SOLID_COLOR;
930
Lloyd Pique9755fb72019-03-26 14:44:40 -0700931 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800932
933 expectPerFrameCommonCalls();
934 expectSetColorCall();
935 expectNoSetCompositionTypeCall();
936
937 mOutputLayer.writeStateToHWC(false);
938}
939
940TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700941 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800942
943 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
944 expectSetColorCall();
945 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
946
947 mOutputLayer.writeStateToHWC(false);
948}
949
950TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
951 mOutputLayer.editState().forceClientComposition = true;
952
Lloyd Pique9755fb72019-03-26 14:44:40 -0700953 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800954
955 expectPerFrameCommonCalls();
956 expectSetColorCall();
957 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
958
959 mOutputLayer.writeStateToHWC(false);
960}
961
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800962TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
963 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
964 includeGenericLayerMetadataInState();
965
966 expectGeometryCommonCalls();
967 expectPerFrameCommonCalls();
968 expectSetHdrMetadataAndBufferCalls();
969 expectGenericLayerMetadataCalls();
970 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
971
972 mOutputLayer.writeStateToHWC(true);
973}
974
975TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
976 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
977 includeGenericLayerMetadataInState();
978
979 expectPerFrameCommonCalls();
980 expectSetHdrMetadataAndBufferCalls();
981 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
982
983 mOutputLayer.writeStateToHWC(false);
984}
985
Lloyd Pique66d68602019-02-13 14:23:31 -0800986/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800987 * OutputLayer::writeCursorPositionToHWC()
988 */
989
990struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
991 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -0700992 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800993
994 static const Rect kDefaultDisplayViewport;
995 static const Rect kDefaultCursorFrame;
996
997 OutputLayerWriteCursorPositionToHWCTest() {
998 auto& outputLayerState = mOutputLayer.editState();
999 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1000
Lloyd Pique9755fb72019-03-26 14:44:40 -07001001 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001002
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001003 mOutputState.layerStackSpace.content = kDefaultDisplayViewport;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001004 mOutputState.transform = ui::Transform{kDefaultTransform};
1005 }
1006
1007 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1008};
1009
1010const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1011const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1012
Lloyd Piquede196652020-01-22 17:29:58 -08001013TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
1014 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
1015
1016 mOutputLayer.writeCursorPositionToHWC();
1017}
1018
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001019TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1020 mOutputLayer.editState().hwc.reset();
1021
1022 mOutputLayer.writeCursorPositionToHWC();
1023}
1024
1025TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1026 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1027
1028 mOutputLayer.writeCursorPositionToHWC();
1029}
1030
1031TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001032 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001033
1034 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1035
1036 mOutputLayer.writeCursorPositionToHWC();
1037}
1038
1039TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1040 mOutputState.transform = ui::Transform{TR_ROT_90};
1041
1042 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1043
1044 mOutputLayer.writeCursorPositionToHWC();
1045}
1046
1047/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001048 * OutputLayer::getHwcLayer()
1049 */
1050
1051TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1052 mOutputLayer.editState().hwc.reset();
1053
1054 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1055}
1056
1057TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1058 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1059
1060 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1061}
1062
1063TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1064 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1065 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1066
1067 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1068}
1069
1070/*
1071 * OutputLayer::requiresClientComposition()
1072 */
1073
1074TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1075 mOutputLayer.editState().hwc.reset();
1076
1077 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1078}
1079
1080TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1081 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1082 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CLIENT;
1083
1084 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1085}
1086
1087TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1088 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1089 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1090
1091 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1092}
1093
1094/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001095 * OutputLayer::isHardwareCursor()
1096 */
1097
1098TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1099 mOutputLayer.editState().hwc.reset();
1100
1101 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1102}
1103
1104TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1105 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1106 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CURSOR;
1107
1108 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1109}
1110
1111TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1112 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1113 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1114
1115 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1116}
1117
1118/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001119 * OutputLayer::applyDeviceCompositionTypeChange()
1120 */
1121
1122TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1123 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1124 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1125
1126 mOutputLayer.applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT);
1127
1128 ASSERT_TRUE(mOutputLayer.getState().hwc);
1129 EXPECT_EQ(Hwc2::IComposerClient::Composition::CLIENT,
1130 mOutputLayer.getState().hwc->hwcCompositionType);
1131}
1132
1133/*
1134 * OutputLayer::prepareForDeviceLayerRequests()
1135 */
1136
1137TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1138 mOutputLayer.editState().clearClientTarget = true;
1139
1140 mOutputLayer.prepareForDeviceLayerRequests();
1141
1142 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1143}
1144
1145/*
1146 * OutputLayer::applyDeviceLayerRequest()
1147 */
1148
1149TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1150 mOutputLayer.editState().clearClientTarget = false;
1151
1152 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1153
1154 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1155}
1156
1157TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1158 mOutputLayer.editState().clearClientTarget = false;
1159
1160 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1161
1162 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1163}
1164
Lloyd Pique688abd42019-02-15 15:42:24 -08001165/*
1166 * OutputLayer::needsFiltering()
1167 */
1168
1169TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1170 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1171 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1172
1173 EXPECT_FALSE(mOutputLayer.needsFiltering());
1174}
1175
1176TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1177 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1178 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1179
1180 EXPECT_TRUE(mOutputLayer.needsFiltering());
1181}
1182
Lloyd Piquecc01a452018-12-04 17:24:00 -08001183} // namespace
1184} // namespace android::compositionengine