blob: dbffe80a3ad527cdd6a5d4eae5fb1bc9fbbca808 [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));
Lloyd Piquef5275482019-01-29 18:42:42 -0800904 }
905
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500906 void expectSetCompositionTypeCall(Composition compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700907 EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800908 }
909
910 void expectNoSetCompositionTypeCall() {
911 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
912 }
913
914 void expectSetColorCall() {
Ady Abraham6e60b142022-01-06 18:10:35 -0800915 const aidl::android::hardware::graphics::composer3::Color color = {kColor.r, kColor.g,
916 kColor.b, 1.0f};
Lloyd Piquef5275482019-01-29 18:42:42 -0800917
918 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
919 }
920
921 void expectSetSidebandHandleCall() {
922 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
923 }
924
Alec Mourie7cc1c22021-04-27 15:23:26 -0700925 void expectSetHdrMetadataAndBufferCalls(uint32_t hwcSlot = kExpectedHwcSlot,
926 sp<GraphicBuffer> buffer = kBuffer,
Alec Mourib7edfc22021-03-17 16:20:26 -0700927 sp<Fence> fence = kFence) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800928 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
Alec Mourie7cc1c22021-04-27 15:23:26 -0700929 EXPECT_CALL(*mHwcLayer, setBuffer(hwcSlot, buffer, fence));
Lloyd Piquef5275482019-01-29 18:42:42 -0800930 }
931
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800932 void expectGenericLayerMetadataCalls() {
933 // Note: Can be in any order.
934 EXPECT_CALL(*mHwcLayer,
935 setLayerGenericMetadata(kLayerGenericMetadata1Key,
936 kLayerGenericMetadata1Mandatory,
937 kLayerGenericMetadata1Value));
938 EXPECT_CALL(*mHwcLayer,
939 setLayerGenericMetadata(kLayerGenericMetadata2Key,
940 kLayerGenericMetadata2Mandatory,
941 kLayerGenericMetadata2Value));
942 }
943
Lloyd Piquea83776c2019-01-29 18:42:32 -0800944 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800945 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Alec Mouria90a5702021-04-16 16:36:21 +0000946 renderengine::mock::RenderEngine mRenderEngine;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800947};
948
Lloyd Piquef5275482019-01-29 18:42:42 -0800949const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
950 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800951const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Alec Mourib7edfc22021-03-17 16:20:26 -0700952const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044};
Wiwit Rifa'i50abed02022-05-24 02:24:33 +0000953const FloatRect OutputLayerWriteStateToHWCTest::kOverrideSourceCrop{0.f, 0.f, 4.f, 5.f};
Lloyd Piquea2468662019-03-07 21:31:06 -0800954const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
955 Rect{1005, 1006, 1007, 1008}};
Alec Mouri464352b2021-03-24 16:33:21 -0700956const Region OutputLayerWriteStateToHWCTest::kOverrideVisibleRegion{Rect{1006, 1007, 1008, 1009}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800957const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
958 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
959 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
960};
961const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
Alec Mouri464352b2021-03-24 16:33:21 -0700962const Region OutputLayerWriteStateToHWCTest::kOverrideSurfaceDamage{Rect{1026, 1027, 1028, 1029}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800963const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
964native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
965 reinterpret_cast<native_handle_t*>(1031);
Brian Lindahl90553da2022-12-06 13:36:30 -0700966const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer =
967 sp<GraphicBuffer>::make(1, 2, PIXEL_FORMAT_RGBA_8888,
968 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
969 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700970const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kOverrideBuffer =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700971 sp<GraphicBuffer>::make(4, 5, PIXEL_FORMAT_RGBA_8888,
972 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
973 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Lloyd Piquef5275482019-01-29 18:42:42 -0800974const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700975const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = sp<Fence>::make();
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800976const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
977 "com.example.metadata.1";
978const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
979const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
980 "com.example.metadata.2";
981const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
982 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800983
Lloyd Piquede196652020-01-22 17:29:58 -0800984TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
Brian Lindahl90553da2022-12-06 13:36:30 -0700985 EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
Lloyd Piquede196652020-01-22 17:29:58 -0800986
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400987 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
988 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquede196652020-01-22 17:29:58 -0800989}
990
Lloyd Piquea83776c2019-01-29 18:42:32 -0800991TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
992 mOutputLayer.editState().hwc.reset();
993
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400994 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
995 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800996}
997
998TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
999 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
1000
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001001 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1002 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -08001003}
1004
Lloyd Piquef5275482019-01-29 18:42:42 -08001005TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -08001006 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -08001007 expectPerFrameCommonCalls();
1008
1009 expectNoSetCompositionTypeCall();
Brian Lindahl90553da2022-12-06 13:36:30 -07001010 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Piquea83776c2019-01-29 18:42:32 -08001011
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001012 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1013 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -08001014}
1015
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001016TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
1017 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
1018 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
1019 // This test simulates a scenario where displayInstallOrientation is set to
1020 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
1021 // DisplayDevice::setProjection).
Angel Aguayob084e0c2021-08-04 23:27:28 +00001022 mOutputState.displaySpace.setOrientation(ui::ROTATION_0);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001023 mOutputState.transform = ui::Transform{TR_ROT_90};
1024 // Buffers are pre-rotated based on the transform hint (ROT_90); their
1025 // geomBufferTransform is set to the inverse transform.
1026 mLayerFEState.geomBufferTransform = TR_ROT_270;
1027
Snild Dolkow9e217d62020-04-22 15:53:42 +02001028 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001029}
1030
Lloyd Piquef5275482019-01-29 18:42:42 -08001031TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001032 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001033
1034 expectPerFrameCommonCalls();
Lloyd Pique46b72df2019-10-29 13:19:27 -07001035
1036 // Setting the composition type should happen before setting the color. We
1037 // check this in this test only by setting up an testing::InSeqeuence
1038 // instance before setting up the two expectations.
1039 InSequence s;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001040 expectSetCompositionTypeCall(Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -07001041 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -08001042
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001043 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1044 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001045}
1046
1047TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001048 mLayerFEState.compositionType = Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -08001049
1050 expectPerFrameCommonCalls();
1051 expectSetSidebandHandleCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001052 expectSetCompositionTypeCall(Composition::SIDEBAND);
Lloyd Piquef5275482019-01-29 18:42:42 -08001053
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001054 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1055 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001056}
1057
1058TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001059 mLayerFEState.compositionType = Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001060
1061 expectPerFrameCommonCalls();
1062 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001063 expectSetCompositionTypeCall(Composition::CURSOR);
Lloyd Piquef5275482019-01-29 18:42:42 -08001064
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001065 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1066 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001067}
1068
1069TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001070 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -08001071
1072 expectPerFrameCommonCalls();
1073 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001074 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Piquef5275482019-01-29 18:42:42 -08001075
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001076 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1077 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001078}
1079
1080TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001081 (*mOutputLayer.editState().hwc).hwcCompositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001082
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001083 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001084
1085 expectPerFrameCommonCalls();
1086 expectSetColorCall();
1087 expectNoSetCompositionTypeCall();
1088
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001089 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1090 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001091}
1092
1093TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001094 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001095
1096 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
1097 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001098 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001099
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001100 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1101 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001102}
1103
1104TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
1105 mOutputLayer.editState().forceClientComposition = true;
1106
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001107 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001108
1109 expectPerFrameCommonCalls();
1110 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001111 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001112
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001113 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1114 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001115}
1116
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001117TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001118 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001119 includeGenericLayerMetadataInState();
1120
1121 expectGeometryCommonCalls();
1122 expectPerFrameCommonCalls();
1123 expectSetHdrMetadataAndBufferCalls();
1124 expectGenericLayerMetadataCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001125 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001126
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001127 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1128 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001129}
1130
1131TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001132 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001133 includeGenericLayerMetadataInState();
1134
1135 expectPerFrameCommonCalls();
1136 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001137 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001138
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001139 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1140 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001141}
1142
Alec Mouri96ca45c2021-06-09 17:32:26 -07001143TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001144 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mouri96ca45c2021-06-09 17:32:26 -07001145 includeOverrideInfo();
1146
1147 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1148 kOverrideBlendMode, kSkipAlpha);
1149 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001150 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001151 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001152 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001153
1154 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1155 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1156}
1157
Alec Mouri2b1212b2021-12-09 12:02:39 -08001158TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerForSolidColorDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001159 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri2b1212b2021-12-09 12:02:39 -08001160 includeOverrideInfo();
1161
1162 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1163 kOverrideBlendMode, kSkipAlpha);
1164 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001165 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001166 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001167 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001168
1169 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1170 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1171}
1172
Alec Mourib7edfc22021-03-17 16:20:26 -07001173TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001174 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourib7edfc22021-03-17 16:20:26 -07001175 includeOverrideInfo();
1176
Alec Mouri03bf0ff2021-04-19 14:17:31 -07001177 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1178 kOverrideBlendMode, kOverrideAlpha);
Alec Mouri464352b2021-03-24 16:33:21 -07001179 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001180 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mourie7cc1c22021-04-27 15:23:26 -07001181 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001182 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001183
1184 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1185 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1186}
1187
Alec Mouri028676a2021-12-02 15:01:48 -08001188TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoForSolidColorIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001189 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri028676a2021-12-02 15:01:48 -08001190 includeOverrideInfo();
1191
1192 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1193 kOverrideBlendMode, kOverrideAlpha);
1194 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001195 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri028676a2021-12-02 15:01:48 -08001196 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001197 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri028676a2021-12-02 15:01:48 -08001198
1199 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1200 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1201}
1202
Alec Mourid1bf1b52021-05-05 18:44:58 -07001203TEST_F(OutputLayerWriteStateToHWCTest, previousOverriddenLayerSendsSurfaceDamage) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001204 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001205 mOutputLayer.editState().hwc->stateOverridden = true;
1206
1207 expectGeometryCommonCalls();
1208 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1209 Region::INVALID_REGION);
1210 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001211 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001212
1213 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1214 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1215}
1216
1217TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedDeviceCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001218 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001219 mOutputLayer.editState().hwc->stateOverridden = true;
1220 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001221 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001222
1223 expectGeometryCommonCalls();
1224 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1225 Region::INVALID_REGION);
1226 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001227 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001228
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001229 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1230 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Alec Mourib7edfc22021-03-17 16:20:26 -07001231}
1232
Alec Mourid1bf1b52021-05-05 18:44:58 -07001233TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedClientCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001234 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001235 mOutputLayer.editState().forceClientComposition = true;
1236 mOutputLayer.editState().hwc->stateOverridden = true;
1237 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001238 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001239
1240 expectGeometryCommonCalls();
1241 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1242 Region::INVALID_REGION);
1243 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001244 expectSetCompositionTypeCall(Composition::CLIENT);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001245
1246 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1247 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1248}
1249
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001250TEST_F(OutputLayerWriteStateToHWCTest, peekThroughChangesBlendMode) {
Brian Lindahl90553da2022-12-06 13:36:30 -07001251 auto peekThroughLayerFE = sp<NiceMock<compositionengine::mock::LayerFE>>::make();
1252 OutputLayer peekThroughLayer{mOutput, *peekThroughLayerFE};
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001253
1254 mOutputLayer.mState.overrideInfo.peekThroughLayer = &peekThroughLayer;
1255
1256 expectGeometryCommonCalls(kDisplayFrame, kSourceCrop, kBufferTransform,
1257 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED);
1258 expectPerFrameCommonCalls();
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001259
1260 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1261 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1262}
1263
1264TEST_F(OutputLayerWriteStateToHWCTest, isPeekingThroughSetsOverride) {
1265 expectGeometryCommonCalls();
1266 expectPerFrameCommonCalls();
1267
1268 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1269 /*zIsOverridden*/ false, /*isPeekingThrough*/ true);
1270 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1271}
1272
1273TEST_F(OutputLayerWriteStateToHWCTest, zIsOverriddenSetsOverride) {
1274 expectGeometryCommonCalls();
1275 expectPerFrameCommonCalls();
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001276
1277 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1278 /*zIsOverridden*/ true, /*isPeekingThrough*/
1279 false);
1280 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1281}
1282
1283TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersForceClientComposition) {
1284 expectGeometryCommonCalls();
1285 expectPerFrameCommonCalls();
Brian Lindahl90553da2022-12-06 13:36:30 -07001286 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillOnce(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001287 expectSetCompositionTypeCall(Composition::CLIENT);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001288
1289 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1290 /*zIsOverridden*/ false, /*isPeekingThrough*/
1291 false);
1292}
1293
1294TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersPeekingThroughAllowsDeviceComposition) {
1295 expectGeometryCommonCalls();
1296 expectPerFrameCommonCalls();
1297 expectSetHdrMetadataAndBufferCalls();
Brian Lindahl90553da2022-12-06 13:36:30 -07001298 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001299 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001300
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001301 mLayerFEState.compositionType = Composition::DEVICE;
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001302 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1303 /*zIsOverridden*/ false, /*isPeekingThrough*/
1304 true);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001305 EXPECT_EQ(Composition::DEVICE, mOutputLayer.getState().hwc->hwcCompositionType);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001306}
1307
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001308TEST_F(OutputLayerWriteStateToHWCTest, setBlockingRegion) {
1309 mLayerFEState.compositionType = Composition::DISPLAY_DECORATION;
1310 const auto blockingRegion = Region(Rect(0, 0, 1000, 1000));
1311 mOutputLayer.editState().outputSpaceBlockingRegionHint = blockingRegion;
1312
1313 expectGeometryCommonCalls();
1314 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
Alec Mouri6da0e272022-02-07 12:45:57 -08001315 kSurfaceDamage, kLayerBrightness, blockingRegion);
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001316 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001317 expectSetCompositionTypeCall(Composition::DISPLAY_DECORATION);
1318
1319 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1320 /*zIsOverridden*/ false, /*isPeekingThrough*/
1321 false);
1322}
1323
ramindanib2158ee2023-02-13 20:29:59 -08001324TEST_F(OutputLayerWriteStateToHWCTest, setCompositionTypeRefreshRateIndicator) {
1325 mLayerFEState.compositionType = Composition::REFRESH_RATE_INDICATOR;
1326
1327 expectGeometryCommonCalls();
1328 expectPerFrameCommonCalls();
1329 expectSetHdrMetadataAndBufferCalls();
1330 expectSetCompositionTypeCall(Composition::REFRESH_RATE_INDICATOR);
1331
1332 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1333 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1334}
1335
Brian Lindahl1a4ffd82024-10-30 11:00:37 -06001336TEST_F(OutputLayerWriteStateToHWCTest, setsPictureProfileWhenCommitted) {
1337 if (!com_android_graphics_libgui_flags_apply_picture_profiles()) {
1338 GTEST_SKIP() << "Feature flag disabled, skipping";
1339 }
1340 mLayerFEState.compositionType = Composition::DEVICE;
1341 mLayerFEState.pictureProfileHandle = PictureProfileHandle(1);
1342
1343 expectGeometryCommonCalls();
1344 expectPerFrameCommonCalls();
1345 expectSetHdrMetadataAndBufferCalls();
1346 expectSetCompositionTypeCall(Composition::DEVICE);
1347
1348 EXPECT_CALL(*mHwcLayer, setPictureProfileHandle(PictureProfileHandle(1)));
1349
1350 mOutputLayer.commitPictureProfileToCompositionState();
1351 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1352 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1353}
1354
1355TEST_F(OutputLayerWriteStateToHWCTest, doesNotSetPictureProfileWhenNotCommitted) {
1356 if (!com_android_graphics_libgui_flags_apply_picture_profiles()) {
1357 GTEST_SKIP() << "Feature flag disabled, skipping";
1358 }
1359 mLayerFEState.compositionType = Composition::DEVICE;
1360 mLayerFEState.pictureProfileHandle = PictureProfileHandle(1);
1361
1362 expectGeometryCommonCalls();
1363 expectPerFrameCommonCalls();
1364 expectSetHdrMetadataAndBufferCalls();
1365 expectSetCompositionTypeCall(Composition::DEVICE);
1366
1367 EXPECT_CALL(*mHwcLayer, setPictureProfileHandle(_)).Times(0);
1368
1369 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1370 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1371}
1372
1373TEST_F(OutputLayerWriteStateToHWCTest, doesNotSetPictureProfileWhenNotCommittedLater) {
1374 if (!com_android_graphics_libgui_flags_apply_picture_profiles()) {
1375 GTEST_SKIP() << "Feature flag disabled, skipping";
1376 }
1377 mLayerFEState.compositionType = Composition::DEVICE;
1378 mLayerFEState.pictureProfileHandle = PictureProfileHandle(1);
1379
1380 expectGeometryCommonCalls();
1381 expectPerFrameCommonCalls();
1382 expectSetHdrMetadataAndBufferCalls();
1383 expectSetCompositionTypeCall(Composition::DEVICE);
1384
1385 EXPECT_CALL(*mHwcLayer, setPictureProfileHandle(PictureProfileHandle(1)));
1386
1387 mOutputLayer.commitPictureProfileToCompositionState();
1388 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1389 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1390
1391 expectGeometryCommonCalls();
1392 expectPerFrameCommonCalls();
1393 expectSetHdrMetadataAndBufferCalls(kExpectedHwcSlot, nullptr, kFence);
1394
1395 EXPECT_CALL(*mHwcLayer, setPictureProfileHandle(PictureProfileHandle(1))).Times(0);
1396 // No committing of picture profile before writing the state
1397 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1398 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1399}
1400
Lloyd Pique66d68602019-02-13 14:23:31 -08001401/*
Brian Lindahl90553da2022-12-06 13:36:30 -07001402 * OutputLayer::uncacheBuffers
1403 */
1404struct OutputLayerUncacheBufferTest : public OutputLayerTest {
1405 static const sp<GraphicBuffer> kBuffer1;
1406 static const sp<GraphicBuffer> kBuffer2;
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001407 static const sp<GraphicBuffer> kBuffer3;
Brian Lindahl90553da2022-12-06 13:36:30 -07001408 static const sp<Fence> kFence;
1409
1410 OutputLayerUncacheBufferTest() {
1411 auto& outputLayerState = mOutputLayer.editState();
1412 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer_);
1413
1414 mLayerFEState.compositionType = Composition::DEVICE;
1415 mLayerFEState.acquireFence = kFence;
1416
1417 ON_CALL(mOutput, getDisplayColorProfile()).WillByDefault(Return(&mDisplayColorProfile));
1418 }
1419
1420 std::shared_ptr<HWC2::mock::Layer> mHwcLayer_{std::make_shared<NiceMock<HWC2::mock::Layer>>()};
1421 HWC2::mock::Layer& mHwcLayer = *mHwcLayer_;
1422 NiceMock<mock::DisplayColorProfile> mDisplayColorProfile;
1423};
1424
1425const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer1 =
1426 sp<GraphicBuffer>::make(1, 2, PIXEL_FORMAT_RGBA_8888,
1427 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1428 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
1429const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer2 =
1430 sp<GraphicBuffer>::make(2, 3, PIXEL_FORMAT_RGBA_8888,
1431 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1432 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001433const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer3 =
1434 sp<GraphicBuffer>::make(4, 5, PIXEL_FORMAT_RGBA_8888,
1435 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1436 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Brian Lindahl90553da2022-12-06 13:36:30 -07001437const sp<Fence> OutputLayerUncacheBufferTest::kFence = sp<Fence>::make();
1438
1439TEST_F(OutputLayerUncacheBufferTest, canUncacheAndReuseSlot) {
1440 // Buffer1 is stored in slot 0
1441 mLayerFEState.buffer = kBuffer1;
1442 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 0, kBuffer1, kFence));
1443 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1444 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1445 Mock::VerifyAndClearExpectations(&mHwcLayer);
1446
1447 // Buffer2 is stored in slot 1
1448 mLayerFEState.buffer = kBuffer2;
1449 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, kBuffer2, kFence));
1450 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1451 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1452 Mock::VerifyAndClearExpectations(&mHwcLayer);
1453
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001454 // Buffer3 is stored in slot 2
1455 mLayerFEState.buffer = kBuffer3;
1456 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 2, kBuffer3, kFence));
1457 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1458 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Brian Lindahl90553da2022-12-06 13:36:30 -07001459 Mock::VerifyAndClearExpectations(&mHwcLayer);
1460
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001461 // Buffer2 becomes the active buffer again (with a nullptr) and reuses slot 1
1462 mLayerFEState.buffer = kBuffer2;
1463 sp<GraphicBuffer> nullBuffer = nullptr;
1464 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, nullBuffer, kFence));
1465 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1466 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1467 Mock::VerifyAndClearExpectations(&mHwcLayer);
1468
1469 // Buffer slots are cleared
1470 std::vector<uint32_t> slotsToClear = {0, 2, 1}; // order doesn't matter
1471 EXPECT_CALL(mHwcLayer, setBufferSlotsToClear(slotsToClear, /*activeBufferSlot*/ 1));
1472 // Uncache the active buffer in between other buffers to exercise correct algorithmic behavior.
1473 mOutputLayer.uncacheBuffers({kBuffer1->getId(), kBuffer2->getId(), kBuffer3->getId()});
1474 Mock::VerifyAndClearExpectations(&mHwcLayer);
1475
1476 // Buffer1 becomes active again, and rather than allocating a new slot, or re-using slot 0,
1477 // the active buffer slot (slot 1 for Buffer2) is reused first, which allows HWC to free the
1478 // memory for the active buffer. Note: slot 1 is different from the first and last buffer slot
1479 // requested to be cleared in slotsToClear (slot 1), above, indicating that the algorithm
1480 // correctly identifies the active buffer as the buffer in slot 1, despite ping-ponging.
Brian Lindahl90553da2022-12-06 13:36:30 -07001481 mLayerFEState.buffer = kBuffer1;
1482 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, kBuffer1, kFence));
1483 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1484 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1485 Mock::VerifyAndClearExpectations(&mHwcLayer);
Brian Lindahl90553da2022-12-06 13:36:30 -07001486}
1487
1488/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001489 * OutputLayer::writeCursorPositionToHWC()
1490 */
1491
1492struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1493 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -07001494 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001495
1496 static const Rect kDefaultDisplayViewport;
1497 static const Rect kDefaultCursorFrame;
1498
1499 OutputLayerWriteCursorPositionToHWCTest() {
1500 auto& outputLayerState = mOutputLayer.editState();
1501 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1502
Lloyd Pique9755fb72019-03-26 14:44:40 -07001503 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001504
Angel Aguayob084e0c2021-08-04 23:27:28 +00001505 mOutputState.layerStackSpace.setContent(kDefaultDisplayViewport);
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001506 mOutputState.transform = ui::Transform{kDefaultTransform};
1507 }
1508
1509 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1510};
1511
1512const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1513const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1514
Lloyd Piquede196652020-01-22 17:29:58 -08001515TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
Brian Lindahl90553da2022-12-06 13:36:30 -07001516 EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
Lloyd Piquede196652020-01-22 17:29:58 -08001517
1518 mOutputLayer.writeCursorPositionToHWC();
1519}
1520
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001521TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1522 mOutputLayer.editState().hwc.reset();
1523
1524 mOutputLayer.writeCursorPositionToHWC();
1525}
1526
1527TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1528 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1529
1530 mOutputLayer.writeCursorPositionToHWC();
1531}
1532
1533TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001534 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001535
1536 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1537
1538 mOutputLayer.writeCursorPositionToHWC();
1539}
1540
1541TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1542 mOutputState.transform = ui::Transform{TR_ROT_90};
1543
1544 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1545
1546 mOutputLayer.writeCursorPositionToHWC();
1547}
1548
1549/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001550 * OutputLayer::getHwcLayer()
1551 */
1552
1553TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1554 mOutputLayer.editState().hwc.reset();
1555
1556 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1557}
1558
1559TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1560 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1561
1562 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1563}
1564
1565TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1566 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1567 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1568
1569 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1570}
1571
1572/*
1573 * OutputLayer::requiresClientComposition()
1574 */
1575
1576TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1577 mOutputLayer.editState().hwc.reset();
1578
1579 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1580}
1581
1582TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1583 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001584 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Lloyd Pique66d68602019-02-13 14:23:31 -08001585
1586 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1587}
1588
1589TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1590 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001591 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001592
1593 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1594}
1595
1596/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001597 * OutputLayer::isHardwareCursor()
1598 */
1599
1600TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1601 mOutputLayer.editState().hwc.reset();
1602
1603 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1604}
1605
1606TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1607 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001608 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CURSOR;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001609
1610 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1611}
1612
1613TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1614 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001615 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001616
1617 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1618}
1619
1620/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001621 * OutputLayer::applyDeviceCompositionTypeChange()
1622 */
1623
1624TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1625 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001626 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001627
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001628 mOutputLayer.applyDeviceCompositionTypeChange(Composition::CLIENT);
Lloyd Pique66d68602019-02-13 14:23:31 -08001629
1630 ASSERT_TRUE(mOutputLayer.getState().hwc);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001631 EXPECT_EQ(Composition::CLIENT, mOutputLayer.getState().hwc->hwcCompositionType);
Lloyd Pique66d68602019-02-13 14:23:31 -08001632}
1633
1634/*
1635 * OutputLayer::prepareForDeviceLayerRequests()
1636 */
1637
1638TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1639 mOutputLayer.editState().clearClientTarget = true;
1640
1641 mOutputLayer.prepareForDeviceLayerRequests();
1642
1643 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1644}
1645
1646/*
1647 * OutputLayer::applyDeviceLayerRequest()
1648 */
1649
1650TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1651 mOutputLayer.editState().clearClientTarget = false;
1652
1653 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1654
1655 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1656}
1657
1658TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1659 mOutputLayer.editState().clearClientTarget = false;
1660
1661 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1662
1663 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1664}
1665
Lloyd Pique688abd42019-02-15 15:42:24 -08001666/*
1667 * OutputLayer::needsFiltering()
1668 */
1669
1670TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1671 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1672 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1673
1674 EXPECT_FALSE(mOutputLayer.needsFiltering());
1675}
1676
1677TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1678 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1679 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1680
1681 EXPECT_TRUE(mOutputLayer.needsFiltering());
1682}
1683
Alec Mourib6d78932023-09-20 16:05:42 +00001684TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfRotatedDisplaySizeSameAsSourceSize) {
1685 mOutputLayer.editState().displayFrame = Rect(100, 100, 300, 200);
1686 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 200.f};
1687 mOutputLayer.editState().bufferTransform = Hwc2::Transform::ROT_90;
1688
1689 EXPECT_FALSE(mOutputLayer.needsFiltering());
1690}
1691
1692TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfRotatedDisplaySizeDiffersFromSourceSize) {
1693 mOutputLayer.editState().displayFrame = Rect(100, 100, 300, 200);
1694 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 200.f};
1695
1696 EXPECT_TRUE(mOutputLayer.needsFiltering());
1697}
1698
Lloyd Piquecc01a452018-12-04 17:24:00 -08001699} // namespace
1700} // namespace android::compositionengine