blob: 034c768ff3685c6906ae40f3c1d9b13635bec8eb [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
Brian Lindahl1a4ffd82024-10-30 11:00:37 -060017#include <com_android_graphics_libgui_flags.h>
Alec Mourie7cc1c22021-04-27 15:23:26 -070018#include <compositionengine/impl/HwcBufferCache.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080019#include <compositionengine/impl/OutputLayer.h>
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070020#include <compositionengine/impl/OutputLayerCompositionState.h>
Lloyd Pique07e33212018-12-18 16:33:37 -080021#include <compositionengine/mock/CompositionEngine.h>
Lloyd Piquef5275482019-01-29 18:42:42 -080022#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080023#include <compositionengine/mock/LayerFE.h>
24#include <compositionengine/mock/Output.h>
25#include <gtest/gtest.h>
Marin Shalamanov68933fb2020-09-10 17:58:12 +020026#include <log/log.h>
Vishnu Nairdbbe3852022-01-12 20:22:11 -080027#include <renderengine/impl/ExternalTexture.h>
Alec Mouri03bf0ff2021-04-19 14:17:31 -070028#include <renderengine/mock/RenderEngine.h>
Lloyd Piquee98286f2024-09-16 16:23:24 -070029#include <ui/FloatRect.h>
Alec Mouri03bf0ff2021-04-19 14:17:31 -070030#include <ui/PixelFormat.h>
Lloyd Piquee98286f2024-09-16 16:23:24 -070031
Lloyd Piquef5275482019-01-29 18:42:42 -080032#include "RegionMatcher.h"
Lloyd Piquee98286f2024-09-16 16:23:24 -070033#include "mock/DisplayHardware/MockHWC2.h"
34#include "mock/DisplayHardware/MockHWComposer.h"
Lloyd Pique07e33212018-12-18 16:33:37 -080035
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050036#include <aidl/android/hardware/graphics/composer3/Composition.h>
37
38using aidl::android::hardware::graphics::composer3::Composition;
39
Lloyd Piquecc01a452018-12-04 17:24:00 -080040namespace android::compositionengine {
41namespace {
42
Peiyong Line9d809e2020-04-14 13:10:48 -070043namespace hal = android::hardware::graphics::composer::hal;
44
Lloyd Piquea83776c2019-01-29 18:42:32 -080045using testing::_;
Lloyd Pique46b72df2019-10-29 13:19:27 -070046using testing::InSequence;
Brian Lindahl90553da2022-12-06 13:36:30 -070047using testing::Mock;
48using testing::NiceMock;
Lloyd Piquea83776c2019-01-29 18:42:32 -080049using testing::Return;
50using testing::ReturnRef;
Lloyd Piquecc01a452018-12-04 17:24:00 -080051using testing::StrictMock;
52
Lloyd Piquea83776c2019-01-29 18:42:32 -080053constexpr auto TR_IDENT = 0u;
54constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H;
55constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V;
56constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
57constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V;
58constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180;
59
60const std::string kOutputName{"Test Output"};
61
Lloyd Piquef5275482019-01-29 18:42:42 -080062MATCHER_P(ColorEq, expected, "") {
63 *result_listener << "Colors are not equal\n";
64 *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " "
65 << expected.a << "\n";
66 *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n";
67
68 return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a;
69}
70
Marin Shalamanov68933fb2020-09-10 17:58:12 +020071ui::Rotation toRotation(uint32_t rotationFlag) {
72 switch (rotationFlag) {
73 case ui::Transform::RotationFlags::ROT_0:
74 return ui::ROTATION_0;
75 case ui::Transform::RotationFlags::ROT_90:
76 return ui::ROTATION_90;
77 case ui::Transform::RotationFlags::ROT_180:
78 return ui::ROTATION_180;
79 case ui::Transform::RotationFlags::ROT_270:
80 return ui::ROTATION_270;
81 default:
82 LOG_FATAL("Unexpected rotation flag %d", rotationFlag);
83 return ui::Rotation(-1);
84 }
85}
86
Lloyd Pique66d68602019-02-13 14:23:31 -080087struct OutputLayerTest : public testing::Test {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070088 struct OutputLayer final : public impl::OutputLayer {
Brian Lindahl90553da2022-12-06 13:36:30 -070089 OutputLayer(const compositionengine::Output& output, compositionengine::LayerFE& layerFE)
Lloyd Piquede196652020-01-22 17:29:58 -080090 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070091 ~OutputLayer() override = default;
92
93 // compositionengine::OutputLayer overrides
94 const compositionengine::Output& getOutput() const override { return mOutput; }
Brian Lindahl90553da2022-12-06 13:36:30 -070095 compositionengine::LayerFE& getLayerFE() const override { return mLayerFE; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070096 const impl::OutputLayerCompositionState& getState() const override { return mState; }
97 impl::OutputLayerCompositionState& editState() override { return mState; }
98
99 // compositionengine::impl::OutputLayer overrides
100 void dumpState(std::string& out) const override { mState.dump(out); }
101
102 const compositionengine::Output& mOutput;
Brian Lindahl90553da2022-12-06 13:36:30 -0700103 compositionengine::LayerFE& mLayerFE;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700104 impl::OutputLayerCompositionState mState;
105 };
106
Lloyd Piquea83776c2019-01-29 18:42:32 -0800107 OutputLayerTest() {
Brian Lindahl90553da2022-12-06 13:36:30 -0700108 ON_CALL(mLayerFE, getDebugName()).WillByDefault(Return("Test LayerFE"));
109 ON_CALL(mOutput, getName()).WillByDefault(ReturnRef(kOutputName));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800110
Brian Lindahl90553da2022-12-06 13:36:30 -0700111 ON_CALL(mLayerFE, getCompositionState()).WillByDefault(Return(&mLayerFEState));
112 ON_CALL(mOutput, getState()).WillByDefault(ReturnRef(mOutputState));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800113 }
114
Brian Lindahl90553da2022-12-06 13:36:30 -0700115 NiceMock<compositionengine::mock::Output> mOutput;
116 sp<NiceMock<compositionengine::mock::LayerFE>> mLayerFE_ =
117 sp<NiceMock<compositionengine::mock::LayerFE>>::make();
118 NiceMock<compositionengine::mock::LayerFE>& mLayerFE = *mLayerFE_;
Lloyd Piquede196652020-01-22 17:29:58 -0800119 OutputLayer mOutputLayer{mOutput, mLayerFE};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800120
Lloyd Pique9755fb72019-03-26 14:44:40 -0700121 LayerFECompositionState mLayerFEState;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800122 impl::OutputCompositionState mOutputState;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800123};
124
Lloyd Piquea83776c2019-01-29 18:42:32 -0800125/*
Lloyd Piquecc01a452018-12-04 17:24:00 -0800126 * Basic construction
127 */
128
129TEST_F(OutputLayerTest, canInstantiateOutputLayer) {}
130
Lloyd Piquea83776c2019-01-29 18:42:32 -0800131/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800132 * OutputLayer::setHwcLayer()
Lloyd Pique07e33212018-12-18 16:33:37 -0800133 */
134
Lloyd Piquedf336d92019-03-07 21:38:42 -0800135TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) {
Lloyd Pique07e33212018-12-18 16:33:37 -0800136 StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
137
Lloyd Piquedf336d92019-03-07 21:38:42 -0800138 mOutputLayer.setHwcLayer(nullptr);
Lloyd Pique07e33212018-12-18 16:33:37 -0800139
140 EXPECT_FALSE(mOutputLayer.getState().hwc);
141}
142
Lloyd Piquedf336d92019-03-07 21:38:42 -0800143TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) {
144 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Pique07e33212018-12-18 16:33:37 -0800145
Lloyd Piquedf336d92019-03-07 21:38:42 -0800146 mOutputLayer.setHwcLayer(hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800147
Lloyd Piquea83776c2019-01-29 18:42:32 -0800148 const auto& outputLayerState = mOutputLayer.getState();
149 ASSERT_TRUE(outputLayerState.hwc);
Lloyd Pique07e33212018-12-18 16:33:37 -0800150
Lloyd Piquea83776c2019-01-29 18:42:32 -0800151 const auto& hwcState = *outputLayerState.hwc;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800152 EXPECT_EQ(hwcLayer, hwcState.hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800153}
154
Lloyd Piquea83776c2019-01-29 18:42:32 -0800155/*
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000156 * OutputLayer::calculateOutputSourceCrop()
157 */
158
159struct OutputLayerSourceCropTest : public OutputLayerTest {
160 OutputLayerSourceCropTest() {
161 // Set reasonable default values for a simple case. Each test will
162 // set one specific value to something different.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700163 mLayerFEState.geomUsesSourceCrop = true;
164 mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080};
165 mLayerFEState.transparentRegionHint = Region{};
166 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
167 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
168 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
169 mLayerFEState.geomBufferTransform = TR_IDENT;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000170
Angel Aguayob084e0c2021-08-04 23:27:28 +0000171 mOutputState.layerStackSpace.setContent(Rect{0, 0, 1920, 1080});
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000172 }
173
174 FloatRect calculateOutputSourceCrop() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700175 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000176
ramindani2c043be2022-04-19 20:11:10 +0000177 return mOutputLayer.calculateOutputSourceCrop(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000178 }
179};
180
181TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700182 mLayerFEState.geomUsesSourceCrop = false;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000183
184 const FloatRect expected{};
Lloyd Piqueea629282019-12-03 15:57:10 -0800185 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000186}
187
188TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) {
189 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800190 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000191}
192
193TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700194 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000195
196 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800197 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000198}
199
200TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700201 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
202 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000203
204 const FloatRect expected{0.f, 0.f, 1080.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800205 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000206}
207
208TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) {
209 struct Entry {
210 uint32_t bufferInvDisplay;
211 uint32_t buffer;
212 uint32_t display;
213 FloatRect expected;
214 };
215 // Not an exhaustive list of cases, but hopefully enough.
216 const std::array<Entry, 12> testData = {
217 // clang-format off
218 // inv buffer display expected
219 /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
220 /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
221 /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
222 /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
223
224 /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
225 /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
226 /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
227 /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
228
229 /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
230 /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
231 /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
232 /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
233
234 // clang-format on
235 };
236
237 for (size_t i = 0; i < testData.size(); i++) {
238 const auto& entry = testData[i];
239
Lloyd Pique9755fb72019-03-26 14:44:40 -0700240 mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay;
241 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000242 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000243
Lloyd Piqueea629282019-12-03 15:57:10 -0800244 EXPECT_THAT(calculateOutputSourceCrop(), entry.expected) << "entry " << i;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000245 }
246}
247
248TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700249 mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000250
251 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800252 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000253}
254
255TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) {
Angel Aguayob084e0c2021-08-04 23:27:28 +0000256 mOutputState.layerStackSpace.setContent(Rect{0, 0, 960, 540});
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000257
258 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800259 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000260}
261
262/*
Lloyd Piquea83776c2019-01-29 18:42:32 -0800263 * OutputLayer::calculateOutputDisplayFrame()
264 */
265
266struct OutputLayerDisplayFrameTest : public OutputLayerTest {
267 OutputLayerDisplayFrameTest() {
268 // Set reasonable default values for a simple case. Each test will
269 // set one specific value to something different.
270
Lloyd Pique9755fb72019-03-26 14:44:40 -0700271 mLayerFEState.transparentRegionHint = Region{};
272 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
273 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
274 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
Vishnu Naira9123c82024-10-03 03:56:44 +0000275 mLayerFEState.geomCrop = FloatRect{0, 0, 1920, 1080};
Lloyd Pique9755fb72019-03-26 14:44:40 -0700276 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800277
Angel Aguayob084e0c2021-08-04 23:27:28 +0000278 mOutputState.layerStackSpace.setContent(Rect{0, 0, 1920, 1080});
Lloyd Piquea83776c2019-01-29 18:42:32 -0800279 mOutputState.transform = ui::Transform{TR_IDENT};
280 }
281
282 Rect calculateOutputDisplayFrame() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700283 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800284
285 return mOutputLayer.calculateOutputDisplayFrame();
286 }
287};
288
289TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) {
290 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800291 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800292}
293
294TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700295 mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800296 const Rect expected{0, 0, 0, 0};
Lloyd Piqueea629282019-12-03 15:57:10 -0800297 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800298}
299
300TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) {
Vishnu Naira9123c82024-10-03 03:56:44 +0000301 mLayerFEState.geomCrop = FloatRect{100, 200, 300, 500};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800302 const Rect expected{100, 200, 300, 500};
Lloyd Piqueea629282019-12-03 15:57:10 -0800303 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800304}
305
306TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) {
Vishnu Naira9123c82024-10-03 03:56:44 +0000307 mLayerFEState.geomCrop = FloatRect{100, 200, 300, 500};
Lloyd Pique9755fb72019-03-26 14:44:40 -0700308 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800309 const Rect expected{1420, 100, 1720, 300};
Lloyd Piqueea629282019-12-03 15:57:10 -0800310 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800311}
312
313TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) {
Vishnu Naira9123c82024-10-03 03:56:44 +0000314 mLayerFEState.geomCrop = FloatRect{};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800315 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800316 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800317}
318
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000319TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700320 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800321 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800322 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800323}
324
325TEST_F(OutputLayerDisplayFrameTest, viewportAffectsFrame) {
Angel Aguayob084e0c2021-08-04 23:27:28 +0000326 mOutputState.layerStackSpace.setContent(Rect{0, 0, 960, 540});
Lloyd Piquea83776c2019-01-29 18:42:32 -0800327 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800328 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800329}
330
331TEST_F(OutputLayerDisplayFrameTest, outputTransformAffectsDisplayFrame) {
332 mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90};
333 const Rect expected{-1080, 0, 0, 1920};
Lloyd Piqueea629282019-12-03 15:57:10 -0800334 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800335}
336
Leon Scroggins IIId394d3c2021-06-24 11:30:32 -0400337TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame) {
338 const int kShadowRadius = 5;
Vishnu Naird9e4f462023-10-06 04:05:45 +0000339 mLayerFEState.shadowSettings.length = kShadowRadius;
Leon Scroggins IIId394d3c2021-06-24 11:30:32 -0400340 mLayerFEState.forceClientComposition = true;
341
342 mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
343 Rect expected{mLayerFEState.geomLayerBounds};
Alec Mourida128512024-09-28 23:46:58 +0000344 expected.inset(-2 * kShadowRadius, -2 * kShadowRadius, -2 * kShadowRadius, -2 * kShadowRadius);
Leon Scroggins IIId394d3c2021-06-24 11:30:32 -0400345 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
346}
347
348TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame_onlyIfForcingClientComposition) {
349 const int kShadowRadius = 5;
Vishnu Naird9e4f462023-10-06 04:05:45 +0000350 mLayerFEState.shadowSettings.length = kShadowRadius;
Leon Scroggins IIId394d3c2021-06-24 11:30:32 -0400351 mLayerFEState.forceClientComposition = false;
352
353 mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
354 Rect expected{mLayerFEState.geomLayerBounds};
355 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
356}
357
Lloyd Piquea83776c2019-01-29 18:42:32 -0800358/*
359 * OutputLayer::calculateOutputRelativeBufferTransform()
360 */
361
362TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700363 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800364
365 struct Entry {
366 uint32_t layer;
367 uint32_t buffer;
368 uint32_t display;
369 uint32_t expected;
370 };
371 // Not an exhaustive list of cases, but hopefully enough.
372 const std::array<Entry, 24> testData = {
373 // clang-format off
374 // layer buffer display expected
375 /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
376 /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_90},
377 /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
378 /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270},
379
380 /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_IDENT},
381 /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_90},
382 /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_180},
383 /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_ROT_270},
384
385 /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V},
386 /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_180},
387 /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
388 /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_180},
389
390 /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_90},
391 /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_180},
392 /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT ^ TR_ROT_270},
393 /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_IDENT},
394
395 /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_ROT_180},
396 /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT ^ TR_ROT_270},
397 /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_IDENT},
398 /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_90},
399
400 /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_270},
401 /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_IDENT},
402 /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_90},
403 /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_180},
404 // clang-format on
405 };
406
407 for (size_t i = 0; i < testData.size(); i++) {
408 const auto& entry = testData[i];
409
Lloyd Pique9755fb72019-03-26 14:44:40 -0700410 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
411 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000412 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700413 mOutputState.transform = ui::Transform{entry.display};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800414
Snild Dolkow9e217d62020-04-22 15:53:42 +0200415 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.display);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800416 EXPECT_EQ(entry.expected, actual) << "entry " << i;
417 }
418}
419
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000420TEST_F(OutputLayerTest,
421 calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700422 mLayerFEState.geomBufferUsesDisplayInverseTransform = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000423
424 struct Entry {
Snild Dolkow9e217d62020-04-22 15:53:42 +0200425 uint32_t layer; /* shouldn't affect the result, so we just use arbitrary values */
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000426 uint32_t buffer;
427 uint32_t display;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200428 uint32_t internal;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000429 uint32_t expected;
430 };
Snild Dolkow9e217d62020-04-22 15:53:42 +0200431 const std::array<Entry, 64> testData = {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000432 // clang-format off
Snild Dolkow9e217d62020-04-22 15:53:42 +0200433 // layer buffer display internal expected
434 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
435 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_270},
436 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
437 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_90},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000438
Snild Dolkow9e217d62020-04-22 15:53:42 +0200439 Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT, TR_ROT_90},
440 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_90, TR_IDENT},
441 Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_180, TR_ROT_270},
442 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000443
Snild Dolkow9e217d62020-04-22 15:53:42 +0200444 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_180},
445 Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_90, TR_ROT_90},
446 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
447 Entry{TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000448
Snild Dolkow9e217d62020-04-22 15:53:42 +0200449 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270},
450 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_ROT_90, TR_ROT_180},
451 Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_180, TR_ROT_90},
452 Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000453
Snild Dolkow9e217d62020-04-22 15:53:42 +0200454 // layer buffer display internal expected
455 Entry{TR_IDENT, TR_ROT_90, TR_IDENT, TR_IDENT, TR_ROT_90},
456 Entry{TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_90, TR_IDENT},
457 Entry{TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_270},
458 Entry{TR_ROT_270, TR_ROT_90, TR_IDENT, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000459
Snild Dolkow9e217d62020-04-22 15:53:42 +0200460 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_180},
461 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90},
462 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_IDENT},
463 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270, TR_ROT_270},
464
465 Entry{TR_IDENT, TR_ROT_90, TR_ROT_180, TR_IDENT, TR_ROT_270},
466 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_180},
467 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_180, TR_ROT_90},
468 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_270, TR_IDENT},
469
470 Entry{TR_IDENT, TR_ROT_90, TR_ROT_270, TR_IDENT, TR_IDENT},
471 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270},
472 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_ROT_180, TR_ROT_180},
473 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90},
474
475 // layer buffer display internal expected
476 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_IDENT, TR_ROT_180},
477 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_90},
478 Entry{TR_ROT_180, TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT},
479 Entry{TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_270},
480
481 Entry{TR_IDENT, TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_270},
482 Entry{TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_90, TR_ROT_180},
483 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_90},
484 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_IDENT},
485
486 Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT, TR_IDENT},
487 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270},
488 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180},
489 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90},
490
491 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_IDENT, TR_ROT_90},
492 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_IDENT},
493 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_270},
494 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_270, TR_ROT_180},
495
496 // layer buffer display internal expected
497 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_IDENT, TR_ROT_270},
498 Entry{TR_ROT_90, TR_ROT_270, TR_IDENT, TR_ROT_90, TR_ROT_180},
499 Entry{TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_90},
500 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT},
501
502 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_IDENT, TR_IDENT},
503 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270},
504 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_ROT_180, TR_ROT_180},
505 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90},
506
507 Entry{TR_IDENT, TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_90},
508 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_90, TR_IDENT},
509 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270},
510 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_180},
511
512 Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180},
513 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_ROT_90},
514 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_IDENT},
515 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000516 // clang-format on
517 };
518
519 for (size_t i = 0; i < testData.size(); i++) {
520 const auto& entry = testData[i];
521
Snild Dolkow9e217d62020-04-22 15:53:42 +0200522 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
Lloyd Pique9755fb72019-03-26 14:44:40 -0700523 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000524 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700525 mOutputState.transform = ui::Transform{entry.display};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000526
Snild Dolkow9e217d62020-04-22 15:53:42 +0200527 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.internal);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000528 EXPECT_EQ(entry.expected, actual) << "entry " << i;
529 }
530}
531
532/*
533 * OutputLayer::updateCompositionState()
534 */
535
536struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer {
537 OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output,
Brian Lindahl90553da2022-12-06 13:36:30 -0700538 compositionengine::LayerFE& layerFE)
Lloyd Piquede196652020-01-22 17:29:58 -0800539 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000540 // Mock everything called by updateCompositionState to simplify testing it.
ramindani2c043be2022-04-19 20:11:10 +0000541 MOCK_CONST_METHOD1(calculateOutputSourceCrop, FloatRect(uint32_t));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000542 MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect());
Snild Dolkow9e217d62020-04-22 15:53:42 +0200543 MOCK_CONST_METHOD1(calculateOutputRelativeBufferTransform, uint32_t(uint32_t));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700544
545 // compositionengine::OutputLayer overrides
546 const compositionengine::Output& getOutput() const override { return mOutput; }
Brian Lindahl90553da2022-12-06 13:36:30 -0700547 compositionengine::LayerFE& getLayerFE() const override { return mLayerFE; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700548 const impl::OutputLayerCompositionState& getState() const override { return mState; }
549 impl::OutputLayerCompositionState& editState() override { return mState; }
550
551 // These need implementations though are not expected to be called.
552 MOCK_CONST_METHOD1(dumpState, void(std::string&));
553
554 const compositionengine::Output& mOutput;
Brian Lindahl90553da2022-12-06 13:36:30 -0700555 compositionengine::LayerFE& mLayerFE;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700556 impl::OutputLayerCompositionState mState;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000557};
558
559struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest {
560public:
561 OutputLayerUpdateCompositionStateTest() {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000562 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
Lloyd Piquef5275482019-01-29 18:42:42 -0800563 EXPECT_CALL(mOutput, getDisplayColorProfile())
564 .WillRepeatedly(Return(&mDisplayColorProfile));
565 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000566 }
567
568 ~OutputLayerUpdateCompositionStateTest() = default;
569
Snild Dolkow9e217d62020-04-22 15:53:42 +0200570 void setupGeometryChildCallValues(ui::Transform::RotationFlags internalDisplayRotationFlags) {
ramindani2c043be2022-04-19 20:11:10 +0000571 EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop(internalDisplayRotationFlags))
572 .WillOnce(Return(kSourceCrop));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000573 EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200574 EXPECT_CALL(mOutputLayer,
575 calculateOutputRelativeBufferTransform(internalDisplayRotationFlags))
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000576 .WillOnce(Return(mBufferTransform));
577 }
578
579 void validateComputedGeometryState() {
580 const auto& state = mOutputLayer.getState();
581 EXPECT_EQ(kSourceCrop, state.sourceCrop);
582 EXPECT_EQ(kDisplayFrame, state.displayFrame);
583 EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform);
584 }
585
586 const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f};
587 const Rect kDisplayFrame{11, 12, 13, 14};
588 uint32_t mBufferTransform{21};
589
590 using OutputLayer = OutputLayerPartialMockForUpdateCompositionState;
Lloyd Piquede196652020-01-22 17:29:58 -0800591 StrictMock<OutputLayer> mOutputLayer{mOutput, mLayerFE};
Lloyd Piquef5275482019-01-29 18:42:42 -0800592 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000593};
594
Lloyd Piquede196652020-01-22 17:29:58 -0800595TEST_F(OutputLayerUpdateCompositionStateTest, doesNothingIfNoFECompositionState) {
Brian Lindahl90553da2022-12-06 13:36:30 -0700596 EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
Lloyd Piquede196652020-01-22 17:29:58 -0800597
Snild Dolkow9e217d62020-04-22 15:53:42 +0200598 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Piquede196652020-01-22 17:29:58 -0800599}
600
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000601TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700602 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000603 mOutputState.isSecure = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700604 mOutputLayer.editState().forceClientComposition = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000605
Snild Dolkow9e217d62020-04-22 15:53:42 +0200606 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000607
Snild Dolkow9e217d62020-04-22 15:53:42 +0200608 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000609
610 validateComputedGeometryState();
611
612 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
613}
614
615TEST_F(OutputLayerUpdateCompositionStateTest,
616 alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700617 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000618 mOutputState.isSecure = false;
619
Snild Dolkow9e217d62020-04-22 15:53:42 +0200620 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000621
Snild Dolkow9e217d62020-04-22 15:53:42 +0200622 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000623
624 validateComputedGeometryState();
625
626 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
627}
628
629TEST_F(OutputLayerUpdateCompositionStateTest,
630 alsoSetsForceCompositionIfUnsupportedBufferTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700631 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000632 mOutputState.isSecure = true;
633
634 mBufferTransform = ui::Transform::ROT_INVALID;
635
Snild Dolkow9e217d62020-04-22 15:53:42 +0200636 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000637
Snild Dolkow9e217d62020-04-22 15:53:42 +0200638 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000639
640 validateComputedGeometryState();
641
642 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
643}
644
Lloyd Piquef5275482019-01-29 18:42:42 -0800645TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700646 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
Alec Mouri88790f32023-07-21 01:25:14 +0000647 mOutputState.dataspace = ui::Dataspace::V0_SCRGB;
Lloyd Piquef5275482019-01-29 18:42:42 -0800648
649 // If the layer is not colorspace agnostic, the output layer dataspace
650 // should use the layers requested colorspace.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700651 mLayerFEState.isColorspaceAgnostic = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800652
Snild Dolkow9e217d62020-04-22 15:53:42 +0200653 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800654
655 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
656
657 // If the layer is colorspace agnostic, the output layer dataspace
658 // should use the colorspace chosen for the whole output.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700659 mLayerFEState.isColorspaceAgnostic = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800660
Snild Dolkow9e217d62020-04-22 15:53:42 +0200661 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800662
663 EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace);
Alec Mouri88790f32023-07-21 01:25:14 +0000664
665 // If the output is HDR, then don't blind the user with a colorspace agnostic dataspace
666 // drawing all white
667 mOutputState.dataspace = ui::Dataspace::BT2020_PQ;
668
669 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
670
671 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
Lloyd Piquef5275482019-01-29 18:42:42 -0800672}
673
Alec Mouridda07d92022-04-25 22:39:25 +0000674TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceWith170mReplacement) {
675 mLayerFEState.dataspace = ui::Dataspace::TRANSFER_SMPTE_170M;
Alec Mouridda07d92022-04-25 22:39:25 +0000676 mOutputState.treat170mAsSrgb = false;
677 mLayerFEState.isColorspaceAgnostic = false;
678
679 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
680
681 EXPECT_EQ(ui::Dataspace::TRANSFER_SMPTE_170M, mOutputLayer.getState().dataspace);
682
683 // Rewrite SMPTE 170M as sRGB
684 mOutputState.treat170mAsSrgb = true;
685 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
686
687 EXPECT_EQ(ui::Dataspace::TRANSFER_SRGB, mOutputLayer.getState().dataspace);
688}
689
Alec Mourie8dd3562022-02-11 14:18:57 -0800690TEST_F(OutputLayerUpdateCompositionStateTest, setsWhitePointNitsAndDimmingRatioCorrectly) {
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700691 mOutputState.sdrWhitePointNits = 200.f;
692 mOutputState.displayBrightnessNits = 800.f;
693
694 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
695 mLayerFEState.isColorspaceAgnostic = false;
696 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
697 EXPECT_EQ(mOutputState.sdrWhitePointNits, mOutputLayer.getState().whitePointNits);
Alec Mourie8dd3562022-02-11 14:18:57 -0800698 EXPECT_EQ(mOutputState.sdrWhitePointNits / mOutputState.displayBrightnessNits,
699 mOutputLayer.getState().dimmingRatio);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700700
Sally Qi81d95e62022-03-21 19:41:33 -0700701 mLayerFEState.dimmingEnabled = false;
702 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
703 EXPECT_EQ(mOutputState.displayBrightnessNits, mOutputLayer.getState().whitePointNits);
704 EXPECT_EQ(1.f, mOutputLayer.getState().dimmingRatio);
705
706 // change dimmingEnabled back to true.
707 mLayerFEState.dimmingEnabled = true;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700708 mLayerFEState.dataspace = ui::Dataspace::BT2020_ITU_PQ;
709 mLayerFEState.isColorspaceAgnostic = false;
710 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
711
712 EXPECT_EQ(mOutputState.displayBrightnessNits, mOutputLayer.getState().whitePointNits);
Alec Mourie8dd3562022-02-11 14:18:57 -0800713 EXPECT_EQ(1.f, mOutputLayer.getState().dimmingRatio);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700714}
715
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000716TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700717 mOutputLayer.editState().forceClientComposition = false;
718
Snild Dolkow9e217d62020-04-22 15:53:42 +0200719 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000720
721 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
722}
723
Lloyd Piquefe671022019-09-24 10:43:03 -0700724TEST_F(OutputLayerUpdateCompositionStateTest,
725 doesNotClearForceClientCompositionIfNotDoingGeometry) {
726 mOutputLayer.editState().forceClientComposition = true;
727
Snild Dolkow9e217d62020-04-22 15:53:42 +0200728 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquefe671022019-09-24 10:43:03 -0700729
730 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
731}
732
Lloyd Piquef5275482019-01-29 18:42:42 -0800733TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700734 mLayerFEState.forceClientComposition = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700735 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800736
Snild Dolkow9e217d62020-04-22 15:53:42 +0200737 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800738
739 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
740}
741
742TEST_F(OutputLayerUpdateCompositionStateTest,
743 clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700744 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800745 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false));
746
Snild Dolkow9e217d62020-04-22 15:53:42 +0200747 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700748
749 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
750}
751
752TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromArgumentFlag) {
753 mLayerFEState.forceClientComposition = false;
754 mOutputLayer.editState().forceClientComposition = false;
755
Snild Dolkow9e217d62020-04-22 15:53:42 +0200756 mOutputLayer.updateCompositionState(false, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700757
758 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
759
760 mOutputLayer.editState().forceClientComposition = false;
761
Snild Dolkow9e217d62020-04-22 15:53:42 +0200762 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700763
Snild Dolkow9e217d62020-04-22 15:53:42 +0200764 mOutputLayer.updateCompositionState(true, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800765
766 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
767}
768
Lloyd Piquea83776c2019-01-29 18:42:32 -0800769/*
770 * OutputLayer::writeStateToHWC()
771 */
772
773struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
Peiyong Line9d809e2020-04-14 13:10:48 -0700774 static constexpr hal::Error kError = hal::Error::UNSUPPORTED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800775 static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800776 static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31);
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700777 static constexpr Hwc2::Transform kOverrideBufferTransform = static_cast<Hwc2::Transform>(0);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800778 static constexpr Hwc2::IComposerClient::BlendMode kBlendMode =
779 static_cast<Hwc2::IComposerClient::BlendMode>(41);
Alec Mouriee69a592021-03-23 15:00:45 -0700780 static constexpr Hwc2::IComposerClient::BlendMode kOverrideBlendMode =
781 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800782 static constexpr float kAlpha = 51.f;
Alec Mouriee69a592021-03-23 15:00:45 -0700783 static constexpr float kOverrideAlpha = 1.f;
Alec Mouri96ca45c2021-06-09 17:32:26 -0700784 static constexpr float kSkipAlpha = 0.f;
Lloyd Piquef5275482019-01-29 18:42:42 -0800785 static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
Alec Mourib7edfc22021-03-17 16:20:26 -0700786 static constexpr ui::Dataspace kOverrideDataspace = static_cast<ui::Dataspace>(72);
Lloyd Piquef5275482019-01-29 18:42:42 -0800787 static constexpr int kSupportedPerFrameMetadata = 101;
788 static constexpr int kExpectedHwcSlot = 0;
Brian Lindahl439afad2022-11-14 11:16:55 -0700789 static constexpr int kOverrideHwcSlot = impl::HwcBufferCache::kOverrideBufferSlot;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800790 static constexpr bool kLayerGenericMetadata1Mandatory = true;
791 static constexpr bool kLayerGenericMetadata2Mandatory = true;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700792 static constexpr float kWhitePointNits = 200.f;
Alec Mourie8dd3562022-02-11 14:18:57 -0800793 static constexpr float kSdrWhitePointNits = 100.f;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700794 static constexpr float kDisplayBrightnessNits = 400.f;
Alec Mouri6da0e272022-02-07 12:45:57 -0800795 static constexpr float kLayerBrightness = kWhitePointNits / kDisplayBrightnessNits;
Alec Mourie8dd3562022-02-11 14:18:57 -0800796 static constexpr float kOverrideLayerBrightness = kSdrWhitePointNits / kDisplayBrightnessNits;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800797
Lloyd Piquef5275482019-01-29 18:42:42 -0800798 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800799 static const Rect kDisplayFrame;
Alec Mourib7edfc22021-03-17 16:20:26 -0700800 static const Rect kOverrideDisplayFrame;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700801 static const FloatRect kOverrideSourceCrop;
Lloyd Piquea2468662019-03-07 21:31:06 -0800802 static const Region kOutputSpaceVisibleRegion;
Alec Mouri464352b2021-03-24 16:33:21 -0700803 static const Region kOverrideVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800804 static const mat4 kColorTransform;
805 static const Region kSurfaceDamage;
Alec Mouri464352b2021-03-24 16:33:21 -0700806 static const Region kOverrideSurfaceDamage;
Lloyd Piquef5275482019-01-29 18:42:42 -0800807 static const HdrMetadata kHdrMetadata;
808 static native_handle_t* kSidebandStreamHandle;
809 static const sp<GraphicBuffer> kBuffer;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700810 static const sp<GraphicBuffer> kOverrideBuffer;
Lloyd Piquef5275482019-01-29 18:42:42 -0800811 static const sp<Fence> kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700812 static const sp<Fence> kOverrideFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800813 static const std::string kLayerGenericMetadata1Key;
814 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
815 static const std::string kLayerGenericMetadata2Key;
816 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800817
818 OutputLayerWriteStateToHWCTest() {
819 auto& outputLayerState = mOutputLayer.editState();
820 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
821
822 outputLayerState.displayFrame = kDisplayFrame;
823 outputLayerState.sourceCrop = kSourceCrop;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800824 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800825 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800826 outputLayerState.dataspace = kDataspace;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700827 outputLayerState.whitePointNits = kWhitePointNits;
Alec Mouri6da0e272022-02-07 12:45:57 -0800828 outputLayerState.dimmingRatio = kLayerBrightness;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800829
Lloyd Pique9755fb72019-03-26 14:44:40 -0700830 mLayerFEState.blendMode = kBlendMode;
831 mLayerFEState.alpha = kAlpha;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700832 mLayerFEState.colorTransform = kColorTransform;
833 mLayerFEState.color = kColor;
834 mLayerFEState.surfaceDamage = kSurfaceDamage;
835 mLayerFEState.hdrMetadata = kHdrMetadata;
836 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
837 mLayerFEState.buffer = kBuffer;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700838 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800839
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700840 mOutputState.displayBrightnessNits = kDisplayBrightnessNits;
Alec Mourie8dd3562022-02-11 14:18:57 -0800841 mOutputState.sdrWhitePointNits = kSdrWhitePointNits;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700842
Lloyd Piquef5275482019-01-29 18:42:42 -0800843 EXPECT_CALL(mOutput, getDisplayColorProfile())
844 .WillRepeatedly(Return(&mDisplayColorProfile));
845 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
846 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800847 }
Lloyd Piquef5275482019-01-29 18:42:42 -0800848 // Some tests may need to simulate unsupported HWC calls
849 enum class SimulateUnsupported { None, ColorTransform };
850
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800851 void includeGenericLayerMetadataInState() {
852 mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory,
853 kLayerGenericMetadata1Value};
854 mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory,
855 kLayerGenericMetadata2Value};
856 }
857
Alec Mourib7edfc22021-03-17 16:20:26 -0700858 void includeOverrideInfo() {
859 auto& overrideInfo = mOutputLayer.editState().overrideInfo;
860
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700861 overrideInfo.buffer = std::make_shared<
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800862 renderengine::impl::ExternalTexture>(kOverrideBuffer, mRenderEngine,
863 renderengine::impl::ExternalTexture::Usage::
864 READABLE |
865 renderengine::impl::ExternalTexture::
866 Usage::WRITEABLE);
Alec Mourib7edfc22021-03-17 16:20:26 -0700867 overrideInfo.acquireFence = kOverrideFence;
868 overrideInfo.displayFrame = kOverrideDisplayFrame;
869 overrideInfo.dataspace = kOverrideDataspace;
Alec Mouri464352b2021-03-24 16:33:21 -0700870 overrideInfo.damageRegion = kOverrideSurfaceDamage;
871 overrideInfo.visibleRegion = kOverrideVisibleRegion;
Alec Mourib7edfc22021-03-17 16:20:26 -0700872 }
873
874 void expectGeometryCommonCalls(Rect displayFrame = kDisplayFrame,
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700875 FloatRect sourceCrop = kSourceCrop,
Alec Mouriee69a592021-03-23 15:00:45 -0700876 Hwc2::Transform bufferTransform = kBufferTransform,
877 Hwc2::IComposerClient::BlendMode blendMode = kBlendMode,
878 float alpha = kAlpha) {
Alec Mourib7edfc22021-03-17 16:20:26 -0700879 EXPECT_CALL(*mHwcLayer, setDisplayFrame(displayFrame)).WillOnce(Return(kError));
880 EXPECT_CALL(*mHwcLayer, setSourceCrop(sourceCrop)).WillOnce(Return(kError));
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400881 EXPECT_CALL(*mHwcLayer, setZOrder(_)).WillOnce(Return(kError));
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700882 EXPECT_CALL(*mHwcLayer, setTransform(bufferTransform)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800883
Alec Mouriee69a592021-03-23 15:00:45 -0700884 EXPECT_CALL(*mHwcLayer, setBlendMode(blendMode)).WillOnce(Return(kError));
885 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(alpha)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800886 }
887
Alec Mourib7edfc22021-03-17 16:20:26 -0700888 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None,
Alec Mouri464352b2021-03-24 16:33:21 -0700889 ui::Dataspace dataspace = kDataspace,
890 const Region& visibleRegion = kOutputSpaceVisibleRegion,
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700891 const Region& surfaceDamage = kSurfaceDamage,
Alec Mouri6da0e272022-02-07 12:45:57 -0800892 float brightness = kLayerBrightness,
Leon Scroggins III9a0afda2022-01-11 16:53:09 -0500893 const Region& blockingRegion = Region()) {
Alec Mouri464352b2021-03-24 16:33:21 -0700894 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(visibleRegion))).WillOnce(Return(kError));
Alec Mourib7edfc22021-03-17 16:20:26 -0700895 EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError));
Alec Mouri6da0e272022-02-07 12:45:57 -0800896 EXPECT_CALL(*mHwcLayer, setBrightness(brightness)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800897 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
898 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700899 ? hal::Error::UNSUPPORTED
900 : hal::Error::NONE));
Alec Mouri464352b2021-03-24 16:33:21 -0700901 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(surfaceDamage))).WillOnce(Return(kError));
Leon Scroggins III9a0afda2022-01-11 16:53:09 -0500902 EXPECT_CALL(*mHwcLayer, setBlockingRegion(RegionEq(blockingRegion)))
903 .WillOnce(Return(kError));
Sally Qi36349ac2024-11-25 08:00:26 +0000904 EXPECT_CALL(*mHwcLayer, setLuts(_)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800905 }
906
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500907 void expectSetCompositionTypeCall(Composition compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700908 EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800909 }
910
911 void expectNoSetCompositionTypeCall() {
912 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
913 }
914
915 void expectSetColorCall() {
Ady Abraham6e60b142022-01-06 18:10:35 -0800916 const aidl::android::hardware::graphics::composer3::Color color = {kColor.r, kColor.g,
917 kColor.b, 1.0f};
Lloyd Piquef5275482019-01-29 18:42:42 -0800918
919 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
920 }
921
922 void expectSetSidebandHandleCall() {
923 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
924 }
925
Alec Mourie7cc1c22021-04-27 15:23:26 -0700926 void expectSetHdrMetadataAndBufferCalls(uint32_t hwcSlot = kExpectedHwcSlot,
927 sp<GraphicBuffer> buffer = kBuffer,
Alec Mourib7edfc22021-03-17 16:20:26 -0700928 sp<Fence> fence = kFence) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800929 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
Alec Mourie7cc1c22021-04-27 15:23:26 -0700930 EXPECT_CALL(*mHwcLayer, setBuffer(hwcSlot, buffer, fence));
Lloyd Piquef5275482019-01-29 18:42:42 -0800931 }
932
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800933 void expectGenericLayerMetadataCalls() {
934 // Note: Can be in any order.
935 EXPECT_CALL(*mHwcLayer,
936 setLayerGenericMetadata(kLayerGenericMetadata1Key,
937 kLayerGenericMetadata1Mandatory,
938 kLayerGenericMetadata1Value));
939 EXPECT_CALL(*mHwcLayer,
940 setLayerGenericMetadata(kLayerGenericMetadata2Key,
941 kLayerGenericMetadata2Mandatory,
942 kLayerGenericMetadata2Value));
943 }
944
Lloyd Piquea83776c2019-01-29 18:42:32 -0800945 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800946 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Alec Mouria90a5702021-04-16 16:36:21 +0000947 renderengine::mock::RenderEngine mRenderEngine;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800948};
949
Lloyd Piquef5275482019-01-29 18:42:42 -0800950const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
951 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800952const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Alec Mourib7edfc22021-03-17 16:20:26 -0700953const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044};
Wiwit Rifa'i50abed02022-05-24 02:24:33 +0000954const FloatRect OutputLayerWriteStateToHWCTest::kOverrideSourceCrop{0.f, 0.f, 4.f, 5.f};
Lloyd Piquea2468662019-03-07 21:31:06 -0800955const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
956 Rect{1005, 1006, 1007, 1008}};
Alec Mouri464352b2021-03-24 16:33:21 -0700957const Region OutputLayerWriteStateToHWCTest::kOverrideVisibleRegion{Rect{1006, 1007, 1008, 1009}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800958const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
959 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
960 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
961};
962const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
Alec Mouri464352b2021-03-24 16:33:21 -0700963const Region OutputLayerWriteStateToHWCTest::kOverrideSurfaceDamage{Rect{1026, 1027, 1028, 1029}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800964const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
965native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
966 reinterpret_cast<native_handle_t*>(1031);
Brian Lindahl90553da2022-12-06 13:36:30 -0700967const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer =
968 sp<GraphicBuffer>::make(1, 2, PIXEL_FORMAT_RGBA_8888,
969 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
970 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700971const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kOverrideBuffer =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700972 sp<GraphicBuffer>::make(4, 5, PIXEL_FORMAT_RGBA_8888,
973 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
974 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Lloyd Piquef5275482019-01-29 18:42:42 -0800975const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700976const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = sp<Fence>::make();
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800977const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
978 "com.example.metadata.1";
979const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
980const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
981 "com.example.metadata.2";
982const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
983 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800984
Lloyd Piquede196652020-01-22 17:29:58 -0800985TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
Brian Lindahl90553da2022-12-06 13:36:30 -0700986 EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
Lloyd Piquede196652020-01-22 17:29:58 -0800987
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400988 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
989 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquede196652020-01-22 17:29:58 -0800990}
991
Lloyd Piquea83776c2019-01-29 18:42:32 -0800992TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
993 mOutputLayer.editState().hwc.reset();
994
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400995 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
996 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800997}
998
999TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
1000 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
1001
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001002 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1003 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -08001004}
1005
Lloyd Piquef5275482019-01-29 18:42:42 -08001006TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -08001007 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -08001008 expectPerFrameCommonCalls();
1009
1010 expectNoSetCompositionTypeCall();
Brian Lindahl90553da2022-12-06 13:36:30 -07001011 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Piquea83776c2019-01-29 18:42:32 -08001012
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001013 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1014 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -08001015}
1016
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001017TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
1018 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
1019 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
1020 // This test simulates a scenario where displayInstallOrientation is set to
1021 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
1022 // DisplayDevice::setProjection).
Angel Aguayob084e0c2021-08-04 23:27:28 +00001023 mOutputState.displaySpace.setOrientation(ui::ROTATION_0);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001024 mOutputState.transform = ui::Transform{TR_ROT_90};
1025 // Buffers are pre-rotated based on the transform hint (ROT_90); their
1026 // geomBufferTransform is set to the inverse transform.
1027 mLayerFEState.geomBufferTransform = TR_ROT_270;
1028
Snild Dolkow9e217d62020-04-22 15:53:42 +02001029 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001030}
1031
Lloyd Piquef5275482019-01-29 18:42:42 -08001032TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001033 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001034
1035 expectPerFrameCommonCalls();
Lloyd Pique46b72df2019-10-29 13:19:27 -07001036
1037 // Setting the composition type should happen before setting the color. We
1038 // check this in this test only by setting up an testing::InSeqeuence
1039 // instance before setting up the two expectations.
1040 InSequence s;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001041 expectSetCompositionTypeCall(Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -07001042 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -08001043
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001044 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1045 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001046}
1047
1048TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001049 mLayerFEState.compositionType = Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -08001050
1051 expectPerFrameCommonCalls();
1052 expectSetSidebandHandleCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001053 expectSetCompositionTypeCall(Composition::SIDEBAND);
Lloyd Piquef5275482019-01-29 18:42:42 -08001054
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001055 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1056 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001057}
1058
1059TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001060 mLayerFEState.compositionType = Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001061
1062 expectPerFrameCommonCalls();
1063 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001064 expectSetCompositionTypeCall(Composition::CURSOR);
Lloyd Piquef5275482019-01-29 18:42:42 -08001065
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001066 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1067 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001068}
1069
1070TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001071 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -08001072
1073 expectPerFrameCommonCalls();
1074 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001075 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Piquef5275482019-01-29 18:42:42 -08001076
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001077 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1078 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001079}
1080
1081TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001082 (*mOutputLayer.editState().hwc).hwcCompositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001083
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001084 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001085
1086 expectPerFrameCommonCalls();
1087 expectSetColorCall();
1088 expectNoSetCompositionTypeCall();
1089
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001090 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1091 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001092}
1093
1094TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001095 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001096
1097 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
1098 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001099 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001100
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001101 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1102 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001103}
1104
1105TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
1106 mOutputLayer.editState().forceClientComposition = true;
1107
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001108 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001109
1110 expectPerFrameCommonCalls();
1111 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001112 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001113
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001114 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1115 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001116}
1117
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001118TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001119 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001120 includeGenericLayerMetadataInState();
1121
1122 expectGeometryCommonCalls();
1123 expectPerFrameCommonCalls();
1124 expectSetHdrMetadataAndBufferCalls();
1125 expectGenericLayerMetadataCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001126 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001127
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001128 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1129 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001130}
1131
1132TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001133 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001134 includeGenericLayerMetadataInState();
1135
1136 expectPerFrameCommonCalls();
1137 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001138 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001139
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001140 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1141 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001142}
1143
Alec Mouri96ca45c2021-06-09 17:32:26 -07001144TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001145 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mouri96ca45c2021-06-09 17:32:26 -07001146 includeOverrideInfo();
1147
1148 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1149 kOverrideBlendMode, kSkipAlpha);
1150 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001151 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001152 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001153 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001154
1155 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1156 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1157}
1158
Alec Mouri2b1212b2021-12-09 12:02:39 -08001159TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerForSolidColorDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001160 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri2b1212b2021-12-09 12:02:39 -08001161 includeOverrideInfo();
1162
1163 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1164 kOverrideBlendMode, kSkipAlpha);
1165 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001166 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001167 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001168 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001169
1170 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1171 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1172}
1173
Alec Mourib7edfc22021-03-17 16:20:26 -07001174TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001175 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourib7edfc22021-03-17 16:20:26 -07001176 includeOverrideInfo();
1177
Alec Mouri03bf0ff2021-04-19 14:17:31 -07001178 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1179 kOverrideBlendMode, kOverrideAlpha);
Alec Mouri464352b2021-03-24 16:33:21 -07001180 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001181 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mourie7cc1c22021-04-27 15:23:26 -07001182 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001183 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001184
1185 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1186 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1187}
1188
Alec Mouri028676a2021-12-02 15:01:48 -08001189TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoForSolidColorIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001190 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri028676a2021-12-02 15:01:48 -08001191 includeOverrideInfo();
1192
1193 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1194 kOverrideBlendMode, kOverrideAlpha);
1195 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001196 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri028676a2021-12-02 15:01:48 -08001197 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001198 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri028676a2021-12-02 15:01:48 -08001199
1200 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1201 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1202}
1203
Alec Mourid1bf1b52021-05-05 18:44:58 -07001204TEST_F(OutputLayerWriteStateToHWCTest, previousOverriddenLayerSendsSurfaceDamage) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001205 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001206 mOutputLayer.editState().hwc->stateOverridden = true;
1207
1208 expectGeometryCommonCalls();
1209 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1210 Region::INVALID_REGION);
1211 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001212 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001213
1214 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1215 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1216}
1217
1218TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedDeviceCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001219 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001220 mOutputLayer.editState().hwc->stateOverridden = true;
1221 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001222 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001223
1224 expectGeometryCommonCalls();
1225 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1226 Region::INVALID_REGION);
1227 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001228 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001229
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001230 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1231 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Alec Mourib7edfc22021-03-17 16:20:26 -07001232}
1233
Alec Mourid1bf1b52021-05-05 18:44:58 -07001234TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedClientCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001235 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001236 mOutputLayer.editState().forceClientComposition = true;
1237 mOutputLayer.editState().hwc->stateOverridden = true;
1238 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001239 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001240
1241 expectGeometryCommonCalls();
1242 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1243 Region::INVALID_REGION);
1244 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001245 expectSetCompositionTypeCall(Composition::CLIENT);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001246
1247 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1248 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1249}
1250
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001251TEST_F(OutputLayerWriteStateToHWCTest, peekThroughChangesBlendMode) {
Brian Lindahl90553da2022-12-06 13:36:30 -07001252 auto peekThroughLayerFE = sp<NiceMock<compositionengine::mock::LayerFE>>::make();
1253 OutputLayer peekThroughLayer{mOutput, *peekThroughLayerFE};
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001254
1255 mOutputLayer.mState.overrideInfo.peekThroughLayer = &peekThroughLayer;
1256
1257 expectGeometryCommonCalls(kDisplayFrame, kSourceCrop, kBufferTransform,
1258 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED);
1259 expectPerFrameCommonCalls();
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001260
1261 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1262 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1263}
1264
1265TEST_F(OutputLayerWriteStateToHWCTest, isPeekingThroughSetsOverride) {
1266 expectGeometryCommonCalls();
1267 expectPerFrameCommonCalls();
1268
1269 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1270 /*zIsOverridden*/ false, /*isPeekingThrough*/ true);
1271 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1272}
1273
1274TEST_F(OutputLayerWriteStateToHWCTest, zIsOverriddenSetsOverride) {
1275 expectGeometryCommonCalls();
1276 expectPerFrameCommonCalls();
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001277
1278 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1279 /*zIsOverridden*/ true, /*isPeekingThrough*/
1280 false);
1281 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1282}
1283
1284TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersForceClientComposition) {
1285 expectGeometryCommonCalls();
1286 expectPerFrameCommonCalls();
Brian Lindahl90553da2022-12-06 13:36:30 -07001287 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillOnce(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001288 expectSetCompositionTypeCall(Composition::CLIENT);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001289
1290 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1291 /*zIsOverridden*/ false, /*isPeekingThrough*/
1292 false);
1293}
1294
1295TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersPeekingThroughAllowsDeviceComposition) {
1296 expectGeometryCommonCalls();
1297 expectPerFrameCommonCalls();
1298 expectSetHdrMetadataAndBufferCalls();
Brian Lindahl90553da2022-12-06 13:36:30 -07001299 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001300 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001301
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001302 mLayerFEState.compositionType = Composition::DEVICE;
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001303 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1304 /*zIsOverridden*/ false, /*isPeekingThrough*/
1305 true);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001306 EXPECT_EQ(Composition::DEVICE, mOutputLayer.getState().hwc->hwcCompositionType);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001307}
1308
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001309TEST_F(OutputLayerWriteStateToHWCTest, setBlockingRegion) {
1310 mLayerFEState.compositionType = Composition::DISPLAY_DECORATION;
1311 const auto blockingRegion = Region(Rect(0, 0, 1000, 1000));
1312 mOutputLayer.editState().outputSpaceBlockingRegionHint = blockingRegion;
1313
1314 expectGeometryCommonCalls();
1315 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
Alec Mouri6da0e272022-02-07 12:45:57 -08001316 kSurfaceDamage, kLayerBrightness, blockingRegion);
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001317 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001318 expectSetCompositionTypeCall(Composition::DISPLAY_DECORATION);
1319
1320 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1321 /*zIsOverridden*/ false, /*isPeekingThrough*/
1322 false);
1323}
1324
ramindanib2158ee2023-02-13 20:29:59 -08001325TEST_F(OutputLayerWriteStateToHWCTest, setCompositionTypeRefreshRateIndicator) {
1326 mLayerFEState.compositionType = Composition::REFRESH_RATE_INDICATOR;
1327
1328 expectGeometryCommonCalls();
1329 expectPerFrameCommonCalls();
1330 expectSetHdrMetadataAndBufferCalls();
1331 expectSetCompositionTypeCall(Composition::REFRESH_RATE_INDICATOR);
1332
1333 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1334 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1335}
1336
Brian Lindahl1a4ffd82024-10-30 11:00:37 -06001337TEST_F(OutputLayerWriteStateToHWCTest, setsPictureProfileWhenCommitted) {
1338 if (!com_android_graphics_libgui_flags_apply_picture_profiles()) {
1339 GTEST_SKIP() << "Feature flag disabled, skipping";
1340 }
1341 mLayerFEState.compositionType = Composition::DEVICE;
1342 mLayerFEState.pictureProfileHandle = PictureProfileHandle(1);
1343
1344 expectGeometryCommonCalls();
1345 expectPerFrameCommonCalls();
1346 expectSetHdrMetadataAndBufferCalls();
1347 expectSetCompositionTypeCall(Composition::DEVICE);
1348
1349 EXPECT_CALL(*mHwcLayer, setPictureProfileHandle(PictureProfileHandle(1)));
1350
1351 mOutputLayer.commitPictureProfileToCompositionState();
1352 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1353 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1354}
1355
1356TEST_F(OutputLayerWriteStateToHWCTest, doesNotSetPictureProfileWhenNotCommitted) {
1357 if (!com_android_graphics_libgui_flags_apply_picture_profiles()) {
1358 GTEST_SKIP() << "Feature flag disabled, skipping";
1359 }
1360 mLayerFEState.compositionType = Composition::DEVICE;
1361 mLayerFEState.pictureProfileHandle = PictureProfileHandle(1);
1362
1363 expectGeometryCommonCalls();
1364 expectPerFrameCommonCalls();
1365 expectSetHdrMetadataAndBufferCalls();
1366 expectSetCompositionTypeCall(Composition::DEVICE);
1367
1368 EXPECT_CALL(*mHwcLayer, setPictureProfileHandle(_)).Times(0);
1369
1370 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1371 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1372}
1373
1374TEST_F(OutputLayerWriteStateToHWCTest, doesNotSetPictureProfileWhenNotCommittedLater) {
1375 if (!com_android_graphics_libgui_flags_apply_picture_profiles()) {
1376 GTEST_SKIP() << "Feature flag disabled, skipping";
1377 }
1378 mLayerFEState.compositionType = Composition::DEVICE;
1379 mLayerFEState.pictureProfileHandle = PictureProfileHandle(1);
1380
1381 expectGeometryCommonCalls();
1382 expectPerFrameCommonCalls();
1383 expectSetHdrMetadataAndBufferCalls();
1384 expectSetCompositionTypeCall(Composition::DEVICE);
1385
1386 EXPECT_CALL(*mHwcLayer, setPictureProfileHandle(PictureProfileHandle(1)));
1387
1388 mOutputLayer.commitPictureProfileToCompositionState();
1389 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1390 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1391
1392 expectGeometryCommonCalls();
1393 expectPerFrameCommonCalls();
1394 expectSetHdrMetadataAndBufferCalls(kExpectedHwcSlot, nullptr, kFence);
1395
1396 EXPECT_CALL(*mHwcLayer, setPictureProfileHandle(PictureProfileHandle(1))).Times(0);
1397 // No committing of picture profile before writing the state
1398 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1399 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1400}
1401
Lloyd Pique66d68602019-02-13 14:23:31 -08001402/*
Brian Lindahl90553da2022-12-06 13:36:30 -07001403 * OutputLayer::uncacheBuffers
1404 */
1405struct OutputLayerUncacheBufferTest : public OutputLayerTest {
1406 static const sp<GraphicBuffer> kBuffer1;
1407 static const sp<GraphicBuffer> kBuffer2;
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001408 static const sp<GraphicBuffer> kBuffer3;
Brian Lindahl90553da2022-12-06 13:36:30 -07001409 static const sp<Fence> kFence;
1410
1411 OutputLayerUncacheBufferTest() {
1412 auto& outputLayerState = mOutputLayer.editState();
1413 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer_);
1414
1415 mLayerFEState.compositionType = Composition::DEVICE;
1416 mLayerFEState.acquireFence = kFence;
1417
1418 ON_CALL(mOutput, getDisplayColorProfile()).WillByDefault(Return(&mDisplayColorProfile));
1419 }
1420
1421 std::shared_ptr<HWC2::mock::Layer> mHwcLayer_{std::make_shared<NiceMock<HWC2::mock::Layer>>()};
1422 HWC2::mock::Layer& mHwcLayer = *mHwcLayer_;
1423 NiceMock<mock::DisplayColorProfile> mDisplayColorProfile;
1424};
1425
1426const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer1 =
1427 sp<GraphicBuffer>::make(1, 2, PIXEL_FORMAT_RGBA_8888,
1428 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1429 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
1430const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer2 =
1431 sp<GraphicBuffer>::make(2, 3, PIXEL_FORMAT_RGBA_8888,
1432 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1433 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001434const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer3 =
1435 sp<GraphicBuffer>::make(4, 5, PIXEL_FORMAT_RGBA_8888,
1436 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1437 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Brian Lindahl90553da2022-12-06 13:36:30 -07001438const sp<Fence> OutputLayerUncacheBufferTest::kFence = sp<Fence>::make();
1439
1440TEST_F(OutputLayerUncacheBufferTest, canUncacheAndReuseSlot) {
1441 // Buffer1 is stored in slot 0
1442 mLayerFEState.buffer = kBuffer1;
1443 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 0, kBuffer1, kFence));
1444 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1445 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1446 Mock::VerifyAndClearExpectations(&mHwcLayer);
1447
1448 // Buffer2 is stored in slot 1
1449 mLayerFEState.buffer = kBuffer2;
1450 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, kBuffer2, kFence));
1451 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1452 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1453 Mock::VerifyAndClearExpectations(&mHwcLayer);
1454
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001455 // Buffer3 is stored in slot 2
1456 mLayerFEState.buffer = kBuffer3;
1457 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 2, kBuffer3, kFence));
1458 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1459 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Brian Lindahl90553da2022-12-06 13:36:30 -07001460 Mock::VerifyAndClearExpectations(&mHwcLayer);
1461
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001462 // Buffer2 becomes the active buffer again (with a nullptr) and reuses slot 1
1463 mLayerFEState.buffer = kBuffer2;
1464 sp<GraphicBuffer> nullBuffer = nullptr;
1465 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, nullBuffer, kFence));
1466 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1467 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1468 Mock::VerifyAndClearExpectations(&mHwcLayer);
1469
1470 // Buffer slots are cleared
1471 std::vector<uint32_t> slotsToClear = {0, 2, 1}; // order doesn't matter
1472 EXPECT_CALL(mHwcLayer, setBufferSlotsToClear(slotsToClear, /*activeBufferSlot*/ 1));
1473 // Uncache the active buffer in between other buffers to exercise correct algorithmic behavior.
1474 mOutputLayer.uncacheBuffers({kBuffer1->getId(), kBuffer2->getId(), kBuffer3->getId()});
1475 Mock::VerifyAndClearExpectations(&mHwcLayer);
1476
1477 // Buffer1 becomes active again, and rather than allocating a new slot, or re-using slot 0,
1478 // the active buffer slot (slot 1 for Buffer2) is reused first, which allows HWC to free the
1479 // memory for the active buffer. Note: slot 1 is different from the first and last buffer slot
1480 // requested to be cleared in slotsToClear (slot 1), above, indicating that the algorithm
1481 // correctly identifies the active buffer as the buffer in slot 1, despite ping-ponging.
Brian Lindahl90553da2022-12-06 13:36:30 -07001482 mLayerFEState.buffer = kBuffer1;
1483 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, kBuffer1, kFence));
1484 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1485 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1486 Mock::VerifyAndClearExpectations(&mHwcLayer);
Brian Lindahl90553da2022-12-06 13:36:30 -07001487}
1488
1489/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001490 * OutputLayer::writeCursorPositionToHWC()
1491 */
1492
1493struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1494 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -07001495 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001496
1497 static const Rect kDefaultDisplayViewport;
1498 static const Rect kDefaultCursorFrame;
1499
1500 OutputLayerWriteCursorPositionToHWCTest() {
1501 auto& outputLayerState = mOutputLayer.editState();
1502 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1503
Lloyd Pique9755fb72019-03-26 14:44:40 -07001504 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001505
Angel Aguayob084e0c2021-08-04 23:27:28 +00001506 mOutputState.layerStackSpace.setContent(kDefaultDisplayViewport);
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001507 mOutputState.transform = ui::Transform{kDefaultTransform};
1508 }
1509
1510 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1511};
1512
1513const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1514const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1515
Lloyd Piquede196652020-01-22 17:29:58 -08001516TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
Brian Lindahl90553da2022-12-06 13:36:30 -07001517 EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
Lloyd Piquede196652020-01-22 17:29:58 -08001518
1519 mOutputLayer.writeCursorPositionToHWC();
1520}
1521
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001522TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1523 mOutputLayer.editState().hwc.reset();
1524
1525 mOutputLayer.writeCursorPositionToHWC();
1526}
1527
1528TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1529 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1530
1531 mOutputLayer.writeCursorPositionToHWC();
1532}
1533
1534TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001535 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001536
1537 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1538
1539 mOutputLayer.writeCursorPositionToHWC();
1540}
1541
1542TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1543 mOutputState.transform = ui::Transform{TR_ROT_90};
1544
1545 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1546
1547 mOutputLayer.writeCursorPositionToHWC();
1548}
1549
1550/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001551 * OutputLayer::getHwcLayer()
1552 */
1553
1554TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1555 mOutputLayer.editState().hwc.reset();
1556
1557 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1558}
1559
1560TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1561 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1562
1563 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1564}
1565
1566TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1567 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1568 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1569
1570 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1571}
1572
1573/*
1574 * OutputLayer::requiresClientComposition()
1575 */
1576
1577TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1578 mOutputLayer.editState().hwc.reset();
1579
1580 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1581}
1582
1583TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1584 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001585 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Lloyd Pique66d68602019-02-13 14:23:31 -08001586
1587 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1588}
1589
1590TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1591 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001592 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001593
1594 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1595}
1596
1597/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001598 * OutputLayer::isHardwareCursor()
1599 */
1600
1601TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1602 mOutputLayer.editState().hwc.reset();
1603
1604 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1605}
1606
1607TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1608 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001609 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CURSOR;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001610
1611 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1612}
1613
1614TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1615 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001616 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001617
1618 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1619}
1620
1621/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001622 * OutputLayer::applyDeviceCompositionTypeChange()
1623 */
1624
1625TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1626 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001627 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001628
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001629 mOutputLayer.applyDeviceCompositionTypeChange(Composition::CLIENT);
Lloyd Pique66d68602019-02-13 14:23:31 -08001630
1631 ASSERT_TRUE(mOutputLayer.getState().hwc);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001632 EXPECT_EQ(Composition::CLIENT, mOutputLayer.getState().hwc->hwcCompositionType);
Lloyd Pique66d68602019-02-13 14:23:31 -08001633}
1634
1635/*
1636 * OutputLayer::prepareForDeviceLayerRequests()
1637 */
1638
1639TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1640 mOutputLayer.editState().clearClientTarget = true;
1641
1642 mOutputLayer.prepareForDeviceLayerRequests();
1643
1644 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1645}
1646
1647/*
1648 * OutputLayer::applyDeviceLayerRequest()
1649 */
1650
1651TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1652 mOutputLayer.editState().clearClientTarget = false;
1653
1654 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1655
1656 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1657}
1658
1659TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1660 mOutputLayer.editState().clearClientTarget = false;
1661
1662 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1663
1664 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1665}
1666
Lloyd Pique688abd42019-02-15 15:42:24 -08001667/*
1668 * OutputLayer::needsFiltering()
1669 */
1670
1671TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1672 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1673 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1674
1675 EXPECT_FALSE(mOutputLayer.needsFiltering());
1676}
1677
1678TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1679 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1680 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1681
1682 EXPECT_TRUE(mOutputLayer.needsFiltering());
1683}
1684
Alec Mourib6d78932023-09-20 16:05:42 +00001685TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfRotatedDisplaySizeSameAsSourceSize) {
1686 mOutputLayer.editState().displayFrame = Rect(100, 100, 300, 200);
1687 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 200.f};
1688 mOutputLayer.editState().bufferTransform = Hwc2::Transform::ROT_90;
1689
1690 EXPECT_FALSE(mOutputLayer.needsFiltering());
1691}
1692
1693TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfRotatedDisplaySizeDiffersFromSourceSize) {
1694 mOutputLayer.editState().displayFrame = Rect(100, 100, 300, 200);
1695 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 200.f};
1696
1697 EXPECT_TRUE(mOutputLayer.needsFiltering());
1698}
1699
Lloyd Piquecc01a452018-12-04 17:24:00 -08001700} // namespace
1701} // namespace android::compositionengine