blob: f34b621adbbb89e6121af92247237617bc784c99 [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() {
Ady Abraham6e60b142022-01-06 18:10:35 -0800867 const aidl::android::hardware::graphics::composer3::Color color = {kColor.r, kColor.g,
868 kColor.b, 1.0f};
Lloyd Piquef5275482019-01-29 18:42:42 -0800869
870 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
871 }
872
873 void expectSetSidebandHandleCall() {
874 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
875 }
876
Alec Mourie7cc1c22021-04-27 15:23:26 -0700877 void expectSetHdrMetadataAndBufferCalls(uint32_t hwcSlot = kExpectedHwcSlot,
878 sp<GraphicBuffer> buffer = kBuffer,
Alec Mourib7edfc22021-03-17 16:20:26 -0700879 sp<Fence> fence = kFence) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800880 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
Alec Mourie7cc1c22021-04-27 15:23:26 -0700881 EXPECT_CALL(*mHwcLayer, setBuffer(hwcSlot, buffer, fence));
Lloyd Piquef5275482019-01-29 18:42:42 -0800882 }
883
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800884 void expectGenericLayerMetadataCalls() {
885 // Note: Can be in any order.
886 EXPECT_CALL(*mHwcLayer,
887 setLayerGenericMetadata(kLayerGenericMetadata1Key,
888 kLayerGenericMetadata1Mandatory,
889 kLayerGenericMetadata1Value));
890 EXPECT_CALL(*mHwcLayer,
891 setLayerGenericMetadata(kLayerGenericMetadata2Key,
892 kLayerGenericMetadata2Mandatory,
893 kLayerGenericMetadata2Value));
894 }
895
Lloyd Piquea83776c2019-01-29 18:42:32 -0800896 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800897 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Alec Mouria90a5702021-04-16 16:36:21 +0000898 renderengine::mock::RenderEngine mRenderEngine;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800899};
900
Lloyd Piquef5275482019-01-29 18:42:42 -0800901const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
902 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800903const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Alec Mourib7edfc22021-03-17 16:20:26 -0700904const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044};
Wiwit Rifa'ie30a5852021-06-25 19:20:48 +0800905const FloatRect OutputLayerWriteStateToHWCTest::kOverrideSourceCrop{1002, 1003, 1004, 20044};
Lloyd Piquea2468662019-03-07 21:31:06 -0800906const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
907 Rect{1005, 1006, 1007, 1008}};
Alec Mouri464352b2021-03-24 16:33:21 -0700908const Region OutputLayerWriteStateToHWCTest::kOverrideVisibleRegion{Rect{1006, 1007, 1008, 1009}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800909const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
910 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
911 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
912};
913const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
Alec Mouri464352b2021-03-24 16:33:21 -0700914const Region OutputLayerWriteStateToHWCTest::kOverrideSurfaceDamage{Rect{1026, 1027, 1028, 1029}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800915const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
916native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
917 reinterpret_cast<native_handle_t*>(1031);
918const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700919const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kOverrideBuffer =
920 new GraphicBuffer(4, 5, PIXEL_FORMAT_RGBA_8888,
921 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
922 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Lloyd Piquef5275482019-01-29 18:42:42 -0800923const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700924const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = new Fence();
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800925const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
926 "com.example.metadata.1";
927const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
928const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
929 "com.example.metadata.2";
930const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
931 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800932
Lloyd Piquede196652020-01-22 17:29:58 -0800933TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
934 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
935
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400936 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
937 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquede196652020-01-22 17:29:58 -0800938}
939
Lloyd Piquea83776c2019-01-29 18:42:32 -0800940TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
941 mOutputLayer.editState().hwc.reset();
942
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400943 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
944 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800945}
946
947TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
948 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
949
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400950 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
951 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800952}
953
Lloyd Piquef5275482019-01-29 18:42:42 -0800954TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800955 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -0800956 expectPerFrameCommonCalls();
957
958 expectNoSetCompositionTypeCall();
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400959 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800960
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400961 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
962 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800963}
964
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700965TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
966 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
967 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
968 // This test simulates a scenario where displayInstallOrientation is set to
969 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
970 // DisplayDevice::setProjection).
Angel Aguayob084e0c2021-08-04 23:27:28 +0000971 mOutputState.displaySpace.setOrientation(ui::ROTATION_0);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700972 mOutputState.transform = ui::Transform{TR_ROT_90};
973 // Buffers are pre-rotated based on the transform hint (ROT_90); their
974 // geomBufferTransform is set to the inverse transform.
975 mLayerFEState.geomBufferTransform = TR_ROT_270;
976
Snild Dolkow9e217d62020-04-22 15:53:42 +0200977 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700978}
979
Lloyd Piquef5275482019-01-29 18:42:42 -0800980TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500981 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800982
983 expectPerFrameCommonCalls();
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400984 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Pique46b72df2019-10-29 13:19:27 -0700985
986 // Setting the composition type should happen before setting the color. We
987 // check this in this test only by setting up an testing::InSeqeuence
988 // instance before setting up the two expectations.
989 InSequence s;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500990 expectSetCompositionTypeCall(Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -0700991 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -0800992
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400993 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
994 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800995}
996
997TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500998 mLayerFEState.compositionType = Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -0800999
1000 expectPerFrameCommonCalls();
1001 expectSetSidebandHandleCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001002 expectSetCompositionTypeCall(Composition::SIDEBAND);
Lloyd Piquef5275482019-01-29 18:42:42 -08001003
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001004 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1005
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001006 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1007 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001008}
1009
1010TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001011 mLayerFEState.compositionType = Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001012
1013 expectPerFrameCommonCalls();
1014 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001015 expectSetCompositionTypeCall(Composition::CURSOR);
Lloyd Piquef5275482019-01-29 18:42:42 -08001016
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001017 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1018
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001019 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1020 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001021}
1022
1023TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001024 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -08001025
1026 expectPerFrameCommonCalls();
1027 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001028 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Piquef5275482019-01-29 18:42:42 -08001029
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001030 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1031
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001032 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1033 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001034}
1035
1036TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001037 (*mOutputLayer.editState().hwc).hwcCompositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001038
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001039 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001040
1041 expectPerFrameCommonCalls();
1042 expectSetColorCall();
1043 expectNoSetCompositionTypeCall();
1044
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001045 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1046
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001047 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1048 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001049}
1050
1051TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001052 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001053
1054 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
1055 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001056 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001057
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001058 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1059 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001060}
1061
1062TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
1063 mOutputLayer.editState().forceClientComposition = true;
1064
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001065 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001066
1067 expectPerFrameCommonCalls();
1068 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001069 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001070
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001071 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1072 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001073}
1074
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001075TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001076 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001077 includeGenericLayerMetadataInState();
1078
1079 expectGeometryCommonCalls();
1080 expectPerFrameCommonCalls();
1081 expectSetHdrMetadataAndBufferCalls();
1082 expectGenericLayerMetadataCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001083 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001084
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001085 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1086
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001087 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1088 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001089}
1090
1091TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001092 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001093 includeGenericLayerMetadataInState();
1094
1095 expectPerFrameCommonCalls();
1096 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001097 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001098
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001099 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1100
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001101 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1102 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001103}
1104
Alec Mouri96ca45c2021-06-09 17:32:26 -07001105TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001106 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mouri96ca45c2021-06-09 17:32:26 -07001107 includeOverrideInfo();
1108
1109 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1110 kOverrideBlendMode, kSkipAlpha);
1111 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001112 kOverrideSurfaceDamage, kDisplayBrightnessNits);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001113 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001114 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001115 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1116
1117 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1118 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1119}
1120
Alec Mouri2b1212b2021-12-09 12:02:39 -08001121TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerForSolidColorDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001122 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri2b1212b2021-12-09 12:02:39 -08001123 includeOverrideInfo();
1124
1125 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1126 kOverrideBlendMode, kSkipAlpha);
1127 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001128 kOverrideSurfaceDamage, kDisplayBrightnessNits);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001129 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001130 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001131 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1132
1133 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1134 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1135}
1136
Alec Mourib7edfc22021-03-17 16:20:26 -07001137TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001138 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourib7edfc22021-03-17 16:20:26 -07001139 includeOverrideInfo();
1140
Alec Mouri03bf0ff2021-04-19 14:17:31 -07001141 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1142 kOverrideBlendMode, kOverrideAlpha);
Alec Mouri464352b2021-03-24 16:33:21 -07001143 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001144 kOverrideSurfaceDamage, kDisplayBrightnessNits);
Alec Mourie7cc1c22021-04-27 15:23:26 -07001145 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001146 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001147 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1148
1149 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1150 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1151}
1152
Alec Mouri028676a2021-12-02 15:01:48 -08001153TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoForSolidColorIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001154 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri028676a2021-12-02 15:01:48 -08001155 includeOverrideInfo();
1156
1157 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1158 kOverrideBlendMode, kOverrideAlpha);
1159 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001160 kOverrideSurfaceDamage, kDisplayBrightnessNits);
Alec Mouri028676a2021-12-02 15:01:48 -08001161 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001162 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri028676a2021-12-02 15:01:48 -08001163 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1164
1165 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1166 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1167}
1168
Alec Mourid1bf1b52021-05-05 18:44:58 -07001169TEST_F(OutputLayerWriteStateToHWCTest, previousOverriddenLayerSendsSurfaceDamage) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001170 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001171 mOutputLayer.editState().hwc->stateOverridden = true;
1172
1173 expectGeometryCommonCalls();
1174 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1175 Region::INVALID_REGION);
1176 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001177 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001178 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1179
1180 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1181 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1182}
1183
1184TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedDeviceCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001185 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001186 mOutputLayer.editState().hwc->stateOverridden = true;
1187 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001188 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001189
1190 expectGeometryCommonCalls();
1191 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1192 Region::INVALID_REGION);
1193 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001194 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001195 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1196
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001197 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1198 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Alec Mourib7edfc22021-03-17 16:20:26 -07001199}
1200
Alec Mourid1bf1b52021-05-05 18:44:58 -07001201TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedClientCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001202 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001203 mOutputLayer.editState().forceClientComposition = true;
1204 mOutputLayer.editState().hwc->stateOverridden = true;
1205 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001206 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001207
1208 expectGeometryCommonCalls();
1209 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1210 Region::INVALID_REGION);
1211 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001212 expectSetCompositionTypeCall(Composition::CLIENT);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001213 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1214
1215 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1216 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1217}
1218
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001219TEST_F(OutputLayerWriteStateToHWCTest, peekThroughChangesBlendMode) {
1220 auto peekThroughLayerFE = sp<compositionengine::mock::LayerFE>::make();
1221 OutputLayer peekThroughLayer{mOutput, peekThroughLayerFE};
1222
1223 mOutputLayer.mState.overrideInfo.peekThroughLayer = &peekThroughLayer;
1224
1225 expectGeometryCommonCalls(kDisplayFrame, kSourceCrop, kBufferTransform,
1226 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED);
1227 expectPerFrameCommonCalls();
1228 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1229
1230 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1231 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1232}
1233
1234TEST_F(OutputLayerWriteStateToHWCTest, isPeekingThroughSetsOverride) {
1235 expectGeometryCommonCalls();
1236 expectPerFrameCommonCalls();
1237
1238 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1239 /*zIsOverridden*/ false, /*isPeekingThrough*/ true);
1240 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1241}
1242
1243TEST_F(OutputLayerWriteStateToHWCTest, zIsOverriddenSetsOverride) {
1244 expectGeometryCommonCalls();
1245 expectPerFrameCommonCalls();
1246 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1247
1248 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1249 /*zIsOverridden*/ true, /*isPeekingThrough*/
1250 false);
1251 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1252}
1253
1254TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersForceClientComposition) {
1255 expectGeometryCommonCalls();
1256 expectPerFrameCommonCalls();
1257 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001258 expectSetCompositionTypeCall(Composition::CLIENT);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001259
1260 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1261 /*zIsOverridden*/ false, /*isPeekingThrough*/
1262 false);
1263}
1264
1265TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersPeekingThroughAllowsDeviceComposition) {
1266 expectGeometryCommonCalls();
1267 expectPerFrameCommonCalls();
1268 expectSetHdrMetadataAndBufferCalls();
1269 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001270 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001271
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001272 mLayerFEState.compositionType = Composition::DEVICE;
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001273 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1274 /*zIsOverridden*/ false, /*isPeekingThrough*/
1275 true);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001276 EXPECT_EQ(Composition::DEVICE, mOutputLayer.getState().hwc->hwcCompositionType);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001277}
1278
Lloyd Pique66d68602019-02-13 14:23:31 -08001279/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001280 * OutputLayer::writeCursorPositionToHWC()
1281 */
1282
1283struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1284 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -07001285 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001286
1287 static const Rect kDefaultDisplayViewport;
1288 static const Rect kDefaultCursorFrame;
1289
1290 OutputLayerWriteCursorPositionToHWCTest() {
1291 auto& outputLayerState = mOutputLayer.editState();
1292 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1293
Lloyd Pique9755fb72019-03-26 14:44:40 -07001294 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001295
Angel Aguayob084e0c2021-08-04 23:27:28 +00001296 mOutputState.layerStackSpace.setContent(kDefaultDisplayViewport);
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001297 mOutputState.transform = ui::Transform{kDefaultTransform};
1298 }
1299
1300 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1301};
1302
1303const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1304const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1305
Lloyd Piquede196652020-01-22 17:29:58 -08001306TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
1307 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
1308
1309 mOutputLayer.writeCursorPositionToHWC();
1310}
1311
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001312TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1313 mOutputLayer.editState().hwc.reset();
1314
1315 mOutputLayer.writeCursorPositionToHWC();
1316}
1317
1318TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1319 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1320
1321 mOutputLayer.writeCursorPositionToHWC();
1322}
1323
1324TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001325 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001326
1327 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1328
1329 mOutputLayer.writeCursorPositionToHWC();
1330}
1331
1332TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1333 mOutputState.transform = ui::Transform{TR_ROT_90};
1334
1335 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1336
1337 mOutputLayer.writeCursorPositionToHWC();
1338}
1339
1340/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001341 * OutputLayer::getHwcLayer()
1342 */
1343
1344TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1345 mOutputLayer.editState().hwc.reset();
1346
1347 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1348}
1349
1350TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1351 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1352
1353 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1354}
1355
1356TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1357 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1358 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1359
1360 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1361}
1362
1363/*
1364 * OutputLayer::requiresClientComposition()
1365 */
1366
1367TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1368 mOutputLayer.editState().hwc.reset();
1369
1370 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1371}
1372
1373TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1374 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001375 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Lloyd Pique66d68602019-02-13 14:23:31 -08001376
1377 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1378}
1379
1380TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1381 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001382 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001383
1384 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1385}
1386
1387/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001388 * OutputLayer::isHardwareCursor()
1389 */
1390
1391TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1392 mOutputLayer.editState().hwc.reset();
1393
1394 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1395}
1396
1397TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1398 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001399 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CURSOR;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001400
1401 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1402}
1403
1404TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1405 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001406 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001407
1408 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1409}
1410
1411/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001412 * OutputLayer::applyDeviceCompositionTypeChange()
1413 */
1414
1415TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1416 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001417 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001418
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001419 mOutputLayer.applyDeviceCompositionTypeChange(Composition::CLIENT);
Lloyd Pique66d68602019-02-13 14:23:31 -08001420
1421 ASSERT_TRUE(mOutputLayer.getState().hwc);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001422 EXPECT_EQ(Composition::CLIENT, mOutputLayer.getState().hwc->hwcCompositionType);
Lloyd Pique66d68602019-02-13 14:23:31 -08001423}
1424
1425/*
1426 * OutputLayer::prepareForDeviceLayerRequests()
1427 */
1428
1429TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1430 mOutputLayer.editState().clearClientTarget = true;
1431
1432 mOutputLayer.prepareForDeviceLayerRequests();
1433
1434 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1435}
1436
1437/*
1438 * OutputLayer::applyDeviceLayerRequest()
1439 */
1440
1441TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1442 mOutputLayer.editState().clearClientTarget = false;
1443
1444 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1445
1446 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1447}
1448
1449TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1450 mOutputLayer.editState().clearClientTarget = false;
1451
1452 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1453
1454 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1455}
1456
Lloyd Pique688abd42019-02-15 15:42:24 -08001457/*
1458 * OutputLayer::needsFiltering()
1459 */
1460
1461TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1462 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1463 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1464
1465 EXPECT_FALSE(mOutputLayer.needsFiltering());
1466}
1467
1468TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1469 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1470 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1471
1472 EXPECT_TRUE(mOutputLayer.needsFiltering());
1473}
1474
Lloyd Piquecc01a452018-12-04 17:24:00 -08001475} // namespace
1476} // namespace android::compositionengine