blob: f2c5672ae44c63ad3d3d3ed07655b17558aa25d9 [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>
Vishnu Nairdbbe3852022-01-12 20:22:11 -080026#include <renderengine/impl/ExternalTexture.h>
Alec Mouri03bf0ff2021-04-19 14:17:31 -070027#include <renderengine/mock/RenderEngine.h>
Lloyd Piquee98286f2024-09-16 16:23:24 -070028#include <ui/FloatRect.h>
Alec Mouri03bf0ff2021-04-19 14:17:31 -070029#include <ui/PixelFormat.h>
Lloyd Piquee98286f2024-09-16 16:23:24 -070030
Lloyd Piquef5275482019-01-29 18:42:42 -080031#include "RegionMatcher.h"
Lloyd Piquee98286f2024-09-16 16:23:24 -070032#include "mock/DisplayHardware/MockHWC2.h"
33#include "mock/DisplayHardware/MockHWComposer.h"
Lloyd Pique07e33212018-12-18 16:33:37 -080034
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050035#include <aidl/android/hardware/graphics/composer3/Composition.h>
36
37using aidl::android::hardware::graphics::composer3::Composition;
38
Lloyd Piquecc01a452018-12-04 17:24:00 -080039namespace android::compositionengine {
40namespace {
41
Peiyong Line9d809e2020-04-14 13:10:48 -070042namespace hal = android::hardware::graphics::composer::hal;
43
Lloyd Piquea83776c2019-01-29 18:42:32 -080044using testing::_;
Lloyd Pique46b72df2019-10-29 13:19:27 -070045using testing::InSequence;
Brian Lindahl90553da2022-12-06 13:36:30 -070046using testing::Mock;
47using testing::NiceMock;
Lloyd Piquea83776c2019-01-29 18:42:32 -080048using testing::Return;
49using testing::ReturnRef;
Lloyd Piquecc01a452018-12-04 17:24:00 -080050using testing::StrictMock;
51
Lloyd Piquea83776c2019-01-29 18:42:32 -080052constexpr auto TR_IDENT = 0u;
53constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H;
54constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V;
55constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
56constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V;
57constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180;
58
59const std::string kOutputName{"Test Output"};
60
Lloyd Piquef5275482019-01-29 18:42:42 -080061MATCHER_P(ColorEq, expected, "") {
62 *result_listener << "Colors are not equal\n";
63 *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " "
64 << expected.a << "\n";
65 *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n";
66
67 return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a;
68}
69
Marin Shalamanov68933fb2020-09-10 17:58:12 +020070ui::Rotation toRotation(uint32_t rotationFlag) {
71 switch (rotationFlag) {
72 case ui::Transform::RotationFlags::ROT_0:
73 return ui::ROTATION_0;
74 case ui::Transform::RotationFlags::ROT_90:
75 return ui::ROTATION_90;
76 case ui::Transform::RotationFlags::ROT_180:
77 return ui::ROTATION_180;
78 case ui::Transform::RotationFlags::ROT_270:
79 return ui::ROTATION_270;
80 default:
81 LOG_FATAL("Unexpected rotation flag %d", rotationFlag);
82 return ui::Rotation(-1);
83 }
84}
85
Lloyd Pique66d68602019-02-13 14:23:31 -080086struct OutputLayerTest : public testing::Test {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070087 struct OutputLayer final : public impl::OutputLayer {
Brian Lindahl90553da2022-12-06 13:36:30 -070088 OutputLayer(const compositionengine::Output& output, compositionengine::LayerFE& layerFE)
Lloyd Piquede196652020-01-22 17:29:58 -080089 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070090 ~OutputLayer() override = default;
91
92 // compositionengine::OutputLayer overrides
93 const compositionengine::Output& getOutput() const override { return mOutput; }
Brian Lindahl90553da2022-12-06 13:36:30 -070094 compositionengine::LayerFE& getLayerFE() const override { return mLayerFE; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070095 const impl::OutputLayerCompositionState& getState() const override { return mState; }
96 impl::OutputLayerCompositionState& editState() override { return mState; }
97
98 // compositionengine::impl::OutputLayer overrides
99 void dumpState(std::string& out) const override { mState.dump(out); }
100
101 const compositionengine::Output& mOutput;
Brian Lindahl90553da2022-12-06 13:36:30 -0700102 compositionengine::LayerFE& mLayerFE;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700103 impl::OutputLayerCompositionState mState;
104 };
105
Lloyd Piquea83776c2019-01-29 18:42:32 -0800106 OutputLayerTest() {
Brian Lindahl90553da2022-12-06 13:36:30 -0700107 ON_CALL(mLayerFE, getDebugName()).WillByDefault(Return("Test LayerFE"));
108 ON_CALL(mOutput, getName()).WillByDefault(ReturnRef(kOutputName));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800109
Brian Lindahl90553da2022-12-06 13:36:30 -0700110 ON_CALL(mLayerFE, getCompositionState()).WillByDefault(Return(&mLayerFEState));
111 ON_CALL(mOutput, getState()).WillByDefault(ReturnRef(mOutputState));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800112 }
113
Brian Lindahl90553da2022-12-06 13:36:30 -0700114 NiceMock<compositionengine::mock::Output> mOutput;
115 sp<NiceMock<compositionengine::mock::LayerFE>> mLayerFE_ =
116 sp<NiceMock<compositionengine::mock::LayerFE>>::make();
117 NiceMock<compositionengine::mock::LayerFE>& mLayerFE = *mLayerFE_;
Lloyd Piquede196652020-01-22 17:29:58 -0800118 OutputLayer mOutputLayer{mOutput, mLayerFE};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800119
Lloyd Pique9755fb72019-03-26 14:44:40 -0700120 LayerFECompositionState mLayerFEState;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800121 impl::OutputCompositionState mOutputState;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800122};
123
Lloyd Piquea83776c2019-01-29 18:42:32 -0800124/*
Lloyd Piquecc01a452018-12-04 17:24:00 -0800125 * Basic construction
126 */
127
128TEST_F(OutputLayerTest, canInstantiateOutputLayer) {}
129
Lloyd Piquea83776c2019-01-29 18:42:32 -0800130/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800131 * OutputLayer::setHwcLayer()
Lloyd Pique07e33212018-12-18 16:33:37 -0800132 */
133
Lloyd Piquedf336d92019-03-07 21:38:42 -0800134TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) {
Lloyd Pique07e33212018-12-18 16:33:37 -0800135 StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
136
Lloyd Piquedf336d92019-03-07 21:38:42 -0800137 mOutputLayer.setHwcLayer(nullptr);
Lloyd Pique07e33212018-12-18 16:33:37 -0800138
139 EXPECT_FALSE(mOutputLayer.getState().hwc);
140}
141
Lloyd Piquedf336d92019-03-07 21:38:42 -0800142TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) {
143 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Pique07e33212018-12-18 16:33:37 -0800144
Lloyd Piquedf336d92019-03-07 21:38:42 -0800145 mOutputLayer.setHwcLayer(hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800146
Lloyd Piquea83776c2019-01-29 18:42:32 -0800147 const auto& outputLayerState = mOutputLayer.getState();
148 ASSERT_TRUE(outputLayerState.hwc);
Lloyd Pique07e33212018-12-18 16:33:37 -0800149
Lloyd Piquea83776c2019-01-29 18:42:32 -0800150 const auto& hwcState = *outputLayerState.hwc;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800151 EXPECT_EQ(hwcLayer, hwcState.hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800152}
153
Lloyd Piquea83776c2019-01-29 18:42:32 -0800154/*
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000155 * OutputLayer::calculateOutputSourceCrop()
156 */
157
158struct OutputLayerSourceCropTest : public OutputLayerTest {
159 OutputLayerSourceCropTest() {
160 // Set reasonable default values for a simple case. Each test will
161 // set one specific value to something different.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700162 mLayerFEState.geomUsesSourceCrop = true;
163 mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080};
164 mLayerFEState.transparentRegionHint = Region{};
165 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
166 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
167 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
168 mLayerFEState.geomBufferTransform = TR_IDENT;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000169
Angel Aguayob084e0c2021-08-04 23:27:28 +0000170 mOutputState.layerStackSpace.setContent(Rect{0, 0, 1920, 1080});
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000171 }
172
173 FloatRect calculateOutputSourceCrop() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700174 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000175
ramindani2c043be2022-04-19 20:11:10 +0000176 return mOutputLayer.calculateOutputSourceCrop(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000177 }
178};
179
180TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700181 mLayerFEState.geomUsesSourceCrop = false;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000182
183 const FloatRect expected{};
Lloyd Piqueea629282019-12-03 15:57:10 -0800184 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000185}
186
187TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) {
188 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800189 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000190}
191
192TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700193 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000194
195 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800196 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000197}
198
199TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700200 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
201 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000202
203 const FloatRect expected{0.f, 0.f, 1080.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800204 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000205}
206
207TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) {
208 struct Entry {
209 uint32_t bufferInvDisplay;
210 uint32_t buffer;
211 uint32_t display;
212 FloatRect expected;
213 };
214 // Not an exhaustive list of cases, but hopefully enough.
215 const std::array<Entry, 12> testData = {
216 // clang-format off
217 // inv buffer display expected
218 /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
219 /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
220 /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
221 /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
222
223 /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
224 /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
225 /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
226 /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
227
228 /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
229 /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
230 /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
231 /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
232
233 // clang-format on
234 };
235
236 for (size_t i = 0; i < testData.size(); i++) {
237 const auto& entry = testData[i];
238
Lloyd Pique9755fb72019-03-26 14:44:40 -0700239 mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay;
240 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000241 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000242
Lloyd Piqueea629282019-12-03 15:57:10 -0800243 EXPECT_THAT(calculateOutputSourceCrop(), entry.expected) << "entry " << i;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000244 }
245}
246
247TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700248 mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000249
250 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800251 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000252}
253
254TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) {
Angel Aguayob084e0c2021-08-04 23:27:28 +0000255 mOutputState.layerStackSpace.setContent(Rect{0, 0, 960, 540});
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000256
257 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800258 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000259}
260
261/*
Lloyd Piquea83776c2019-01-29 18:42:32 -0800262 * OutputLayer::calculateOutputDisplayFrame()
263 */
264
265struct OutputLayerDisplayFrameTest : public OutputLayerTest {
266 OutputLayerDisplayFrameTest() {
267 // Set reasonable default values for a simple case. Each test will
268 // set one specific value to something different.
269
Lloyd Pique9755fb72019-03-26 14:44:40 -0700270 mLayerFEState.transparentRegionHint = Region{};
271 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
272 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
273 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
Vishnu Naira9123c82024-10-03 03:56:44 +0000274 mLayerFEState.geomCrop = FloatRect{0, 0, 1920, 1080};
Lloyd Pique9755fb72019-03-26 14:44:40 -0700275 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800276
Angel Aguayob084e0c2021-08-04 23:27:28 +0000277 mOutputState.layerStackSpace.setContent(Rect{0, 0, 1920, 1080});
Lloyd Piquea83776c2019-01-29 18:42:32 -0800278 mOutputState.transform = ui::Transform{TR_IDENT};
279 }
280
281 Rect calculateOutputDisplayFrame() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700282 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800283
284 return mOutputLayer.calculateOutputDisplayFrame();
285 }
286};
287
288TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) {
289 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800290 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800291}
292
293TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700294 mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800295 const Rect expected{0, 0, 0, 0};
Lloyd Piqueea629282019-12-03 15:57:10 -0800296 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800297}
298
299TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) {
Vishnu Naira9123c82024-10-03 03:56:44 +0000300 mLayerFEState.geomCrop = FloatRect{100, 200, 300, 500};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800301 const Rect expected{100, 200, 300, 500};
Lloyd Piqueea629282019-12-03 15:57:10 -0800302 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800303}
304
305TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) {
Vishnu Naira9123c82024-10-03 03:56:44 +0000306 mLayerFEState.geomCrop = FloatRect{100, 200, 300, 500};
Lloyd Pique9755fb72019-03-26 14:44:40 -0700307 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800308 const Rect expected{1420, 100, 1720, 300};
Lloyd Piqueea629282019-12-03 15:57:10 -0800309 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800310}
311
312TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) {
Vishnu Naira9123c82024-10-03 03:56:44 +0000313 mLayerFEState.geomCrop = FloatRect{};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800314 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800315 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800316}
317
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000318TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700319 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800320 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800321 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800322}
323
324TEST_F(OutputLayerDisplayFrameTest, viewportAffectsFrame) {
Angel Aguayob084e0c2021-08-04 23:27:28 +0000325 mOutputState.layerStackSpace.setContent(Rect{0, 0, 960, 540});
Lloyd Piquea83776c2019-01-29 18:42:32 -0800326 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800327 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800328}
329
330TEST_F(OutputLayerDisplayFrameTest, outputTransformAffectsDisplayFrame) {
331 mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90};
332 const Rect expected{-1080, 0, 0, 1920};
Lloyd Piqueea629282019-12-03 15:57:10 -0800333 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800334}
335
Leon Scroggins IIId394d3c2021-06-24 11:30:32 -0400336TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame) {
337 const int kShadowRadius = 5;
Vishnu Naird9e4f462023-10-06 04:05:45 +0000338 mLayerFEState.shadowSettings.length = kShadowRadius;
Leon Scroggins IIId394d3c2021-06-24 11:30:32 -0400339 mLayerFEState.forceClientComposition = true;
340
341 mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
342 Rect expected{mLayerFEState.geomLayerBounds};
Alec Mourida128512024-09-28 23:46:58 +0000343 expected.inset(-2 * kShadowRadius, -2 * kShadowRadius, -2 * kShadowRadius, -2 * kShadowRadius);
Leon Scroggins IIId394d3c2021-06-24 11:30:32 -0400344 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
345}
346
347TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame_onlyIfForcingClientComposition) {
348 const int kShadowRadius = 5;
Vishnu Naird9e4f462023-10-06 04:05:45 +0000349 mLayerFEState.shadowSettings.length = kShadowRadius;
Leon Scroggins IIId394d3c2021-06-24 11:30:32 -0400350 mLayerFEState.forceClientComposition = false;
351
352 mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
353 Rect expected{mLayerFEState.geomLayerBounds};
354 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
355}
356
Lloyd Piquea83776c2019-01-29 18:42:32 -0800357/*
358 * OutputLayer::calculateOutputRelativeBufferTransform()
359 */
360
361TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700362 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800363
364 struct Entry {
365 uint32_t layer;
366 uint32_t buffer;
367 uint32_t display;
368 uint32_t expected;
369 };
370 // Not an exhaustive list of cases, but hopefully enough.
371 const std::array<Entry, 24> testData = {
372 // clang-format off
373 // layer buffer display expected
374 /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
375 /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_90},
376 /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
377 /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270},
378
379 /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_IDENT},
380 /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_90},
381 /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_180},
382 /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_ROT_270},
383
384 /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V},
385 /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_180},
386 /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
387 /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_180},
388
389 /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_90},
390 /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_180},
391 /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT ^ TR_ROT_270},
392 /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_IDENT},
393
394 /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_ROT_180},
395 /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT ^ TR_ROT_270},
396 /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_IDENT},
397 /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_90},
398
399 /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_270},
400 /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_IDENT},
401 /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_90},
402 /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_180},
403 // clang-format on
404 };
405
406 for (size_t i = 0; i < testData.size(); i++) {
407 const auto& entry = testData[i];
408
Lloyd Pique9755fb72019-03-26 14:44:40 -0700409 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
410 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000411 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700412 mOutputState.transform = ui::Transform{entry.display};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800413
Snild Dolkow9e217d62020-04-22 15:53:42 +0200414 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.display);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800415 EXPECT_EQ(entry.expected, actual) << "entry " << i;
416 }
417}
418
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000419TEST_F(OutputLayerTest,
420 calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700421 mLayerFEState.geomBufferUsesDisplayInverseTransform = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000422
423 struct Entry {
Snild Dolkow9e217d62020-04-22 15:53:42 +0200424 uint32_t layer; /* shouldn't affect the result, so we just use arbitrary values */
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000425 uint32_t buffer;
426 uint32_t display;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200427 uint32_t internal;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000428 uint32_t expected;
429 };
Snild Dolkow9e217d62020-04-22 15:53:42 +0200430 const std::array<Entry, 64> testData = {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000431 // clang-format off
Snild Dolkow9e217d62020-04-22 15:53:42 +0200432 // layer buffer display internal expected
433 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
434 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_270},
435 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
436 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_90},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000437
Snild Dolkow9e217d62020-04-22 15:53:42 +0200438 Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT, TR_ROT_90},
439 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_90, TR_IDENT},
440 Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_180, TR_ROT_270},
441 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000442
Snild Dolkow9e217d62020-04-22 15:53:42 +0200443 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_180},
444 Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_90, TR_ROT_90},
445 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
446 Entry{TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000447
Snild Dolkow9e217d62020-04-22 15:53:42 +0200448 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270},
449 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_ROT_90, TR_ROT_180},
450 Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_180, TR_ROT_90},
451 Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000452
Snild Dolkow9e217d62020-04-22 15:53:42 +0200453 // layer buffer display internal expected
454 Entry{TR_IDENT, TR_ROT_90, TR_IDENT, TR_IDENT, TR_ROT_90},
455 Entry{TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_90, TR_IDENT},
456 Entry{TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_270},
457 Entry{TR_ROT_270, TR_ROT_90, TR_IDENT, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000458
Snild Dolkow9e217d62020-04-22 15:53:42 +0200459 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_180},
460 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90},
461 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_IDENT},
462 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270, TR_ROT_270},
463
464 Entry{TR_IDENT, TR_ROT_90, TR_ROT_180, TR_IDENT, TR_ROT_270},
465 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_180},
466 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_180, TR_ROT_90},
467 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_270, TR_IDENT},
468
469 Entry{TR_IDENT, TR_ROT_90, TR_ROT_270, TR_IDENT, TR_IDENT},
470 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270},
471 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_ROT_180, TR_ROT_180},
472 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90},
473
474 // layer buffer display internal expected
475 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_IDENT, TR_ROT_180},
476 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_90},
477 Entry{TR_ROT_180, TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT},
478 Entry{TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_270},
479
480 Entry{TR_IDENT, TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_270},
481 Entry{TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_90, TR_ROT_180},
482 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_90},
483 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_IDENT},
484
485 Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT, TR_IDENT},
486 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270},
487 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180},
488 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90},
489
490 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_IDENT, TR_ROT_90},
491 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_IDENT},
492 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_270},
493 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_270, TR_ROT_180},
494
495 // layer buffer display internal expected
496 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_IDENT, TR_ROT_270},
497 Entry{TR_ROT_90, TR_ROT_270, TR_IDENT, TR_ROT_90, TR_ROT_180},
498 Entry{TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_90},
499 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT},
500
501 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_IDENT, TR_IDENT},
502 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270},
503 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_ROT_180, TR_ROT_180},
504 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90},
505
506 Entry{TR_IDENT, TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_90},
507 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_90, TR_IDENT},
508 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270},
509 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_180},
510
511 Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180},
512 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_ROT_90},
513 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_IDENT},
514 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000515 // clang-format on
516 };
517
518 for (size_t i = 0; i < testData.size(); i++) {
519 const auto& entry = testData[i];
520
Snild Dolkow9e217d62020-04-22 15:53:42 +0200521 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
Lloyd Pique9755fb72019-03-26 14:44:40 -0700522 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000523 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700524 mOutputState.transform = ui::Transform{entry.display};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000525
Snild Dolkow9e217d62020-04-22 15:53:42 +0200526 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.internal);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000527 EXPECT_EQ(entry.expected, actual) << "entry " << i;
528 }
529}
530
531/*
532 * OutputLayer::updateCompositionState()
533 */
534
535struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer {
536 OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output,
Brian Lindahl90553da2022-12-06 13:36:30 -0700537 compositionengine::LayerFE& layerFE)
Lloyd Piquede196652020-01-22 17:29:58 -0800538 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000539 // Mock everything called by updateCompositionState to simplify testing it.
ramindani2c043be2022-04-19 20:11:10 +0000540 MOCK_CONST_METHOD1(calculateOutputSourceCrop, FloatRect(uint32_t));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000541 MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect());
Snild Dolkow9e217d62020-04-22 15:53:42 +0200542 MOCK_CONST_METHOD1(calculateOutputRelativeBufferTransform, uint32_t(uint32_t));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700543
544 // compositionengine::OutputLayer overrides
545 const compositionengine::Output& getOutput() const override { return mOutput; }
Brian Lindahl90553da2022-12-06 13:36:30 -0700546 compositionengine::LayerFE& getLayerFE() const override { return mLayerFE; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700547 const impl::OutputLayerCompositionState& getState() const override { return mState; }
548 impl::OutputLayerCompositionState& editState() override { return mState; }
549
550 // These need implementations though are not expected to be called.
551 MOCK_CONST_METHOD1(dumpState, void(std::string&));
552
553 const compositionengine::Output& mOutput;
Brian Lindahl90553da2022-12-06 13:36:30 -0700554 compositionengine::LayerFE& mLayerFE;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700555 impl::OutputLayerCompositionState mState;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000556};
557
558struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest {
559public:
560 OutputLayerUpdateCompositionStateTest() {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000561 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
Lloyd Piquef5275482019-01-29 18:42:42 -0800562 EXPECT_CALL(mOutput, getDisplayColorProfile())
563 .WillRepeatedly(Return(&mDisplayColorProfile));
564 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000565 }
566
567 ~OutputLayerUpdateCompositionStateTest() = default;
568
Snild Dolkow9e217d62020-04-22 15:53:42 +0200569 void setupGeometryChildCallValues(ui::Transform::RotationFlags internalDisplayRotationFlags) {
ramindani2c043be2022-04-19 20:11:10 +0000570 EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop(internalDisplayRotationFlags))
571 .WillOnce(Return(kSourceCrop));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000572 EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200573 EXPECT_CALL(mOutputLayer,
574 calculateOutputRelativeBufferTransform(internalDisplayRotationFlags))
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000575 .WillOnce(Return(mBufferTransform));
576 }
577
578 void validateComputedGeometryState() {
579 const auto& state = mOutputLayer.getState();
580 EXPECT_EQ(kSourceCrop, state.sourceCrop);
581 EXPECT_EQ(kDisplayFrame, state.displayFrame);
582 EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform);
583 }
584
585 const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f};
586 const Rect kDisplayFrame{11, 12, 13, 14};
587 uint32_t mBufferTransform{21};
588
589 using OutputLayer = OutputLayerPartialMockForUpdateCompositionState;
Lloyd Piquede196652020-01-22 17:29:58 -0800590 StrictMock<OutputLayer> mOutputLayer{mOutput, mLayerFE};
Lloyd Piquef5275482019-01-29 18:42:42 -0800591 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000592};
593
Lloyd Piquede196652020-01-22 17:29:58 -0800594TEST_F(OutputLayerUpdateCompositionStateTest, doesNothingIfNoFECompositionState) {
Brian Lindahl90553da2022-12-06 13:36:30 -0700595 EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
Lloyd Piquede196652020-01-22 17:29:58 -0800596
Snild Dolkow9e217d62020-04-22 15:53:42 +0200597 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Piquede196652020-01-22 17:29:58 -0800598}
599
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000600TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700601 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000602 mOutputState.isSecure = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700603 mOutputLayer.editState().forceClientComposition = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000604
Snild Dolkow9e217d62020-04-22 15:53:42 +0200605 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000606
Snild Dolkow9e217d62020-04-22 15:53:42 +0200607 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000608
609 validateComputedGeometryState();
610
611 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
612}
613
614TEST_F(OutputLayerUpdateCompositionStateTest,
615 alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700616 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000617 mOutputState.isSecure = false;
618
Snild Dolkow9e217d62020-04-22 15:53:42 +0200619 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000620
Snild Dolkow9e217d62020-04-22 15:53:42 +0200621 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000622
623 validateComputedGeometryState();
624
625 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
626}
627
628TEST_F(OutputLayerUpdateCompositionStateTest,
629 alsoSetsForceCompositionIfUnsupportedBufferTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700630 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000631 mOutputState.isSecure = true;
632
633 mBufferTransform = ui::Transform::ROT_INVALID;
634
Snild Dolkow9e217d62020-04-22 15:53:42 +0200635 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000636
Snild Dolkow9e217d62020-04-22 15:53:42 +0200637 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000638
639 validateComputedGeometryState();
640
641 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
642}
643
Lloyd Piquef5275482019-01-29 18:42:42 -0800644TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700645 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
Alec Mouri88790f32023-07-21 01:25:14 +0000646 mOutputState.dataspace = ui::Dataspace::V0_SCRGB;
Lloyd Piquef5275482019-01-29 18:42:42 -0800647
648 // If the layer is not colorspace agnostic, the output layer dataspace
649 // should use the layers requested colorspace.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700650 mLayerFEState.isColorspaceAgnostic = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800651
Snild Dolkow9e217d62020-04-22 15:53:42 +0200652 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800653
654 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
655
656 // If the layer is colorspace agnostic, the output layer dataspace
657 // should use the colorspace chosen for the whole output.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700658 mLayerFEState.isColorspaceAgnostic = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800659
Snild Dolkow9e217d62020-04-22 15:53:42 +0200660 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800661
662 EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace);
Alec Mouri88790f32023-07-21 01:25:14 +0000663
664 // If the output is HDR, then don't blind the user with a colorspace agnostic dataspace
665 // drawing all white
666 mOutputState.dataspace = ui::Dataspace::BT2020_PQ;
667
668 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
669
670 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
Lloyd Piquef5275482019-01-29 18:42:42 -0800671}
672
Alec Mouridda07d92022-04-25 22:39:25 +0000673TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceWith170mReplacement) {
674 mLayerFEState.dataspace = ui::Dataspace::TRANSFER_SMPTE_170M;
Alec Mouridda07d92022-04-25 22:39:25 +0000675 mOutputState.treat170mAsSrgb = false;
676 mLayerFEState.isColorspaceAgnostic = false;
677
678 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
679
680 EXPECT_EQ(ui::Dataspace::TRANSFER_SMPTE_170M, mOutputLayer.getState().dataspace);
681
682 // Rewrite SMPTE 170M as sRGB
683 mOutputState.treat170mAsSrgb = true;
684 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
685
686 EXPECT_EQ(ui::Dataspace::TRANSFER_SRGB, mOutputLayer.getState().dataspace);
687}
688
Alec Mourie8dd3562022-02-11 14:18:57 -0800689TEST_F(OutputLayerUpdateCompositionStateTest, setsWhitePointNitsAndDimmingRatioCorrectly) {
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700690 mOutputState.sdrWhitePointNits = 200.f;
691 mOutputState.displayBrightnessNits = 800.f;
692
693 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
694 mLayerFEState.isColorspaceAgnostic = false;
695 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
696 EXPECT_EQ(mOutputState.sdrWhitePointNits, mOutputLayer.getState().whitePointNits);
Alec Mourie8dd3562022-02-11 14:18:57 -0800697 EXPECT_EQ(mOutputState.sdrWhitePointNits / mOutputState.displayBrightnessNits,
698 mOutputLayer.getState().dimmingRatio);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700699
Sally Qi81d95e62022-03-21 19:41:33 -0700700 mLayerFEState.dimmingEnabled = false;
701 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
702 EXPECT_EQ(mOutputState.displayBrightnessNits, mOutputLayer.getState().whitePointNits);
703 EXPECT_EQ(1.f, mOutputLayer.getState().dimmingRatio);
704
705 // change dimmingEnabled back to true.
706 mLayerFEState.dimmingEnabled = true;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700707 mLayerFEState.dataspace = ui::Dataspace::BT2020_ITU_PQ;
708 mLayerFEState.isColorspaceAgnostic = false;
709 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
710
711 EXPECT_EQ(mOutputState.displayBrightnessNits, mOutputLayer.getState().whitePointNits);
Alec Mourie8dd3562022-02-11 14:18:57 -0800712 EXPECT_EQ(1.f, mOutputLayer.getState().dimmingRatio);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700713}
714
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000715TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700716 mOutputLayer.editState().forceClientComposition = false;
717
Snild Dolkow9e217d62020-04-22 15:53:42 +0200718 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000719
720 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
721}
722
Lloyd Piquefe671022019-09-24 10:43:03 -0700723TEST_F(OutputLayerUpdateCompositionStateTest,
724 doesNotClearForceClientCompositionIfNotDoingGeometry) {
725 mOutputLayer.editState().forceClientComposition = true;
726
Snild Dolkow9e217d62020-04-22 15:53:42 +0200727 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquefe671022019-09-24 10:43:03 -0700728
729 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
730}
731
Lloyd Piquef5275482019-01-29 18:42:42 -0800732TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700733 mLayerFEState.forceClientComposition = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700734 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800735
Snild Dolkow9e217d62020-04-22 15:53:42 +0200736 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800737
738 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
739}
740
741TEST_F(OutputLayerUpdateCompositionStateTest,
742 clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700743 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800744 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false));
745
Snild Dolkow9e217d62020-04-22 15:53:42 +0200746 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700747
748 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
749}
750
751TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromArgumentFlag) {
752 mLayerFEState.forceClientComposition = false;
753 mOutputLayer.editState().forceClientComposition = false;
754
Snild Dolkow9e217d62020-04-22 15:53:42 +0200755 mOutputLayer.updateCompositionState(false, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700756
757 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
758
759 mOutputLayer.editState().forceClientComposition = false;
760
Snild Dolkow9e217d62020-04-22 15:53:42 +0200761 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700762
Snild Dolkow9e217d62020-04-22 15:53:42 +0200763 mOutputLayer.updateCompositionState(true, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800764
765 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
766}
767
Lloyd Piquea83776c2019-01-29 18:42:32 -0800768/*
769 * OutputLayer::writeStateToHWC()
770 */
771
772struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
Peiyong Line9d809e2020-04-14 13:10:48 -0700773 static constexpr hal::Error kError = hal::Error::UNSUPPORTED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800774 static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800775 static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31);
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700776 static constexpr Hwc2::Transform kOverrideBufferTransform = static_cast<Hwc2::Transform>(0);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800777 static constexpr Hwc2::IComposerClient::BlendMode kBlendMode =
778 static_cast<Hwc2::IComposerClient::BlendMode>(41);
Alec Mouriee69a592021-03-23 15:00:45 -0700779 static constexpr Hwc2::IComposerClient::BlendMode kOverrideBlendMode =
780 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800781 static constexpr float kAlpha = 51.f;
Alec Mouriee69a592021-03-23 15:00:45 -0700782 static constexpr float kOverrideAlpha = 1.f;
Alec Mouri96ca45c2021-06-09 17:32:26 -0700783 static constexpr float kSkipAlpha = 0.f;
Lloyd Piquef5275482019-01-29 18:42:42 -0800784 static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
Alec Mourib7edfc22021-03-17 16:20:26 -0700785 static constexpr ui::Dataspace kOverrideDataspace = static_cast<ui::Dataspace>(72);
Lloyd Piquef5275482019-01-29 18:42:42 -0800786 static constexpr int kSupportedPerFrameMetadata = 101;
787 static constexpr int kExpectedHwcSlot = 0;
Brian Lindahl439afad2022-11-14 11:16:55 -0700788 static constexpr int kOverrideHwcSlot = impl::HwcBufferCache::kOverrideBufferSlot;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800789 static constexpr bool kLayerGenericMetadata1Mandatory = true;
790 static constexpr bool kLayerGenericMetadata2Mandatory = true;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700791 static constexpr float kWhitePointNits = 200.f;
Alec Mourie8dd3562022-02-11 14:18:57 -0800792 static constexpr float kSdrWhitePointNits = 100.f;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700793 static constexpr float kDisplayBrightnessNits = 400.f;
Alec Mouri6da0e272022-02-07 12:45:57 -0800794 static constexpr float kLayerBrightness = kWhitePointNits / kDisplayBrightnessNits;
Alec Mourie8dd3562022-02-11 14:18:57 -0800795 static constexpr float kOverrideLayerBrightness = kSdrWhitePointNits / kDisplayBrightnessNits;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800796
Lloyd Piquef5275482019-01-29 18:42:42 -0800797 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800798 static const Rect kDisplayFrame;
Alec Mourib7edfc22021-03-17 16:20:26 -0700799 static const Rect kOverrideDisplayFrame;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700800 static const FloatRect kOverrideSourceCrop;
Lloyd Piquea2468662019-03-07 21:31:06 -0800801 static const Region kOutputSpaceVisibleRegion;
Alec Mouri464352b2021-03-24 16:33:21 -0700802 static const Region kOverrideVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800803 static const mat4 kColorTransform;
804 static const Region kSurfaceDamage;
Alec Mouri464352b2021-03-24 16:33:21 -0700805 static const Region kOverrideSurfaceDamage;
Lloyd Piquef5275482019-01-29 18:42:42 -0800806 static const HdrMetadata kHdrMetadata;
807 static native_handle_t* kSidebandStreamHandle;
808 static const sp<GraphicBuffer> kBuffer;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700809 static const sp<GraphicBuffer> kOverrideBuffer;
Lloyd Piquef5275482019-01-29 18:42:42 -0800810 static const sp<Fence> kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700811 static const sp<Fence> kOverrideFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800812 static const std::string kLayerGenericMetadata1Key;
813 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
814 static const std::string kLayerGenericMetadata2Key;
815 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800816
817 OutputLayerWriteStateToHWCTest() {
818 auto& outputLayerState = mOutputLayer.editState();
819 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
820
821 outputLayerState.displayFrame = kDisplayFrame;
822 outputLayerState.sourceCrop = kSourceCrop;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800823 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800824 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800825 outputLayerState.dataspace = kDataspace;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700826 outputLayerState.whitePointNits = kWhitePointNits;
Alec Mouri6da0e272022-02-07 12:45:57 -0800827 outputLayerState.dimmingRatio = kLayerBrightness;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800828
Lloyd Pique9755fb72019-03-26 14:44:40 -0700829 mLayerFEState.blendMode = kBlendMode;
830 mLayerFEState.alpha = kAlpha;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700831 mLayerFEState.colorTransform = kColorTransform;
832 mLayerFEState.color = kColor;
833 mLayerFEState.surfaceDamage = kSurfaceDamage;
834 mLayerFEState.hdrMetadata = kHdrMetadata;
835 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
836 mLayerFEState.buffer = kBuffer;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700837 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800838
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700839 mOutputState.displayBrightnessNits = kDisplayBrightnessNits;
Alec Mourie8dd3562022-02-11 14:18:57 -0800840 mOutputState.sdrWhitePointNits = kSdrWhitePointNits;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700841
Lloyd Piquef5275482019-01-29 18:42:42 -0800842 EXPECT_CALL(mOutput, getDisplayColorProfile())
843 .WillRepeatedly(Return(&mDisplayColorProfile));
844 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
845 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800846 }
Lloyd Piquef5275482019-01-29 18:42:42 -0800847 // Some tests may need to simulate unsupported HWC calls
848 enum class SimulateUnsupported { None, ColorTransform };
849
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800850 void includeGenericLayerMetadataInState() {
851 mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory,
852 kLayerGenericMetadata1Value};
853 mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory,
854 kLayerGenericMetadata2Value};
855 }
856
Alec Mourib7edfc22021-03-17 16:20:26 -0700857 void includeOverrideInfo() {
858 auto& overrideInfo = mOutputLayer.editState().overrideInfo;
859
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700860 overrideInfo.buffer = std::make_shared<
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800861 renderengine::impl::ExternalTexture>(kOverrideBuffer, mRenderEngine,
862 renderengine::impl::ExternalTexture::Usage::
863 READABLE |
864 renderengine::impl::ExternalTexture::
865 Usage::WRITEABLE);
Alec Mourib7edfc22021-03-17 16:20:26 -0700866 overrideInfo.acquireFence = kOverrideFence;
867 overrideInfo.displayFrame = kOverrideDisplayFrame;
868 overrideInfo.dataspace = kOverrideDataspace;
Alec Mouri464352b2021-03-24 16:33:21 -0700869 overrideInfo.damageRegion = kOverrideSurfaceDamage;
870 overrideInfo.visibleRegion = kOverrideVisibleRegion;
Alec Mourib7edfc22021-03-17 16:20:26 -0700871 }
872
873 void expectGeometryCommonCalls(Rect displayFrame = kDisplayFrame,
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700874 FloatRect sourceCrop = kSourceCrop,
Alec Mouriee69a592021-03-23 15:00:45 -0700875 Hwc2::Transform bufferTransform = kBufferTransform,
876 Hwc2::IComposerClient::BlendMode blendMode = kBlendMode,
877 float alpha = kAlpha) {
Alec Mourib7edfc22021-03-17 16:20:26 -0700878 EXPECT_CALL(*mHwcLayer, setDisplayFrame(displayFrame)).WillOnce(Return(kError));
879 EXPECT_CALL(*mHwcLayer, setSourceCrop(sourceCrop)).WillOnce(Return(kError));
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400880 EXPECT_CALL(*mHwcLayer, setZOrder(_)).WillOnce(Return(kError));
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700881 EXPECT_CALL(*mHwcLayer, setTransform(bufferTransform)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800882
Alec Mouriee69a592021-03-23 15:00:45 -0700883 EXPECT_CALL(*mHwcLayer, setBlendMode(blendMode)).WillOnce(Return(kError));
884 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(alpha)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800885 }
886
Alec Mourib7edfc22021-03-17 16:20:26 -0700887 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None,
Alec Mouri464352b2021-03-24 16:33:21 -0700888 ui::Dataspace dataspace = kDataspace,
889 const Region& visibleRegion = kOutputSpaceVisibleRegion,
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700890 const Region& surfaceDamage = kSurfaceDamage,
Alec Mouri6da0e272022-02-07 12:45:57 -0800891 float brightness = kLayerBrightness,
Leon Scroggins III9a0afda2022-01-11 16:53:09 -0500892 const Region& blockingRegion = Region()) {
Alec Mouri464352b2021-03-24 16:33:21 -0700893 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(visibleRegion))).WillOnce(Return(kError));
Alec Mourib7edfc22021-03-17 16:20:26 -0700894 EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError));
Alec Mouri6da0e272022-02-07 12:45:57 -0800895 EXPECT_CALL(*mHwcLayer, setBrightness(brightness)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800896 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
897 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700898 ? hal::Error::UNSUPPORTED
899 : hal::Error::NONE));
Alec Mouri464352b2021-03-24 16:33:21 -0700900 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(surfaceDamage))).WillOnce(Return(kError));
Leon Scroggins III9a0afda2022-01-11 16:53:09 -0500901 EXPECT_CALL(*mHwcLayer, setBlockingRegion(RegionEq(blockingRegion)))
902 .WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800903 }
904
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500905 void expectSetCompositionTypeCall(Composition compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700906 EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800907 }
908
909 void expectNoSetCompositionTypeCall() {
910 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
911 }
912
913 void expectSetColorCall() {
Ady Abraham6e60b142022-01-06 18:10:35 -0800914 const aidl::android::hardware::graphics::composer3::Color color = {kColor.r, kColor.g,
915 kColor.b, 1.0f};
Lloyd Piquef5275482019-01-29 18:42:42 -0800916
917 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
918 }
919
920 void expectSetSidebandHandleCall() {
921 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
922 }
923
Alec Mourie7cc1c22021-04-27 15:23:26 -0700924 void expectSetHdrMetadataAndBufferCalls(uint32_t hwcSlot = kExpectedHwcSlot,
925 sp<GraphicBuffer> buffer = kBuffer,
Alec Mourib7edfc22021-03-17 16:20:26 -0700926 sp<Fence> fence = kFence) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800927 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
Alec Mourie7cc1c22021-04-27 15:23:26 -0700928 EXPECT_CALL(*mHwcLayer, setBuffer(hwcSlot, buffer, fence));
Lloyd Piquef5275482019-01-29 18:42:42 -0800929 }
930
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800931 void expectGenericLayerMetadataCalls() {
932 // Note: Can be in any order.
933 EXPECT_CALL(*mHwcLayer,
934 setLayerGenericMetadata(kLayerGenericMetadata1Key,
935 kLayerGenericMetadata1Mandatory,
936 kLayerGenericMetadata1Value));
937 EXPECT_CALL(*mHwcLayer,
938 setLayerGenericMetadata(kLayerGenericMetadata2Key,
939 kLayerGenericMetadata2Mandatory,
940 kLayerGenericMetadata2Value));
941 }
942
Lloyd Piquea83776c2019-01-29 18:42:32 -0800943 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800944 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Alec Mouria90a5702021-04-16 16:36:21 +0000945 renderengine::mock::RenderEngine mRenderEngine;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800946};
947
Lloyd Piquef5275482019-01-29 18:42:42 -0800948const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
949 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800950const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Alec Mourib7edfc22021-03-17 16:20:26 -0700951const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044};
Wiwit Rifa'i50abed02022-05-24 02:24:33 +0000952const FloatRect OutputLayerWriteStateToHWCTest::kOverrideSourceCrop{0.f, 0.f, 4.f, 5.f};
Lloyd Piquea2468662019-03-07 21:31:06 -0800953const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
954 Rect{1005, 1006, 1007, 1008}};
Alec Mouri464352b2021-03-24 16:33:21 -0700955const Region OutputLayerWriteStateToHWCTest::kOverrideVisibleRegion{Rect{1006, 1007, 1008, 1009}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800956const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
957 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
958 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
959};
960const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
Alec Mouri464352b2021-03-24 16:33:21 -0700961const Region OutputLayerWriteStateToHWCTest::kOverrideSurfaceDamage{Rect{1026, 1027, 1028, 1029}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800962const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
963native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
964 reinterpret_cast<native_handle_t*>(1031);
Brian Lindahl90553da2022-12-06 13:36:30 -0700965const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer =
966 sp<GraphicBuffer>::make(1, 2, PIXEL_FORMAT_RGBA_8888,
967 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
968 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700969const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kOverrideBuffer =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700970 sp<GraphicBuffer>::make(4, 5, PIXEL_FORMAT_RGBA_8888,
971 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
972 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Lloyd Piquef5275482019-01-29 18:42:42 -0800973const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700974const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = sp<Fence>::make();
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800975const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
976 "com.example.metadata.1";
977const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
978const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
979 "com.example.metadata.2";
980const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
981 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800982
Lloyd Piquede196652020-01-22 17:29:58 -0800983TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
Brian Lindahl90553da2022-12-06 13:36:30 -0700984 EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
Lloyd Piquede196652020-01-22 17:29:58 -0800985
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400986 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
987 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquede196652020-01-22 17:29:58 -0800988}
989
Lloyd Piquea83776c2019-01-29 18:42:32 -0800990TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
991 mOutputLayer.editState().hwc.reset();
992
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400993 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
994 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800995}
996
997TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
998 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
999
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001000 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1001 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -08001002}
1003
Lloyd Piquef5275482019-01-29 18:42:42 -08001004TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -08001005 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -08001006 expectPerFrameCommonCalls();
1007
1008 expectNoSetCompositionTypeCall();
Brian Lindahl90553da2022-12-06 13:36:30 -07001009 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Piquea83776c2019-01-29 18:42:32 -08001010
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001011 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1012 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -08001013}
1014
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001015TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
1016 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
1017 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
1018 // This test simulates a scenario where displayInstallOrientation is set to
1019 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
1020 // DisplayDevice::setProjection).
Angel Aguayob084e0c2021-08-04 23:27:28 +00001021 mOutputState.displaySpace.setOrientation(ui::ROTATION_0);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001022 mOutputState.transform = ui::Transform{TR_ROT_90};
1023 // Buffers are pre-rotated based on the transform hint (ROT_90); their
1024 // geomBufferTransform is set to the inverse transform.
1025 mLayerFEState.geomBufferTransform = TR_ROT_270;
1026
Snild Dolkow9e217d62020-04-22 15:53:42 +02001027 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001028}
1029
Lloyd Piquef5275482019-01-29 18:42:42 -08001030TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001031 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001032
1033 expectPerFrameCommonCalls();
Lloyd Pique46b72df2019-10-29 13:19:27 -07001034
1035 // Setting the composition type should happen before setting the color. We
1036 // check this in this test only by setting up an testing::InSeqeuence
1037 // instance before setting up the two expectations.
1038 InSequence s;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001039 expectSetCompositionTypeCall(Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -07001040 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -08001041
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001042 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1043 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001044}
1045
1046TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001047 mLayerFEState.compositionType = Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -08001048
1049 expectPerFrameCommonCalls();
1050 expectSetSidebandHandleCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001051 expectSetCompositionTypeCall(Composition::SIDEBAND);
Lloyd Piquef5275482019-01-29 18:42:42 -08001052
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001053 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1054 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001055}
1056
1057TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001058 mLayerFEState.compositionType = Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001059
1060 expectPerFrameCommonCalls();
1061 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001062 expectSetCompositionTypeCall(Composition::CURSOR);
Lloyd Piquef5275482019-01-29 18:42:42 -08001063
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001064 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1065 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001066}
1067
1068TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001069 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -08001070
1071 expectPerFrameCommonCalls();
1072 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001073 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Piquef5275482019-01-29 18:42:42 -08001074
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001075 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1076 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001077}
1078
1079TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001080 (*mOutputLayer.editState().hwc).hwcCompositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001081
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001082 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001083
1084 expectPerFrameCommonCalls();
1085 expectSetColorCall();
1086 expectNoSetCompositionTypeCall();
1087
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001088 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1089 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001090}
1091
1092TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001093 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001094
1095 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
1096 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001097 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001098
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001099 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1100 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001101}
1102
1103TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
1104 mOutputLayer.editState().forceClientComposition = true;
1105
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001106 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001107
1108 expectPerFrameCommonCalls();
1109 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001110 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001111
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001112 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1113 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001114}
1115
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001116TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001117 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001118 includeGenericLayerMetadataInState();
1119
1120 expectGeometryCommonCalls();
1121 expectPerFrameCommonCalls();
1122 expectSetHdrMetadataAndBufferCalls();
1123 expectGenericLayerMetadataCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001124 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001125
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001126 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1127 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001128}
1129
1130TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001131 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001132 includeGenericLayerMetadataInState();
1133
1134 expectPerFrameCommonCalls();
1135 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001136 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001137
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001138 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1139 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001140}
1141
Alec Mouri96ca45c2021-06-09 17:32:26 -07001142TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001143 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mouri96ca45c2021-06-09 17:32:26 -07001144 includeOverrideInfo();
1145
1146 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1147 kOverrideBlendMode, kSkipAlpha);
1148 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001149 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001150 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001151 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001152
1153 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1154 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1155}
1156
Alec Mouri2b1212b2021-12-09 12:02:39 -08001157TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerForSolidColorDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001158 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri2b1212b2021-12-09 12:02:39 -08001159 includeOverrideInfo();
1160
1161 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1162 kOverrideBlendMode, kSkipAlpha);
1163 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001164 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001165 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001166 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001167
1168 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1169 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1170}
1171
Alec Mourib7edfc22021-03-17 16:20:26 -07001172TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001173 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourib7edfc22021-03-17 16:20:26 -07001174 includeOverrideInfo();
1175
Alec Mouri03bf0ff2021-04-19 14:17:31 -07001176 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1177 kOverrideBlendMode, kOverrideAlpha);
Alec Mouri464352b2021-03-24 16:33:21 -07001178 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001179 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mourie7cc1c22021-04-27 15:23:26 -07001180 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001181 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001182
1183 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1184 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1185}
1186
Alec Mouri028676a2021-12-02 15:01:48 -08001187TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoForSolidColorIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001188 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri028676a2021-12-02 15:01:48 -08001189 includeOverrideInfo();
1190
1191 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1192 kOverrideBlendMode, kOverrideAlpha);
1193 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001194 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri028676a2021-12-02 15:01:48 -08001195 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001196 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri028676a2021-12-02 15:01:48 -08001197
1198 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1199 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1200}
1201
Alec Mourid1bf1b52021-05-05 18:44:58 -07001202TEST_F(OutputLayerWriteStateToHWCTest, previousOverriddenLayerSendsSurfaceDamage) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001203 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001204 mOutputLayer.editState().hwc->stateOverridden = true;
1205
1206 expectGeometryCommonCalls();
1207 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1208 Region::INVALID_REGION);
1209 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001210 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001211
1212 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1213 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1214}
1215
1216TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedDeviceCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001217 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001218 mOutputLayer.editState().hwc->stateOverridden = true;
1219 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001220 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001221
1222 expectGeometryCommonCalls();
1223 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1224 Region::INVALID_REGION);
1225 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001226 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001227
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001228 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1229 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Alec Mourib7edfc22021-03-17 16:20:26 -07001230}
1231
Alec Mourid1bf1b52021-05-05 18:44:58 -07001232TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedClientCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001233 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001234 mOutputLayer.editState().forceClientComposition = true;
1235 mOutputLayer.editState().hwc->stateOverridden = true;
1236 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001237 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001238
1239 expectGeometryCommonCalls();
1240 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1241 Region::INVALID_REGION);
1242 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001243 expectSetCompositionTypeCall(Composition::CLIENT);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001244
1245 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1246 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1247}
1248
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001249TEST_F(OutputLayerWriteStateToHWCTest, peekThroughChangesBlendMode) {
Brian Lindahl90553da2022-12-06 13:36:30 -07001250 auto peekThroughLayerFE = sp<NiceMock<compositionengine::mock::LayerFE>>::make();
1251 OutputLayer peekThroughLayer{mOutput, *peekThroughLayerFE};
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001252
1253 mOutputLayer.mState.overrideInfo.peekThroughLayer = &peekThroughLayer;
1254
1255 expectGeometryCommonCalls(kDisplayFrame, kSourceCrop, kBufferTransform,
1256 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED);
1257 expectPerFrameCommonCalls();
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001258
1259 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1260 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1261}
1262
1263TEST_F(OutputLayerWriteStateToHWCTest, isPeekingThroughSetsOverride) {
1264 expectGeometryCommonCalls();
1265 expectPerFrameCommonCalls();
1266
1267 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1268 /*zIsOverridden*/ false, /*isPeekingThrough*/ true);
1269 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1270}
1271
1272TEST_F(OutputLayerWriteStateToHWCTest, zIsOverriddenSetsOverride) {
1273 expectGeometryCommonCalls();
1274 expectPerFrameCommonCalls();
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001275
1276 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1277 /*zIsOverridden*/ true, /*isPeekingThrough*/
1278 false);
1279 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1280}
1281
1282TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersForceClientComposition) {
1283 expectGeometryCommonCalls();
1284 expectPerFrameCommonCalls();
Brian Lindahl90553da2022-12-06 13:36:30 -07001285 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillOnce(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001286 expectSetCompositionTypeCall(Composition::CLIENT);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001287
1288 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1289 /*zIsOverridden*/ false, /*isPeekingThrough*/
1290 false);
1291}
1292
1293TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersPeekingThroughAllowsDeviceComposition) {
1294 expectGeometryCommonCalls();
1295 expectPerFrameCommonCalls();
1296 expectSetHdrMetadataAndBufferCalls();
Brian Lindahl90553da2022-12-06 13:36:30 -07001297 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001298 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001299
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001300 mLayerFEState.compositionType = Composition::DEVICE;
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001301 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1302 /*zIsOverridden*/ false, /*isPeekingThrough*/
1303 true);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001304 EXPECT_EQ(Composition::DEVICE, mOutputLayer.getState().hwc->hwcCompositionType);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001305}
1306
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001307TEST_F(OutputLayerWriteStateToHWCTest, setBlockingRegion) {
1308 mLayerFEState.compositionType = Composition::DISPLAY_DECORATION;
1309 const auto blockingRegion = Region(Rect(0, 0, 1000, 1000));
1310 mOutputLayer.editState().outputSpaceBlockingRegionHint = blockingRegion;
1311
1312 expectGeometryCommonCalls();
1313 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
Alec Mouri6da0e272022-02-07 12:45:57 -08001314 kSurfaceDamage, kLayerBrightness, blockingRegion);
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001315 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001316 expectSetCompositionTypeCall(Composition::DISPLAY_DECORATION);
1317
1318 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1319 /*zIsOverridden*/ false, /*isPeekingThrough*/
1320 false);
1321}
1322
ramindanib2158ee2023-02-13 20:29:59 -08001323TEST_F(OutputLayerWriteStateToHWCTest, setCompositionTypeRefreshRateIndicator) {
1324 mLayerFEState.compositionType = Composition::REFRESH_RATE_INDICATOR;
1325
1326 expectGeometryCommonCalls();
1327 expectPerFrameCommonCalls();
1328 expectSetHdrMetadataAndBufferCalls();
1329 expectSetCompositionTypeCall(Composition::REFRESH_RATE_INDICATOR);
1330
1331 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1332 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1333}
1334
Lloyd Pique66d68602019-02-13 14:23:31 -08001335/*
Brian Lindahl90553da2022-12-06 13:36:30 -07001336 * OutputLayer::uncacheBuffers
1337 */
1338struct OutputLayerUncacheBufferTest : public OutputLayerTest {
1339 static const sp<GraphicBuffer> kBuffer1;
1340 static const sp<GraphicBuffer> kBuffer2;
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001341 static const sp<GraphicBuffer> kBuffer3;
Brian Lindahl90553da2022-12-06 13:36:30 -07001342 static const sp<Fence> kFence;
1343
1344 OutputLayerUncacheBufferTest() {
1345 auto& outputLayerState = mOutputLayer.editState();
1346 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer_);
1347
1348 mLayerFEState.compositionType = Composition::DEVICE;
1349 mLayerFEState.acquireFence = kFence;
1350
1351 ON_CALL(mOutput, getDisplayColorProfile()).WillByDefault(Return(&mDisplayColorProfile));
1352 }
1353
1354 std::shared_ptr<HWC2::mock::Layer> mHwcLayer_{std::make_shared<NiceMock<HWC2::mock::Layer>>()};
1355 HWC2::mock::Layer& mHwcLayer = *mHwcLayer_;
1356 NiceMock<mock::DisplayColorProfile> mDisplayColorProfile;
1357};
1358
1359const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer1 =
1360 sp<GraphicBuffer>::make(1, 2, PIXEL_FORMAT_RGBA_8888,
1361 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1362 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
1363const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer2 =
1364 sp<GraphicBuffer>::make(2, 3, PIXEL_FORMAT_RGBA_8888,
1365 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1366 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001367const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer3 =
1368 sp<GraphicBuffer>::make(4, 5, PIXEL_FORMAT_RGBA_8888,
1369 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1370 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Brian Lindahl90553da2022-12-06 13:36:30 -07001371const sp<Fence> OutputLayerUncacheBufferTest::kFence = sp<Fence>::make();
1372
1373TEST_F(OutputLayerUncacheBufferTest, canUncacheAndReuseSlot) {
1374 // Buffer1 is stored in slot 0
1375 mLayerFEState.buffer = kBuffer1;
1376 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 0, kBuffer1, kFence));
1377 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1378 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1379 Mock::VerifyAndClearExpectations(&mHwcLayer);
1380
1381 // Buffer2 is stored in slot 1
1382 mLayerFEState.buffer = kBuffer2;
1383 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, kBuffer2, kFence));
1384 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1385 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1386 Mock::VerifyAndClearExpectations(&mHwcLayer);
1387
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001388 // Buffer3 is stored in slot 2
1389 mLayerFEState.buffer = kBuffer3;
1390 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 2, kBuffer3, kFence));
1391 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1392 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Brian Lindahl90553da2022-12-06 13:36:30 -07001393 Mock::VerifyAndClearExpectations(&mHwcLayer);
1394
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001395 // Buffer2 becomes the active buffer again (with a nullptr) and reuses slot 1
1396 mLayerFEState.buffer = kBuffer2;
1397 sp<GraphicBuffer> nullBuffer = nullptr;
1398 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, nullBuffer, kFence));
1399 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1400 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1401 Mock::VerifyAndClearExpectations(&mHwcLayer);
1402
1403 // Buffer slots are cleared
1404 std::vector<uint32_t> slotsToClear = {0, 2, 1}; // order doesn't matter
1405 EXPECT_CALL(mHwcLayer, setBufferSlotsToClear(slotsToClear, /*activeBufferSlot*/ 1));
1406 // Uncache the active buffer in between other buffers to exercise correct algorithmic behavior.
1407 mOutputLayer.uncacheBuffers({kBuffer1->getId(), kBuffer2->getId(), kBuffer3->getId()});
1408 Mock::VerifyAndClearExpectations(&mHwcLayer);
1409
1410 // Buffer1 becomes active again, and rather than allocating a new slot, or re-using slot 0,
1411 // the active buffer slot (slot 1 for Buffer2) is reused first, which allows HWC to free the
1412 // memory for the active buffer. Note: slot 1 is different from the first and last buffer slot
1413 // requested to be cleared in slotsToClear (slot 1), above, indicating that the algorithm
1414 // correctly identifies the active buffer as the buffer in slot 1, despite ping-ponging.
Brian Lindahl90553da2022-12-06 13:36:30 -07001415 mLayerFEState.buffer = kBuffer1;
1416 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, kBuffer1, kFence));
1417 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1418 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1419 Mock::VerifyAndClearExpectations(&mHwcLayer);
Brian Lindahl90553da2022-12-06 13:36:30 -07001420}
1421
1422/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001423 * OutputLayer::writeCursorPositionToHWC()
1424 */
1425
1426struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1427 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -07001428 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001429
1430 static const Rect kDefaultDisplayViewport;
1431 static const Rect kDefaultCursorFrame;
1432
1433 OutputLayerWriteCursorPositionToHWCTest() {
1434 auto& outputLayerState = mOutputLayer.editState();
1435 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1436
Lloyd Pique9755fb72019-03-26 14:44:40 -07001437 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001438
Angel Aguayob084e0c2021-08-04 23:27:28 +00001439 mOutputState.layerStackSpace.setContent(kDefaultDisplayViewport);
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001440 mOutputState.transform = ui::Transform{kDefaultTransform};
1441 }
1442
1443 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1444};
1445
1446const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1447const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1448
Lloyd Piquede196652020-01-22 17:29:58 -08001449TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
Brian Lindahl90553da2022-12-06 13:36:30 -07001450 EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
Lloyd Piquede196652020-01-22 17:29:58 -08001451
1452 mOutputLayer.writeCursorPositionToHWC();
1453}
1454
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001455TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1456 mOutputLayer.editState().hwc.reset();
1457
1458 mOutputLayer.writeCursorPositionToHWC();
1459}
1460
1461TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1462 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1463
1464 mOutputLayer.writeCursorPositionToHWC();
1465}
1466
1467TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001468 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001469
1470 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1471
1472 mOutputLayer.writeCursorPositionToHWC();
1473}
1474
1475TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1476 mOutputState.transform = ui::Transform{TR_ROT_90};
1477
1478 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1479
1480 mOutputLayer.writeCursorPositionToHWC();
1481}
1482
1483/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001484 * OutputLayer::getHwcLayer()
1485 */
1486
1487TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1488 mOutputLayer.editState().hwc.reset();
1489
1490 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1491}
1492
1493TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1494 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1495
1496 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1497}
1498
1499TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1500 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1501 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1502
1503 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1504}
1505
1506/*
1507 * OutputLayer::requiresClientComposition()
1508 */
1509
1510TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1511 mOutputLayer.editState().hwc.reset();
1512
1513 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1514}
1515
1516TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1517 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001518 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Lloyd Pique66d68602019-02-13 14:23:31 -08001519
1520 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1521}
1522
1523TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1524 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001525 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001526
1527 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1528}
1529
1530/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001531 * OutputLayer::isHardwareCursor()
1532 */
1533
1534TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1535 mOutputLayer.editState().hwc.reset();
1536
1537 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1538}
1539
1540TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1541 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001542 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CURSOR;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001543
1544 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1545}
1546
1547TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1548 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001549 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001550
1551 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1552}
1553
1554/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001555 * OutputLayer::applyDeviceCompositionTypeChange()
1556 */
1557
1558TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1559 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001560 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001561
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001562 mOutputLayer.applyDeviceCompositionTypeChange(Composition::CLIENT);
Lloyd Pique66d68602019-02-13 14:23:31 -08001563
1564 ASSERT_TRUE(mOutputLayer.getState().hwc);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001565 EXPECT_EQ(Composition::CLIENT, mOutputLayer.getState().hwc->hwcCompositionType);
Lloyd Pique66d68602019-02-13 14:23:31 -08001566}
1567
1568/*
1569 * OutputLayer::prepareForDeviceLayerRequests()
1570 */
1571
1572TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1573 mOutputLayer.editState().clearClientTarget = true;
1574
1575 mOutputLayer.prepareForDeviceLayerRequests();
1576
1577 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1578}
1579
1580/*
1581 * OutputLayer::applyDeviceLayerRequest()
1582 */
1583
1584TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1585 mOutputLayer.editState().clearClientTarget = false;
1586
1587 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1588
1589 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1590}
1591
1592TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1593 mOutputLayer.editState().clearClientTarget = false;
1594
1595 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1596
1597 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1598}
1599
Lloyd Pique688abd42019-02-15 15:42:24 -08001600/*
1601 * OutputLayer::needsFiltering()
1602 */
1603
1604TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1605 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1606 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1607
1608 EXPECT_FALSE(mOutputLayer.needsFiltering());
1609}
1610
1611TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1612 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1613 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1614
1615 EXPECT_TRUE(mOutputLayer.needsFiltering());
1616}
1617
Alec Mourib6d78932023-09-20 16:05:42 +00001618TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfRotatedDisplaySizeSameAsSourceSize) {
1619 mOutputLayer.editState().displayFrame = Rect(100, 100, 300, 200);
1620 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 200.f};
1621 mOutputLayer.editState().bufferTransform = Hwc2::Transform::ROT_90;
1622
1623 EXPECT_FALSE(mOutputLayer.needsFiltering());
1624}
1625
1626TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfRotatedDisplaySizeDiffersFromSourceSize) {
1627 mOutputLayer.editState().displayFrame = Rect(100, 100, 300, 200);
1628 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 200.f};
1629
1630 EXPECT_TRUE(mOutputLayer.needsFiltering());
1631}
1632
Lloyd Piquecc01a452018-12-04 17:24:00 -08001633} // namespace
1634} // namespace android::compositionengine