blob: 83fb9e3f789f9ba3ee7c7eb1eb8e27bfcfea711a [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);
Alec Mourib7edfc22021-03-17 16:20:26 -0700697 static constexpr ui::Dataspace kOverrideDataspace = static_cast<ui::Dataspace>(72);
Lloyd Piquef5275482019-01-29 18:42:42 -0800698 static constexpr int kSupportedPerFrameMetadata = 101;
699 static constexpr int kExpectedHwcSlot = 0;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800700 static constexpr bool kLayerGenericMetadata1Mandatory = true;
701 static constexpr bool kLayerGenericMetadata2Mandatory = true;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800702
Lloyd Piquef5275482019-01-29 18:42:42 -0800703 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800704 static const Rect kDisplayFrame;
Alec Mourib7edfc22021-03-17 16:20:26 -0700705 static const Rect kOverrideDisplayFrame;
Lloyd Piquea2468662019-03-07 21:31:06 -0800706 static const Region kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800707 static const mat4 kColorTransform;
708 static const Region kSurfaceDamage;
709 static const HdrMetadata kHdrMetadata;
710 static native_handle_t* kSidebandStreamHandle;
711 static const sp<GraphicBuffer> kBuffer;
Alec Mourib7edfc22021-03-17 16:20:26 -0700712 static const sp<GraphicBuffer> kOverrideBuffer;
Lloyd Piquef5275482019-01-29 18:42:42 -0800713 static const sp<Fence> kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700714 static const sp<Fence> kOverrideFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800715 static const std::string kLayerGenericMetadata1Key;
716 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
717 static const std::string kLayerGenericMetadata2Key;
718 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800719
720 OutputLayerWriteStateToHWCTest() {
721 auto& outputLayerState = mOutputLayer.editState();
722 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
723
724 outputLayerState.displayFrame = kDisplayFrame;
725 outputLayerState.sourceCrop = kSourceCrop;
726 outputLayerState.z = kZOrder;
727 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800728 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800729 outputLayerState.dataspace = kDataspace;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800730
Lloyd Pique9755fb72019-03-26 14:44:40 -0700731 mLayerFEState.blendMode = kBlendMode;
732 mLayerFEState.alpha = kAlpha;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700733 mLayerFEState.colorTransform = kColorTransform;
734 mLayerFEState.color = kColor;
735 mLayerFEState.surfaceDamage = kSurfaceDamage;
736 mLayerFEState.hdrMetadata = kHdrMetadata;
737 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
738 mLayerFEState.buffer = kBuffer;
739 mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
740 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800741
742 EXPECT_CALL(mOutput, getDisplayColorProfile())
743 .WillRepeatedly(Return(&mDisplayColorProfile));
744 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
745 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800746 }
747
Lloyd Piquef5275482019-01-29 18:42:42 -0800748 // Some tests may need to simulate unsupported HWC calls
749 enum class SimulateUnsupported { None, ColorTransform };
750
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800751 void includeGenericLayerMetadataInState() {
752 mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory,
753 kLayerGenericMetadata1Value};
754 mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory,
755 kLayerGenericMetadata2Value};
756 }
757
Alec Mourib7edfc22021-03-17 16:20:26 -0700758 void includeOverrideInfo() {
759 auto& overrideInfo = mOutputLayer.editState().overrideInfo;
760
761 overrideInfo.buffer = kOverrideBuffer;
762 overrideInfo.acquireFence = kOverrideFence;
763 overrideInfo.displayFrame = kOverrideDisplayFrame;
764 overrideInfo.dataspace = kOverrideDataspace;
765 }
766
767 void expectGeometryCommonCalls(Rect displayFrame = kDisplayFrame,
768 FloatRect sourceCrop = kSourceCrop) {
769 EXPECT_CALL(*mHwcLayer, setDisplayFrame(displayFrame)).WillOnce(Return(kError));
770 EXPECT_CALL(*mHwcLayer, setSourceCrop(sourceCrop)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800771 EXPECT_CALL(*mHwcLayer, setZOrder(kZOrder)).WillOnce(Return(kError));
Peiyong Line9d809e2020-04-14 13:10:48 -0700772 EXPECT_CALL(*mHwcLayer, setTransform(kBufferTransform)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800773
Peiyong Line9d809e2020-04-14 13:10:48 -0700774 EXPECT_CALL(*mHwcLayer, setBlendMode(kBlendMode)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800775 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(kAlpha)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800776 }
777
Alec Mourib7edfc22021-03-17 16:20:26 -0700778 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None,
779 ui::Dataspace dataspace = kDataspace) {
Lloyd Piquea2468662019-03-07 21:31:06 -0800780 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(kOutputSpaceVisibleRegion)))
Lloyd Piquef5275482019-01-29 18:42:42 -0800781 .WillOnce(Return(kError));
Alec Mourib7edfc22021-03-17 16:20:26 -0700782 EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800783 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
784 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700785 ? hal::Error::UNSUPPORTED
786 : hal::Error::NONE));
Lloyd Piquef5275482019-01-29 18:42:42 -0800787 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(kSurfaceDamage)))
788 .WillOnce(Return(kError));
789 }
790
791 void expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700792 EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800793 }
794
795 void expectNoSetCompositionTypeCall() {
796 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
797 }
798
799 void expectSetColorCall() {
Peiyong Lin65248e02020-04-18 21:15:07 -0700800 const hal::Color color = {static_cast<uint8_t>(std::round(kColor.r * 255)),
801 static_cast<uint8_t>(std::round(kColor.g * 255)),
802 static_cast<uint8_t>(std::round(kColor.b * 255)), 255};
Lloyd Piquef5275482019-01-29 18:42:42 -0800803
804 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
805 }
806
807 void expectSetSidebandHandleCall() {
808 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
809 }
810
Alec Mourib7edfc22021-03-17 16:20:26 -0700811 void expectSetHdrMetadataAndBufferCalls(sp<GraphicBuffer> buffer = kBuffer,
812 sp<Fence> fence = kFence) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800813 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
Alec Mourib7edfc22021-03-17 16:20:26 -0700814 EXPECT_CALL(*mHwcLayer, setBuffer(kExpectedHwcSlot, buffer, fence));
Lloyd Piquef5275482019-01-29 18:42:42 -0800815 }
816
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800817 void expectGenericLayerMetadataCalls() {
818 // Note: Can be in any order.
819 EXPECT_CALL(*mHwcLayer,
820 setLayerGenericMetadata(kLayerGenericMetadata1Key,
821 kLayerGenericMetadata1Mandatory,
822 kLayerGenericMetadata1Value));
823 EXPECT_CALL(*mHwcLayer,
824 setLayerGenericMetadata(kLayerGenericMetadata2Key,
825 kLayerGenericMetadata2Mandatory,
826 kLayerGenericMetadata2Value));
827 }
828
Lloyd Piquea83776c2019-01-29 18:42:32 -0800829 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800830 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800831};
832
Lloyd Piquef5275482019-01-29 18:42:42 -0800833const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
834 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800835const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Alec Mourib7edfc22021-03-17 16:20:26 -0700836const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044};
Lloyd Piquea2468662019-03-07 21:31:06 -0800837const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
838 Rect{1005, 1006, 1007, 1008}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800839const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
840 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
841 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
842};
843const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
844const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
845native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
846 reinterpret_cast<native_handle_t*>(1031);
847const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer;
Alec Mourib7edfc22021-03-17 16:20:26 -0700848const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kOverrideBuffer = new GraphicBuffer();
Lloyd Piquef5275482019-01-29 18:42:42 -0800849const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700850const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = new Fence();
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800851const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
852 "com.example.metadata.1";
853const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
854const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
855 "com.example.metadata.2";
856const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
857 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800858
Lloyd Piquede196652020-01-22 17:29:58 -0800859TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
860 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
861
Dan Stoza6166c312021-01-15 16:34:05 -0800862 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false);
Lloyd Piquede196652020-01-22 17:29:58 -0800863}
864
Lloyd Piquea83776c2019-01-29 18:42:32 -0800865TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
866 mOutputLayer.editState().hwc.reset();
867
Dan Stoza6166c312021-01-15 16:34:05 -0800868 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800869}
870
871TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
872 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
873
Dan Stoza6166c312021-01-15 16:34:05 -0800874 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800875}
876
Lloyd Piquef5275482019-01-29 18:42:42 -0800877TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800878 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -0800879 expectPerFrameCommonCalls();
880
881 expectNoSetCompositionTypeCall();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800882
Dan Stoza6166c312021-01-15 16:34:05 -0800883 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800884}
885
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700886TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
887 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
888 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
889 // This test simulates a scenario where displayInstallOrientation is set to
890 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
891 // DisplayDevice::setProjection).
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200892 mOutputState.displaySpace.orientation = ui::ROTATION_0;
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700893 mOutputState.transform = ui::Transform{TR_ROT_90};
894 // Buffers are pre-rotated based on the transform hint (ROT_90); their
895 // geomBufferTransform is set to the inverse transform.
896 mLayerFEState.geomBufferTransform = TR_ROT_270;
897
Snild Dolkow9e217d62020-04-22 15:53:42 +0200898 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700899}
900
Lloyd Piquef5275482019-01-29 18:42:42 -0800901TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700902 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800903
904 expectPerFrameCommonCalls();
Lloyd Pique46b72df2019-10-29 13:19:27 -0700905
906 // Setting the composition type should happen before setting the color. We
907 // check this in this test only by setting up an testing::InSeqeuence
908 // instance before setting up the two expectations.
909 InSequence s;
Lloyd Piquef5275482019-01-29 18:42:42 -0800910 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -0700911 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -0800912
Dan Stoza6166c312021-01-15 16:34:05 -0800913 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800914}
915
916TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700917 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -0800918
919 expectPerFrameCommonCalls();
920 expectSetSidebandHandleCall();
921 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SIDEBAND);
922
Dan Stoza6166c312021-01-15 16:34:05 -0800923 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800924}
925
926TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700927 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800928
929 expectPerFrameCommonCalls();
930 expectSetHdrMetadataAndBufferCalls();
931 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CURSOR);
932
Dan Stoza6166c312021-01-15 16:34:05 -0800933 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800934}
935
936TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700937 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -0800938
939 expectPerFrameCommonCalls();
940 expectSetHdrMetadataAndBufferCalls();
941 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
942
Dan Stoza6166c312021-01-15 16:34:05 -0800943 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800944}
945
946TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
947 (*mOutputLayer.editState().hwc).hwcCompositionType =
948 Hwc2::IComposerClient::Composition::SOLID_COLOR;
949
Lloyd Pique9755fb72019-03-26 14:44:40 -0700950 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800951
952 expectPerFrameCommonCalls();
953 expectSetColorCall();
954 expectNoSetCompositionTypeCall();
955
Dan Stoza6166c312021-01-15 16:34:05 -0800956 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800957}
958
959TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700960 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800961
962 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
963 expectSetColorCall();
964 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
965
Dan Stoza6166c312021-01-15 16:34:05 -0800966 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800967}
968
969TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
970 mOutputLayer.editState().forceClientComposition = true;
971
Lloyd Pique9755fb72019-03-26 14:44:40 -0700972 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800973
974 expectPerFrameCommonCalls();
975 expectSetColorCall();
976 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
977
Dan Stoza6166c312021-01-15 16:34:05 -0800978 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800979}
980
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800981TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
982 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
983 includeGenericLayerMetadataInState();
984
985 expectGeometryCommonCalls();
986 expectPerFrameCommonCalls();
987 expectSetHdrMetadataAndBufferCalls();
988 expectGenericLayerMetadataCalls();
989 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
990
Dan Stoza6166c312021-01-15 16:34:05 -0800991 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800992}
993
994TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
995 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
996 includeGenericLayerMetadataInState();
997
998 expectPerFrameCommonCalls();
999 expectSetHdrMetadataAndBufferCalls();
1000 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1001
Dan Stoza6166c312021-01-15 16:34:05 -08001002 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001003}
1004
Alec Mourib7edfc22021-03-17 16:20:26 -07001005TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
1006 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1007 includeOverrideInfo();
1008
1009 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideDisplayFrame.toFloatRect());
1010 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace);
1011 expectSetHdrMetadataAndBufferCalls(kOverrideBuffer, kOverrideFence);
1012 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1013
1014 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false);
1015}
1016
Lloyd Pique66d68602019-02-13 14:23:31 -08001017/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001018 * OutputLayer::writeCursorPositionToHWC()
1019 */
1020
1021struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1022 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -07001023 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001024
1025 static const Rect kDefaultDisplayViewport;
1026 static const Rect kDefaultCursorFrame;
1027
1028 OutputLayerWriteCursorPositionToHWCTest() {
1029 auto& outputLayerState = mOutputLayer.editState();
1030 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1031
Lloyd Pique9755fb72019-03-26 14:44:40 -07001032 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001033
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001034 mOutputState.layerStackSpace.content = kDefaultDisplayViewport;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001035 mOutputState.transform = ui::Transform{kDefaultTransform};
1036 }
1037
1038 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1039};
1040
1041const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1042const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1043
Lloyd Piquede196652020-01-22 17:29:58 -08001044TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
1045 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
1046
1047 mOutputLayer.writeCursorPositionToHWC();
1048}
1049
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001050TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1051 mOutputLayer.editState().hwc.reset();
1052
1053 mOutputLayer.writeCursorPositionToHWC();
1054}
1055
1056TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1057 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1058
1059 mOutputLayer.writeCursorPositionToHWC();
1060}
1061
1062TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001063 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001064
1065 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1066
1067 mOutputLayer.writeCursorPositionToHWC();
1068}
1069
1070TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1071 mOutputState.transform = ui::Transform{TR_ROT_90};
1072
1073 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1074
1075 mOutputLayer.writeCursorPositionToHWC();
1076}
1077
1078/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001079 * OutputLayer::getHwcLayer()
1080 */
1081
1082TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1083 mOutputLayer.editState().hwc.reset();
1084
1085 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1086}
1087
1088TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1089 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1090
1091 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1092}
1093
1094TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1095 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1096 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1097
1098 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1099}
1100
1101/*
1102 * OutputLayer::requiresClientComposition()
1103 */
1104
1105TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1106 mOutputLayer.editState().hwc.reset();
1107
1108 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1109}
1110
1111TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1112 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1113 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CLIENT;
1114
1115 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1116}
1117
1118TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1119 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1120 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1121
1122 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1123}
1124
1125/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001126 * OutputLayer::isHardwareCursor()
1127 */
1128
1129TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1130 mOutputLayer.editState().hwc.reset();
1131
1132 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1133}
1134
1135TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1136 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1137 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CURSOR;
1138
1139 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1140}
1141
1142TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1143 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1144 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1145
1146 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1147}
1148
1149/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001150 * OutputLayer::applyDeviceCompositionTypeChange()
1151 */
1152
1153TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1154 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1155 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1156
1157 mOutputLayer.applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT);
1158
1159 ASSERT_TRUE(mOutputLayer.getState().hwc);
1160 EXPECT_EQ(Hwc2::IComposerClient::Composition::CLIENT,
1161 mOutputLayer.getState().hwc->hwcCompositionType);
1162}
1163
1164/*
1165 * OutputLayer::prepareForDeviceLayerRequests()
1166 */
1167
1168TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1169 mOutputLayer.editState().clearClientTarget = true;
1170
1171 mOutputLayer.prepareForDeviceLayerRequests();
1172
1173 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1174}
1175
1176/*
1177 * OutputLayer::applyDeviceLayerRequest()
1178 */
1179
1180TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1181 mOutputLayer.editState().clearClientTarget = false;
1182
1183 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1184
1185 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1186}
1187
1188TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1189 mOutputLayer.editState().clearClientTarget = false;
1190
1191 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1192
1193 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1194}
1195
Lloyd Pique688abd42019-02-15 15:42:24 -08001196/*
1197 * OutputLayer::needsFiltering()
1198 */
1199
1200TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1201 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1202 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1203
1204 EXPECT_FALSE(mOutputLayer.needsFiltering());
1205}
1206
1207TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1208 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1209 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1210
1211 EXPECT_TRUE(mOutputLayer.needsFiltering());
1212}
1213
Lloyd Piquecc01a452018-12-04 17:24:00 -08001214} // namespace
1215} // namespace android::compositionengine