blob: ad7976f64cdca166cf2e855842d43f352118445f [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
Alec Mourie7cc1c22021-04-27 15:23:26 -070017#include <compositionengine/impl/HwcBufferCache.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080018#include <compositionengine/impl/OutputLayer.h>
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070019#include <compositionengine/impl/OutputLayerCompositionState.h>
Lloyd Pique07e33212018-12-18 16:33:37 -080020#include <compositionengine/mock/CompositionEngine.h>
Lloyd Piquef5275482019-01-29 18:42:42 -080021#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080022#include <compositionengine/mock/LayerFE.h>
23#include <compositionengine/mock/Output.h>
24#include <gtest/gtest.h>
Marin Shalamanov68933fb2020-09-10 17:58:12 +020025#include <log/log.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080026
Alec Mouri03bf0ff2021-04-19 14:17:31 -070027#include <renderengine/mock/RenderEngine.h>
28#include <ui/PixelFormat.h>
Lloyd Pique07e33212018-12-18 16:33:37 -080029#include "MockHWC2.h"
30#include "MockHWComposer.h"
Lloyd Piquef5275482019-01-29 18:42:42 -080031#include "RegionMatcher.h"
Lloyd Pique07e33212018-12-18 16:33:37 -080032
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050033#include <aidl/android/hardware/graphics/composer3/Composition.h>
34
35using aidl::android::hardware::graphics::composer3::Composition;
36
Lloyd Piquecc01a452018-12-04 17:24:00 -080037namespace android::compositionengine {
38namespace {
39
Peiyong Line9d809e2020-04-14 13:10:48 -070040namespace hal = android::hardware::graphics::composer::hal;
41
Lloyd Piquea83776c2019-01-29 18:42:32 -080042using testing::_;
Lloyd Pique46b72df2019-10-29 13:19:27 -070043using testing::InSequence;
Lloyd Piquea83776c2019-01-29 18:42:32 -080044using testing::Return;
45using testing::ReturnRef;
Lloyd Piquecc01a452018-12-04 17:24:00 -080046using testing::StrictMock;
47
Lloyd Piquea83776c2019-01-29 18:42:32 -080048constexpr auto TR_IDENT = 0u;
49constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H;
50constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V;
51constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
52constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V;
53constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180;
54
55const std::string kOutputName{"Test Output"};
56
Lloyd Piquef5275482019-01-29 18:42:42 -080057MATCHER_P(ColorEq, expected, "") {
58 *result_listener << "Colors are not equal\n";
59 *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " "
60 << expected.a << "\n";
61 *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n";
62
63 return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a;
64}
65
Marin Shalamanov68933fb2020-09-10 17:58:12 +020066ui::Rotation toRotation(uint32_t rotationFlag) {
67 switch (rotationFlag) {
68 case ui::Transform::RotationFlags::ROT_0:
69 return ui::ROTATION_0;
70 case ui::Transform::RotationFlags::ROT_90:
71 return ui::ROTATION_90;
72 case ui::Transform::RotationFlags::ROT_180:
73 return ui::ROTATION_180;
74 case ui::Transform::RotationFlags::ROT_270:
75 return ui::ROTATION_270;
76 default:
77 LOG_FATAL("Unexpected rotation flag %d", rotationFlag);
78 return ui::Rotation(-1);
79 }
80}
81
Lloyd Pique66d68602019-02-13 14:23:31 -080082struct OutputLayerTest : public testing::Test {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070083 struct OutputLayer final : public impl::OutputLayer {
Lloyd Piquede196652020-01-22 17:29:58 -080084 OutputLayer(const compositionengine::Output& output, sp<compositionengine::LayerFE> layerFE)
85 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070086 ~OutputLayer() override = default;
87
88 // compositionengine::OutputLayer overrides
89 const compositionengine::Output& getOutput() const override { return mOutput; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070090 compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
91 const impl::OutputLayerCompositionState& getState() const override { return mState; }
92 impl::OutputLayerCompositionState& editState() override { return mState; }
93
94 // compositionengine::impl::OutputLayer overrides
95 void dumpState(std::string& out) const override { mState.dump(out); }
96
97 const compositionengine::Output& mOutput;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070098 sp<compositionengine::LayerFE> mLayerFE;
99 impl::OutputLayerCompositionState mState;
100 };
101
Lloyd Piquea83776c2019-01-29 18:42:32 -0800102 OutputLayerTest() {
103 EXPECT_CALL(*mLayerFE, getDebugName()).WillRepeatedly(Return("Test LayerFE"));
104 EXPECT_CALL(mOutput, getName()).WillRepeatedly(ReturnRef(kOutputName));
105
Lloyd Piquede196652020-01-22 17:29:58 -0800106 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800107 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
108 }
109
Lloyd Piquecc01a452018-12-04 17:24:00 -0800110 compositionengine::mock::Output mOutput;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800111 sp<compositionengine::mock::LayerFE> mLayerFE{
112 new StrictMock<compositionengine::mock::LayerFE>()};
Lloyd Piquede196652020-01-22 17:29:58 -0800113 OutputLayer mOutputLayer{mOutput, mLayerFE};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800114
Lloyd Pique9755fb72019-03-26 14:44:40 -0700115 LayerFECompositionState mLayerFEState;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800116 impl::OutputCompositionState mOutputState;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800117};
118
Lloyd Piquea83776c2019-01-29 18:42:32 -0800119/*
Lloyd Piquecc01a452018-12-04 17:24:00 -0800120 * Basic construction
121 */
122
123TEST_F(OutputLayerTest, canInstantiateOutputLayer) {}
124
Lloyd Piquea83776c2019-01-29 18:42:32 -0800125/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800126 * OutputLayer::setHwcLayer()
Lloyd Pique07e33212018-12-18 16:33:37 -0800127 */
128
Lloyd Piquedf336d92019-03-07 21:38:42 -0800129TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) {
Lloyd Pique07e33212018-12-18 16:33:37 -0800130 StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
131
Lloyd Piquedf336d92019-03-07 21:38:42 -0800132 mOutputLayer.setHwcLayer(nullptr);
Lloyd Pique07e33212018-12-18 16:33:37 -0800133
134 EXPECT_FALSE(mOutputLayer.getState().hwc);
135}
136
Lloyd Piquedf336d92019-03-07 21:38:42 -0800137TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) {
138 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Pique07e33212018-12-18 16:33:37 -0800139
Lloyd Piquedf336d92019-03-07 21:38:42 -0800140 mOutputLayer.setHwcLayer(hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800141
Lloyd Piquea83776c2019-01-29 18:42:32 -0800142 const auto& outputLayerState = mOutputLayer.getState();
143 ASSERT_TRUE(outputLayerState.hwc);
Lloyd Pique07e33212018-12-18 16:33:37 -0800144
Lloyd Piquea83776c2019-01-29 18:42:32 -0800145 const auto& hwcState = *outputLayerState.hwc;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800146 EXPECT_EQ(hwcLayer, hwcState.hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800147}
148
Lloyd Piquea83776c2019-01-29 18:42:32 -0800149/*
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000150 * OutputLayer::calculateOutputSourceCrop()
151 */
152
153struct OutputLayerSourceCropTest : public OutputLayerTest {
154 OutputLayerSourceCropTest() {
155 // Set reasonable default values for a simple case. Each test will
156 // set one specific value to something different.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700157 mLayerFEState.geomUsesSourceCrop = true;
158 mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080};
159 mLayerFEState.transparentRegionHint = Region{};
160 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
161 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
162 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
163 mLayerFEState.geomBufferTransform = TR_IDENT;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000164
Angel Aguayob084e0c2021-08-04 23:27:28 +0000165 mOutputState.layerStackSpace.setContent(Rect{0, 0, 1920, 1080});
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000166 }
167
168 FloatRect calculateOutputSourceCrop() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700169 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000170
171 return mOutputLayer.calculateOutputSourceCrop();
172 }
173};
174
175TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700176 mLayerFEState.geomUsesSourceCrop = false;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000177
178 const FloatRect expected{};
Lloyd Piqueea629282019-12-03 15:57:10 -0800179 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000180}
181
182TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) {
183 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800184 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000185}
186
187TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700188 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000189
190 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800191 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000192}
193
194TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700195 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
196 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000197
198 const FloatRect expected{0.f, 0.f, 1080.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800199 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000200}
201
202TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) {
203 struct Entry {
204 uint32_t bufferInvDisplay;
205 uint32_t buffer;
206 uint32_t display;
207 FloatRect expected;
208 };
209 // Not an exhaustive list of cases, but hopefully enough.
210 const std::array<Entry, 12> testData = {
211 // clang-format off
212 // inv buffer display expected
213 /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
214 /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
215 /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
216 /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
217
218 /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
219 /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
220 /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
221 /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
222
223 /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
224 /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
225 /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
226 /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
227
228 // clang-format on
229 };
230
231 for (size_t i = 0; i < testData.size(); i++) {
232 const auto& entry = testData[i];
233
Lloyd Pique9755fb72019-03-26 14:44:40 -0700234 mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay;
235 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000236 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000237
Lloyd Piqueea629282019-12-03 15:57:10 -0800238 EXPECT_THAT(calculateOutputSourceCrop(), entry.expected) << "entry " << i;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000239 }
240}
241
242TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700243 mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000244
245 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800246 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000247}
248
249TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) {
Angel Aguayob084e0c2021-08-04 23:27:28 +0000250 mOutputState.layerStackSpace.setContent(Rect{0, 0, 960, 540});
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000251
252 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800253 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000254}
255
256/*
Lloyd Piquea83776c2019-01-29 18:42:32 -0800257 * OutputLayer::calculateOutputDisplayFrame()
258 */
259
260struct OutputLayerDisplayFrameTest : public OutputLayerTest {
261 OutputLayerDisplayFrameTest() {
262 // Set reasonable default values for a simple case. Each test will
263 // set one specific value to something different.
264
Lloyd Pique9755fb72019-03-26 14:44:40 -0700265 mLayerFEState.transparentRegionHint = Region{};
266 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
267 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
268 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
269 mLayerFEState.geomCrop = Rect{0, 0, 1920, 1080};
270 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800271
Angel Aguayob084e0c2021-08-04 23:27:28 +0000272 mOutputState.layerStackSpace.setContent(Rect{0, 0, 1920, 1080});
Lloyd Piquea83776c2019-01-29 18:42:32 -0800273 mOutputState.transform = ui::Transform{TR_IDENT};
274 }
275
276 Rect calculateOutputDisplayFrame() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700277 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800278
279 return mOutputLayer.calculateOutputDisplayFrame();
280 }
281};
282
283TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) {
284 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800285 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800286}
287
288TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700289 mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800290 const Rect expected{0, 0, 0, 0};
Lloyd Piqueea629282019-12-03 15:57:10 -0800291 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800292}
293
294TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700295 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800296 const Rect expected{100, 200, 300, 500};
Lloyd Piqueea629282019-12-03 15:57:10 -0800297 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800298}
299
300TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700301 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
302 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800303 const Rect expected{1420, 100, 1720, 300};
Lloyd Piqueea629282019-12-03 15:57:10 -0800304 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800305}
306
307TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700308 mLayerFEState.geomCrop = Rect{};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800309 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800310 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800311}
312
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000313TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700314 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f};
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, viewportAffectsFrame) {
Angel Aguayob084e0c2021-08-04 23:27:28 +0000320 mOutputState.layerStackSpace.setContent(Rect{0, 0, 960, 540});
Lloyd Piquea83776c2019-01-29 18:42:32 -0800321 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800322 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800323}
324
325TEST_F(OutputLayerDisplayFrameTest, outputTransformAffectsDisplayFrame) {
326 mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90};
327 const Rect expected{-1080, 0, 0, 1920};
Lloyd Piqueea629282019-12-03 15:57:10 -0800328 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800329}
330
Leon Scroggins IIId394d3c2021-06-24 11:30:32 -0400331TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame) {
332 const int kShadowRadius = 5;
333 mLayerFEState.shadowRadius = kShadowRadius;
334 mLayerFEState.forceClientComposition = true;
335
336 mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
337 Rect expected{mLayerFEState.geomLayerBounds};
338 expected.inset(-kShadowRadius, -kShadowRadius, -kShadowRadius, -kShadowRadius);
339 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
340}
341
342TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame_onlyIfForcingClientComposition) {
343 const int kShadowRadius = 5;
344 mLayerFEState.shadowRadius = kShadowRadius;
345 mLayerFEState.forceClientComposition = false;
346
347 mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
348 Rect expected{mLayerFEState.geomLayerBounds};
349 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
350}
351
Lloyd Piquea83776c2019-01-29 18:42:32 -0800352/*
353 * OutputLayer::calculateOutputRelativeBufferTransform()
354 */
355
356TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700357 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800358
359 struct Entry {
360 uint32_t layer;
361 uint32_t buffer;
362 uint32_t display;
363 uint32_t expected;
364 };
365 // Not an exhaustive list of cases, but hopefully enough.
366 const std::array<Entry, 24> testData = {
367 // clang-format off
368 // layer buffer display expected
369 /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
370 /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_90},
371 /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
372 /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270},
373
374 /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_IDENT},
375 /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_90},
376 /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_180},
377 /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_ROT_270},
378
379 /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V},
380 /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_180},
381 /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
382 /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_180},
383
384 /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_90},
385 /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_180},
386 /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT ^ TR_ROT_270},
387 /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_IDENT},
388
389 /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_ROT_180},
390 /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT ^ TR_ROT_270},
391 /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_IDENT},
392 /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_90},
393
394 /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_270},
395 /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_IDENT},
396 /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_90},
397 /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_180},
398 // clang-format on
399 };
400
401 for (size_t i = 0; i < testData.size(); i++) {
402 const auto& entry = testData[i];
403
Lloyd Pique9755fb72019-03-26 14:44:40 -0700404 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
405 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000406 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700407 mOutputState.transform = ui::Transform{entry.display};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800408
Snild Dolkow9e217d62020-04-22 15:53:42 +0200409 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.display);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800410 EXPECT_EQ(entry.expected, actual) << "entry " << i;
411 }
412}
413
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000414TEST_F(OutputLayerTest,
415 calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700416 mLayerFEState.geomBufferUsesDisplayInverseTransform = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000417
418 struct Entry {
Snild Dolkow9e217d62020-04-22 15:53:42 +0200419 uint32_t layer; /* shouldn't affect the result, so we just use arbitrary values */
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000420 uint32_t buffer;
421 uint32_t display;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200422 uint32_t internal;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000423 uint32_t expected;
424 };
Snild Dolkow9e217d62020-04-22 15:53:42 +0200425 const std::array<Entry, 64> testData = {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000426 // clang-format off
Snild Dolkow9e217d62020-04-22 15:53:42 +0200427 // layer buffer display internal expected
428 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
429 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_270},
430 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
431 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_90},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000432
Snild Dolkow9e217d62020-04-22 15:53:42 +0200433 Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT, TR_ROT_90},
434 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_90, TR_IDENT},
435 Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_180, TR_ROT_270},
436 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000437
Snild Dolkow9e217d62020-04-22 15:53:42 +0200438 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_180},
439 Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_90, TR_ROT_90},
440 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
441 Entry{TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000442
Snild Dolkow9e217d62020-04-22 15:53:42 +0200443 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270},
444 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_ROT_90, TR_ROT_180},
445 Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_180, TR_ROT_90},
446 Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000447
Snild Dolkow9e217d62020-04-22 15:53:42 +0200448 // layer buffer display internal expected
449 Entry{TR_IDENT, TR_ROT_90, TR_IDENT, TR_IDENT, TR_ROT_90},
450 Entry{TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_90, TR_IDENT},
451 Entry{TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_270},
452 Entry{TR_ROT_270, TR_ROT_90, TR_IDENT, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000453
Snild Dolkow9e217d62020-04-22 15:53:42 +0200454 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_180},
455 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90},
456 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_IDENT},
457 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270, TR_ROT_270},
458
459 Entry{TR_IDENT, TR_ROT_90, TR_ROT_180, TR_IDENT, TR_ROT_270},
460 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_180},
461 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_180, TR_ROT_90},
462 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_270, TR_IDENT},
463
464 Entry{TR_IDENT, TR_ROT_90, TR_ROT_270, TR_IDENT, TR_IDENT},
465 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270},
466 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_ROT_180, TR_ROT_180},
467 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90},
468
469 // layer buffer display internal expected
470 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_IDENT, TR_ROT_180},
471 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_90},
472 Entry{TR_ROT_180, TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT},
473 Entry{TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_270},
474
475 Entry{TR_IDENT, TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_270},
476 Entry{TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_90, TR_ROT_180},
477 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_90},
478 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_IDENT},
479
480 Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT, TR_IDENT},
481 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270},
482 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180},
483 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90},
484
485 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_IDENT, TR_ROT_90},
486 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_IDENT},
487 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_270},
488 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_270, TR_ROT_180},
489
490 // layer buffer display internal expected
491 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_IDENT, TR_ROT_270},
492 Entry{TR_ROT_90, TR_ROT_270, TR_IDENT, TR_ROT_90, TR_ROT_180},
493 Entry{TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_90},
494 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT},
495
496 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_IDENT, TR_IDENT},
497 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270},
498 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_ROT_180, TR_ROT_180},
499 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90},
500
501 Entry{TR_IDENT, TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_90},
502 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_90, TR_IDENT},
503 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270},
504 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_180},
505
506 Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180},
507 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_ROT_90},
508 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_IDENT},
509 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000510 // clang-format on
511 };
512
513 for (size_t i = 0; i < testData.size(); i++) {
514 const auto& entry = testData[i];
515
Snild Dolkow9e217d62020-04-22 15:53:42 +0200516 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
Lloyd Pique9755fb72019-03-26 14:44:40 -0700517 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000518 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700519 mOutputState.transform = ui::Transform{entry.display};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000520
Snild Dolkow9e217d62020-04-22 15:53:42 +0200521 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.internal);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000522 EXPECT_EQ(entry.expected, actual) << "entry " << i;
523 }
524}
525
526/*
527 * OutputLayer::updateCompositionState()
528 */
529
530struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer {
531 OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output,
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000532 sp<compositionengine::LayerFE> layerFE)
Lloyd Piquede196652020-01-22 17:29:58 -0800533 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000534 // Mock everything called by updateCompositionState to simplify testing it.
535 MOCK_CONST_METHOD0(calculateOutputSourceCrop, FloatRect());
536 MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect());
Snild Dolkow9e217d62020-04-22 15:53:42 +0200537 MOCK_CONST_METHOD1(calculateOutputRelativeBufferTransform, uint32_t(uint32_t));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700538
539 // compositionengine::OutputLayer overrides
540 const compositionengine::Output& getOutput() const override { return mOutput; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700541 compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
542 const impl::OutputLayerCompositionState& getState() const override { return mState; }
543 impl::OutputLayerCompositionState& editState() override { return mState; }
544
545 // These need implementations though are not expected to be called.
546 MOCK_CONST_METHOD1(dumpState, void(std::string&));
547
548 const compositionengine::Output& mOutput;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700549 sp<compositionengine::LayerFE> mLayerFE;
550 impl::OutputLayerCompositionState mState;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000551};
552
553struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest {
554public:
555 OutputLayerUpdateCompositionStateTest() {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000556 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
Lloyd Piquef5275482019-01-29 18:42:42 -0800557 EXPECT_CALL(mOutput, getDisplayColorProfile())
558 .WillRepeatedly(Return(&mDisplayColorProfile));
559 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000560 }
561
562 ~OutputLayerUpdateCompositionStateTest() = default;
563
Snild Dolkow9e217d62020-04-22 15:53:42 +0200564 void setupGeometryChildCallValues(ui::Transform::RotationFlags internalDisplayRotationFlags) {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000565 EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop()).WillOnce(Return(kSourceCrop));
566 EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200567 EXPECT_CALL(mOutputLayer,
568 calculateOutputRelativeBufferTransform(internalDisplayRotationFlags))
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000569 .WillOnce(Return(mBufferTransform));
570 }
571
572 void validateComputedGeometryState() {
573 const auto& state = mOutputLayer.getState();
574 EXPECT_EQ(kSourceCrop, state.sourceCrop);
575 EXPECT_EQ(kDisplayFrame, state.displayFrame);
576 EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform);
577 }
578
579 const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f};
580 const Rect kDisplayFrame{11, 12, 13, 14};
581 uint32_t mBufferTransform{21};
582
583 using OutputLayer = OutputLayerPartialMockForUpdateCompositionState;
Lloyd Piquede196652020-01-22 17:29:58 -0800584 StrictMock<OutputLayer> mOutputLayer{mOutput, mLayerFE};
Lloyd Piquef5275482019-01-29 18:42:42 -0800585 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000586};
587
Lloyd Piquede196652020-01-22 17:29:58 -0800588TEST_F(OutputLayerUpdateCompositionStateTest, doesNothingIfNoFECompositionState) {
589 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
590
Snild Dolkow9e217d62020-04-22 15:53:42 +0200591 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Piquede196652020-01-22 17:29:58 -0800592}
593
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000594TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700595 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000596 mOutputState.isSecure = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700597 mOutputLayer.editState().forceClientComposition = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000598
Snild Dolkow9e217d62020-04-22 15:53:42 +0200599 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000600
Snild Dolkow9e217d62020-04-22 15:53:42 +0200601 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000602
603 validateComputedGeometryState();
604
605 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
606}
607
608TEST_F(OutputLayerUpdateCompositionStateTest,
609 alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700610 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000611 mOutputState.isSecure = false;
612
Snild Dolkow9e217d62020-04-22 15:53:42 +0200613 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000614
Snild Dolkow9e217d62020-04-22 15:53:42 +0200615 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000616
617 validateComputedGeometryState();
618
619 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
620}
621
622TEST_F(OutputLayerUpdateCompositionStateTest,
623 alsoSetsForceCompositionIfUnsupportedBufferTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700624 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000625 mOutputState.isSecure = true;
626
627 mBufferTransform = ui::Transform::ROT_INVALID;
628
Snild Dolkow9e217d62020-04-22 15:53:42 +0200629 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000630
Snild Dolkow9e217d62020-04-22 15:53:42 +0200631 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000632
633 validateComputedGeometryState();
634
635 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
636}
637
Lloyd Piquef5275482019-01-29 18:42:42 -0800638TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700639 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
Lloyd Piquef5275482019-01-29 18:42:42 -0800640 mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB;
641
642 // If the layer is not colorspace agnostic, the output layer dataspace
643 // should use the layers requested colorspace.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700644 mLayerFEState.isColorspaceAgnostic = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800645
Snild Dolkow9e217d62020-04-22 15:53:42 +0200646 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800647
648 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
649
650 // If the layer is colorspace agnostic, the output layer dataspace
651 // should use the colorspace chosen for the whole output.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700652 mLayerFEState.isColorspaceAgnostic = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800653
Snild Dolkow9e217d62020-04-22 15:53:42 +0200654 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800655
656 EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace);
657}
658
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700659TEST_F(OutputLayerUpdateCompositionStateTest, setsWhitePointNitsCorrectly) {
660 mOutputState.sdrWhitePointNits = 200.f;
661 mOutputState.displayBrightnessNits = 800.f;
662
663 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
664 mLayerFEState.isColorspaceAgnostic = false;
665 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
666 EXPECT_EQ(mOutputState.sdrWhitePointNits, mOutputLayer.getState().whitePointNits);
667
668 mLayerFEState.dataspace = ui::Dataspace::BT2020_ITU_PQ;
669 mLayerFEState.isColorspaceAgnostic = false;
670 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
671
672 EXPECT_EQ(mOutputState.displayBrightnessNits, mOutputLayer.getState().whitePointNits);
673}
674
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000675TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700676 mOutputLayer.editState().forceClientComposition = false;
677
Snild Dolkow9e217d62020-04-22 15:53:42 +0200678 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000679
680 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
681}
682
Lloyd Piquefe671022019-09-24 10:43:03 -0700683TEST_F(OutputLayerUpdateCompositionStateTest,
684 doesNotClearForceClientCompositionIfNotDoingGeometry) {
685 mOutputLayer.editState().forceClientComposition = true;
686
Snild Dolkow9e217d62020-04-22 15:53:42 +0200687 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquefe671022019-09-24 10:43:03 -0700688
689 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
690}
691
Lloyd Piquef5275482019-01-29 18:42:42 -0800692TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700693 mLayerFEState.forceClientComposition = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700694 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800695
Snild Dolkow9e217d62020-04-22 15:53:42 +0200696 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800697
698 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
699}
700
701TEST_F(OutputLayerUpdateCompositionStateTest,
702 clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700703 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800704 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false));
705
Snild Dolkow9e217d62020-04-22 15:53:42 +0200706 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700707
708 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
709}
710
711TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromArgumentFlag) {
712 mLayerFEState.forceClientComposition = false;
713 mOutputLayer.editState().forceClientComposition = false;
714
Snild Dolkow9e217d62020-04-22 15:53:42 +0200715 mOutputLayer.updateCompositionState(false, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700716
717 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
718
719 mOutputLayer.editState().forceClientComposition = false;
720
Snild Dolkow9e217d62020-04-22 15:53:42 +0200721 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700722
Snild Dolkow9e217d62020-04-22 15:53:42 +0200723 mOutputLayer.updateCompositionState(true, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800724
725 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
726}
727
Lloyd Piquea83776c2019-01-29 18:42:32 -0800728/*
729 * OutputLayer::writeStateToHWC()
730 */
731
732struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
Peiyong Line9d809e2020-04-14 13:10:48 -0700733 static constexpr hal::Error kError = hal::Error::UNSUPPORTED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800734 static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800735 static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31);
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700736 static constexpr Hwc2::Transform kOverrideBufferTransform = static_cast<Hwc2::Transform>(0);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800737 static constexpr Hwc2::IComposerClient::BlendMode kBlendMode =
738 static_cast<Hwc2::IComposerClient::BlendMode>(41);
Alec Mouriee69a592021-03-23 15:00:45 -0700739 static constexpr Hwc2::IComposerClient::BlendMode kOverrideBlendMode =
740 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800741 static constexpr float kAlpha = 51.f;
Alec Mouriee69a592021-03-23 15:00:45 -0700742 static constexpr float kOverrideAlpha = 1.f;
Alec Mouri96ca45c2021-06-09 17:32:26 -0700743 static constexpr float kSkipAlpha = 0.f;
Lloyd Piquef5275482019-01-29 18:42:42 -0800744 static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
Alec Mourib7edfc22021-03-17 16:20:26 -0700745 static constexpr ui::Dataspace kOverrideDataspace = static_cast<ui::Dataspace>(72);
Lloyd Piquef5275482019-01-29 18:42:42 -0800746 static constexpr int kSupportedPerFrameMetadata = 101;
747 static constexpr int kExpectedHwcSlot = 0;
Alec Mourie7cc1c22021-04-27 15:23:26 -0700748 static constexpr int kOverrideHwcSlot = impl::HwcBufferCache::FLATTENER_CACHING_SLOT;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800749 static constexpr bool kLayerGenericMetadata1Mandatory = true;
750 static constexpr bool kLayerGenericMetadata2Mandatory = true;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700751 static constexpr float kWhitePointNits = 200.f;
752 static constexpr float kDisplayBrightnessNits = 400.f;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800753
Lloyd Piquef5275482019-01-29 18:42:42 -0800754 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800755 static const Rect kDisplayFrame;
Alec Mourib7edfc22021-03-17 16:20:26 -0700756 static const Rect kOverrideDisplayFrame;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700757 static const FloatRect kOverrideSourceCrop;
Lloyd Piquea2468662019-03-07 21:31:06 -0800758 static const Region kOutputSpaceVisibleRegion;
Alec Mouri464352b2021-03-24 16:33:21 -0700759 static const Region kOverrideVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800760 static const mat4 kColorTransform;
761 static const Region kSurfaceDamage;
Alec Mouri464352b2021-03-24 16:33:21 -0700762 static const Region kOverrideSurfaceDamage;
Lloyd Piquef5275482019-01-29 18:42:42 -0800763 static const HdrMetadata kHdrMetadata;
764 static native_handle_t* kSidebandStreamHandle;
765 static const sp<GraphicBuffer> kBuffer;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700766 static const sp<GraphicBuffer> kOverrideBuffer;
Lloyd Piquef5275482019-01-29 18:42:42 -0800767 static const sp<Fence> kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700768 static const sp<Fence> kOverrideFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800769 static const std::string kLayerGenericMetadata1Key;
770 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
771 static const std::string kLayerGenericMetadata2Key;
772 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800773
774 OutputLayerWriteStateToHWCTest() {
775 auto& outputLayerState = mOutputLayer.editState();
776 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
777
778 outputLayerState.displayFrame = kDisplayFrame;
779 outputLayerState.sourceCrop = kSourceCrop;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800780 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800781 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800782 outputLayerState.dataspace = kDataspace;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700783 outputLayerState.whitePointNits = kWhitePointNits;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800784
Lloyd Pique9755fb72019-03-26 14:44:40 -0700785 mLayerFEState.blendMode = kBlendMode;
786 mLayerFEState.alpha = kAlpha;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700787 mLayerFEState.colorTransform = kColorTransform;
788 mLayerFEState.color = kColor;
789 mLayerFEState.surfaceDamage = kSurfaceDamage;
790 mLayerFEState.hdrMetadata = kHdrMetadata;
791 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
792 mLayerFEState.buffer = kBuffer;
793 mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
794 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800795
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700796 mOutputState.displayBrightnessNits = kDisplayBrightnessNits;
797
Lloyd Piquef5275482019-01-29 18:42:42 -0800798 EXPECT_CALL(mOutput, getDisplayColorProfile())
799 .WillRepeatedly(Return(&mDisplayColorProfile));
800 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
801 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800802 }
803
Lloyd Piquef5275482019-01-29 18:42:42 -0800804 // Some tests may need to simulate unsupported HWC calls
805 enum class SimulateUnsupported { None, ColorTransform };
806
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800807 void includeGenericLayerMetadataInState() {
808 mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory,
809 kLayerGenericMetadata1Value};
810 mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory,
811 kLayerGenericMetadata2Value};
812 }
813
Alec Mourib7edfc22021-03-17 16:20:26 -0700814 void includeOverrideInfo() {
815 auto& overrideInfo = mOutputLayer.editState().overrideInfo;
816
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700817 overrideInfo.buffer = std::make_shared<
818 renderengine::ExternalTexture>(kOverrideBuffer, mRenderEngine,
819 renderengine::ExternalTexture::Usage::READABLE |
820 renderengine::ExternalTexture::Usage::
821 WRITEABLE);
Alec Mourib7edfc22021-03-17 16:20:26 -0700822 overrideInfo.acquireFence = kOverrideFence;
823 overrideInfo.displayFrame = kOverrideDisplayFrame;
824 overrideInfo.dataspace = kOverrideDataspace;
Alec Mouri464352b2021-03-24 16:33:21 -0700825 overrideInfo.damageRegion = kOverrideSurfaceDamage;
826 overrideInfo.visibleRegion = kOverrideVisibleRegion;
Alec Mourib7edfc22021-03-17 16:20:26 -0700827 }
828
829 void expectGeometryCommonCalls(Rect displayFrame = kDisplayFrame,
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700830 FloatRect sourceCrop = kSourceCrop,
Alec Mouriee69a592021-03-23 15:00:45 -0700831 Hwc2::Transform bufferTransform = kBufferTransform,
832 Hwc2::IComposerClient::BlendMode blendMode = kBlendMode,
833 float alpha = kAlpha) {
Alec Mourib7edfc22021-03-17 16:20:26 -0700834 EXPECT_CALL(*mHwcLayer, setDisplayFrame(displayFrame)).WillOnce(Return(kError));
835 EXPECT_CALL(*mHwcLayer, setSourceCrop(sourceCrop)).WillOnce(Return(kError));
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400836 EXPECT_CALL(*mHwcLayer, setZOrder(_)).WillOnce(Return(kError));
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700837 EXPECT_CALL(*mHwcLayer, setTransform(bufferTransform)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800838
Alec Mouriee69a592021-03-23 15:00:45 -0700839 EXPECT_CALL(*mHwcLayer, setBlendMode(blendMode)).WillOnce(Return(kError));
840 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(alpha)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800841 }
842
Alec Mourib7edfc22021-03-17 16:20:26 -0700843 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None,
Alec Mouri464352b2021-03-24 16:33:21 -0700844 ui::Dataspace dataspace = kDataspace,
845 const Region& visibleRegion = kOutputSpaceVisibleRegion,
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700846 const Region& surfaceDamage = kSurfaceDamage,
847 float whitePointNits = kWhitePointNits) {
Alec Mouri464352b2021-03-24 16:33:21 -0700848 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(visibleRegion))).WillOnce(Return(kError));
Alec Mourib7edfc22021-03-17 16:20:26 -0700849 EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError));
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700850 EXPECT_CALL(*mHwcLayer, setWhitePointNits(whitePointNits)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800851 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
852 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700853 ? hal::Error::UNSUPPORTED
854 : hal::Error::NONE));
Alec Mouri464352b2021-03-24 16:33:21 -0700855 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(surfaceDamage))).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800856 }
857
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500858 void expectSetCompositionTypeCall(Composition compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700859 EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800860 }
861
862 void expectNoSetCompositionTypeCall() {
863 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
864 }
865
866 void expectSetColorCall() {
Peiyong Lin65248e02020-04-18 21:15:07 -0700867 const hal::Color color = {static_cast<uint8_t>(std::round(kColor.r * 255)),
868 static_cast<uint8_t>(std::round(kColor.g * 255)),
869 static_cast<uint8_t>(std::round(kColor.b * 255)), 255};
Lloyd Piquef5275482019-01-29 18:42:42 -0800870
871 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
872 }
873
874 void expectSetSidebandHandleCall() {
875 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
876 }
877
Alec Mourie7cc1c22021-04-27 15:23:26 -0700878 void expectSetHdrMetadataAndBufferCalls(uint32_t hwcSlot = kExpectedHwcSlot,
879 sp<GraphicBuffer> buffer = kBuffer,
Alec Mourib7edfc22021-03-17 16:20:26 -0700880 sp<Fence> fence = kFence) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800881 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
Alec Mourie7cc1c22021-04-27 15:23:26 -0700882 EXPECT_CALL(*mHwcLayer, setBuffer(hwcSlot, buffer, fence));
Lloyd Piquef5275482019-01-29 18:42:42 -0800883 }
884
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800885 void expectGenericLayerMetadataCalls() {
886 // Note: Can be in any order.
887 EXPECT_CALL(*mHwcLayer,
888 setLayerGenericMetadata(kLayerGenericMetadata1Key,
889 kLayerGenericMetadata1Mandatory,
890 kLayerGenericMetadata1Value));
891 EXPECT_CALL(*mHwcLayer,
892 setLayerGenericMetadata(kLayerGenericMetadata2Key,
893 kLayerGenericMetadata2Mandatory,
894 kLayerGenericMetadata2Value));
895 }
896
Lloyd Piquea83776c2019-01-29 18:42:32 -0800897 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800898 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Alec Mouria90a5702021-04-16 16:36:21 +0000899 renderengine::mock::RenderEngine mRenderEngine;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800900};
901
Lloyd Piquef5275482019-01-29 18:42:42 -0800902const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
903 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800904const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Alec Mourib7edfc22021-03-17 16:20:26 -0700905const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044};
Wiwit Rifa'ie30a5852021-06-25 19:20:48 +0800906const FloatRect OutputLayerWriteStateToHWCTest::kOverrideSourceCrop{1002, 1003, 1004, 20044};
Lloyd Piquea2468662019-03-07 21:31:06 -0800907const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
908 Rect{1005, 1006, 1007, 1008}};
Alec Mouri464352b2021-03-24 16:33:21 -0700909const Region OutputLayerWriteStateToHWCTest::kOverrideVisibleRegion{Rect{1006, 1007, 1008, 1009}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800910const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
911 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
912 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
913};
914const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
Alec Mouri464352b2021-03-24 16:33:21 -0700915const Region OutputLayerWriteStateToHWCTest::kOverrideSurfaceDamage{Rect{1026, 1027, 1028, 1029}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800916const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
917native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
918 reinterpret_cast<native_handle_t*>(1031);
919const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700920const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kOverrideBuffer =
921 new GraphicBuffer(4, 5, PIXEL_FORMAT_RGBA_8888,
922 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
923 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Lloyd Piquef5275482019-01-29 18:42:42 -0800924const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700925const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = new Fence();
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800926const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
927 "com.example.metadata.1";
928const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
929const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
930 "com.example.metadata.2";
931const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
932 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800933
Lloyd Piquede196652020-01-22 17:29:58 -0800934TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
935 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
936
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400937 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
938 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquede196652020-01-22 17:29:58 -0800939}
940
Lloyd Piquea83776c2019-01-29 18:42:32 -0800941TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
942 mOutputLayer.editState().hwc.reset();
943
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400944 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
945 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800946}
947
948TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
949 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
950
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400951 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
952 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800953}
954
Lloyd Piquef5275482019-01-29 18:42:42 -0800955TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800956 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -0800957 expectPerFrameCommonCalls();
958
959 expectNoSetCompositionTypeCall();
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400960 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800961
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400962 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
963 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800964}
965
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700966TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
967 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
968 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
969 // This test simulates a scenario where displayInstallOrientation is set to
970 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
971 // DisplayDevice::setProjection).
Angel Aguayob084e0c2021-08-04 23:27:28 +0000972 mOutputState.displaySpace.setOrientation(ui::ROTATION_0);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700973 mOutputState.transform = ui::Transform{TR_ROT_90};
974 // Buffers are pre-rotated based on the transform hint (ROT_90); their
975 // geomBufferTransform is set to the inverse transform.
976 mLayerFEState.geomBufferTransform = TR_ROT_270;
977
Snild Dolkow9e217d62020-04-22 15:53:42 +0200978 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700979}
980
Lloyd Piquef5275482019-01-29 18:42:42 -0800981TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500982 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800983
984 expectPerFrameCommonCalls();
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400985 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Pique46b72df2019-10-29 13:19:27 -0700986
987 // Setting the composition type should happen before setting the color. We
988 // check this in this test only by setting up an testing::InSeqeuence
989 // instance before setting up the two expectations.
990 InSequence s;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500991 expectSetCompositionTypeCall(Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -0700992 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -0800993
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400994 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
995 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800996}
997
998TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500999 mLayerFEState.compositionType = Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -08001000
1001 expectPerFrameCommonCalls();
1002 expectSetSidebandHandleCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001003 expectSetCompositionTypeCall(Composition::SIDEBAND);
Lloyd Piquef5275482019-01-29 18:42:42 -08001004
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001005 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1006
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001007 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1008 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001009}
1010
1011TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001012 mLayerFEState.compositionType = Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001013
1014 expectPerFrameCommonCalls();
1015 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001016 expectSetCompositionTypeCall(Composition::CURSOR);
Lloyd Piquef5275482019-01-29 18:42:42 -08001017
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001018 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1019
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001020 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1021 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001022}
1023
1024TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001025 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -08001026
1027 expectPerFrameCommonCalls();
1028 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001029 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Piquef5275482019-01-29 18:42:42 -08001030
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001031 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1032
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001033 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1034 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001035}
1036
1037TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001038 (*mOutputLayer.editState().hwc).hwcCompositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001039
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001040 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001041
1042 expectPerFrameCommonCalls();
1043 expectSetColorCall();
1044 expectNoSetCompositionTypeCall();
1045
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001046 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1047
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001048 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1049 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001050}
1051
1052TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001053 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001054
1055 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
1056 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001057 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001058
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001059 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1060 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001061}
1062
1063TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
1064 mOutputLayer.editState().forceClientComposition = true;
1065
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001066 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001067
1068 expectPerFrameCommonCalls();
1069 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001070 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001071
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001072 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1073 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001074}
1075
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001076TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001077 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001078 includeGenericLayerMetadataInState();
1079
1080 expectGeometryCommonCalls();
1081 expectPerFrameCommonCalls();
1082 expectSetHdrMetadataAndBufferCalls();
1083 expectGenericLayerMetadataCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001084 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001085
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001086 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1087
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001088 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1089 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001090}
1091
1092TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001093 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001094 includeGenericLayerMetadataInState();
1095
1096 expectPerFrameCommonCalls();
1097 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001098 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001099
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001100 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1101
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001102 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1103 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001104}
1105
Alec Mouri96ca45c2021-06-09 17:32:26 -07001106TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001107 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mouri96ca45c2021-06-09 17:32:26 -07001108 includeOverrideInfo();
1109
1110 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1111 kOverrideBlendMode, kSkipAlpha);
1112 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001113 kOverrideSurfaceDamage, kDisplayBrightnessNits);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001114 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001115 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001116 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1117
1118 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1119 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1120}
1121
Alec Mouri2b1212b2021-12-09 12:02:39 -08001122TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerForSolidColorDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001123 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri2b1212b2021-12-09 12:02:39 -08001124 includeOverrideInfo();
1125
1126 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1127 kOverrideBlendMode, kSkipAlpha);
1128 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001129 kOverrideSurfaceDamage, kDisplayBrightnessNits);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001130 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001131 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001132 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1133
1134 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1135 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1136}
1137
Alec Mourib7edfc22021-03-17 16:20:26 -07001138TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001139 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourib7edfc22021-03-17 16:20:26 -07001140 includeOverrideInfo();
1141
Alec Mouri03bf0ff2021-04-19 14:17:31 -07001142 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1143 kOverrideBlendMode, kOverrideAlpha);
Alec Mouri464352b2021-03-24 16:33:21 -07001144 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001145 kOverrideSurfaceDamage, kDisplayBrightnessNits);
Alec Mourie7cc1c22021-04-27 15:23:26 -07001146 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001147 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001148 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1149
1150 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1151 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1152}
1153
Alec Mouri028676a2021-12-02 15:01:48 -08001154TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoForSolidColorIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001155 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri028676a2021-12-02 15:01:48 -08001156 includeOverrideInfo();
1157
1158 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1159 kOverrideBlendMode, kOverrideAlpha);
1160 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001161 kOverrideSurfaceDamage, kDisplayBrightnessNits);
Alec Mouri028676a2021-12-02 15:01:48 -08001162 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001163 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri028676a2021-12-02 15:01:48 -08001164 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1165
1166 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1167 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1168}
1169
Alec Mourid1bf1b52021-05-05 18:44:58 -07001170TEST_F(OutputLayerWriteStateToHWCTest, previousOverriddenLayerSendsSurfaceDamage) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001171 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001172 mOutputLayer.editState().hwc->stateOverridden = true;
1173
1174 expectGeometryCommonCalls();
1175 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1176 Region::INVALID_REGION);
1177 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001178 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001179 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1180
1181 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1182 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1183}
1184
1185TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedDeviceCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001186 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001187 mOutputLayer.editState().hwc->stateOverridden = true;
1188 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001189 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001190
1191 expectGeometryCommonCalls();
1192 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1193 Region::INVALID_REGION);
1194 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001195 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001196 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1197
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001198 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1199 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Alec Mourib7edfc22021-03-17 16:20:26 -07001200}
1201
Alec Mourid1bf1b52021-05-05 18:44:58 -07001202TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedClientCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001203 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001204 mOutputLayer.editState().forceClientComposition = true;
1205 mOutputLayer.editState().hwc->stateOverridden = true;
1206 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001207 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001208
1209 expectGeometryCommonCalls();
1210 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1211 Region::INVALID_REGION);
1212 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001213 expectSetCompositionTypeCall(Composition::CLIENT);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001214 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1215
1216 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1217 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1218}
1219
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001220TEST_F(OutputLayerWriteStateToHWCTest, peekThroughChangesBlendMode) {
1221 auto peekThroughLayerFE = sp<compositionengine::mock::LayerFE>::make();
1222 OutputLayer peekThroughLayer{mOutput, peekThroughLayerFE};
1223
1224 mOutputLayer.mState.overrideInfo.peekThroughLayer = &peekThroughLayer;
1225
1226 expectGeometryCommonCalls(kDisplayFrame, kSourceCrop, kBufferTransform,
1227 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED);
1228 expectPerFrameCommonCalls();
1229 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1230
1231 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1232 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1233}
1234
1235TEST_F(OutputLayerWriteStateToHWCTest, isPeekingThroughSetsOverride) {
1236 expectGeometryCommonCalls();
1237 expectPerFrameCommonCalls();
1238
1239 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1240 /*zIsOverridden*/ false, /*isPeekingThrough*/ true);
1241 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1242}
1243
1244TEST_F(OutputLayerWriteStateToHWCTest, zIsOverriddenSetsOverride) {
1245 expectGeometryCommonCalls();
1246 expectPerFrameCommonCalls();
1247 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1248
1249 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1250 /*zIsOverridden*/ true, /*isPeekingThrough*/
1251 false);
1252 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1253}
1254
1255TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersForceClientComposition) {
1256 expectGeometryCommonCalls();
1257 expectPerFrameCommonCalls();
1258 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001259 expectSetCompositionTypeCall(Composition::CLIENT);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001260
1261 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1262 /*zIsOverridden*/ false, /*isPeekingThrough*/
1263 false);
1264}
1265
1266TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersPeekingThroughAllowsDeviceComposition) {
1267 expectGeometryCommonCalls();
1268 expectPerFrameCommonCalls();
1269 expectSetHdrMetadataAndBufferCalls();
1270 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001271 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001272
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001273 mLayerFEState.compositionType = Composition::DEVICE;
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001274 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1275 /*zIsOverridden*/ false, /*isPeekingThrough*/
1276 true);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001277 EXPECT_EQ(Composition::DEVICE, mOutputLayer.getState().hwc->hwcCompositionType);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001278}
1279
Lloyd Pique66d68602019-02-13 14:23:31 -08001280/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001281 * OutputLayer::writeCursorPositionToHWC()
1282 */
1283
1284struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1285 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -07001286 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001287
1288 static const Rect kDefaultDisplayViewport;
1289 static const Rect kDefaultCursorFrame;
1290
1291 OutputLayerWriteCursorPositionToHWCTest() {
1292 auto& outputLayerState = mOutputLayer.editState();
1293 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1294
Lloyd Pique9755fb72019-03-26 14:44:40 -07001295 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001296
Angel Aguayob084e0c2021-08-04 23:27:28 +00001297 mOutputState.layerStackSpace.setContent(kDefaultDisplayViewport);
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001298 mOutputState.transform = ui::Transform{kDefaultTransform};
1299 }
1300
1301 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1302};
1303
1304const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1305const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1306
Lloyd Piquede196652020-01-22 17:29:58 -08001307TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
1308 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
1309
1310 mOutputLayer.writeCursorPositionToHWC();
1311}
1312
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001313TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1314 mOutputLayer.editState().hwc.reset();
1315
1316 mOutputLayer.writeCursorPositionToHWC();
1317}
1318
1319TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1320 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1321
1322 mOutputLayer.writeCursorPositionToHWC();
1323}
1324
1325TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001326 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001327
1328 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1329
1330 mOutputLayer.writeCursorPositionToHWC();
1331}
1332
1333TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1334 mOutputState.transform = ui::Transform{TR_ROT_90};
1335
1336 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1337
1338 mOutputLayer.writeCursorPositionToHWC();
1339}
1340
1341/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001342 * OutputLayer::getHwcLayer()
1343 */
1344
1345TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1346 mOutputLayer.editState().hwc.reset();
1347
1348 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1349}
1350
1351TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1352 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1353
1354 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1355}
1356
1357TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1358 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1359 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1360
1361 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1362}
1363
1364/*
1365 * OutputLayer::requiresClientComposition()
1366 */
1367
1368TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1369 mOutputLayer.editState().hwc.reset();
1370
1371 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1372}
1373
1374TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1375 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001376 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Lloyd Pique66d68602019-02-13 14:23:31 -08001377
1378 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1379}
1380
1381TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1382 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001383 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001384
1385 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1386}
1387
1388/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001389 * OutputLayer::isHardwareCursor()
1390 */
1391
1392TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1393 mOutputLayer.editState().hwc.reset();
1394
1395 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1396}
1397
1398TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1399 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001400 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CURSOR;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001401
1402 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1403}
1404
1405TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1406 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001407 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001408
1409 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1410}
1411
1412/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001413 * OutputLayer::applyDeviceCompositionTypeChange()
1414 */
1415
1416TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1417 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001418 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001419
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001420 mOutputLayer.applyDeviceCompositionTypeChange(Composition::CLIENT);
Lloyd Pique66d68602019-02-13 14:23:31 -08001421
1422 ASSERT_TRUE(mOutputLayer.getState().hwc);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001423 EXPECT_EQ(Composition::CLIENT, mOutputLayer.getState().hwc->hwcCompositionType);
Lloyd Pique66d68602019-02-13 14:23:31 -08001424}
1425
1426/*
1427 * OutputLayer::prepareForDeviceLayerRequests()
1428 */
1429
1430TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1431 mOutputLayer.editState().clearClientTarget = true;
1432
1433 mOutputLayer.prepareForDeviceLayerRequests();
1434
1435 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1436}
1437
1438/*
1439 * OutputLayer::applyDeviceLayerRequest()
1440 */
1441
1442TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1443 mOutputLayer.editState().clearClientTarget = false;
1444
1445 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1446
1447 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1448}
1449
1450TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1451 mOutputLayer.editState().clearClientTarget = false;
1452
1453 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1454
1455 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1456}
1457
Lloyd Pique688abd42019-02-15 15:42:24 -08001458/*
1459 * OutputLayer::needsFiltering()
1460 */
1461
1462TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1463 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1464 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1465
1466 EXPECT_FALSE(mOutputLayer.needsFiltering());
1467}
1468
1469TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1470 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1471 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1472
1473 EXPECT_TRUE(mOutputLayer.needsFiltering());
1474}
1475
Lloyd Piquecc01a452018-12-04 17:24:00 -08001476} // namespace
1477} // namespace android::compositionengine