blob: 630906a5b79d38e9762669078ea9349d2d27d110 [file] [log] [blame]
Lloyd Piquecc01a452018-12-04 17:24:00 -08001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Alec Mourie7cc1c22021-04-27 15:23:26 -070017#include <compositionengine/impl/HwcBufferCache.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080018#include <compositionengine/impl/OutputLayer.h>
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070019#include <compositionengine/impl/OutputLayerCompositionState.h>
Lloyd Pique07e33212018-12-18 16:33:37 -080020#include <compositionengine/mock/CompositionEngine.h>
Lloyd Piquef5275482019-01-29 18:42:42 -080021#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080022#include <compositionengine/mock/LayerFE.h>
23#include <compositionengine/mock/Output.h>
24#include <gtest/gtest.h>
Marin Shalamanov68933fb2020-09-10 17:58:12 +020025#include <log/log.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080026
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>
29#include <ui/PixelFormat.h>
Lloyd Pique07e33212018-12-18 16:33:37 -080030#include "MockHWC2.h"
31#include "MockHWComposer.h"
Lloyd Piquef5275482019-01-29 18:42:42 -080032#include "RegionMatcher.h"
Lloyd Pique07e33212018-12-18 16:33:37 -080033
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050034#include <aidl/android/hardware/graphics/composer3/Composition.h>
35
36using aidl::android::hardware::graphics::composer3::Composition;
37
Lloyd Piquecc01a452018-12-04 17:24:00 -080038namespace android::compositionengine {
39namespace {
40
Peiyong Line9d809e2020-04-14 13:10:48 -070041namespace hal = android::hardware::graphics::composer::hal;
42
Lloyd Piquea83776c2019-01-29 18:42:32 -080043using testing::_;
Lloyd Pique46b72df2019-10-29 13:19:27 -070044using testing::InSequence;
Brian Lindahl90553da2022-12-06 13:36:30 -070045using testing::Mock;
46using testing::NiceMock;
Lloyd Piquea83776c2019-01-29 18:42:32 -080047using testing::Return;
48using testing::ReturnRef;
Lloyd Piquecc01a452018-12-04 17:24:00 -080049using testing::StrictMock;
50
Lloyd Piquea83776c2019-01-29 18:42:32 -080051constexpr auto TR_IDENT = 0u;
52constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H;
53constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V;
54constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
55constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V;
56constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180;
57
58const std::string kOutputName{"Test Output"};
59
Lloyd Piquef5275482019-01-29 18:42:42 -080060MATCHER_P(ColorEq, expected, "") {
61 *result_listener << "Colors are not equal\n";
62 *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " "
63 << expected.a << "\n";
64 *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n";
65
66 return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a;
67}
68
Marin Shalamanov68933fb2020-09-10 17:58:12 +020069ui::Rotation toRotation(uint32_t rotationFlag) {
70 switch (rotationFlag) {
71 case ui::Transform::RotationFlags::ROT_0:
72 return ui::ROTATION_0;
73 case ui::Transform::RotationFlags::ROT_90:
74 return ui::ROTATION_90;
75 case ui::Transform::RotationFlags::ROT_180:
76 return ui::ROTATION_180;
77 case ui::Transform::RotationFlags::ROT_270:
78 return ui::ROTATION_270;
79 default:
80 LOG_FATAL("Unexpected rotation flag %d", rotationFlag);
81 return ui::Rotation(-1);
82 }
83}
84
Lloyd Pique66d68602019-02-13 14:23:31 -080085struct OutputLayerTest : public testing::Test {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070086 struct OutputLayer final : public impl::OutputLayer {
Brian Lindahl90553da2022-12-06 13:36:30 -070087 OutputLayer(const compositionengine::Output& output, compositionengine::LayerFE& layerFE)
Lloyd Piquede196652020-01-22 17:29:58 -080088 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070089 ~OutputLayer() override = default;
90
91 // compositionengine::OutputLayer overrides
92 const compositionengine::Output& getOutput() const override { return mOutput; }
Brian Lindahl90553da2022-12-06 13:36:30 -070093 compositionengine::LayerFE& getLayerFE() const override { return mLayerFE; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070094 const impl::OutputLayerCompositionState& getState() const override { return mState; }
95 impl::OutputLayerCompositionState& editState() override { return mState; }
96
97 // compositionengine::impl::OutputLayer overrides
98 void dumpState(std::string& out) const override { mState.dump(out); }
99
100 const compositionengine::Output& mOutput;
Brian Lindahl90553da2022-12-06 13:36:30 -0700101 compositionengine::LayerFE& mLayerFE;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700102 impl::OutputLayerCompositionState mState;
103 };
104
Lloyd Piquea83776c2019-01-29 18:42:32 -0800105 OutputLayerTest() {
Brian Lindahl90553da2022-12-06 13:36:30 -0700106 ON_CALL(mLayerFE, getDebugName()).WillByDefault(Return("Test LayerFE"));
107 ON_CALL(mOutput, getName()).WillByDefault(ReturnRef(kOutputName));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800108
Brian Lindahl90553da2022-12-06 13:36:30 -0700109 ON_CALL(mLayerFE, getCompositionState()).WillByDefault(Return(&mLayerFEState));
110 ON_CALL(mOutput, getState()).WillByDefault(ReturnRef(mOutputState));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800111 }
112
Brian Lindahl90553da2022-12-06 13:36:30 -0700113 NiceMock<compositionengine::mock::Output> mOutput;
114 sp<NiceMock<compositionengine::mock::LayerFE>> mLayerFE_ =
115 sp<NiceMock<compositionengine::mock::LayerFE>>::make();
116 NiceMock<compositionengine::mock::LayerFE>& mLayerFE = *mLayerFE_;
Lloyd Piquede196652020-01-22 17:29:58 -0800117 OutputLayer mOutputLayer{mOutput, mLayerFE};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800118
Lloyd Pique9755fb72019-03-26 14:44:40 -0700119 LayerFECompositionState mLayerFEState;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800120 impl::OutputCompositionState mOutputState;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800121};
122
Lloyd Piquea83776c2019-01-29 18:42:32 -0800123/*
Lloyd Piquecc01a452018-12-04 17:24:00 -0800124 * Basic construction
125 */
126
127TEST_F(OutputLayerTest, canInstantiateOutputLayer) {}
128
Lloyd Piquea83776c2019-01-29 18:42:32 -0800129/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800130 * OutputLayer::setHwcLayer()
Lloyd Pique07e33212018-12-18 16:33:37 -0800131 */
132
Lloyd Piquedf336d92019-03-07 21:38:42 -0800133TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) {
Lloyd Pique07e33212018-12-18 16:33:37 -0800134 StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
135
Lloyd Piquedf336d92019-03-07 21:38:42 -0800136 mOutputLayer.setHwcLayer(nullptr);
Lloyd Pique07e33212018-12-18 16:33:37 -0800137
138 EXPECT_FALSE(mOutputLayer.getState().hwc);
139}
140
Lloyd Piquedf336d92019-03-07 21:38:42 -0800141TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) {
142 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Pique07e33212018-12-18 16:33:37 -0800143
Lloyd Piquedf336d92019-03-07 21:38:42 -0800144 mOutputLayer.setHwcLayer(hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800145
Lloyd Piquea83776c2019-01-29 18:42:32 -0800146 const auto& outputLayerState = mOutputLayer.getState();
147 ASSERT_TRUE(outputLayerState.hwc);
Lloyd Pique07e33212018-12-18 16:33:37 -0800148
Lloyd Piquea83776c2019-01-29 18:42:32 -0800149 const auto& hwcState = *outputLayerState.hwc;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800150 EXPECT_EQ(hwcLayer, hwcState.hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800151}
152
Lloyd Piquea83776c2019-01-29 18:42:32 -0800153/*
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000154 * OutputLayer::calculateOutputSourceCrop()
155 */
156
157struct OutputLayerSourceCropTest : public OutputLayerTest {
158 OutputLayerSourceCropTest() {
159 // Set reasonable default values for a simple case. Each test will
160 // set one specific value to something different.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700161 mLayerFEState.geomUsesSourceCrop = true;
162 mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080};
163 mLayerFEState.transparentRegionHint = Region{};
164 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
165 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
166 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
167 mLayerFEState.geomBufferTransform = TR_IDENT;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000168
Angel Aguayob084e0c2021-08-04 23:27:28 +0000169 mOutputState.layerStackSpace.setContent(Rect{0, 0, 1920, 1080});
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000170 }
171
172 FloatRect calculateOutputSourceCrop() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700173 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000174
ramindani2c043be2022-04-19 20:11:10 +0000175 return mOutputLayer.calculateOutputSourceCrop(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000176 }
177};
178
179TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700180 mLayerFEState.geomUsesSourceCrop = false;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000181
182 const FloatRect expected{};
Lloyd Piqueea629282019-12-03 15:57:10 -0800183 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000184}
185
186TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) {
187 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800188 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000189}
190
191TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700192 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000193
194 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800195 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000196}
197
198TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700199 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
200 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000201
202 const FloatRect expected{0.f, 0.f, 1080.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800203 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000204}
205
206TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) {
207 struct Entry {
208 uint32_t bufferInvDisplay;
209 uint32_t buffer;
210 uint32_t display;
211 FloatRect expected;
212 };
213 // Not an exhaustive list of cases, but hopefully enough.
214 const std::array<Entry, 12> testData = {
215 // clang-format off
216 // inv buffer display expected
217 /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
218 /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
219 /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
220 /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
221
222 /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
223 /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
224 /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
225 /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
226
227 /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
228 /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
229 /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
230 /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
231
232 // clang-format on
233 };
234
235 for (size_t i = 0; i < testData.size(); i++) {
236 const auto& entry = testData[i];
237
Lloyd Pique9755fb72019-03-26 14:44:40 -0700238 mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay;
239 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000240 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000241
Lloyd Piqueea629282019-12-03 15:57:10 -0800242 EXPECT_THAT(calculateOutputSourceCrop(), entry.expected) << "entry " << i;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000243 }
244}
245
246TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700247 mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000248
249 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800250 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000251}
252
253TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) {
Angel Aguayob084e0c2021-08-04 23:27:28 +0000254 mOutputState.layerStackSpace.setContent(Rect{0, 0, 960, 540});
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000255
256 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800257 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000258}
259
260/*
Lloyd Piquea83776c2019-01-29 18:42:32 -0800261 * OutputLayer::calculateOutputDisplayFrame()
262 */
263
264struct OutputLayerDisplayFrameTest : public OutputLayerTest {
265 OutputLayerDisplayFrameTest() {
266 // Set reasonable default values for a simple case. Each test will
267 // set one specific value to something different.
268
Lloyd Pique9755fb72019-03-26 14:44:40 -0700269 mLayerFEState.transparentRegionHint = Region{};
270 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
271 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
272 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
273 mLayerFEState.geomCrop = Rect{0, 0, 1920, 1080};
274 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800275
Angel Aguayob084e0c2021-08-04 23:27:28 +0000276 mOutputState.layerStackSpace.setContent(Rect{0, 0, 1920, 1080});
Lloyd Piquea83776c2019-01-29 18:42:32 -0800277 mOutputState.transform = ui::Transform{TR_IDENT};
278 }
279
280 Rect calculateOutputDisplayFrame() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700281 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800282
283 return mOutputLayer.calculateOutputDisplayFrame();
284 }
285};
286
287TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) {
288 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800289 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800290}
291
292TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700293 mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800294 const Rect expected{0, 0, 0, 0};
Lloyd Piqueea629282019-12-03 15:57:10 -0800295 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800296}
297
298TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700299 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800300 const Rect expected{100, 200, 300, 500};
Lloyd Piqueea629282019-12-03 15:57:10 -0800301 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800302}
303
304TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700305 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
306 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800307 const Rect expected{1420, 100, 1720, 300};
Lloyd Piqueea629282019-12-03 15:57:10 -0800308 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800309}
310
311TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700312 mLayerFEState.geomCrop = Rect{};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800313 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800314 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800315}
316
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000317TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700318 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800319 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800320 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800321}
322
323TEST_F(OutputLayerDisplayFrameTest, viewportAffectsFrame) {
Angel Aguayob084e0c2021-08-04 23:27:28 +0000324 mOutputState.layerStackSpace.setContent(Rect{0, 0, 960, 540});
Lloyd Piquea83776c2019-01-29 18:42:32 -0800325 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800326 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800327}
328
329TEST_F(OutputLayerDisplayFrameTest, outputTransformAffectsDisplayFrame) {
330 mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90};
331 const Rect expected{-1080, 0, 0, 1920};
Lloyd Piqueea629282019-12-03 15:57:10 -0800332 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800333}
334
Leon Scroggins IIId394d3c2021-06-24 11:30:32 -0400335TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame) {
336 const int kShadowRadius = 5;
337 mLayerFEState.shadowRadius = kShadowRadius;
338 mLayerFEState.forceClientComposition = true;
339
340 mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
341 Rect expected{mLayerFEState.geomLayerBounds};
342 expected.inset(-kShadowRadius, -kShadowRadius, -kShadowRadius, -kShadowRadius);
343 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
344}
345
346TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame_onlyIfForcingClientComposition) {
347 const int kShadowRadius = 5;
348 mLayerFEState.shadowRadius = kShadowRadius;
349 mLayerFEState.forceClientComposition = false;
350
351 mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
352 Rect expected{mLayerFEState.geomLayerBounds};
353 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
354}
355
Lloyd Piquea83776c2019-01-29 18:42:32 -0800356/*
357 * OutputLayer::calculateOutputRelativeBufferTransform()
358 */
359
360TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700361 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800362
363 struct Entry {
364 uint32_t layer;
365 uint32_t buffer;
366 uint32_t display;
367 uint32_t expected;
368 };
369 // Not an exhaustive list of cases, but hopefully enough.
370 const std::array<Entry, 24> testData = {
371 // clang-format off
372 // layer buffer display expected
373 /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
374 /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_90},
375 /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
376 /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270},
377
378 /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_IDENT},
379 /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_90},
380 /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_180},
381 /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_ROT_270},
382
383 /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V},
384 /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_180},
385 /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
386 /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_180},
387
388 /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_90},
389 /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_180},
390 /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT ^ TR_ROT_270},
391 /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_IDENT},
392
393 /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_ROT_180},
394 /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT ^ TR_ROT_270},
395 /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_IDENT},
396 /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_90},
397
398 /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_270},
399 /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_IDENT},
400 /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_90},
401 /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_180},
402 // clang-format on
403 };
404
405 for (size_t i = 0; i < testData.size(); i++) {
406 const auto& entry = testData[i];
407
Lloyd Pique9755fb72019-03-26 14:44:40 -0700408 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
409 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000410 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700411 mOutputState.transform = ui::Transform{entry.display};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800412
Snild Dolkow9e217d62020-04-22 15:53:42 +0200413 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.display);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800414 EXPECT_EQ(entry.expected, actual) << "entry " << i;
415 }
416}
417
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000418TEST_F(OutputLayerTest,
419 calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700420 mLayerFEState.geomBufferUsesDisplayInverseTransform = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000421
422 struct Entry {
Snild Dolkow9e217d62020-04-22 15:53:42 +0200423 uint32_t layer; /* shouldn't affect the result, so we just use arbitrary values */
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000424 uint32_t buffer;
425 uint32_t display;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200426 uint32_t internal;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000427 uint32_t expected;
428 };
Snild Dolkow9e217d62020-04-22 15:53:42 +0200429 const std::array<Entry, 64> testData = {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000430 // clang-format off
Snild Dolkow9e217d62020-04-22 15:53:42 +0200431 // layer buffer display internal expected
432 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
433 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_270},
434 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
435 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_90},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000436
Snild Dolkow9e217d62020-04-22 15:53:42 +0200437 Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT, TR_ROT_90},
438 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_90, TR_IDENT},
439 Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_180, TR_ROT_270},
440 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000441
Snild Dolkow9e217d62020-04-22 15:53:42 +0200442 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_180},
443 Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_90, TR_ROT_90},
444 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
445 Entry{TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000446
Snild Dolkow9e217d62020-04-22 15:53:42 +0200447 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270},
448 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_ROT_90, TR_ROT_180},
449 Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_180, TR_ROT_90},
450 Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000451
Snild Dolkow9e217d62020-04-22 15:53:42 +0200452 // layer buffer display internal expected
453 Entry{TR_IDENT, TR_ROT_90, TR_IDENT, TR_IDENT, TR_ROT_90},
454 Entry{TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_90, TR_IDENT},
455 Entry{TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_270},
456 Entry{TR_ROT_270, TR_ROT_90, TR_IDENT, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000457
Snild Dolkow9e217d62020-04-22 15:53:42 +0200458 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_180},
459 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90},
460 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_IDENT},
461 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270, TR_ROT_270},
462
463 Entry{TR_IDENT, TR_ROT_90, TR_ROT_180, TR_IDENT, TR_ROT_270},
464 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_180},
465 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_180, TR_ROT_90},
466 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_270, TR_IDENT},
467
468 Entry{TR_IDENT, TR_ROT_90, TR_ROT_270, TR_IDENT, TR_IDENT},
469 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270},
470 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_ROT_180, TR_ROT_180},
471 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90},
472
473 // layer buffer display internal expected
474 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_IDENT, TR_ROT_180},
475 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_90},
476 Entry{TR_ROT_180, TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT},
477 Entry{TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_270},
478
479 Entry{TR_IDENT, TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_270},
480 Entry{TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_90, TR_ROT_180},
481 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_90},
482 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_IDENT},
483
484 Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT, TR_IDENT},
485 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270},
486 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180},
487 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90},
488
489 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_IDENT, TR_ROT_90},
490 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_IDENT},
491 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_270},
492 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_270, TR_ROT_180},
493
494 // layer buffer display internal expected
495 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_IDENT, TR_ROT_270},
496 Entry{TR_ROT_90, TR_ROT_270, TR_IDENT, TR_ROT_90, TR_ROT_180},
497 Entry{TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_90},
498 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT},
499
500 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_IDENT, TR_IDENT},
501 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270},
502 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_ROT_180, TR_ROT_180},
503 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90},
504
505 Entry{TR_IDENT, TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_90},
506 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_90, TR_IDENT},
507 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270},
508 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_180},
509
510 Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180},
511 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_ROT_90},
512 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_IDENT},
513 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000514 // clang-format on
515 };
516
517 for (size_t i = 0; i < testData.size(); i++) {
518 const auto& entry = testData[i];
519
Snild Dolkow9e217d62020-04-22 15:53:42 +0200520 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
Lloyd Pique9755fb72019-03-26 14:44:40 -0700521 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000522 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700523 mOutputState.transform = ui::Transform{entry.display};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000524
Snild Dolkow9e217d62020-04-22 15:53:42 +0200525 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.internal);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000526 EXPECT_EQ(entry.expected, actual) << "entry " << i;
527 }
528}
529
530/*
531 * OutputLayer::updateCompositionState()
532 */
533
534struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer {
535 OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output,
Brian Lindahl90553da2022-12-06 13:36:30 -0700536 compositionengine::LayerFE& layerFE)
Lloyd Piquede196652020-01-22 17:29:58 -0800537 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000538 // Mock everything called by updateCompositionState to simplify testing it.
ramindani2c043be2022-04-19 20:11:10 +0000539 MOCK_CONST_METHOD1(calculateOutputSourceCrop, FloatRect(uint32_t));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000540 MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect());
Snild Dolkow9e217d62020-04-22 15:53:42 +0200541 MOCK_CONST_METHOD1(calculateOutputRelativeBufferTransform, uint32_t(uint32_t));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700542
543 // compositionengine::OutputLayer overrides
544 const compositionengine::Output& getOutput() const override { return mOutput; }
Brian Lindahl90553da2022-12-06 13:36:30 -0700545 compositionengine::LayerFE& getLayerFE() const override { return mLayerFE; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700546 const impl::OutputLayerCompositionState& getState() const override { return mState; }
547 impl::OutputLayerCompositionState& editState() override { return mState; }
548
549 // These need implementations though are not expected to be called.
550 MOCK_CONST_METHOD1(dumpState, void(std::string&));
551
552 const compositionengine::Output& mOutput;
Brian Lindahl90553da2022-12-06 13:36:30 -0700553 compositionengine::LayerFE& mLayerFE;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700554 impl::OutputLayerCompositionState mState;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000555};
556
557struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest {
558public:
559 OutputLayerUpdateCompositionStateTest() {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000560 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
Lloyd Piquef5275482019-01-29 18:42:42 -0800561 EXPECT_CALL(mOutput, getDisplayColorProfile())
562 .WillRepeatedly(Return(&mDisplayColorProfile));
563 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000564 }
565
566 ~OutputLayerUpdateCompositionStateTest() = default;
567
Snild Dolkow9e217d62020-04-22 15:53:42 +0200568 void setupGeometryChildCallValues(ui::Transform::RotationFlags internalDisplayRotationFlags) {
ramindani2c043be2022-04-19 20:11:10 +0000569 EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop(internalDisplayRotationFlags))
570 .WillOnce(Return(kSourceCrop));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000571 EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200572 EXPECT_CALL(mOutputLayer,
573 calculateOutputRelativeBufferTransform(internalDisplayRotationFlags))
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000574 .WillOnce(Return(mBufferTransform));
575 }
576
577 void validateComputedGeometryState() {
578 const auto& state = mOutputLayer.getState();
579 EXPECT_EQ(kSourceCrop, state.sourceCrop);
580 EXPECT_EQ(kDisplayFrame, state.displayFrame);
581 EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform);
582 }
583
584 const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f};
585 const Rect kDisplayFrame{11, 12, 13, 14};
586 uint32_t mBufferTransform{21};
587
588 using OutputLayer = OutputLayerPartialMockForUpdateCompositionState;
Lloyd Piquede196652020-01-22 17:29:58 -0800589 StrictMock<OutputLayer> mOutputLayer{mOutput, mLayerFE};
Lloyd Piquef5275482019-01-29 18:42:42 -0800590 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000591};
592
Lloyd Piquede196652020-01-22 17:29:58 -0800593TEST_F(OutputLayerUpdateCompositionStateTest, doesNothingIfNoFECompositionState) {
Brian Lindahl90553da2022-12-06 13:36:30 -0700594 EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
Lloyd Piquede196652020-01-22 17:29:58 -0800595
Snild Dolkow9e217d62020-04-22 15:53:42 +0200596 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Piquede196652020-01-22 17:29:58 -0800597}
598
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000599TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700600 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000601 mOutputState.isSecure = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700602 mOutputLayer.editState().forceClientComposition = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000603
Snild Dolkow9e217d62020-04-22 15:53:42 +0200604 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000605
Snild Dolkow9e217d62020-04-22 15:53:42 +0200606 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000607
608 validateComputedGeometryState();
609
610 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
611}
612
613TEST_F(OutputLayerUpdateCompositionStateTest,
614 alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700615 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000616 mOutputState.isSecure = false;
617
Snild Dolkow9e217d62020-04-22 15:53:42 +0200618 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000619
Snild Dolkow9e217d62020-04-22 15:53:42 +0200620 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000621
622 validateComputedGeometryState();
623
624 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
625}
626
627TEST_F(OutputLayerUpdateCompositionStateTest,
628 alsoSetsForceCompositionIfUnsupportedBufferTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700629 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000630 mOutputState.isSecure = true;
631
632 mBufferTransform = ui::Transform::ROT_INVALID;
633
Snild Dolkow9e217d62020-04-22 15:53:42 +0200634 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000635
Snild Dolkow9e217d62020-04-22 15:53:42 +0200636 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000637
638 validateComputedGeometryState();
639
640 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
641}
642
Lloyd Piquef5275482019-01-29 18:42:42 -0800643TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700644 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
Alec Mouri88790f32023-07-21 01:25:14 +0000645 mOutputState.dataspace = ui::Dataspace::V0_SCRGB;
Lloyd Piquef5275482019-01-29 18:42:42 -0800646
647 // If the layer is not colorspace agnostic, the output layer dataspace
648 // should use the layers requested colorspace.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700649 mLayerFEState.isColorspaceAgnostic = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800650
Snild Dolkow9e217d62020-04-22 15:53:42 +0200651 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800652
653 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
654
655 // If the layer is colorspace agnostic, the output layer dataspace
656 // should use the colorspace chosen for the whole output.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700657 mLayerFEState.isColorspaceAgnostic = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800658
Snild Dolkow9e217d62020-04-22 15:53:42 +0200659 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800660
661 EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace);
Alec Mouri88790f32023-07-21 01:25:14 +0000662
663 // If the output is HDR, then don't blind the user with a colorspace agnostic dataspace
664 // drawing all white
665 mOutputState.dataspace = ui::Dataspace::BT2020_PQ;
666
667 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
668
669 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
Lloyd Piquef5275482019-01-29 18:42:42 -0800670}
671
Alec Mouridda07d92022-04-25 22:39:25 +0000672TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceWith170mReplacement) {
673 mLayerFEState.dataspace = ui::Dataspace::TRANSFER_SMPTE_170M;
Alec Mouridda07d92022-04-25 22:39:25 +0000674 mOutputState.treat170mAsSrgb = false;
675 mLayerFEState.isColorspaceAgnostic = false;
676
677 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
678
679 EXPECT_EQ(ui::Dataspace::TRANSFER_SMPTE_170M, mOutputLayer.getState().dataspace);
680
681 // Rewrite SMPTE 170M as sRGB
682 mOutputState.treat170mAsSrgb = true;
683 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
684
685 EXPECT_EQ(ui::Dataspace::TRANSFER_SRGB, mOutputLayer.getState().dataspace);
686}
687
Alec Mourie8dd3562022-02-11 14:18:57 -0800688TEST_F(OutputLayerUpdateCompositionStateTest, setsWhitePointNitsAndDimmingRatioCorrectly) {
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700689 mOutputState.sdrWhitePointNits = 200.f;
690 mOutputState.displayBrightnessNits = 800.f;
691
692 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
693 mLayerFEState.isColorspaceAgnostic = false;
694 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
695 EXPECT_EQ(mOutputState.sdrWhitePointNits, mOutputLayer.getState().whitePointNits);
Alec Mourie8dd3562022-02-11 14:18:57 -0800696 EXPECT_EQ(mOutputState.sdrWhitePointNits / mOutputState.displayBrightnessNits,
697 mOutputLayer.getState().dimmingRatio);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700698
Sally Qi81d95e62022-03-21 19:41:33 -0700699 mLayerFEState.dimmingEnabled = false;
700 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
701 EXPECT_EQ(mOutputState.displayBrightnessNits, mOutputLayer.getState().whitePointNits);
702 EXPECT_EQ(1.f, mOutputLayer.getState().dimmingRatio);
703
704 // change dimmingEnabled back to true.
705 mLayerFEState.dimmingEnabled = true;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700706 mLayerFEState.dataspace = ui::Dataspace::BT2020_ITU_PQ;
707 mLayerFEState.isColorspaceAgnostic = false;
708 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
709
710 EXPECT_EQ(mOutputState.displayBrightnessNits, mOutputLayer.getState().whitePointNits);
Alec Mourie8dd3562022-02-11 14:18:57 -0800711 EXPECT_EQ(1.f, mOutputLayer.getState().dimmingRatio);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700712}
713
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000714TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700715 mOutputLayer.editState().forceClientComposition = false;
716
Snild Dolkow9e217d62020-04-22 15:53:42 +0200717 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000718
719 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
720}
721
Lloyd Piquefe671022019-09-24 10:43:03 -0700722TEST_F(OutputLayerUpdateCompositionStateTest,
723 doesNotClearForceClientCompositionIfNotDoingGeometry) {
724 mOutputLayer.editState().forceClientComposition = true;
725
Snild Dolkow9e217d62020-04-22 15:53:42 +0200726 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquefe671022019-09-24 10:43:03 -0700727
728 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
729}
730
Lloyd Piquef5275482019-01-29 18:42:42 -0800731TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700732 mLayerFEState.forceClientComposition = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700733 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800734
Snild Dolkow9e217d62020-04-22 15:53:42 +0200735 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800736
737 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
738}
739
740TEST_F(OutputLayerUpdateCompositionStateTest,
741 clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700742 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800743 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false));
744
Snild Dolkow9e217d62020-04-22 15:53:42 +0200745 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700746
747 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
748}
749
750TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromArgumentFlag) {
751 mLayerFEState.forceClientComposition = false;
752 mOutputLayer.editState().forceClientComposition = false;
753
Snild Dolkow9e217d62020-04-22 15:53:42 +0200754 mOutputLayer.updateCompositionState(false, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700755
756 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
757
758 mOutputLayer.editState().forceClientComposition = false;
759
Snild Dolkow9e217d62020-04-22 15:53:42 +0200760 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700761
Snild Dolkow9e217d62020-04-22 15:53:42 +0200762 mOutputLayer.updateCompositionState(true, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800763
764 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
765}
766
Lloyd Piquea83776c2019-01-29 18:42:32 -0800767/*
768 * OutputLayer::writeStateToHWC()
769 */
770
771struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
Peiyong Line9d809e2020-04-14 13:10:48 -0700772 static constexpr hal::Error kError = hal::Error::UNSUPPORTED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800773 static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800774 static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31);
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700775 static constexpr Hwc2::Transform kOverrideBufferTransform = static_cast<Hwc2::Transform>(0);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800776 static constexpr Hwc2::IComposerClient::BlendMode kBlendMode =
777 static_cast<Hwc2::IComposerClient::BlendMode>(41);
Alec Mouriee69a592021-03-23 15:00:45 -0700778 static constexpr Hwc2::IComposerClient::BlendMode kOverrideBlendMode =
779 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800780 static constexpr float kAlpha = 51.f;
Alec Mouriee69a592021-03-23 15:00:45 -0700781 static constexpr float kOverrideAlpha = 1.f;
Alec Mouri96ca45c2021-06-09 17:32:26 -0700782 static constexpr float kSkipAlpha = 0.f;
Lloyd Piquef5275482019-01-29 18:42:42 -0800783 static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
Alec Mourib7edfc22021-03-17 16:20:26 -0700784 static constexpr ui::Dataspace kOverrideDataspace = static_cast<ui::Dataspace>(72);
Lloyd Piquef5275482019-01-29 18:42:42 -0800785 static constexpr int kSupportedPerFrameMetadata = 101;
786 static constexpr int kExpectedHwcSlot = 0;
Brian Lindahl439afad2022-11-14 11:16:55 -0700787 static constexpr int kOverrideHwcSlot = impl::HwcBufferCache::kOverrideBufferSlot;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800788 static constexpr bool kLayerGenericMetadata1Mandatory = true;
789 static constexpr bool kLayerGenericMetadata2Mandatory = true;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700790 static constexpr float kWhitePointNits = 200.f;
Alec Mourie8dd3562022-02-11 14:18:57 -0800791 static constexpr float kSdrWhitePointNits = 100.f;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700792 static constexpr float kDisplayBrightnessNits = 400.f;
Alec Mouri6da0e272022-02-07 12:45:57 -0800793 static constexpr float kLayerBrightness = kWhitePointNits / kDisplayBrightnessNits;
Alec Mourie8dd3562022-02-11 14:18:57 -0800794 static constexpr float kOverrideLayerBrightness = kSdrWhitePointNits / kDisplayBrightnessNits;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800795
Lloyd Piquef5275482019-01-29 18:42:42 -0800796 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800797 static const Rect kDisplayFrame;
Alec Mourib7edfc22021-03-17 16:20:26 -0700798 static const Rect kOverrideDisplayFrame;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700799 static const FloatRect kOverrideSourceCrop;
Lloyd Piquea2468662019-03-07 21:31:06 -0800800 static const Region kOutputSpaceVisibleRegion;
Alec Mouri464352b2021-03-24 16:33:21 -0700801 static const Region kOverrideVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800802 static const mat4 kColorTransform;
803 static const Region kSurfaceDamage;
Alec Mouri464352b2021-03-24 16:33:21 -0700804 static const Region kOverrideSurfaceDamage;
Lloyd Piquef5275482019-01-29 18:42:42 -0800805 static const HdrMetadata kHdrMetadata;
806 static native_handle_t* kSidebandStreamHandle;
807 static const sp<GraphicBuffer> kBuffer;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700808 static const sp<GraphicBuffer> kOverrideBuffer;
Lloyd Piquef5275482019-01-29 18:42:42 -0800809 static const sp<Fence> kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700810 static const sp<Fence> kOverrideFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800811 static const std::string kLayerGenericMetadata1Key;
812 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
813 static const std::string kLayerGenericMetadata2Key;
814 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800815
816 OutputLayerWriteStateToHWCTest() {
817 auto& outputLayerState = mOutputLayer.editState();
818 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
819
820 outputLayerState.displayFrame = kDisplayFrame;
821 outputLayerState.sourceCrop = kSourceCrop;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800822 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800823 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800824 outputLayerState.dataspace = kDataspace;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700825 outputLayerState.whitePointNits = kWhitePointNits;
Alec Mouri6da0e272022-02-07 12:45:57 -0800826 outputLayerState.dimmingRatio = kLayerBrightness;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800827
Lloyd Pique9755fb72019-03-26 14:44:40 -0700828 mLayerFEState.blendMode = kBlendMode;
829 mLayerFEState.alpha = kAlpha;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700830 mLayerFEState.colorTransform = kColorTransform;
831 mLayerFEState.color = kColor;
832 mLayerFEState.surfaceDamage = kSurfaceDamage;
833 mLayerFEState.hdrMetadata = kHdrMetadata;
834 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
835 mLayerFEState.buffer = kBuffer;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700836 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800837
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700838 mOutputState.displayBrightnessNits = kDisplayBrightnessNits;
Alec Mourie8dd3562022-02-11 14:18:57 -0800839 mOutputState.sdrWhitePointNits = kSdrWhitePointNits;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700840
Lloyd Piquef5275482019-01-29 18:42:42 -0800841 EXPECT_CALL(mOutput, getDisplayColorProfile())
842 .WillRepeatedly(Return(&mDisplayColorProfile));
843 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
844 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800845 }
Lloyd Piquef5275482019-01-29 18:42:42 -0800846 // Some tests may need to simulate unsupported HWC calls
847 enum class SimulateUnsupported { None, ColorTransform };
848
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800849 void includeGenericLayerMetadataInState() {
850 mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory,
851 kLayerGenericMetadata1Value};
852 mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory,
853 kLayerGenericMetadata2Value};
854 }
855
Alec Mourib7edfc22021-03-17 16:20:26 -0700856 void includeOverrideInfo() {
857 auto& overrideInfo = mOutputLayer.editState().overrideInfo;
858
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700859 overrideInfo.buffer = std::make_shared<
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800860 renderengine::impl::ExternalTexture>(kOverrideBuffer, mRenderEngine,
861 renderengine::impl::ExternalTexture::Usage::
862 READABLE |
863 renderengine::impl::ExternalTexture::
864 Usage::WRITEABLE);
Alec Mourib7edfc22021-03-17 16:20:26 -0700865 overrideInfo.acquireFence = kOverrideFence;
866 overrideInfo.displayFrame = kOverrideDisplayFrame;
867 overrideInfo.dataspace = kOverrideDataspace;
Alec Mouri464352b2021-03-24 16:33:21 -0700868 overrideInfo.damageRegion = kOverrideSurfaceDamage;
869 overrideInfo.visibleRegion = kOverrideVisibleRegion;
Alec Mourib7edfc22021-03-17 16:20:26 -0700870 }
871
872 void expectGeometryCommonCalls(Rect displayFrame = kDisplayFrame,
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700873 FloatRect sourceCrop = kSourceCrop,
Alec Mouriee69a592021-03-23 15:00:45 -0700874 Hwc2::Transform bufferTransform = kBufferTransform,
875 Hwc2::IComposerClient::BlendMode blendMode = kBlendMode,
876 float alpha = kAlpha) {
Alec Mourib7edfc22021-03-17 16:20:26 -0700877 EXPECT_CALL(*mHwcLayer, setDisplayFrame(displayFrame)).WillOnce(Return(kError));
878 EXPECT_CALL(*mHwcLayer, setSourceCrop(sourceCrop)).WillOnce(Return(kError));
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400879 EXPECT_CALL(*mHwcLayer, setZOrder(_)).WillOnce(Return(kError));
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700880 EXPECT_CALL(*mHwcLayer, setTransform(bufferTransform)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800881
Alec Mouriee69a592021-03-23 15:00:45 -0700882 EXPECT_CALL(*mHwcLayer, setBlendMode(blendMode)).WillOnce(Return(kError));
883 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(alpha)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800884 }
885
Alec Mourib7edfc22021-03-17 16:20:26 -0700886 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None,
Alec Mouri464352b2021-03-24 16:33:21 -0700887 ui::Dataspace dataspace = kDataspace,
888 const Region& visibleRegion = kOutputSpaceVisibleRegion,
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700889 const Region& surfaceDamage = kSurfaceDamage,
Alec Mouri6da0e272022-02-07 12:45:57 -0800890 float brightness = kLayerBrightness,
Leon Scroggins III9a0afda2022-01-11 16:53:09 -0500891 const Region& blockingRegion = Region()) {
Alec Mouri464352b2021-03-24 16:33:21 -0700892 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(visibleRegion))).WillOnce(Return(kError));
Alec Mourib7edfc22021-03-17 16:20:26 -0700893 EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError));
Alec Mouri6da0e272022-02-07 12:45:57 -0800894 EXPECT_CALL(*mHwcLayer, setBrightness(brightness)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800895 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
896 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700897 ? hal::Error::UNSUPPORTED
898 : hal::Error::NONE));
Alec Mouri464352b2021-03-24 16:33:21 -0700899 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(surfaceDamage))).WillOnce(Return(kError));
Leon Scroggins III9a0afda2022-01-11 16:53:09 -0500900 EXPECT_CALL(*mHwcLayer, setBlockingRegion(RegionEq(blockingRegion)))
901 .WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800902 }
903
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500904 void expectSetCompositionTypeCall(Composition compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700905 EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800906 }
907
908 void expectNoSetCompositionTypeCall() {
909 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
910 }
911
912 void expectSetColorCall() {
Ady Abraham6e60b142022-01-06 18:10:35 -0800913 const aidl::android::hardware::graphics::composer3::Color color = {kColor.r, kColor.g,
914 kColor.b, 1.0f};
Lloyd Piquef5275482019-01-29 18:42:42 -0800915
916 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
917 }
918
919 void expectSetSidebandHandleCall() {
920 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
921 }
922
Alec Mourie7cc1c22021-04-27 15:23:26 -0700923 void expectSetHdrMetadataAndBufferCalls(uint32_t hwcSlot = kExpectedHwcSlot,
924 sp<GraphicBuffer> buffer = kBuffer,
Alec Mourib7edfc22021-03-17 16:20:26 -0700925 sp<Fence> fence = kFence) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800926 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
Alec Mourie7cc1c22021-04-27 15:23:26 -0700927 EXPECT_CALL(*mHwcLayer, setBuffer(hwcSlot, buffer, fence));
Lloyd Piquef5275482019-01-29 18:42:42 -0800928 }
929
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800930 void expectGenericLayerMetadataCalls() {
931 // Note: Can be in any order.
932 EXPECT_CALL(*mHwcLayer,
933 setLayerGenericMetadata(kLayerGenericMetadata1Key,
934 kLayerGenericMetadata1Mandatory,
935 kLayerGenericMetadata1Value));
936 EXPECT_CALL(*mHwcLayer,
937 setLayerGenericMetadata(kLayerGenericMetadata2Key,
938 kLayerGenericMetadata2Mandatory,
939 kLayerGenericMetadata2Value));
940 }
941
Lloyd Piquea83776c2019-01-29 18:42:32 -0800942 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800943 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Alec Mouria90a5702021-04-16 16:36:21 +0000944 renderengine::mock::RenderEngine mRenderEngine;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800945};
946
Lloyd Piquef5275482019-01-29 18:42:42 -0800947const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
948 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800949const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Alec Mourib7edfc22021-03-17 16:20:26 -0700950const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044};
Wiwit Rifa'i50abed02022-05-24 02:24:33 +0000951const FloatRect OutputLayerWriteStateToHWCTest::kOverrideSourceCrop{0.f, 0.f, 4.f, 5.f};
Lloyd Piquea2468662019-03-07 21:31:06 -0800952const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
953 Rect{1005, 1006, 1007, 1008}};
Alec Mouri464352b2021-03-24 16:33:21 -0700954const Region OutputLayerWriteStateToHWCTest::kOverrideVisibleRegion{Rect{1006, 1007, 1008, 1009}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800955const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
956 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
957 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
958};
959const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
Alec Mouri464352b2021-03-24 16:33:21 -0700960const Region OutputLayerWriteStateToHWCTest::kOverrideSurfaceDamage{Rect{1026, 1027, 1028, 1029}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800961const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
962native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
963 reinterpret_cast<native_handle_t*>(1031);
Brian Lindahl90553da2022-12-06 13:36:30 -0700964const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer =
965 sp<GraphicBuffer>::make(1, 2, PIXEL_FORMAT_RGBA_8888,
966 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
967 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700968const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kOverrideBuffer =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700969 sp<GraphicBuffer>::make(4, 5, PIXEL_FORMAT_RGBA_8888,
970 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
971 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Lloyd Piquef5275482019-01-29 18:42:42 -0800972const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700973const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = sp<Fence>::make();
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800974const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
975 "com.example.metadata.1";
976const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
977const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
978 "com.example.metadata.2";
979const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
980 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800981
Lloyd Piquede196652020-01-22 17:29:58 -0800982TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
Brian Lindahl90553da2022-12-06 13:36:30 -0700983 EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
Lloyd Piquede196652020-01-22 17:29:58 -0800984
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400985 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
986 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquede196652020-01-22 17:29:58 -0800987}
988
Lloyd Piquea83776c2019-01-29 18:42:32 -0800989TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
990 mOutputLayer.editState().hwc.reset();
991
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400992 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
993 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800994}
995
996TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
997 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
998
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400999 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1000 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -08001001}
1002
Lloyd Piquef5275482019-01-29 18:42:42 -08001003TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -08001004 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -08001005 expectPerFrameCommonCalls();
1006
1007 expectNoSetCompositionTypeCall();
Brian Lindahl90553da2022-12-06 13:36:30 -07001008 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Piquea83776c2019-01-29 18:42:32 -08001009
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001010 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1011 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -08001012}
1013
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001014TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
1015 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
1016 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
1017 // This test simulates a scenario where displayInstallOrientation is set to
1018 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
1019 // DisplayDevice::setProjection).
Angel Aguayob084e0c2021-08-04 23:27:28 +00001020 mOutputState.displaySpace.setOrientation(ui::ROTATION_0);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001021 mOutputState.transform = ui::Transform{TR_ROT_90};
1022 // Buffers are pre-rotated based on the transform hint (ROT_90); their
1023 // geomBufferTransform is set to the inverse transform.
1024 mLayerFEState.geomBufferTransform = TR_ROT_270;
1025
Snild Dolkow9e217d62020-04-22 15:53:42 +02001026 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001027}
1028
Lloyd Piquef5275482019-01-29 18:42:42 -08001029TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001030 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001031
1032 expectPerFrameCommonCalls();
Lloyd Pique46b72df2019-10-29 13:19:27 -07001033
1034 // Setting the composition type should happen before setting the color. We
1035 // check this in this test only by setting up an testing::InSeqeuence
1036 // instance before setting up the two expectations.
1037 InSequence s;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001038 expectSetCompositionTypeCall(Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -07001039 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -08001040
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001041 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1042 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001043}
1044
1045TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001046 mLayerFEState.compositionType = Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -08001047
1048 expectPerFrameCommonCalls();
1049 expectSetSidebandHandleCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001050 expectSetCompositionTypeCall(Composition::SIDEBAND);
Lloyd Piquef5275482019-01-29 18:42:42 -08001051
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001052 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1053 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001054}
1055
1056TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001057 mLayerFEState.compositionType = Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001058
1059 expectPerFrameCommonCalls();
1060 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001061 expectSetCompositionTypeCall(Composition::CURSOR);
Lloyd Piquef5275482019-01-29 18:42:42 -08001062
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001063 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1064 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001065}
1066
1067TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001068 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -08001069
1070 expectPerFrameCommonCalls();
1071 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001072 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Piquef5275482019-01-29 18:42:42 -08001073
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001074 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1075 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001076}
1077
1078TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001079 (*mOutputLayer.editState().hwc).hwcCompositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001080
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001081 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001082
1083 expectPerFrameCommonCalls();
1084 expectSetColorCall();
1085 expectNoSetCompositionTypeCall();
1086
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001087 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1088 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001089}
1090
1091TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001092 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001093
1094 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
1095 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001096 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001097
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001098 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1099 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001100}
1101
1102TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
1103 mOutputLayer.editState().forceClientComposition = true;
1104
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001105 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001106
1107 expectPerFrameCommonCalls();
1108 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001109 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001110
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001111 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1112 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001113}
1114
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001115TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001116 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001117 includeGenericLayerMetadataInState();
1118
1119 expectGeometryCommonCalls();
1120 expectPerFrameCommonCalls();
1121 expectSetHdrMetadataAndBufferCalls();
1122 expectGenericLayerMetadataCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001123 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001124
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001125 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1126 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001127}
1128
1129TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001130 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001131 includeGenericLayerMetadataInState();
1132
1133 expectPerFrameCommonCalls();
1134 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001135 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001136
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001137 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1138 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001139}
1140
Alec Mouri96ca45c2021-06-09 17:32:26 -07001141TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001142 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mouri96ca45c2021-06-09 17:32:26 -07001143 includeOverrideInfo();
1144
1145 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1146 kOverrideBlendMode, kSkipAlpha);
1147 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001148 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001149 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001150 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001151
1152 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1153 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1154}
1155
Alec Mouri2b1212b2021-12-09 12:02:39 -08001156TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerForSolidColorDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001157 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri2b1212b2021-12-09 12:02:39 -08001158 includeOverrideInfo();
1159
1160 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1161 kOverrideBlendMode, kSkipAlpha);
1162 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001163 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001164 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001165 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001166
1167 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1168 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1169}
1170
Alec Mourib7edfc22021-03-17 16:20:26 -07001171TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001172 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourib7edfc22021-03-17 16:20:26 -07001173 includeOverrideInfo();
1174
Alec Mouri03bf0ff2021-04-19 14:17:31 -07001175 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1176 kOverrideBlendMode, kOverrideAlpha);
Alec Mouri464352b2021-03-24 16:33:21 -07001177 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001178 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mourie7cc1c22021-04-27 15:23:26 -07001179 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001180 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001181
1182 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1183 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1184}
1185
Alec Mouri028676a2021-12-02 15:01:48 -08001186TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoForSolidColorIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001187 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri028676a2021-12-02 15:01:48 -08001188 includeOverrideInfo();
1189
1190 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1191 kOverrideBlendMode, kOverrideAlpha);
1192 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001193 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri028676a2021-12-02 15:01:48 -08001194 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001195 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri028676a2021-12-02 15:01:48 -08001196
1197 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1198 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1199}
1200
Alec Mourid1bf1b52021-05-05 18:44:58 -07001201TEST_F(OutputLayerWriteStateToHWCTest, previousOverriddenLayerSendsSurfaceDamage) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001202 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001203 mOutputLayer.editState().hwc->stateOverridden = true;
1204
1205 expectGeometryCommonCalls();
1206 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1207 Region::INVALID_REGION);
1208 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001209 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001210
1211 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1212 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1213}
1214
1215TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedDeviceCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001216 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001217 mOutputLayer.editState().hwc->stateOverridden = true;
1218 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001219 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001220
1221 expectGeometryCommonCalls();
1222 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1223 Region::INVALID_REGION);
1224 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001225 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001226
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001227 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1228 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Alec Mourib7edfc22021-03-17 16:20:26 -07001229}
1230
Alec Mourid1bf1b52021-05-05 18:44:58 -07001231TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedClientCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001232 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001233 mOutputLayer.editState().forceClientComposition = true;
1234 mOutputLayer.editState().hwc->stateOverridden = true;
1235 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001236 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001237
1238 expectGeometryCommonCalls();
1239 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1240 Region::INVALID_REGION);
1241 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001242 expectSetCompositionTypeCall(Composition::CLIENT);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001243
1244 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1245 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1246}
1247
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001248TEST_F(OutputLayerWriteStateToHWCTest, peekThroughChangesBlendMode) {
Brian Lindahl90553da2022-12-06 13:36:30 -07001249 auto peekThroughLayerFE = sp<NiceMock<compositionengine::mock::LayerFE>>::make();
1250 OutputLayer peekThroughLayer{mOutput, *peekThroughLayerFE};
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001251
1252 mOutputLayer.mState.overrideInfo.peekThroughLayer = &peekThroughLayer;
1253
1254 expectGeometryCommonCalls(kDisplayFrame, kSourceCrop, kBufferTransform,
1255 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED);
1256 expectPerFrameCommonCalls();
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001257
1258 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1259 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1260}
1261
1262TEST_F(OutputLayerWriteStateToHWCTest, isPeekingThroughSetsOverride) {
1263 expectGeometryCommonCalls();
1264 expectPerFrameCommonCalls();
1265
1266 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1267 /*zIsOverridden*/ false, /*isPeekingThrough*/ true);
1268 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1269}
1270
1271TEST_F(OutputLayerWriteStateToHWCTest, zIsOverriddenSetsOverride) {
1272 expectGeometryCommonCalls();
1273 expectPerFrameCommonCalls();
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001274
1275 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1276 /*zIsOverridden*/ true, /*isPeekingThrough*/
1277 false);
1278 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1279}
1280
1281TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersForceClientComposition) {
1282 expectGeometryCommonCalls();
1283 expectPerFrameCommonCalls();
Brian Lindahl90553da2022-12-06 13:36:30 -07001284 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillOnce(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001285 expectSetCompositionTypeCall(Composition::CLIENT);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001286
1287 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1288 /*zIsOverridden*/ false, /*isPeekingThrough*/
1289 false);
1290}
1291
1292TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersPeekingThroughAllowsDeviceComposition) {
1293 expectGeometryCommonCalls();
1294 expectPerFrameCommonCalls();
1295 expectSetHdrMetadataAndBufferCalls();
Brian Lindahl90553da2022-12-06 13:36:30 -07001296 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001297 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001298
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001299 mLayerFEState.compositionType = Composition::DEVICE;
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001300 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1301 /*zIsOverridden*/ false, /*isPeekingThrough*/
1302 true);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001303 EXPECT_EQ(Composition::DEVICE, mOutputLayer.getState().hwc->hwcCompositionType);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001304}
1305
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001306TEST_F(OutputLayerWriteStateToHWCTest, setBlockingRegion) {
1307 mLayerFEState.compositionType = Composition::DISPLAY_DECORATION;
1308 const auto blockingRegion = Region(Rect(0, 0, 1000, 1000));
1309 mOutputLayer.editState().outputSpaceBlockingRegionHint = blockingRegion;
1310
1311 expectGeometryCommonCalls();
1312 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
Alec Mouri6da0e272022-02-07 12:45:57 -08001313 kSurfaceDamage, kLayerBrightness, blockingRegion);
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001314 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001315 expectSetCompositionTypeCall(Composition::DISPLAY_DECORATION);
1316
1317 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1318 /*zIsOverridden*/ false, /*isPeekingThrough*/
1319 false);
1320}
1321
ramindanib2158ee2023-02-13 20:29:59 -08001322TEST_F(OutputLayerWriteStateToHWCTest, setCompositionTypeRefreshRateIndicator) {
1323 mLayerFEState.compositionType = Composition::REFRESH_RATE_INDICATOR;
1324
1325 expectGeometryCommonCalls();
1326 expectPerFrameCommonCalls();
1327 expectSetHdrMetadataAndBufferCalls();
1328 expectSetCompositionTypeCall(Composition::REFRESH_RATE_INDICATOR);
1329
1330 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1331 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1332}
1333
Lloyd Pique66d68602019-02-13 14:23:31 -08001334/*
Brian Lindahl90553da2022-12-06 13:36:30 -07001335 * OutputLayer::uncacheBuffers
1336 */
1337struct OutputLayerUncacheBufferTest : public OutputLayerTest {
1338 static const sp<GraphicBuffer> kBuffer1;
1339 static const sp<GraphicBuffer> kBuffer2;
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001340 static const sp<GraphicBuffer> kBuffer3;
Brian Lindahl90553da2022-12-06 13:36:30 -07001341 static const sp<Fence> kFence;
1342
1343 OutputLayerUncacheBufferTest() {
1344 auto& outputLayerState = mOutputLayer.editState();
1345 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer_);
1346
1347 mLayerFEState.compositionType = Composition::DEVICE;
1348 mLayerFEState.acquireFence = kFence;
1349
1350 ON_CALL(mOutput, getDisplayColorProfile()).WillByDefault(Return(&mDisplayColorProfile));
1351 }
1352
1353 std::shared_ptr<HWC2::mock::Layer> mHwcLayer_{std::make_shared<NiceMock<HWC2::mock::Layer>>()};
1354 HWC2::mock::Layer& mHwcLayer = *mHwcLayer_;
1355 NiceMock<mock::DisplayColorProfile> mDisplayColorProfile;
1356};
1357
1358const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer1 =
1359 sp<GraphicBuffer>::make(1, 2, PIXEL_FORMAT_RGBA_8888,
1360 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1361 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
1362const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer2 =
1363 sp<GraphicBuffer>::make(2, 3, PIXEL_FORMAT_RGBA_8888,
1364 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1365 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001366const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer3 =
1367 sp<GraphicBuffer>::make(4, 5, PIXEL_FORMAT_RGBA_8888,
1368 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1369 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Brian Lindahl90553da2022-12-06 13:36:30 -07001370const sp<Fence> OutputLayerUncacheBufferTest::kFence = sp<Fence>::make();
1371
1372TEST_F(OutputLayerUncacheBufferTest, canUncacheAndReuseSlot) {
1373 // Buffer1 is stored in slot 0
1374 mLayerFEState.buffer = kBuffer1;
1375 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 0, kBuffer1, kFence));
1376 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1377 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1378 Mock::VerifyAndClearExpectations(&mHwcLayer);
1379
1380 // Buffer2 is stored in slot 1
1381 mLayerFEState.buffer = kBuffer2;
1382 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, kBuffer2, kFence));
1383 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1384 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1385 Mock::VerifyAndClearExpectations(&mHwcLayer);
1386
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001387 // Buffer3 is stored in slot 2
1388 mLayerFEState.buffer = kBuffer3;
1389 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 2, kBuffer3, kFence));
1390 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1391 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Brian Lindahl90553da2022-12-06 13:36:30 -07001392 Mock::VerifyAndClearExpectations(&mHwcLayer);
1393
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001394 // Buffer2 becomes the active buffer again (with a nullptr) and reuses slot 1
1395 mLayerFEState.buffer = kBuffer2;
1396 sp<GraphicBuffer> nullBuffer = nullptr;
1397 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, nullBuffer, kFence));
1398 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1399 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1400 Mock::VerifyAndClearExpectations(&mHwcLayer);
1401
1402 // Buffer slots are cleared
1403 std::vector<uint32_t> slotsToClear = {0, 2, 1}; // order doesn't matter
1404 EXPECT_CALL(mHwcLayer, setBufferSlotsToClear(slotsToClear, /*activeBufferSlot*/ 1));
1405 // Uncache the active buffer in between other buffers to exercise correct algorithmic behavior.
1406 mOutputLayer.uncacheBuffers({kBuffer1->getId(), kBuffer2->getId(), kBuffer3->getId()});
1407 Mock::VerifyAndClearExpectations(&mHwcLayer);
1408
1409 // Buffer1 becomes active again, and rather than allocating a new slot, or re-using slot 0,
1410 // the active buffer slot (slot 1 for Buffer2) is reused first, which allows HWC to free the
1411 // memory for the active buffer. Note: slot 1 is different from the first and last buffer slot
1412 // requested to be cleared in slotsToClear (slot 1), above, indicating that the algorithm
1413 // correctly identifies the active buffer as the buffer in slot 1, despite ping-ponging.
Brian Lindahl90553da2022-12-06 13:36:30 -07001414 mLayerFEState.buffer = kBuffer1;
1415 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, kBuffer1, kFence));
1416 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1417 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1418 Mock::VerifyAndClearExpectations(&mHwcLayer);
Brian Lindahl90553da2022-12-06 13:36:30 -07001419}
1420
1421/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001422 * OutputLayer::writeCursorPositionToHWC()
1423 */
1424
1425struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1426 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -07001427 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001428
1429 static const Rect kDefaultDisplayViewport;
1430 static const Rect kDefaultCursorFrame;
1431
1432 OutputLayerWriteCursorPositionToHWCTest() {
1433 auto& outputLayerState = mOutputLayer.editState();
1434 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1435
Lloyd Pique9755fb72019-03-26 14:44:40 -07001436 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001437
Angel Aguayob084e0c2021-08-04 23:27:28 +00001438 mOutputState.layerStackSpace.setContent(kDefaultDisplayViewport);
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001439 mOutputState.transform = ui::Transform{kDefaultTransform};
1440 }
1441
1442 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1443};
1444
1445const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1446const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1447
Lloyd Piquede196652020-01-22 17:29:58 -08001448TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
Brian Lindahl90553da2022-12-06 13:36:30 -07001449 EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
Lloyd Piquede196652020-01-22 17:29:58 -08001450
1451 mOutputLayer.writeCursorPositionToHWC();
1452}
1453
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001454TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1455 mOutputLayer.editState().hwc.reset();
1456
1457 mOutputLayer.writeCursorPositionToHWC();
1458}
1459
1460TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1461 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1462
1463 mOutputLayer.writeCursorPositionToHWC();
1464}
1465
1466TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001467 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001468
1469 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1470
1471 mOutputLayer.writeCursorPositionToHWC();
1472}
1473
1474TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1475 mOutputState.transform = ui::Transform{TR_ROT_90};
1476
1477 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1478
1479 mOutputLayer.writeCursorPositionToHWC();
1480}
1481
1482/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001483 * OutputLayer::getHwcLayer()
1484 */
1485
1486TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1487 mOutputLayer.editState().hwc.reset();
1488
1489 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1490}
1491
1492TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1493 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1494
1495 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1496}
1497
1498TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1499 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1500 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1501
1502 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1503}
1504
1505/*
1506 * OutputLayer::requiresClientComposition()
1507 */
1508
1509TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1510 mOutputLayer.editState().hwc.reset();
1511
1512 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1513}
1514
1515TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1516 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001517 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Lloyd Pique66d68602019-02-13 14:23:31 -08001518
1519 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1520}
1521
1522TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1523 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001524 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001525
1526 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1527}
1528
1529/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001530 * OutputLayer::isHardwareCursor()
1531 */
1532
1533TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1534 mOutputLayer.editState().hwc.reset();
1535
1536 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1537}
1538
1539TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1540 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001541 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CURSOR;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001542
1543 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1544}
1545
1546TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1547 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001548 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001549
1550 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1551}
1552
1553/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001554 * OutputLayer::applyDeviceCompositionTypeChange()
1555 */
1556
1557TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1558 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001559 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001560
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001561 mOutputLayer.applyDeviceCompositionTypeChange(Composition::CLIENT);
Lloyd Pique66d68602019-02-13 14:23:31 -08001562
1563 ASSERT_TRUE(mOutputLayer.getState().hwc);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001564 EXPECT_EQ(Composition::CLIENT, mOutputLayer.getState().hwc->hwcCompositionType);
Lloyd Pique66d68602019-02-13 14:23:31 -08001565}
1566
1567/*
1568 * OutputLayer::prepareForDeviceLayerRequests()
1569 */
1570
1571TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1572 mOutputLayer.editState().clearClientTarget = true;
1573
1574 mOutputLayer.prepareForDeviceLayerRequests();
1575
1576 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1577}
1578
1579/*
1580 * OutputLayer::applyDeviceLayerRequest()
1581 */
1582
1583TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1584 mOutputLayer.editState().clearClientTarget = false;
1585
1586 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1587
1588 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1589}
1590
1591TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1592 mOutputLayer.editState().clearClientTarget = false;
1593
1594 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1595
1596 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1597}
1598
Lloyd Pique688abd42019-02-15 15:42:24 -08001599/*
1600 * OutputLayer::needsFiltering()
1601 */
1602
1603TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1604 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1605 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1606
1607 EXPECT_FALSE(mOutputLayer.needsFiltering());
1608}
1609
1610TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1611 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1612 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1613
1614 EXPECT_TRUE(mOutputLayer.needsFiltering());
1615}
1616
Alec Mourib6d78932023-09-20 16:05:42 +00001617TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfRotatedDisplaySizeSameAsSourceSize) {
1618 mOutputLayer.editState().displayFrame = Rect(100, 100, 300, 200);
1619 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 200.f};
1620 mOutputLayer.editState().bufferTransform = Hwc2::Transform::ROT_90;
1621
1622 EXPECT_FALSE(mOutputLayer.needsFiltering());
1623}
1624
1625TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfRotatedDisplaySizeDiffersFromSourceSize) {
1626 mOutputLayer.editState().displayFrame = Rect(100, 100, 300, 200);
1627 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 200.f};
1628
1629 EXPECT_TRUE(mOutputLayer.needsFiltering());
1630}
1631
Lloyd Piquecc01a452018-12-04 17:24:00 -08001632} // namespace
1633} // namespace android::compositionengine