blob: cbbc9667907ff3100b575609fae17e630863385d [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);
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700693 static constexpr Hwc2::Transform kOverrideBufferTransform = static_cast<Hwc2::Transform>(0);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800694 static constexpr Hwc2::IComposerClient::BlendMode kBlendMode =
695 static_cast<Hwc2::IComposerClient::BlendMode>(41);
696 static constexpr float kAlpha = 51.f;
Lloyd Piquef5275482019-01-29 18:42:42 -0800697 static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
Alec Mourib7edfc22021-03-17 16:20:26 -0700698 static constexpr ui::Dataspace kOverrideDataspace = static_cast<ui::Dataspace>(72);
Lloyd Piquef5275482019-01-29 18:42:42 -0800699 static constexpr int kSupportedPerFrameMetadata = 101;
700 static constexpr int kExpectedHwcSlot = 0;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800701 static constexpr bool kLayerGenericMetadata1Mandatory = true;
702 static constexpr bool kLayerGenericMetadata2Mandatory = true;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800703
Lloyd Piquef5275482019-01-29 18:42:42 -0800704 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800705 static const Rect kDisplayFrame;
Alec Mourib7edfc22021-03-17 16:20:26 -0700706 static const Rect kOverrideDisplayFrame;
Lloyd Piquea2468662019-03-07 21:31:06 -0800707 static const Region kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800708 static const mat4 kColorTransform;
709 static const Region kSurfaceDamage;
710 static const HdrMetadata kHdrMetadata;
711 static native_handle_t* kSidebandStreamHandle;
712 static const sp<GraphicBuffer> kBuffer;
Alec Mourib7edfc22021-03-17 16:20:26 -0700713 static const sp<GraphicBuffer> kOverrideBuffer;
Lloyd Piquef5275482019-01-29 18:42:42 -0800714 static const sp<Fence> kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700715 static const sp<Fence> kOverrideFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800716 static const std::string kLayerGenericMetadata1Key;
717 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
718 static const std::string kLayerGenericMetadata2Key;
719 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800720
721 OutputLayerWriteStateToHWCTest() {
722 auto& outputLayerState = mOutputLayer.editState();
723 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
724
725 outputLayerState.displayFrame = kDisplayFrame;
726 outputLayerState.sourceCrop = kSourceCrop;
727 outputLayerState.z = kZOrder;
728 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800729 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800730 outputLayerState.dataspace = kDataspace;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800731
Lloyd Pique9755fb72019-03-26 14:44:40 -0700732 mLayerFEState.blendMode = kBlendMode;
733 mLayerFEState.alpha = kAlpha;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700734 mLayerFEState.colorTransform = kColorTransform;
735 mLayerFEState.color = kColor;
736 mLayerFEState.surfaceDamage = kSurfaceDamage;
737 mLayerFEState.hdrMetadata = kHdrMetadata;
738 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
739 mLayerFEState.buffer = kBuffer;
740 mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
741 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800742
743 EXPECT_CALL(mOutput, getDisplayColorProfile())
744 .WillRepeatedly(Return(&mDisplayColorProfile));
745 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
746 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800747 }
748
Lloyd Piquef5275482019-01-29 18:42:42 -0800749 // Some tests may need to simulate unsupported HWC calls
750 enum class SimulateUnsupported { None, ColorTransform };
751
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800752 void includeGenericLayerMetadataInState() {
753 mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory,
754 kLayerGenericMetadata1Value};
755 mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory,
756 kLayerGenericMetadata2Value};
757 }
758
Alec Mourib7edfc22021-03-17 16:20:26 -0700759 void includeOverrideInfo() {
760 auto& overrideInfo = mOutputLayer.editState().overrideInfo;
761
762 overrideInfo.buffer = kOverrideBuffer;
763 overrideInfo.acquireFence = kOverrideFence;
764 overrideInfo.displayFrame = kOverrideDisplayFrame;
765 overrideInfo.dataspace = kOverrideDataspace;
766 }
767
768 void expectGeometryCommonCalls(Rect displayFrame = kDisplayFrame,
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700769 FloatRect sourceCrop = kSourceCrop,
770 Hwc2::Transform bufferTransform = kBufferTransform) {
Alec Mourib7edfc22021-03-17 16:20:26 -0700771 EXPECT_CALL(*mHwcLayer, setDisplayFrame(displayFrame)).WillOnce(Return(kError));
772 EXPECT_CALL(*mHwcLayer, setSourceCrop(sourceCrop)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800773 EXPECT_CALL(*mHwcLayer, setZOrder(kZOrder)).WillOnce(Return(kError));
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700774 EXPECT_CALL(*mHwcLayer, setTransform(bufferTransform)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800775
Peiyong Line9d809e2020-04-14 13:10:48 -0700776 EXPECT_CALL(*mHwcLayer, setBlendMode(kBlendMode)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800777 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(kAlpha)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800778 }
779
Alec Mourib7edfc22021-03-17 16:20:26 -0700780 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None,
781 ui::Dataspace dataspace = kDataspace) {
Lloyd Piquea2468662019-03-07 21:31:06 -0800782 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(kOutputSpaceVisibleRegion)))
Lloyd Piquef5275482019-01-29 18:42:42 -0800783 .WillOnce(Return(kError));
Alec Mourib7edfc22021-03-17 16:20:26 -0700784 EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800785 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
786 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700787 ? hal::Error::UNSUPPORTED
788 : hal::Error::NONE));
Lloyd Piquef5275482019-01-29 18:42:42 -0800789 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(kSurfaceDamage)))
790 .WillOnce(Return(kError));
791 }
792
793 void expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700794 EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800795 }
796
797 void expectNoSetCompositionTypeCall() {
798 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
799 }
800
801 void expectSetColorCall() {
Peiyong Lin65248e02020-04-18 21:15:07 -0700802 const hal::Color color = {static_cast<uint8_t>(std::round(kColor.r * 255)),
803 static_cast<uint8_t>(std::round(kColor.g * 255)),
804 static_cast<uint8_t>(std::round(kColor.b * 255)), 255};
Lloyd Piquef5275482019-01-29 18:42:42 -0800805
806 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
807 }
808
809 void expectSetSidebandHandleCall() {
810 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
811 }
812
Alec Mourib7edfc22021-03-17 16:20:26 -0700813 void expectSetHdrMetadataAndBufferCalls(sp<GraphicBuffer> buffer = kBuffer,
814 sp<Fence> fence = kFence) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800815 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
Alec Mourib7edfc22021-03-17 16:20:26 -0700816 EXPECT_CALL(*mHwcLayer, setBuffer(kExpectedHwcSlot, buffer, fence));
Lloyd Piquef5275482019-01-29 18:42:42 -0800817 }
818
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800819 void expectGenericLayerMetadataCalls() {
820 // Note: Can be in any order.
821 EXPECT_CALL(*mHwcLayer,
822 setLayerGenericMetadata(kLayerGenericMetadata1Key,
823 kLayerGenericMetadata1Mandatory,
824 kLayerGenericMetadata1Value));
825 EXPECT_CALL(*mHwcLayer,
826 setLayerGenericMetadata(kLayerGenericMetadata2Key,
827 kLayerGenericMetadata2Mandatory,
828 kLayerGenericMetadata2Value));
829 }
830
Lloyd Piquea83776c2019-01-29 18:42:32 -0800831 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800832 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800833};
834
Lloyd Piquef5275482019-01-29 18:42:42 -0800835const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
836 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800837const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Alec Mourib7edfc22021-03-17 16:20:26 -0700838const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044};
Lloyd Piquea2468662019-03-07 21:31:06 -0800839const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
840 Rect{1005, 1006, 1007, 1008}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800841const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
842 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
843 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
844};
845const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
846const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
847native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
848 reinterpret_cast<native_handle_t*>(1031);
849const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer;
Alec Mourib7edfc22021-03-17 16:20:26 -0700850const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kOverrideBuffer = new GraphicBuffer();
Lloyd Piquef5275482019-01-29 18:42:42 -0800851const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700852const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = new Fence();
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800853const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
854 "com.example.metadata.1";
855const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
856const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
857 "com.example.metadata.2";
858const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
859 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800860
Lloyd Piquede196652020-01-22 17:29:58 -0800861TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
862 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
863
Dan Stoza6166c312021-01-15 16:34:05 -0800864 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false);
Lloyd Piquede196652020-01-22 17:29:58 -0800865}
866
Lloyd Piquea83776c2019-01-29 18:42:32 -0800867TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
868 mOutputLayer.editState().hwc.reset();
869
Dan Stoza6166c312021-01-15 16:34:05 -0800870 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800871}
872
873TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
874 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
875
Dan Stoza6166c312021-01-15 16:34:05 -0800876 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800877}
878
Lloyd Piquef5275482019-01-29 18:42:42 -0800879TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800880 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -0800881 expectPerFrameCommonCalls();
882
883 expectNoSetCompositionTypeCall();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800884
Dan Stoza6166c312021-01-15 16:34:05 -0800885 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800886}
887
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700888TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
889 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
890 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
891 // This test simulates a scenario where displayInstallOrientation is set to
892 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
893 // DisplayDevice::setProjection).
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200894 mOutputState.displaySpace.orientation = ui::ROTATION_0;
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700895 mOutputState.transform = ui::Transform{TR_ROT_90};
896 // Buffers are pre-rotated based on the transform hint (ROT_90); their
897 // geomBufferTransform is set to the inverse transform.
898 mLayerFEState.geomBufferTransform = TR_ROT_270;
899
Snild Dolkow9e217d62020-04-22 15:53:42 +0200900 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700901}
902
Lloyd Piquef5275482019-01-29 18:42:42 -0800903TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700904 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800905
906 expectPerFrameCommonCalls();
Lloyd Pique46b72df2019-10-29 13:19:27 -0700907
908 // Setting the composition type should happen before setting the color. We
909 // check this in this test only by setting up an testing::InSeqeuence
910 // instance before setting up the two expectations.
911 InSequence s;
Lloyd Piquef5275482019-01-29 18:42:42 -0800912 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -0700913 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -0800914
Dan Stoza6166c312021-01-15 16:34:05 -0800915 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800916}
917
918TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700919 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -0800920
921 expectPerFrameCommonCalls();
922 expectSetSidebandHandleCall();
923 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SIDEBAND);
924
Dan Stoza6166c312021-01-15 16:34:05 -0800925 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800926}
927
928TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700929 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800930
931 expectPerFrameCommonCalls();
932 expectSetHdrMetadataAndBufferCalls();
933 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CURSOR);
934
Dan Stoza6166c312021-01-15 16:34:05 -0800935 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800936}
937
938TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700939 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -0800940
941 expectPerFrameCommonCalls();
942 expectSetHdrMetadataAndBufferCalls();
943 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
944
Dan Stoza6166c312021-01-15 16:34:05 -0800945 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800946}
947
948TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
949 (*mOutputLayer.editState().hwc).hwcCompositionType =
950 Hwc2::IComposerClient::Composition::SOLID_COLOR;
951
Lloyd Pique9755fb72019-03-26 14:44:40 -0700952 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800953
954 expectPerFrameCommonCalls();
955 expectSetColorCall();
956 expectNoSetCompositionTypeCall();
957
Dan Stoza6166c312021-01-15 16:34:05 -0800958 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800959}
960
961TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700962 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800963
964 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
965 expectSetColorCall();
966 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
967
Dan Stoza6166c312021-01-15 16:34:05 -0800968 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800969}
970
971TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
972 mOutputLayer.editState().forceClientComposition = true;
973
Lloyd Pique9755fb72019-03-26 14:44:40 -0700974 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800975
976 expectPerFrameCommonCalls();
977 expectSetColorCall();
978 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
979
Dan Stoza6166c312021-01-15 16:34:05 -0800980 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800981}
982
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800983TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
984 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
985 includeGenericLayerMetadataInState();
986
987 expectGeometryCommonCalls();
988 expectPerFrameCommonCalls();
989 expectSetHdrMetadataAndBufferCalls();
990 expectGenericLayerMetadataCalls();
991 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
992
Dan Stoza6166c312021-01-15 16:34:05 -0800993 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800994}
995
996TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
997 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
998 includeGenericLayerMetadataInState();
999
1000 expectPerFrameCommonCalls();
1001 expectSetHdrMetadataAndBufferCalls();
1002 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1003
Dan Stoza6166c312021-01-15 16:34:05 -08001004 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001005}
1006
Alec Mourib7edfc22021-03-17 16:20:26 -07001007TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
1008 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1009 includeOverrideInfo();
1010
Alec Mouri7be6c0a2021-03-19 15:22:01 -07001011 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideDisplayFrame.toFloatRect(),
1012 kOverrideBufferTransform);
Alec Mourib7edfc22021-03-17 16:20:26 -07001013 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace);
1014 expectSetHdrMetadataAndBufferCalls(kOverrideBuffer, kOverrideFence);
1015 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1016
1017 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false);
1018}
1019
Lloyd Pique66d68602019-02-13 14:23:31 -08001020/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001021 * OutputLayer::writeCursorPositionToHWC()
1022 */
1023
1024struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1025 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -07001026 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001027
1028 static const Rect kDefaultDisplayViewport;
1029 static const Rect kDefaultCursorFrame;
1030
1031 OutputLayerWriteCursorPositionToHWCTest() {
1032 auto& outputLayerState = mOutputLayer.editState();
1033 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1034
Lloyd Pique9755fb72019-03-26 14:44:40 -07001035 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001036
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001037 mOutputState.layerStackSpace.content = kDefaultDisplayViewport;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001038 mOutputState.transform = ui::Transform{kDefaultTransform};
1039 }
1040
1041 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1042};
1043
1044const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1045const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1046
Lloyd Piquede196652020-01-22 17:29:58 -08001047TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
1048 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
1049
1050 mOutputLayer.writeCursorPositionToHWC();
1051}
1052
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001053TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1054 mOutputLayer.editState().hwc.reset();
1055
1056 mOutputLayer.writeCursorPositionToHWC();
1057}
1058
1059TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1060 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1061
1062 mOutputLayer.writeCursorPositionToHWC();
1063}
1064
1065TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001066 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001067
1068 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1069
1070 mOutputLayer.writeCursorPositionToHWC();
1071}
1072
1073TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1074 mOutputState.transform = ui::Transform{TR_ROT_90};
1075
1076 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1077
1078 mOutputLayer.writeCursorPositionToHWC();
1079}
1080
1081/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001082 * OutputLayer::getHwcLayer()
1083 */
1084
1085TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1086 mOutputLayer.editState().hwc.reset();
1087
1088 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1089}
1090
1091TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1092 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1093
1094 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1095}
1096
1097TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1098 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1099 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1100
1101 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1102}
1103
1104/*
1105 * OutputLayer::requiresClientComposition()
1106 */
1107
1108TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1109 mOutputLayer.editState().hwc.reset();
1110
1111 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1112}
1113
1114TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1115 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1116 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CLIENT;
1117
1118 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1119}
1120
1121TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1122 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1123 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1124
1125 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1126}
1127
1128/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001129 * OutputLayer::isHardwareCursor()
1130 */
1131
1132TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1133 mOutputLayer.editState().hwc.reset();
1134
1135 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1136}
1137
1138TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1139 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1140 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CURSOR;
1141
1142 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1143}
1144
1145TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1146 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1147 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1148
1149 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1150}
1151
1152/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001153 * OutputLayer::applyDeviceCompositionTypeChange()
1154 */
1155
1156TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1157 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1158 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1159
1160 mOutputLayer.applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT);
1161
1162 ASSERT_TRUE(mOutputLayer.getState().hwc);
1163 EXPECT_EQ(Hwc2::IComposerClient::Composition::CLIENT,
1164 mOutputLayer.getState().hwc->hwcCompositionType);
1165}
1166
1167/*
1168 * OutputLayer::prepareForDeviceLayerRequests()
1169 */
1170
1171TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1172 mOutputLayer.editState().clearClientTarget = true;
1173
1174 mOutputLayer.prepareForDeviceLayerRequests();
1175
1176 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1177}
1178
1179/*
1180 * OutputLayer::applyDeviceLayerRequest()
1181 */
1182
1183TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1184 mOutputLayer.editState().clearClientTarget = false;
1185
1186 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1187
1188 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1189}
1190
1191TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1192 mOutputLayer.editState().clearClientTarget = false;
1193
1194 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1195
1196 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1197}
1198
Lloyd Pique688abd42019-02-15 15:42:24 -08001199/*
1200 * OutputLayer::needsFiltering()
1201 */
1202
1203TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1204 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1205 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1206
1207 EXPECT_FALSE(mOutputLayer.needsFiltering());
1208}
1209
1210TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1211 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1212 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1213
1214 EXPECT_TRUE(mOutputLayer.needsFiltering());
1215}
1216
Lloyd Piquecc01a452018-12-04 17:24:00 -08001217} // namespace
1218} // namespace android::compositionengine