blob: 5a92f26ff876d0ad9c7a1505e9ee417979d52b9b [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 III9aa25c22021-04-15 15:30:19 -0400879 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
880 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquede196652020-01-22 17:29:58 -0800881}
882
Lloyd Piquea83776c2019-01-29 18:42:32 -0800883TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
884 mOutputLayer.editState().hwc.reset();
885
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400886 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
887 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800888}
889
890TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
891 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
892
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400893 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
894 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800895}
896
Lloyd Piquef5275482019-01-29 18:42:42 -0800897TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800898 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -0800899 expectPerFrameCommonCalls();
900
901 expectNoSetCompositionTypeCall();
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400902 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800903
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400904 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
905 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800906}
907
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700908TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
909 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
910 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
911 // This test simulates a scenario where displayInstallOrientation is set to
912 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
913 // DisplayDevice::setProjection).
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200914 mOutputState.displaySpace.orientation = ui::ROTATION_0;
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700915 mOutputState.transform = ui::Transform{TR_ROT_90};
916 // Buffers are pre-rotated based on the transform hint (ROT_90); their
917 // geomBufferTransform is set to the inverse transform.
918 mLayerFEState.geomBufferTransform = TR_ROT_270;
919
Snild Dolkow9e217d62020-04-22 15:53:42 +0200920 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700921}
922
Lloyd Piquef5275482019-01-29 18:42:42 -0800923TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700924 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800925
926 expectPerFrameCommonCalls();
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400927 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Pique46b72df2019-10-29 13:19:27 -0700928
929 // Setting the composition type should happen before setting the color. We
930 // check this in this test only by setting up an testing::InSeqeuence
931 // instance before setting up the two expectations.
932 InSequence s;
Lloyd Piquef5275482019-01-29 18:42:42 -0800933 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -0700934 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -0800935
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400936 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
937 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800938}
939
940TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700941 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -0800942
943 expectPerFrameCommonCalls();
944 expectSetSidebandHandleCall();
945 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SIDEBAND);
946
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400947 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
948
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400949 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
950 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800951}
952
953TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700954 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800955
956 expectPerFrameCommonCalls();
957 expectSetHdrMetadataAndBufferCalls();
958 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CURSOR);
959
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400960 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
961
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400962 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
963 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800964}
965
966TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700967 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -0800968
969 expectPerFrameCommonCalls();
970 expectSetHdrMetadataAndBufferCalls();
971 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
972
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400973 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
974
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400975 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
976 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800977}
978
979TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
980 (*mOutputLayer.editState().hwc).hwcCompositionType =
981 Hwc2::IComposerClient::Composition::SOLID_COLOR;
982
Lloyd Pique9755fb72019-03-26 14:44:40 -0700983 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800984
985 expectPerFrameCommonCalls();
986 expectSetColorCall();
987 expectNoSetCompositionTypeCall();
988
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400989 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
990
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400991 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
992 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800993}
994
995TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700996 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800997
998 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
999 expectSetColorCall();
1000 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
1001
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001002 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1003 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001004}
1005
1006TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
1007 mOutputLayer.editState().forceClientComposition = true;
1008
Lloyd Pique9755fb72019-03-26 14:44:40 -07001009 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001010
1011 expectPerFrameCommonCalls();
1012 expectSetColorCall();
1013 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
1014
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001015 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1016 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001017}
1018
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001019TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
1020 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1021 includeGenericLayerMetadataInState();
1022
1023 expectGeometryCommonCalls();
1024 expectPerFrameCommonCalls();
1025 expectSetHdrMetadataAndBufferCalls();
1026 expectGenericLayerMetadataCalls();
1027 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1028
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001029 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1030
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001031 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1032 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001033}
1034
1035TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
1036 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1037 includeGenericLayerMetadataInState();
1038
1039 expectPerFrameCommonCalls();
1040 expectSetHdrMetadataAndBufferCalls();
1041 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1042
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001043 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1044
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001045 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1046 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001047}
1048
Alec Mourib7edfc22021-03-17 16:20:26 -07001049TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
1050 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1051 includeOverrideInfo();
1052
Alec Mouri7be6c0a2021-03-19 15:22:01 -07001053 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideDisplayFrame.toFloatRect(),
Alec Mouriee69a592021-03-23 15:00:45 -07001054 kOverrideBufferTransform, kOverrideBlendMode, kOverrideAlpha);
Alec Mouri464352b2021-03-24 16:33:21 -07001055 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
1056 kOverrideSurfaceDamage);
Alec Mouria90a5702021-04-16 16:36:21 +00001057 expectSetHdrMetadataAndBufferCalls(kOverrideBuffer->getBuffer(), kOverrideFence);
Alec Mourib7edfc22021-03-17 16:20:26 -07001058 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1059
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001060 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1061
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001062 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1063 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Alec Mourib7edfc22021-03-17 16:20:26 -07001064}
1065
Lloyd Pique66d68602019-02-13 14:23:31 -08001066/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001067 * OutputLayer::writeCursorPositionToHWC()
1068 */
1069
1070struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1071 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -07001072 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001073
1074 static const Rect kDefaultDisplayViewport;
1075 static const Rect kDefaultCursorFrame;
1076
1077 OutputLayerWriteCursorPositionToHWCTest() {
1078 auto& outputLayerState = mOutputLayer.editState();
1079 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1080
Lloyd Pique9755fb72019-03-26 14:44:40 -07001081 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001082
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001083 mOutputState.layerStackSpace.content = kDefaultDisplayViewport;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001084 mOutputState.transform = ui::Transform{kDefaultTransform};
1085 }
1086
1087 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1088};
1089
1090const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1091const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1092
Lloyd Piquede196652020-01-22 17:29:58 -08001093TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
1094 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
1095
1096 mOutputLayer.writeCursorPositionToHWC();
1097}
1098
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001099TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1100 mOutputLayer.editState().hwc.reset();
1101
1102 mOutputLayer.writeCursorPositionToHWC();
1103}
1104
1105TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1106 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1107
1108 mOutputLayer.writeCursorPositionToHWC();
1109}
1110
1111TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001112 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001113
1114 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1115
1116 mOutputLayer.writeCursorPositionToHWC();
1117}
1118
1119TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1120 mOutputState.transform = ui::Transform{TR_ROT_90};
1121
1122 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1123
1124 mOutputLayer.writeCursorPositionToHWC();
1125}
1126
1127/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001128 * OutputLayer::getHwcLayer()
1129 */
1130
1131TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1132 mOutputLayer.editState().hwc.reset();
1133
1134 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1135}
1136
1137TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1138 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1139
1140 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1141}
1142
1143TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1144 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1145 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1146
1147 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1148}
1149
1150/*
1151 * OutputLayer::requiresClientComposition()
1152 */
1153
1154TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1155 mOutputLayer.editState().hwc.reset();
1156
1157 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1158}
1159
1160TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1161 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1162 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CLIENT;
1163
1164 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1165}
1166
1167TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1168 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1169 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1170
1171 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1172}
1173
1174/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001175 * OutputLayer::isHardwareCursor()
1176 */
1177
1178TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1179 mOutputLayer.editState().hwc.reset();
1180
1181 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1182}
1183
1184TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1185 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1186 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CURSOR;
1187
1188 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1189}
1190
1191TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1192 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1193 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1194
1195 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1196}
1197
1198/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001199 * OutputLayer::applyDeviceCompositionTypeChange()
1200 */
1201
1202TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1203 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1204 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1205
1206 mOutputLayer.applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT);
1207
1208 ASSERT_TRUE(mOutputLayer.getState().hwc);
1209 EXPECT_EQ(Hwc2::IComposerClient::Composition::CLIENT,
1210 mOutputLayer.getState().hwc->hwcCompositionType);
1211}
1212
1213/*
1214 * OutputLayer::prepareForDeviceLayerRequests()
1215 */
1216
1217TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1218 mOutputLayer.editState().clearClientTarget = true;
1219
1220 mOutputLayer.prepareForDeviceLayerRequests();
1221
1222 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1223}
1224
1225/*
1226 * OutputLayer::applyDeviceLayerRequest()
1227 */
1228
1229TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1230 mOutputLayer.editState().clearClientTarget = false;
1231
1232 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1233
1234 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1235}
1236
1237TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1238 mOutputLayer.editState().clearClientTarget = false;
1239
1240 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1241
1242 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1243}
1244
Lloyd Pique688abd42019-02-15 15:42:24 -08001245/*
1246 * OutputLayer::needsFiltering()
1247 */
1248
1249TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1250 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1251 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1252
1253 EXPECT_FALSE(mOutputLayer.needsFiltering());
1254}
1255
1256TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1257 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1258 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1259
1260 EXPECT_TRUE(mOutputLayer.needsFiltering());
1261}
1262
Lloyd Piquecc01a452018-12-04 17:24:00 -08001263} // namespace
1264} // namespace android::compositionengine