blob: 4d5a8f5fc4d6da87cd953547ab1ecc73294a8a0a [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"
Alec Mouria90a5702021-04-16 16:36:21 +000029#include "renderengine/mock/RenderEngine.h"
Lloyd Pique07e33212018-12-18 16:33:37 -080030
Lloyd Piquecc01a452018-12-04 17:24:00 -080031namespace android::compositionengine {
32namespace {
33
Peiyong Line9d809e2020-04-14 13:10:48 -070034namespace hal = android::hardware::graphics::composer::hal;
35
Lloyd Piquea83776c2019-01-29 18:42:32 -080036using testing::_;
Lloyd Pique46b72df2019-10-29 13:19:27 -070037using testing::InSequence;
Lloyd Piquea83776c2019-01-29 18:42:32 -080038using testing::Return;
39using testing::ReturnRef;
Lloyd Piquecc01a452018-12-04 17:24:00 -080040using testing::StrictMock;
41
Lloyd Piquea83776c2019-01-29 18:42:32 -080042constexpr auto TR_IDENT = 0u;
43constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H;
44constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V;
45constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
46constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V;
47constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180;
48
49const std::string kOutputName{"Test Output"};
50
Lloyd Piquef5275482019-01-29 18:42:42 -080051MATCHER_P(ColorEq, expected, "") {
52 *result_listener << "Colors are not equal\n";
53 *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " "
54 << expected.a << "\n";
55 *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n";
56
57 return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a;
58}
59
Marin Shalamanov68933fb2020-09-10 17:58:12 +020060ui::Rotation toRotation(uint32_t rotationFlag) {
61 switch (rotationFlag) {
62 case ui::Transform::RotationFlags::ROT_0:
63 return ui::ROTATION_0;
64 case ui::Transform::RotationFlags::ROT_90:
65 return ui::ROTATION_90;
66 case ui::Transform::RotationFlags::ROT_180:
67 return ui::ROTATION_180;
68 case ui::Transform::RotationFlags::ROT_270:
69 return ui::ROTATION_270;
70 default:
71 LOG_FATAL("Unexpected rotation flag %d", rotationFlag);
72 return ui::Rotation(-1);
73 }
74}
75
Lloyd Pique66d68602019-02-13 14:23:31 -080076struct OutputLayerTest : public testing::Test {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070077 struct OutputLayer final : public impl::OutputLayer {
Lloyd Piquede196652020-01-22 17:29:58 -080078 OutputLayer(const compositionengine::Output& output, sp<compositionengine::LayerFE> layerFE)
79 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070080 ~OutputLayer() override = default;
81
82 // compositionengine::OutputLayer overrides
83 const compositionengine::Output& getOutput() const override { return mOutput; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070084 compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
85 const impl::OutputLayerCompositionState& getState() const override { return mState; }
86 impl::OutputLayerCompositionState& editState() override { return mState; }
87
88 // compositionengine::impl::OutputLayer overrides
89 void dumpState(std::string& out) const override { mState.dump(out); }
90
91 const compositionengine::Output& mOutput;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070092 sp<compositionengine::LayerFE> mLayerFE;
93 impl::OutputLayerCompositionState mState;
94 };
95
Lloyd Piquea83776c2019-01-29 18:42:32 -080096 OutputLayerTest() {
97 EXPECT_CALL(*mLayerFE, getDebugName()).WillRepeatedly(Return("Test LayerFE"));
98 EXPECT_CALL(mOutput, getName()).WillRepeatedly(ReturnRef(kOutputName));
99
Lloyd Piquede196652020-01-22 17:29:58 -0800100 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800101 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
102 }
103
Lloyd Piquecc01a452018-12-04 17:24:00 -0800104 compositionengine::mock::Output mOutput;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800105 sp<compositionengine::mock::LayerFE> mLayerFE{
106 new StrictMock<compositionengine::mock::LayerFE>()};
Lloyd Piquede196652020-01-22 17:29:58 -0800107 OutputLayer mOutputLayer{mOutput, mLayerFE};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800108
Lloyd Pique9755fb72019-03-26 14:44:40 -0700109 LayerFECompositionState mLayerFEState;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800110 impl::OutputCompositionState mOutputState;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800111};
112
Lloyd Piquea83776c2019-01-29 18:42:32 -0800113/*
Lloyd Piquecc01a452018-12-04 17:24:00 -0800114 * Basic construction
115 */
116
117TEST_F(OutputLayerTest, canInstantiateOutputLayer) {}
118
Lloyd Piquea83776c2019-01-29 18:42:32 -0800119/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800120 * OutputLayer::setHwcLayer()
Lloyd Pique07e33212018-12-18 16:33:37 -0800121 */
122
Lloyd Piquedf336d92019-03-07 21:38:42 -0800123TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) {
Lloyd Pique07e33212018-12-18 16:33:37 -0800124 StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
125
Lloyd Piquedf336d92019-03-07 21:38:42 -0800126 mOutputLayer.setHwcLayer(nullptr);
Lloyd Pique07e33212018-12-18 16:33:37 -0800127
128 EXPECT_FALSE(mOutputLayer.getState().hwc);
129}
130
Lloyd Piquedf336d92019-03-07 21:38:42 -0800131TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) {
132 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Pique07e33212018-12-18 16:33:37 -0800133
Lloyd Piquedf336d92019-03-07 21:38:42 -0800134 mOutputLayer.setHwcLayer(hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800135
Lloyd Piquea83776c2019-01-29 18:42:32 -0800136 const auto& outputLayerState = mOutputLayer.getState();
137 ASSERT_TRUE(outputLayerState.hwc);
Lloyd Pique07e33212018-12-18 16:33:37 -0800138
Lloyd Piquea83776c2019-01-29 18:42:32 -0800139 const auto& hwcState = *outputLayerState.hwc;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800140 EXPECT_EQ(hwcLayer, hwcState.hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800141}
142
Lloyd Piquea83776c2019-01-29 18:42:32 -0800143/*
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000144 * OutputLayer::calculateOutputSourceCrop()
145 */
146
147struct OutputLayerSourceCropTest : public OutputLayerTest {
148 OutputLayerSourceCropTest() {
149 // Set reasonable default values for a simple case. Each test will
150 // set one specific value to something different.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700151 mLayerFEState.geomUsesSourceCrop = true;
152 mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080};
153 mLayerFEState.transparentRegionHint = Region{};
154 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
155 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
156 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
157 mLayerFEState.geomBufferTransform = TR_IDENT;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000158
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200159 mOutputState.layerStackSpace.content = Rect{0, 0, 1920, 1080};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000160 }
161
162 FloatRect calculateOutputSourceCrop() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700163 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000164
165 return mOutputLayer.calculateOutputSourceCrop();
166 }
167};
168
169TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700170 mLayerFEState.geomUsesSourceCrop = false;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000171
172 const FloatRect expected{};
Lloyd Piqueea629282019-12-03 15:57:10 -0800173 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000174}
175
176TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) {
177 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800178 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000179}
180
181TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700182 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000183
184 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800185 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000186}
187
188TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700189 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
190 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000191
192 const FloatRect expected{0.f, 0.f, 1080.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800193 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000194}
195
196TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) {
197 struct Entry {
198 uint32_t bufferInvDisplay;
199 uint32_t buffer;
200 uint32_t display;
201 FloatRect expected;
202 };
203 // Not an exhaustive list of cases, but hopefully enough.
204 const std::array<Entry, 12> testData = {
205 // clang-format off
206 // inv buffer display expected
207 /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
208 /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
209 /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
210 /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
211
212 /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
213 /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
214 /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
215 /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
216
217 /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
218 /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
219 /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
220 /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
221
222 // clang-format on
223 };
224
225 for (size_t i = 0; i < testData.size(); i++) {
226 const auto& entry = testData[i];
227
Lloyd Pique9755fb72019-03-26 14:44:40 -0700228 mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay;
229 mLayerFEState.geomBufferTransform = entry.buffer;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200230 mOutputState.displaySpace.orientation = toRotation(entry.display);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000231
Lloyd Piqueea629282019-12-03 15:57:10 -0800232 EXPECT_THAT(calculateOutputSourceCrop(), entry.expected) << "entry " << i;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000233 }
234}
235
236TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700237 mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000238
239 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800240 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000241}
242
243TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200244 mOutputState.layerStackSpace.content = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000245
246 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800247 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000248}
249
250/*
Lloyd Piquea83776c2019-01-29 18:42:32 -0800251 * OutputLayer::calculateOutputDisplayFrame()
252 */
253
254struct OutputLayerDisplayFrameTest : public OutputLayerTest {
255 OutputLayerDisplayFrameTest() {
256 // Set reasonable default values for a simple case. Each test will
257 // set one specific value to something different.
258
Lloyd Pique9755fb72019-03-26 14:44:40 -0700259 mLayerFEState.transparentRegionHint = Region{};
260 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
261 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
262 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
263 mLayerFEState.geomCrop = Rect{0, 0, 1920, 1080};
264 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800265
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200266 mOutputState.layerStackSpace.content = Rect{0, 0, 1920, 1080};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800267 mOutputState.transform = ui::Transform{TR_IDENT};
268 }
269
270 Rect calculateOutputDisplayFrame() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700271 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800272
273 return mOutputLayer.calculateOutputDisplayFrame();
274 }
275};
276
277TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) {
278 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800279 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800280}
281
282TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700283 mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800284 const Rect expected{0, 0, 0, 0};
Lloyd Piqueea629282019-12-03 15:57:10 -0800285 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800286}
287
288TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700289 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800290 const Rect expected{100, 200, 300, 500};
Lloyd Piqueea629282019-12-03 15:57:10 -0800291 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800292}
293
294TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700295 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
296 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800297 const Rect expected{1420, 100, 1720, 300};
Lloyd Piqueea629282019-12-03 15:57:10 -0800298 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800299}
300
301TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700302 mLayerFEState.geomCrop = Rect{};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800303 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800304 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800305}
306
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000307TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700308 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800309 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800310 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800311}
312
313TEST_F(OutputLayerDisplayFrameTest, viewportAffectsFrame) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200314 mOutputState.layerStackSpace.content = Rect{0, 0, 960, 540};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800315 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800316 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800317}
318
319TEST_F(OutputLayerDisplayFrameTest, outputTransformAffectsDisplayFrame) {
320 mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90};
321 const Rect expected{-1080, 0, 0, 1920};
Lloyd Piqueea629282019-12-03 15:57:10 -0800322 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800323}
324
325/*
326 * OutputLayer::calculateOutputRelativeBufferTransform()
327 */
328
329TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700330 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800331
332 struct Entry {
333 uint32_t layer;
334 uint32_t buffer;
335 uint32_t display;
336 uint32_t expected;
337 };
338 // Not an exhaustive list of cases, but hopefully enough.
339 const std::array<Entry, 24> testData = {
340 // clang-format off
341 // layer buffer display expected
342 /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
343 /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_90},
344 /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
345 /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270},
346
347 /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_IDENT},
348 /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_90},
349 /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_180},
350 /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_ROT_270},
351
352 /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V},
353 /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_180},
354 /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
355 /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_180},
356
357 /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_90},
358 /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_180},
359 /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT ^ TR_ROT_270},
360 /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_IDENT},
361
362 /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_ROT_180},
363 /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT ^ TR_ROT_270},
364 /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_IDENT},
365 /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_90},
366
367 /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_270},
368 /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_IDENT},
369 /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_90},
370 /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_180},
371 // clang-format on
372 };
373
374 for (size_t i = 0; i < testData.size(); i++) {
375 const auto& entry = testData[i];
376
Lloyd Pique9755fb72019-03-26 14:44:40 -0700377 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
378 mLayerFEState.geomBufferTransform = entry.buffer;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200379 mOutputState.displaySpace.orientation = toRotation(entry.display);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700380 mOutputState.transform = ui::Transform{entry.display};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800381
Snild Dolkow9e217d62020-04-22 15:53:42 +0200382 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.display);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800383 EXPECT_EQ(entry.expected, actual) << "entry " << i;
384 }
385}
386
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000387TEST_F(OutputLayerTest,
388 calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700389 mLayerFEState.geomBufferUsesDisplayInverseTransform = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000390
391 struct Entry {
Snild Dolkow9e217d62020-04-22 15:53:42 +0200392 uint32_t layer; /* shouldn't affect the result, so we just use arbitrary values */
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000393 uint32_t buffer;
394 uint32_t display;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200395 uint32_t internal;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000396 uint32_t expected;
397 };
Snild Dolkow9e217d62020-04-22 15:53:42 +0200398 const std::array<Entry, 64> testData = {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000399 // clang-format off
Snild Dolkow9e217d62020-04-22 15:53:42 +0200400 // layer buffer display internal expected
401 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
402 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_270},
403 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
404 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_90},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000405
Snild Dolkow9e217d62020-04-22 15:53:42 +0200406 Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT, TR_ROT_90},
407 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_90, TR_IDENT},
408 Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_180, TR_ROT_270},
409 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000410
Snild Dolkow9e217d62020-04-22 15:53:42 +0200411 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_180},
412 Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_90, TR_ROT_90},
413 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
414 Entry{TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000415
Snild Dolkow9e217d62020-04-22 15:53:42 +0200416 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270},
417 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_ROT_90, TR_ROT_180},
418 Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_180, TR_ROT_90},
419 Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000420
Snild Dolkow9e217d62020-04-22 15:53:42 +0200421 // layer buffer display internal expected
422 Entry{TR_IDENT, TR_ROT_90, TR_IDENT, TR_IDENT, TR_ROT_90},
423 Entry{TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_90, TR_IDENT},
424 Entry{TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_270},
425 Entry{TR_ROT_270, TR_ROT_90, TR_IDENT, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000426
Snild Dolkow9e217d62020-04-22 15:53:42 +0200427 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_180},
428 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90},
429 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_IDENT},
430 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270, TR_ROT_270},
431
432 Entry{TR_IDENT, TR_ROT_90, TR_ROT_180, TR_IDENT, TR_ROT_270},
433 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_180},
434 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_180, TR_ROT_90},
435 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_270, TR_IDENT},
436
437 Entry{TR_IDENT, TR_ROT_90, TR_ROT_270, TR_IDENT, TR_IDENT},
438 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270},
439 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_ROT_180, TR_ROT_180},
440 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90},
441
442 // layer buffer display internal expected
443 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_IDENT, TR_ROT_180},
444 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_90},
445 Entry{TR_ROT_180, TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT},
446 Entry{TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_270},
447
448 Entry{TR_IDENT, TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_270},
449 Entry{TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_90, TR_ROT_180},
450 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_90},
451 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_IDENT},
452
453 Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT, TR_IDENT},
454 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270},
455 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180},
456 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90},
457
458 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_IDENT, TR_ROT_90},
459 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_IDENT},
460 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_270},
461 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_270, TR_ROT_180},
462
463 // layer buffer display internal expected
464 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_IDENT, TR_ROT_270},
465 Entry{TR_ROT_90, TR_ROT_270, TR_IDENT, TR_ROT_90, TR_ROT_180},
466 Entry{TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_90},
467 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT},
468
469 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_IDENT, TR_IDENT},
470 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270},
471 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_ROT_180, TR_ROT_180},
472 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90},
473
474 Entry{TR_IDENT, TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_90},
475 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_90, TR_IDENT},
476 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270},
477 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_180},
478
479 Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180},
480 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_ROT_90},
481 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_IDENT},
482 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000483 // clang-format on
484 };
485
486 for (size_t i = 0; i < testData.size(); i++) {
487 const auto& entry = testData[i];
488
Snild Dolkow9e217d62020-04-22 15:53:42 +0200489 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
Lloyd Pique9755fb72019-03-26 14:44:40 -0700490 mLayerFEState.geomBufferTransform = entry.buffer;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200491 mOutputState.displaySpace.orientation = toRotation(entry.display);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700492 mOutputState.transform = ui::Transform{entry.display};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000493
Snild Dolkow9e217d62020-04-22 15:53:42 +0200494 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.internal);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000495 EXPECT_EQ(entry.expected, actual) << "entry " << i;
496 }
497}
498
499/*
500 * OutputLayer::updateCompositionState()
501 */
502
503struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer {
504 OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output,
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000505 sp<compositionengine::LayerFE> layerFE)
Lloyd Piquede196652020-01-22 17:29:58 -0800506 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000507 // Mock everything called by updateCompositionState to simplify testing it.
508 MOCK_CONST_METHOD0(calculateOutputSourceCrop, FloatRect());
509 MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect());
Snild Dolkow9e217d62020-04-22 15:53:42 +0200510 MOCK_CONST_METHOD1(calculateOutputRelativeBufferTransform, uint32_t(uint32_t));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700511
512 // compositionengine::OutputLayer overrides
513 const compositionengine::Output& getOutput() const override { return mOutput; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700514 compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
515 const impl::OutputLayerCompositionState& getState() const override { return mState; }
516 impl::OutputLayerCompositionState& editState() override { return mState; }
517
518 // These need implementations though are not expected to be called.
519 MOCK_CONST_METHOD1(dumpState, void(std::string&));
520
521 const compositionengine::Output& mOutput;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700522 sp<compositionengine::LayerFE> mLayerFE;
523 impl::OutputLayerCompositionState mState;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000524};
525
526struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest {
527public:
528 OutputLayerUpdateCompositionStateTest() {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000529 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
Lloyd Piquef5275482019-01-29 18:42:42 -0800530 EXPECT_CALL(mOutput, getDisplayColorProfile())
531 .WillRepeatedly(Return(&mDisplayColorProfile));
532 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000533 }
534
535 ~OutputLayerUpdateCompositionStateTest() = default;
536
Snild Dolkow9e217d62020-04-22 15:53:42 +0200537 void setupGeometryChildCallValues(ui::Transform::RotationFlags internalDisplayRotationFlags) {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000538 EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop()).WillOnce(Return(kSourceCrop));
539 EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200540 EXPECT_CALL(mOutputLayer,
541 calculateOutputRelativeBufferTransform(internalDisplayRotationFlags))
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000542 .WillOnce(Return(mBufferTransform));
543 }
544
545 void validateComputedGeometryState() {
546 const auto& state = mOutputLayer.getState();
547 EXPECT_EQ(kSourceCrop, state.sourceCrop);
548 EXPECT_EQ(kDisplayFrame, state.displayFrame);
549 EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform);
550 }
551
552 const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f};
553 const Rect kDisplayFrame{11, 12, 13, 14};
554 uint32_t mBufferTransform{21};
555
556 using OutputLayer = OutputLayerPartialMockForUpdateCompositionState;
Lloyd Piquede196652020-01-22 17:29:58 -0800557 StrictMock<OutputLayer> mOutputLayer{mOutput, mLayerFE};
Lloyd Piquef5275482019-01-29 18:42:42 -0800558 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000559};
560
Lloyd Piquede196652020-01-22 17:29:58 -0800561TEST_F(OutputLayerUpdateCompositionStateTest, doesNothingIfNoFECompositionState) {
562 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
563
Snild Dolkow9e217d62020-04-22 15:53:42 +0200564 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Piquede196652020-01-22 17:29:58 -0800565}
566
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000567TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700568 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000569 mOutputState.isSecure = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700570 mOutputLayer.editState().forceClientComposition = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000571
Snild Dolkow9e217d62020-04-22 15:53:42 +0200572 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000573
Snild Dolkow9e217d62020-04-22 15:53:42 +0200574 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000575
576 validateComputedGeometryState();
577
578 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
579}
580
581TEST_F(OutputLayerUpdateCompositionStateTest,
582 alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700583 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000584 mOutputState.isSecure = false;
585
Snild Dolkow9e217d62020-04-22 15:53:42 +0200586 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000587
Snild Dolkow9e217d62020-04-22 15:53:42 +0200588 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000589
590 validateComputedGeometryState();
591
592 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
593}
594
595TEST_F(OutputLayerUpdateCompositionStateTest,
596 alsoSetsForceCompositionIfUnsupportedBufferTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700597 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000598 mOutputState.isSecure = true;
599
600 mBufferTransform = ui::Transform::ROT_INVALID;
601
Snild Dolkow9e217d62020-04-22 15:53:42 +0200602 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000603
Snild Dolkow9e217d62020-04-22 15:53:42 +0200604 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000605
606 validateComputedGeometryState();
607
608 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
609}
610
Lloyd Piquef5275482019-01-29 18:42:42 -0800611TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700612 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
Lloyd Piquef5275482019-01-29 18:42:42 -0800613 mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB;
614
615 // If the layer is not colorspace agnostic, the output layer dataspace
616 // should use the layers requested colorspace.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700617 mLayerFEState.isColorspaceAgnostic = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800618
Snild Dolkow9e217d62020-04-22 15:53:42 +0200619 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800620
621 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
622
623 // If the layer is colorspace agnostic, the output layer dataspace
624 // should use the colorspace chosen for the whole output.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700625 mLayerFEState.isColorspaceAgnostic = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800626
Snild Dolkow9e217d62020-04-22 15:53:42 +0200627 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800628
629 EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace);
630}
631
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000632TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700633 mOutputLayer.editState().forceClientComposition = false;
634
Snild Dolkow9e217d62020-04-22 15:53:42 +0200635 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000636
637 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
638}
639
Lloyd Piquefe671022019-09-24 10:43:03 -0700640TEST_F(OutputLayerUpdateCompositionStateTest,
641 doesNotClearForceClientCompositionIfNotDoingGeometry) {
642 mOutputLayer.editState().forceClientComposition = true;
643
Snild Dolkow9e217d62020-04-22 15:53:42 +0200644 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquefe671022019-09-24 10:43:03 -0700645
646 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
647}
648
Lloyd Piquef5275482019-01-29 18:42:42 -0800649TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700650 mLayerFEState.forceClientComposition = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700651 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800652
Snild Dolkow9e217d62020-04-22 15:53:42 +0200653 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800654
655 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
656}
657
658TEST_F(OutputLayerUpdateCompositionStateTest,
659 clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700660 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800661 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false));
662
Snild Dolkow9e217d62020-04-22 15:53:42 +0200663 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700664
665 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
666}
667
668TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromArgumentFlag) {
669 mLayerFEState.forceClientComposition = false;
670 mOutputLayer.editState().forceClientComposition = false;
671
Snild Dolkow9e217d62020-04-22 15:53:42 +0200672 mOutputLayer.updateCompositionState(false, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700673
674 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
675
676 mOutputLayer.editState().forceClientComposition = false;
677
Snild Dolkow9e217d62020-04-22 15:53:42 +0200678 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700679
Snild Dolkow9e217d62020-04-22 15:53:42 +0200680 mOutputLayer.updateCompositionState(true, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800681
682 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
683}
684
Lloyd Piquea83776c2019-01-29 18:42:32 -0800685/*
686 * OutputLayer::writeStateToHWC()
687 */
688
689struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
Peiyong Line9d809e2020-04-14 13:10:48 -0700690 static constexpr hal::Error kError = hal::Error::UNSUPPORTED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800691 static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800692 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);
Alec Mouriee69a592021-03-23 15:00:45 -0700696 static constexpr Hwc2::IComposerClient::BlendMode kOverrideBlendMode =
697 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800698 static constexpr float kAlpha = 51.f;
Alec Mouriee69a592021-03-23 15:00:45 -0700699 static constexpr float kOverrideAlpha = 1.f;
Lloyd Piquef5275482019-01-29 18:42:42 -0800700 static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
Alec Mourib7edfc22021-03-17 16:20:26 -0700701 static constexpr ui::Dataspace kOverrideDataspace = static_cast<ui::Dataspace>(72);
Lloyd Piquef5275482019-01-29 18:42:42 -0800702 static constexpr int kSupportedPerFrameMetadata = 101;
703 static constexpr int kExpectedHwcSlot = 0;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800704 static constexpr bool kLayerGenericMetadata1Mandatory = true;
705 static constexpr bool kLayerGenericMetadata2Mandatory = true;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800706
Lloyd Piquef5275482019-01-29 18:42:42 -0800707 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800708 static const Rect kDisplayFrame;
Alec Mourib7edfc22021-03-17 16:20:26 -0700709 static const Rect kOverrideDisplayFrame;
Lloyd Piquea2468662019-03-07 21:31:06 -0800710 static const Region kOutputSpaceVisibleRegion;
Alec Mouri464352b2021-03-24 16:33:21 -0700711 static const Region kOverrideVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800712 static const mat4 kColorTransform;
713 static const Region kSurfaceDamage;
Alec Mouri464352b2021-03-24 16:33:21 -0700714 static const Region kOverrideSurfaceDamage;
Lloyd Piquef5275482019-01-29 18:42:42 -0800715 static const HdrMetadata kHdrMetadata;
716 static native_handle_t* kSidebandStreamHandle;
717 static const sp<GraphicBuffer> kBuffer;
Alec Mouria90a5702021-04-16 16:36:21 +0000718 std::shared_ptr<renderengine::ExternalTexture> kOverrideBuffer;
Lloyd Piquef5275482019-01-29 18:42:42 -0800719 static const sp<Fence> kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700720 static const sp<Fence> kOverrideFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800721 static const std::string kLayerGenericMetadata1Key;
722 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
723 static const std::string kLayerGenericMetadata2Key;
724 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800725
726 OutputLayerWriteStateToHWCTest() {
Alec Mouria90a5702021-04-16 16:36:21 +0000727 kOverrideBuffer = std::make_shared<
728 renderengine::ExternalTexture>(new GraphicBuffer(), mRenderEngine,
729 renderengine::ExternalTexture::Usage::READABLE |
730 renderengine::ExternalTexture::Usage::
731 WRITEABLE);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800732 auto& outputLayerState = mOutputLayer.editState();
733 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
734
735 outputLayerState.displayFrame = kDisplayFrame;
736 outputLayerState.sourceCrop = kSourceCrop;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800737 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800738 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800739 outputLayerState.dataspace = kDataspace;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800740
Lloyd Pique9755fb72019-03-26 14:44:40 -0700741 mLayerFEState.blendMode = kBlendMode;
742 mLayerFEState.alpha = kAlpha;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700743 mLayerFEState.colorTransform = kColorTransform;
744 mLayerFEState.color = kColor;
745 mLayerFEState.surfaceDamage = kSurfaceDamage;
746 mLayerFEState.hdrMetadata = kHdrMetadata;
747 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
748 mLayerFEState.buffer = kBuffer;
749 mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
750 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800751
752 EXPECT_CALL(mOutput, getDisplayColorProfile())
753 .WillRepeatedly(Return(&mDisplayColorProfile));
754 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
755 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800756 }
757
Lloyd Piquef5275482019-01-29 18:42:42 -0800758 // Some tests may need to simulate unsupported HWC calls
759 enum class SimulateUnsupported { None, ColorTransform };
760
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800761 void includeGenericLayerMetadataInState() {
762 mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory,
763 kLayerGenericMetadata1Value};
764 mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory,
765 kLayerGenericMetadata2Value};
766 }
767
Alec Mourib7edfc22021-03-17 16:20:26 -0700768 void includeOverrideInfo() {
769 auto& overrideInfo = mOutputLayer.editState().overrideInfo;
770
771 overrideInfo.buffer = kOverrideBuffer;
772 overrideInfo.acquireFence = kOverrideFence;
773 overrideInfo.displayFrame = kOverrideDisplayFrame;
774 overrideInfo.dataspace = kOverrideDataspace;
Alec Mouri464352b2021-03-24 16:33:21 -0700775 overrideInfo.damageRegion = kOverrideSurfaceDamage;
776 overrideInfo.visibleRegion = kOverrideVisibleRegion;
Alec Mourib7edfc22021-03-17 16:20:26 -0700777 }
778
779 void expectGeometryCommonCalls(Rect displayFrame = kDisplayFrame,
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700780 FloatRect sourceCrop = kSourceCrop,
Alec Mouriee69a592021-03-23 15:00:45 -0700781 Hwc2::Transform bufferTransform = kBufferTransform,
782 Hwc2::IComposerClient::BlendMode blendMode = kBlendMode,
783 float alpha = kAlpha) {
Alec Mourib7edfc22021-03-17 16:20:26 -0700784 EXPECT_CALL(*mHwcLayer, setDisplayFrame(displayFrame)).WillOnce(Return(kError));
785 EXPECT_CALL(*mHwcLayer, setSourceCrop(sourceCrop)).WillOnce(Return(kError));
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400786 EXPECT_CALL(*mHwcLayer, setZOrder(_)).WillOnce(Return(kError));
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700787 EXPECT_CALL(*mHwcLayer, setTransform(bufferTransform)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800788
Alec Mouriee69a592021-03-23 15:00:45 -0700789 EXPECT_CALL(*mHwcLayer, setBlendMode(blendMode)).WillOnce(Return(kError));
790 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(alpha)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800791 }
792
Alec Mourib7edfc22021-03-17 16:20:26 -0700793 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None,
Alec Mouri464352b2021-03-24 16:33:21 -0700794 ui::Dataspace dataspace = kDataspace,
795 const Region& visibleRegion = kOutputSpaceVisibleRegion,
796 const Region& surfaceDamage = kSurfaceDamage) {
797 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(visibleRegion))).WillOnce(Return(kError));
Alec Mourib7edfc22021-03-17 16:20:26 -0700798 EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800799 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
800 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700801 ? hal::Error::UNSUPPORTED
802 : hal::Error::NONE));
Alec Mouri464352b2021-03-24 16:33:21 -0700803 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(surfaceDamage))).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800804 }
805
806 void expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700807 EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800808 }
809
810 void expectNoSetCompositionTypeCall() {
811 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
812 }
813
814 void expectSetColorCall() {
Peiyong Lin65248e02020-04-18 21:15:07 -0700815 const hal::Color color = {static_cast<uint8_t>(std::round(kColor.r * 255)),
816 static_cast<uint8_t>(std::round(kColor.g * 255)),
817 static_cast<uint8_t>(std::round(kColor.b * 255)), 255};
Lloyd Piquef5275482019-01-29 18:42:42 -0800818
819 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
820 }
821
822 void expectSetSidebandHandleCall() {
823 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
824 }
825
Alec Mourib7edfc22021-03-17 16:20:26 -0700826 void expectSetHdrMetadataAndBufferCalls(sp<GraphicBuffer> buffer = kBuffer,
827 sp<Fence> fence = kFence) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800828 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
Alec Mourib7edfc22021-03-17 16:20:26 -0700829 EXPECT_CALL(*mHwcLayer, setBuffer(kExpectedHwcSlot, buffer, fence));
Lloyd Piquef5275482019-01-29 18:42:42 -0800830 }
831
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800832 void expectGenericLayerMetadataCalls() {
833 // Note: Can be in any order.
834 EXPECT_CALL(*mHwcLayer,
835 setLayerGenericMetadata(kLayerGenericMetadata1Key,
836 kLayerGenericMetadata1Mandatory,
837 kLayerGenericMetadata1Value));
838 EXPECT_CALL(*mHwcLayer,
839 setLayerGenericMetadata(kLayerGenericMetadata2Key,
840 kLayerGenericMetadata2Mandatory,
841 kLayerGenericMetadata2Value));
842 }
843
Lloyd Piquea83776c2019-01-29 18:42:32 -0800844 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800845 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Alec Mouria90a5702021-04-16 16:36:21 +0000846 renderengine::mock::RenderEngine mRenderEngine;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800847};
848
Lloyd Piquef5275482019-01-29 18:42:42 -0800849const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
850 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800851const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Alec Mourib7edfc22021-03-17 16:20:26 -0700852const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044};
Lloyd Piquea2468662019-03-07 21:31:06 -0800853const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
854 Rect{1005, 1006, 1007, 1008}};
Alec Mouri464352b2021-03-24 16:33:21 -0700855const Region OutputLayerWriteStateToHWCTest::kOverrideVisibleRegion{Rect{1006, 1007, 1008, 1009}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800856const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
857 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
858 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
859};
860const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
Alec Mouri464352b2021-03-24 16:33:21 -0700861const Region OutputLayerWriteStateToHWCTest::kOverrideSurfaceDamage{Rect{1026, 1027, 1028, 1029}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800862const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
863native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
864 reinterpret_cast<native_handle_t*>(1031);
865const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer;
866const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700867const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = new Fence();
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800868const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
869 "com.example.metadata.1";
870const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
871const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
872 "com.example.metadata.2";
873const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
874 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800875
Lloyd Piquede196652020-01-22 17:29:58 -0800876TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
877 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
878
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400879 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0);
Lloyd Piquede196652020-01-22 17:29:58 -0800880}
881
Lloyd Piquea83776c2019-01-29 18:42:32 -0800882TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
883 mOutputLayer.editState().hwc.reset();
884
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400885 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800886}
887
888TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
889 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
890
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400891 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800892}
893
Lloyd Piquef5275482019-01-29 18:42:42 -0800894TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800895 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -0800896 expectPerFrameCommonCalls();
897
898 expectNoSetCompositionTypeCall();
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400899 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800900
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400901 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800902}
903
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700904TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
905 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
906 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
907 // This test simulates a scenario where displayInstallOrientation is set to
908 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
909 // DisplayDevice::setProjection).
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200910 mOutputState.displaySpace.orientation = ui::ROTATION_0;
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700911 mOutputState.transform = ui::Transform{TR_ROT_90};
912 // Buffers are pre-rotated based on the transform hint (ROT_90); their
913 // geomBufferTransform is set to the inverse transform.
914 mLayerFEState.geomBufferTransform = TR_ROT_270;
915
Snild Dolkow9e217d62020-04-22 15:53:42 +0200916 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700917}
918
Lloyd Piquef5275482019-01-29 18:42:42 -0800919TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700920 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800921
922 expectPerFrameCommonCalls();
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400923 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Pique46b72df2019-10-29 13:19:27 -0700924
925 // Setting the composition type should happen before setting the color. We
926 // check this in this test only by setting up an testing::InSeqeuence
927 // instance before setting up the two expectations.
928 InSequence s;
Lloyd Piquef5275482019-01-29 18:42:42 -0800929 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -0700930 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -0800931
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400932 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800933}
934
935TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700936 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -0800937
938 expectPerFrameCommonCalls();
939 expectSetSidebandHandleCall();
940 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SIDEBAND);
941
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400942 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
943
944 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800945}
946
947TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700948 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800949
950 expectPerFrameCommonCalls();
951 expectSetHdrMetadataAndBufferCalls();
952 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CURSOR);
953
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400954 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
955
956 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800957}
958
959TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700960 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -0800961
962 expectPerFrameCommonCalls();
963 expectSetHdrMetadataAndBufferCalls();
964 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
965
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400966 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
967
968 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800969}
970
971TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
972 (*mOutputLayer.editState().hwc).hwcCompositionType =
973 Hwc2::IComposerClient::Composition::SOLID_COLOR;
974
Lloyd Pique9755fb72019-03-26 14:44:40 -0700975 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800976
977 expectPerFrameCommonCalls();
978 expectSetColorCall();
979 expectNoSetCompositionTypeCall();
980
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400981 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
982
983 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800984}
985
986TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700987 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800988
989 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
990 expectSetColorCall();
991 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
992
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400993 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800994}
995
996TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
997 mOutputLayer.editState().forceClientComposition = true;
998
Lloyd Pique9755fb72019-03-26 14:44:40 -0700999 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001000
1001 expectPerFrameCommonCalls();
1002 expectSetColorCall();
1003 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
1004
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001005 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0);
Lloyd Piquef5275482019-01-29 18:42:42 -08001006}
1007
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001008TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
1009 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1010 includeGenericLayerMetadataInState();
1011
1012 expectGeometryCommonCalls();
1013 expectPerFrameCommonCalls();
1014 expectSetHdrMetadataAndBufferCalls();
1015 expectGenericLayerMetadataCalls();
1016 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1017
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001018 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1019
1020 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001021}
1022
1023TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
1024 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1025 includeGenericLayerMetadataInState();
1026
1027 expectPerFrameCommonCalls();
1028 expectSetHdrMetadataAndBufferCalls();
1029 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1030
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001031 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1032
1033 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001034}
1035
Alec Mourib7edfc22021-03-17 16:20:26 -07001036TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
1037 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1038 includeOverrideInfo();
1039
Alec Mouri7be6c0a2021-03-19 15:22:01 -07001040 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideDisplayFrame.toFloatRect(),
Alec Mouriee69a592021-03-23 15:00:45 -07001041 kOverrideBufferTransform, kOverrideBlendMode, kOverrideAlpha);
Alec Mouri464352b2021-03-24 16:33:21 -07001042 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
1043 kOverrideSurfaceDamage);
Alec Mouria90a5702021-04-16 16:36:21 +00001044 expectSetHdrMetadataAndBufferCalls(kOverrideBuffer->getBuffer(), kOverrideFence);
Alec Mourib7edfc22021-03-17 16:20:26 -07001045 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1046
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001047 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1048
1049 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0);
Alec Mourib7edfc22021-03-17 16:20:26 -07001050}
1051
Lloyd Pique66d68602019-02-13 14:23:31 -08001052/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001053 * OutputLayer::writeCursorPositionToHWC()
1054 */
1055
1056struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1057 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -07001058 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001059
1060 static const Rect kDefaultDisplayViewport;
1061 static const Rect kDefaultCursorFrame;
1062
1063 OutputLayerWriteCursorPositionToHWCTest() {
1064 auto& outputLayerState = mOutputLayer.editState();
1065 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1066
Lloyd Pique9755fb72019-03-26 14:44:40 -07001067 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001068
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001069 mOutputState.layerStackSpace.content = kDefaultDisplayViewport;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001070 mOutputState.transform = ui::Transform{kDefaultTransform};
1071 }
1072
1073 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1074};
1075
1076const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1077const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1078
Lloyd Piquede196652020-01-22 17:29:58 -08001079TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
1080 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
1081
1082 mOutputLayer.writeCursorPositionToHWC();
1083}
1084
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001085TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1086 mOutputLayer.editState().hwc.reset();
1087
1088 mOutputLayer.writeCursorPositionToHWC();
1089}
1090
1091TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1092 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1093
1094 mOutputLayer.writeCursorPositionToHWC();
1095}
1096
1097TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001098 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001099
1100 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1101
1102 mOutputLayer.writeCursorPositionToHWC();
1103}
1104
1105TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1106 mOutputState.transform = ui::Transform{TR_ROT_90};
1107
1108 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1109
1110 mOutputLayer.writeCursorPositionToHWC();
1111}
1112
1113/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001114 * OutputLayer::getHwcLayer()
1115 */
1116
1117TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1118 mOutputLayer.editState().hwc.reset();
1119
1120 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1121}
1122
1123TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1124 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1125
1126 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1127}
1128
1129TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1130 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1131 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1132
1133 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1134}
1135
1136/*
1137 * OutputLayer::requiresClientComposition()
1138 */
1139
1140TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1141 mOutputLayer.editState().hwc.reset();
1142
1143 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1144}
1145
1146TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1147 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1148 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CLIENT;
1149
1150 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1151}
1152
1153TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1154 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1155 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1156
1157 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1158}
1159
1160/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001161 * OutputLayer::isHardwareCursor()
1162 */
1163
1164TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1165 mOutputLayer.editState().hwc.reset();
1166
1167 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1168}
1169
1170TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1171 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1172 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CURSOR;
1173
1174 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1175}
1176
1177TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1178 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1179 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1180
1181 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1182}
1183
1184/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001185 * OutputLayer::applyDeviceCompositionTypeChange()
1186 */
1187
1188TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1189 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1190 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1191
1192 mOutputLayer.applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT);
1193
1194 ASSERT_TRUE(mOutputLayer.getState().hwc);
1195 EXPECT_EQ(Hwc2::IComposerClient::Composition::CLIENT,
1196 mOutputLayer.getState().hwc->hwcCompositionType);
1197}
1198
1199/*
1200 * OutputLayer::prepareForDeviceLayerRequests()
1201 */
1202
1203TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1204 mOutputLayer.editState().clearClientTarget = true;
1205
1206 mOutputLayer.prepareForDeviceLayerRequests();
1207
1208 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1209}
1210
1211/*
1212 * OutputLayer::applyDeviceLayerRequest()
1213 */
1214
1215TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1216 mOutputLayer.editState().clearClientTarget = false;
1217
1218 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1219
1220 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1221}
1222
1223TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1224 mOutputLayer.editState().clearClientTarget = false;
1225
1226 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1227
1228 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1229}
1230
Lloyd Pique688abd42019-02-15 15:42:24 -08001231/*
1232 * OutputLayer::needsFiltering()
1233 */
1234
1235TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1236 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1237 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1238
1239 EXPECT_FALSE(mOutputLayer.needsFiltering());
1240}
1241
1242TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1243 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1244 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1245
1246 EXPECT_TRUE(mOutputLayer.needsFiltering());
1247}
1248
Lloyd Piquecc01a452018-12-04 17:24:00 -08001249} // namespace
1250} // namespace android::compositionengine