blob: aa83883e95ed4bd2bab146d9fe3cdc4ce24cb243 [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;
Lloyd Piquef5275482019-01-29 18:42:42 -0800645 mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB;
646
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);
662}
663
Alec Mouridda07d92022-04-25 22:39:25 +0000664TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceWith170mReplacement) {
665 mLayerFEState.dataspace = ui::Dataspace::TRANSFER_SMPTE_170M;
666 mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB;
667 mOutputState.treat170mAsSrgb = false;
668 mLayerFEState.isColorspaceAgnostic = false;
669
670 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
671
672 EXPECT_EQ(ui::Dataspace::TRANSFER_SMPTE_170M, mOutputLayer.getState().dataspace);
673
674 // Rewrite SMPTE 170M as sRGB
675 mOutputState.treat170mAsSrgb = true;
676 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
677
678 EXPECT_EQ(ui::Dataspace::TRANSFER_SRGB, mOutputLayer.getState().dataspace);
679}
680
Alec Mourie8dd3562022-02-11 14:18:57 -0800681TEST_F(OutputLayerUpdateCompositionStateTest, setsWhitePointNitsAndDimmingRatioCorrectly) {
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700682 mOutputState.sdrWhitePointNits = 200.f;
683 mOutputState.displayBrightnessNits = 800.f;
684
685 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
686 mLayerFEState.isColorspaceAgnostic = false;
687 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
688 EXPECT_EQ(mOutputState.sdrWhitePointNits, mOutputLayer.getState().whitePointNits);
Alec Mourie8dd3562022-02-11 14:18:57 -0800689 EXPECT_EQ(mOutputState.sdrWhitePointNits / mOutputState.displayBrightnessNits,
690 mOutputLayer.getState().dimmingRatio);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700691
Sally Qi81d95e62022-03-21 19:41:33 -0700692 mLayerFEState.dimmingEnabled = false;
693 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
694 EXPECT_EQ(mOutputState.displayBrightnessNits, mOutputLayer.getState().whitePointNits);
695 EXPECT_EQ(1.f, mOutputLayer.getState().dimmingRatio);
696
697 // change dimmingEnabled back to true.
698 mLayerFEState.dimmingEnabled = true;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700699 mLayerFEState.dataspace = ui::Dataspace::BT2020_ITU_PQ;
700 mLayerFEState.isColorspaceAgnostic = false;
701 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
702
703 EXPECT_EQ(mOutputState.displayBrightnessNits, mOutputLayer.getState().whitePointNits);
Alec Mourie8dd3562022-02-11 14:18:57 -0800704 EXPECT_EQ(1.f, mOutputLayer.getState().dimmingRatio);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700705}
706
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000707TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700708 mOutputLayer.editState().forceClientComposition = false;
709
Snild Dolkow9e217d62020-04-22 15:53:42 +0200710 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000711
712 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
713}
714
Lloyd Piquefe671022019-09-24 10:43:03 -0700715TEST_F(OutputLayerUpdateCompositionStateTest,
716 doesNotClearForceClientCompositionIfNotDoingGeometry) {
717 mOutputLayer.editState().forceClientComposition = true;
718
Snild Dolkow9e217d62020-04-22 15:53:42 +0200719 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquefe671022019-09-24 10:43:03 -0700720
721 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
722}
723
Lloyd Piquef5275482019-01-29 18:42:42 -0800724TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700725 mLayerFEState.forceClientComposition = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700726 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800727
Snild Dolkow9e217d62020-04-22 15:53:42 +0200728 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800729
730 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
731}
732
733TEST_F(OutputLayerUpdateCompositionStateTest,
734 clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700735 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800736 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false));
737
Snild Dolkow9e217d62020-04-22 15:53:42 +0200738 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700739
740 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
741}
742
743TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromArgumentFlag) {
744 mLayerFEState.forceClientComposition = false;
745 mOutputLayer.editState().forceClientComposition = false;
746
Snild Dolkow9e217d62020-04-22 15:53:42 +0200747 mOutputLayer.updateCompositionState(false, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700748
749 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
750
751 mOutputLayer.editState().forceClientComposition = false;
752
Snild Dolkow9e217d62020-04-22 15:53:42 +0200753 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700754
Snild Dolkow9e217d62020-04-22 15:53:42 +0200755 mOutputLayer.updateCompositionState(true, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800756
757 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
758}
759
Lloyd Piquea83776c2019-01-29 18:42:32 -0800760/*
761 * OutputLayer::writeStateToHWC()
762 */
763
764struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
Peiyong Line9d809e2020-04-14 13:10:48 -0700765 static constexpr hal::Error kError = hal::Error::UNSUPPORTED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800766 static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800767 static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31);
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700768 static constexpr Hwc2::Transform kOverrideBufferTransform = static_cast<Hwc2::Transform>(0);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800769 static constexpr Hwc2::IComposerClient::BlendMode kBlendMode =
770 static_cast<Hwc2::IComposerClient::BlendMode>(41);
Alec Mouriee69a592021-03-23 15:00:45 -0700771 static constexpr Hwc2::IComposerClient::BlendMode kOverrideBlendMode =
772 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800773 static constexpr float kAlpha = 51.f;
Alec Mouriee69a592021-03-23 15:00:45 -0700774 static constexpr float kOverrideAlpha = 1.f;
Alec Mouri96ca45c2021-06-09 17:32:26 -0700775 static constexpr float kSkipAlpha = 0.f;
Lloyd Piquef5275482019-01-29 18:42:42 -0800776 static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
Alec Mourib7edfc22021-03-17 16:20:26 -0700777 static constexpr ui::Dataspace kOverrideDataspace = static_cast<ui::Dataspace>(72);
Lloyd Piquef5275482019-01-29 18:42:42 -0800778 static constexpr int kSupportedPerFrameMetadata = 101;
779 static constexpr int kExpectedHwcSlot = 0;
Brian Lindahl439afad2022-11-14 11:16:55 -0700780 static constexpr int kOverrideHwcSlot = impl::HwcBufferCache::kOverrideBufferSlot;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800781 static constexpr bool kLayerGenericMetadata1Mandatory = true;
782 static constexpr bool kLayerGenericMetadata2Mandatory = true;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700783 static constexpr float kWhitePointNits = 200.f;
Alec Mourie8dd3562022-02-11 14:18:57 -0800784 static constexpr float kSdrWhitePointNits = 100.f;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700785 static constexpr float kDisplayBrightnessNits = 400.f;
Alec Mouri6da0e272022-02-07 12:45:57 -0800786 static constexpr float kLayerBrightness = kWhitePointNits / kDisplayBrightnessNits;
Alec Mourie8dd3562022-02-11 14:18:57 -0800787 static constexpr float kOverrideLayerBrightness = kSdrWhitePointNits / kDisplayBrightnessNits;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800788
Lloyd Piquef5275482019-01-29 18:42:42 -0800789 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800790 static const Rect kDisplayFrame;
Alec Mourib7edfc22021-03-17 16:20:26 -0700791 static const Rect kOverrideDisplayFrame;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700792 static const FloatRect kOverrideSourceCrop;
Lloyd Piquea2468662019-03-07 21:31:06 -0800793 static const Region kOutputSpaceVisibleRegion;
Alec Mouri464352b2021-03-24 16:33:21 -0700794 static const Region kOverrideVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800795 static const mat4 kColorTransform;
796 static const Region kSurfaceDamage;
Alec Mouri464352b2021-03-24 16:33:21 -0700797 static const Region kOverrideSurfaceDamage;
Lloyd Piquef5275482019-01-29 18:42:42 -0800798 static const HdrMetadata kHdrMetadata;
799 static native_handle_t* kSidebandStreamHandle;
800 static const sp<GraphicBuffer> kBuffer;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700801 static const sp<GraphicBuffer> kOverrideBuffer;
Lloyd Piquef5275482019-01-29 18:42:42 -0800802 static const sp<Fence> kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700803 static const sp<Fence> kOverrideFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800804 static const std::string kLayerGenericMetadata1Key;
805 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
806 static const std::string kLayerGenericMetadata2Key;
807 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800808
809 OutputLayerWriteStateToHWCTest() {
810 auto& outputLayerState = mOutputLayer.editState();
811 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
812
813 outputLayerState.displayFrame = kDisplayFrame;
814 outputLayerState.sourceCrop = kSourceCrop;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800815 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800816 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800817 outputLayerState.dataspace = kDataspace;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700818 outputLayerState.whitePointNits = kWhitePointNits;
Alec Mouri6da0e272022-02-07 12:45:57 -0800819 outputLayerState.dimmingRatio = kLayerBrightness;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800820
Lloyd Pique9755fb72019-03-26 14:44:40 -0700821 mLayerFEState.blendMode = kBlendMode;
822 mLayerFEState.alpha = kAlpha;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700823 mLayerFEState.colorTransform = kColorTransform;
824 mLayerFEState.color = kColor;
825 mLayerFEState.surfaceDamage = kSurfaceDamage;
826 mLayerFEState.hdrMetadata = kHdrMetadata;
827 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
828 mLayerFEState.buffer = kBuffer;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700829 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800830
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700831 mOutputState.displayBrightnessNits = kDisplayBrightnessNits;
Alec Mourie8dd3562022-02-11 14:18:57 -0800832 mOutputState.sdrWhitePointNits = kSdrWhitePointNits;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700833
Lloyd Piquef5275482019-01-29 18:42:42 -0800834 EXPECT_CALL(mOutput, getDisplayColorProfile())
835 .WillRepeatedly(Return(&mDisplayColorProfile));
836 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
837 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800838 }
Lloyd Piquef5275482019-01-29 18:42:42 -0800839 // Some tests may need to simulate unsupported HWC calls
840 enum class SimulateUnsupported { None, ColorTransform };
841
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800842 void includeGenericLayerMetadataInState() {
843 mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory,
844 kLayerGenericMetadata1Value};
845 mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory,
846 kLayerGenericMetadata2Value};
847 }
848
Alec Mourib7edfc22021-03-17 16:20:26 -0700849 void includeOverrideInfo() {
850 auto& overrideInfo = mOutputLayer.editState().overrideInfo;
851
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700852 overrideInfo.buffer = std::make_shared<
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800853 renderengine::impl::ExternalTexture>(kOverrideBuffer, mRenderEngine,
854 renderengine::impl::ExternalTexture::Usage::
855 READABLE |
856 renderengine::impl::ExternalTexture::
857 Usage::WRITEABLE);
Alec Mourib7edfc22021-03-17 16:20:26 -0700858 overrideInfo.acquireFence = kOverrideFence;
859 overrideInfo.displayFrame = kOverrideDisplayFrame;
860 overrideInfo.dataspace = kOverrideDataspace;
Alec Mouri464352b2021-03-24 16:33:21 -0700861 overrideInfo.damageRegion = kOverrideSurfaceDamage;
862 overrideInfo.visibleRegion = kOverrideVisibleRegion;
Alec Mourib7edfc22021-03-17 16:20:26 -0700863 }
864
865 void expectGeometryCommonCalls(Rect displayFrame = kDisplayFrame,
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700866 FloatRect sourceCrop = kSourceCrop,
Alec Mouriee69a592021-03-23 15:00:45 -0700867 Hwc2::Transform bufferTransform = kBufferTransform,
868 Hwc2::IComposerClient::BlendMode blendMode = kBlendMode,
869 float alpha = kAlpha) {
Alec Mourib7edfc22021-03-17 16:20:26 -0700870 EXPECT_CALL(*mHwcLayer, setDisplayFrame(displayFrame)).WillOnce(Return(kError));
871 EXPECT_CALL(*mHwcLayer, setSourceCrop(sourceCrop)).WillOnce(Return(kError));
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400872 EXPECT_CALL(*mHwcLayer, setZOrder(_)).WillOnce(Return(kError));
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700873 EXPECT_CALL(*mHwcLayer, setTransform(bufferTransform)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800874
Alec Mouriee69a592021-03-23 15:00:45 -0700875 EXPECT_CALL(*mHwcLayer, setBlendMode(blendMode)).WillOnce(Return(kError));
876 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(alpha)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800877 }
878
Alec Mourib7edfc22021-03-17 16:20:26 -0700879 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None,
Alec Mouri464352b2021-03-24 16:33:21 -0700880 ui::Dataspace dataspace = kDataspace,
881 const Region& visibleRegion = kOutputSpaceVisibleRegion,
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700882 const Region& surfaceDamage = kSurfaceDamage,
Alec Mouri6da0e272022-02-07 12:45:57 -0800883 float brightness = kLayerBrightness,
Leon Scroggins III9a0afda2022-01-11 16:53:09 -0500884 const Region& blockingRegion = Region()) {
Alec Mouri464352b2021-03-24 16:33:21 -0700885 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(visibleRegion))).WillOnce(Return(kError));
Alec Mourib7edfc22021-03-17 16:20:26 -0700886 EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError));
Alec Mouri6da0e272022-02-07 12:45:57 -0800887 EXPECT_CALL(*mHwcLayer, setBrightness(brightness)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800888 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
889 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700890 ? hal::Error::UNSUPPORTED
891 : hal::Error::NONE));
Alec Mouri464352b2021-03-24 16:33:21 -0700892 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(surfaceDamage))).WillOnce(Return(kError));
Leon Scroggins III9a0afda2022-01-11 16:53:09 -0500893 EXPECT_CALL(*mHwcLayer, setBlockingRegion(RegionEq(blockingRegion)))
894 .WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800895 }
896
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500897 void expectSetCompositionTypeCall(Composition compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700898 EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800899 }
900
901 void expectNoSetCompositionTypeCall() {
902 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
903 }
904
905 void expectSetColorCall() {
Ady Abraham6e60b142022-01-06 18:10:35 -0800906 const aidl::android::hardware::graphics::composer3::Color color = {kColor.r, kColor.g,
907 kColor.b, 1.0f};
Lloyd Piquef5275482019-01-29 18:42:42 -0800908
909 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
910 }
911
912 void expectSetSidebandHandleCall() {
913 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
914 }
915
Alec Mourie7cc1c22021-04-27 15:23:26 -0700916 void expectSetHdrMetadataAndBufferCalls(uint32_t hwcSlot = kExpectedHwcSlot,
917 sp<GraphicBuffer> buffer = kBuffer,
Alec Mourib7edfc22021-03-17 16:20:26 -0700918 sp<Fence> fence = kFence) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800919 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
Alec Mourie7cc1c22021-04-27 15:23:26 -0700920 EXPECT_CALL(*mHwcLayer, setBuffer(hwcSlot, buffer, fence));
Lloyd Piquef5275482019-01-29 18:42:42 -0800921 }
922
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800923 void expectGenericLayerMetadataCalls() {
924 // Note: Can be in any order.
925 EXPECT_CALL(*mHwcLayer,
926 setLayerGenericMetadata(kLayerGenericMetadata1Key,
927 kLayerGenericMetadata1Mandatory,
928 kLayerGenericMetadata1Value));
929 EXPECT_CALL(*mHwcLayer,
930 setLayerGenericMetadata(kLayerGenericMetadata2Key,
931 kLayerGenericMetadata2Mandatory,
932 kLayerGenericMetadata2Value));
933 }
934
Lloyd Piquea83776c2019-01-29 18:42:32 -0800935 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800936 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Alec Mouria90a5702021-04-16 16:36:21 +0000937 renderengine::mock::RenderEngine mRenderEngine;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800938};
939
Lloyd Piquef5275482019-01-29 18:42:42 -0800940const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
941 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800942const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Alec Mourib7edfc22021-03-17 16:20:26 -0700943const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044};
Wiwit Rifa'i50abed02022-05-24 02:24:33 +0000944const FloatRect OutputLayerWriteStateToHWCTest::kOverrideSourceCrop{0.f, 0.f, 4.f, 5.f};
Lloyd Piquea2468662019-03-07 21:31:06 -0800945const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
946 Rect{1005, 1006, 1007, 1008}};
Alec Mouri464352b2021-03-24 16:33:21 -0700947const Region OutputLayerWriteStateToHWCTest::kOverrideVisibleRegion{Rect{1006, 1007, 1008, 1009}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800948const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
949 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
950 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
951};
952const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
Alec Mouri464352b2021-03-24 16:33:21 -0700953const Region OutputLayerWriteStateToHWCTest::kOverrideSurfaceDamage{Rect{1026, 1027, 1028, 1029}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800954const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
955native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
956 reinterpret_cast<native_handle_t*>(1031);
Brian Lindahl90553da2022-12-06 13:36:30 -0700957const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer =
958 sp<GraphicBuffer>::make(1, 2, PIXEL_FORMAT_RGBA_8888,
959 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
960 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700961const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kOverrideBuffer =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700962 sp<GraphicBuffer>::make(4, 5, PIXEL_FORMAT_RGBA_8888,
963 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
964 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Lloyd Piquef5275482019-01-29 18:42:42 -0800965const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700966const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = sp<Fence>::make();
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800967const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
968 "com.example.metadata.1";
969const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
970const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
971 "com.example.metadata.2";
972const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
973 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800974
Lloyd Piquede196652020-01-22 17:29:58 -0800975TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
Brian Lindahl90553da2022-12-06 13:36:30 -0700976 EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
Lloyd Piquede196652020-01-22 17:29:58 -0800977
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400978 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
979 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquede196652020-01-22 17:29:58 -0800980}
981
Lloyd Piquea83776c2019-01-29 18:42:32 -0800982TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
983 mOutputLayer.editState().hwc.reset();
984
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400985 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
986 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800987}
988
989TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
990 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
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
Lloyd Piquef5275482019-01-29 18:42:42 -0800996TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800997 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -0800998 expectPerFrameCommonCalls();
999
1000 expectNoSetCompositionTypeCall();
Brian Lindahl90553da2022-12-06 13:36:30 -07001001 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Piquea83776c2019-01-29 18:42:32 -08001002
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001003 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1004 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -08001005}
1006
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001007TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
1008 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
1009 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
1010 // This test simulates a scenario where displayInstallOrientation is set to
1011 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
1012 // DisplayDevice::setProjection).
Angel Aguayob084e0c2021-08-04 23:27:28 +00001013 mOutputState.displaySpace.setOrientation(ui::ROTATION_0);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001014 mOutputState.transform = ui::Transform{TR_ROT_90};
1015 // Buffers are pre-rotated based on the transform hint (ROT_90); their
1016 // geomBufferTransform is set to the inverse transform.
1017 mLayerFEState.geomBufferTransform = TR_ROT_270;
1018
Snild Dolkow9e217d62020-04-22 15:53:42 +02001019 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -07001020}
1021
Lloyd Piquef5275482019-01-29 18:42:42 -08001022TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001023 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001024
1025 expectPerFrameCommonCalls();
Lloyd Pique46b72df2019-10-29 13:19:27 -07001026
1027 // Setting the composition type should happen before setting the color. We
1028 // check this in this test only by setting up an testing::InSeqeuence
1029 // instance before setting up the two expectations.
1030 InSequence s;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001031 expectSetCompositionTypeCall(Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -07001032 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -08001033
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001034 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1035 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001036}
1037
1038TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001039 mLayerFEState.compositionType = Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -08001040
1041 expectPerFrameCommonCalls();
1042 expectSetSidebandHandleCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001043 expectSetCompositionTypeCall(Composition::SIDEBAND);
Lloyd Piquef5275482019-01-29 18:42:42 -08001044
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001045 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1046 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001047}
1048
1049TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001050 mLayerFEState.compositionType = Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001051
1052 expectPerFrameCommonCalls();
1053 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001054 expectSetCompositionTypeCall(Composition::CURSOR);
Lloyd Piquef5275482019-01-29 18:42:42 -08001055
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001056 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1057 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001058}
1059
1060TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001061 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -08001062
1063 expectPerFrameCommonCalls();
1064 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001065 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Piquef5275482019-01-29 18:42:42 -08001066
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001067 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1068 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001069}
1070
1071TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001072 (*mOutputLayer.editState().hwc).hwcCompositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001073
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001074 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001075
1076 expectPerFrameCommonCalls();
1077 expectSetColorCall();
1078 expectNoSetCompositionTypeCall();
1079
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001080 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1081 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001082}
1083
1084TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001085 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001086
1087 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
1088 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001089 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001090
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001091 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1092 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001093}
1094
1095TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
1096 mOutputLayer.editState().forceClientComposition = true;
1097
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001098 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001099
1100 expectPerFrameCommonCalls();
1101 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001102 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001103
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001104 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1105 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001106}
1107
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001108TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001109 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001110 includeGenericLayerMetadataInState();
1111
1112 expectGeometryCommonCalls();
1113 expectPerFrameCommonCalls();
1114 expectSetHdrMetadataAndBufferCalls();
1115 expectGenericLayerMetadataCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001116 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001117
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001118 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1119 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001120}
1121
1122TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001123 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001124 includeGenericLayerMetadataInState();
1125
1126 expectPerFrameCommonCalls();
1127 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001128 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001129
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001130 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1131 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001132}
1133
Alec Mouri96ca45c2021-06-09 17:32:26 -07001134TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001135 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mouri96ca45c2021-06-09 17:32:26 -07001136 includeOverrideInfo();
1137
1138 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1139 kOverrideBlendMode, kSkipAlpha);
1140 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001141 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001142 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001143 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001144
1145 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1146 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1147}
1148
Alec Mouri2b1212b2021-12-09 12:02:39 -08001149TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerForSolidColorDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001150 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri2b1212b2021-12-09 12:02:39 -08001151 includeOverrideInfo();
1152
1153 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1154 kOverrideBlendMode, kSkipAlpha);
1155 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001156 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001157 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001158 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001159
1160 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1161 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1162}
1163
Alec Mourib7edfc22021-03-17 16:20:26 -07001164TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001165 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourib7edfc22021-03-17 16:20:26 -07001166 includeOverrideInfo();
1167
Alec Mouri03bf0ff2021-04-19 14:17:31 -07001168 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1169 kOverrideBlendMode, kOverrideAlpha);
Alec Mouri464352b2021-03-24 16:33:21 -07001170 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001171 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mourie7cc1c22021-04-27 15:23:26 -07001172 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001173 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001174
1175 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1176 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1177}
1178
Alec Mouri028676a2021-12-02 15:01:48 -08001179TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoForSolidColorIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001180 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri028676a2021-12-02 15:01:48 -08001181 includeOverrideInfo();
1182
1183 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1184 kOverrideBlendMode, kOverrideAlpha);
1185 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001186 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri028676a2021-12-02 15:01:48 -08001187 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001188 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri028676a2021-12-02 15:01:48 -08001189
1190 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1191 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1192}
1193
Alec Mourid1bf1b52021-05-05 18:44:58 -07001194TEST_F(OutputLayerWriteStateToHWCTest, previousOverriddenLayerSendsSurfaceDamage) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001195 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001196 mOutputLayer.editState().hwc->stateOverridden = true;
1197
1198 expectGeometryCommonCalls();
1199 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1200 Region::INVALID_REGION);
1201 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001202 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001203
1204 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1205 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1206}
1207
1208TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedDeviceCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001209 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001210 mOutputLayer.editState().hwc->stateOverridden = true;
1211 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001212 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001213
1214 expectGeometryCommonCalls();
1215 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1216 Region::INVALID_REGION);
1217 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001218 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001219
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001220 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1221 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Alec Mourib7edfc22021-03-17 16:20:26 -07001222}
1223
Alec Mourid1bf1b52021-05-05 18:44:58 -07001224TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedClientCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001225 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001226 mOutputLayer.editState().forceClientComposition = true;
1227 mOutputLayer.editState().hwc->stateOverridden = true;
1228 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001229 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001230
1231 expectGeometryCommonCalls();
1232 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1233 Region::INVALID_REGION);
1234 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001235 expectSetCompositionTypeCall(Composition::CLIENT);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001236
1237 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1238 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1239}
1240
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001241TEST_F(OutputLayerWriteStateToHWCTest, peekThroughChangesBlendMode) {
Brian Lindahl90553da2022-12-06 13:36:30 -07001242 auto peekThroughLayerFE = sp<NiceMock<compositionengine::mock::LayerFE>>::make();
1243 OutputLayer peekThroughLayer{mOutput, *peekThroughLayerFE};
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001244
1245 mOutputLayer.mState.overrideInfo.peekThroughLayer = &peekThroughLayer;
1246
1247 expectGeometryCommonCalls(kDisplayFrame, kSourceCrop, kBufferTransform,
1248 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED);
1249 expectPerFrameCommonCalls();
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001250
1251 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1252 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1253}
1254
1255TEST_F(OutputLayerWriteStateToHWCTest, isPeekingThroughSetsOverride) {
1256 expectGeometryCommonCalls();
1257 expectPerFrameCommonCalls();
1258
1259 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1260 /*zIsOverridden*/ false, /*isPeekingThrough*/ true);
1261 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1262}
1263
1264TEST_F(OutputLayerWriteStateToHWCTest, zIsOverriddenSetsOverride) {
1265 expectGeometryCommonCalls();
1266 expectPerFrameCommonCalls();
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001267
1268 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1269 /*zIsOverridden*/ true, /*isPeekingThrough*/
1270 false);
1271 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1272}
1273
1274TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersForceClientComposition) {
1275 expectGeometryCommonCalls();
1276 expectPerFrameCommonCalls();
Brian Lindahl90553da2022-12-06 13:36:30 -07001277 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillOnce(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001278 expectSetCompositionTypeCall(Composition::CLIENT);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001279
1280 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1281 /*zIsOverridden*/ false, /*isPeekingThrough*/
1282 false);
1283}
1284
1285TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersPeekingThroughAllowsDeviceComposition) {
1286 expectGeometryCommonCalls();
1287 expectPerFrameCommonCalls();
1288 expectSetHdrMetadataAndBufferCalls();
Brian Lindahl90553da2022-12-06 13:36:30 -07001289 EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001290 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001291
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001292 mLayerFEState.compositionType = Composition::DEVICE;
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001293 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1294 /*zIsOverridden*/ false, /*isPeekingThrough*/
1295 true);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001296 EXPECT_EQ(Composition::DEVICE, mOutputLayer.getState().hwc->hwcCompositionType);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001297}
1298
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001299TEST_F(OutputLayerWriteStateToHWCTest, setBlockingRegion) {
1300 mLayerFEState.compositionType = Composition::DISPLAY_DECORATION;
1301 const auto blockingRegion = Region(Rect(0, 0, 1000, 1000));
1302 mOutputLayer.editState().outputSpaceBlockingRegionHint = blockingRegion;
1303
1304 expectGeometryCommonCalls();
1305 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
Alec Mouri6da0e272022-02-07 12:45:57 -08001306 kSurfaceDamage, kLayerBrightness, blockingRegion);
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001307 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001308 expectSetCompositionTypeCall(Composition::DISPLAY_DECORATION);
1309
1310 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1311 /*zIsOverridden*/ false, /*isPeekingThrough*/
1312 false);
1313}
1314
ramindanib2158ee2023-02-13 20:29:59 -08001315TEST_F(OutputLayerWriteStateToHWCTest, setCompositionTypeRefreshRateIndicator) {
1316 mLayerFEState.compositionType = Composition::REFRESH_RATE_INDICATOR;
1317
1318 expectGeometryCommonCalls();
1319 expectPerFrameCommonCalls();
1320 expectSetHdrMetadataAndBufferCalls();
1321 expectSetCompositionTypeCall(Composition::REFRESH_RATE_INDICATOR);
1322
1323 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1324 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1325}
1326
Lloyd Pique66d68602019-02-13 14:23:31 -08001327/*
Brian Lindahl90553da2022-12-06 13:36:30 -07001328 * OutputLayer::uncacheBuffers
1329 */
1330struct OutputLayerUncacheBufferTest : public OutputLayerTest {
1331 static const sp<GraphicBuffer> kBuffer1;
1332 static const sp<GraphicBuffer> kBuffer2;
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001333 static const sp<GraphicBuffer> kBuffer3;
Brian Lindahl90553da2022-12-06 13:36:30 -07001334 static const sp<Fence> kFence;
1335
1336 OutputLayerUncacheBufferTest() {
1337 auto& outputLayerState = mOutputLayer.editState();
1338 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer_);
1339
1340 mLayerFEState.compositionType = Composition::DEVICE;
1341 mLayerFEState.acquireFence = kFence;
1342
1343 ON_CALL(mOutput, getDisplayColorProfile()).WillByDefault(Return(&mDisplayColorProfile));
1344 }
1345
1346 std::shared_ptr<HWC2::mock::Layer> mHwcLayer_{std::make_shared<NiceMock<HWC2::mock::Layer>>()};
1347 HWC2::mock::Layer& mHwcLayer = *mHwcLayer_;
1348 NiceMock<mock::DisplayColorProfile> mDisplayColorProfile;
1349};
1350
1351const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer1 =
1352 sp<GraphicBuffer>::make(1, 2, PIXEL_FORMAT_RGBA_8888,
1353 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1354 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
1355const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer2 =
1356 sp<GraphicBuffer>::make(2, 3, PIXEL_FORMAT_RGBA_8888,
1357 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1358 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001359const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer3 =
1360 sp<GraphicBuffer>::make(4, 5, PIXEL_FORMAT_RGBA_8888,
1361 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
1362 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Brian Lindahl90553da2022-12-06 13:36:30 -07001363const sp<Fence> OutputLayerUncacheBufferTest::kFence = sp<Fence>::make();
1364
1365TEST_F(OutputLayerUncacheBufferTest, canUncacheAndReuseSlot) {
1366 // Buffer1 is stored in slot 0
1367 mLayerFEState.buffer = kBuffer1;
1368 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 0, kBuffer1, kFence));
1369 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1370 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1371 Mock::VerifyAndClearExpectations(&mHwcLayer);
1372
1373 // Buffer2 is stored in slot 1
1374 mLayerFEState.buffer = kBuffer2;
1375 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, kBuffer2, kFence));
1376 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1377 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1378 Mock::VerifyAndClearExpectations(&mHwcLayer);
1379
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001380 // Buffer3 is stored in slot 2
1381 mLayerFEState.buffer = kBuffer3;
1382 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 2, kBuffer3, kFence));
1383 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1384 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Brian Lindahl90553da2022-12-06 13:36:30 -07001385 Mock::VerifyAndClearExpectations(&mHwcLayer);
1386
Brian Lindahl3e1e1e62022-12-21 14:28:58 -07001387 // Buffer2 becomes the active buffer again (with a nullptr) and reuses slot 1
1388 mLayerFEState.buffer = kBuffer2;
1389 sp<GraphicBuffer> nullBuffer = nullptr;
1390 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, nullBuffer, kFence));
1391 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1392 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1393 Mock::VerifyAndClearExpectations(&mHwcLayer);
1394
1395 // Buffer slots are cleared
1396 std::vector<uint32_t> slotsToClear = {0, 2, 1}; // order doesn't matter
1397 EXPECT_CALL(mHwcLayer, setBufferSlotsToClear(slotsToClear, /*activeBufferSlot*/ 1));
1398 // Uncache the active buffer in between other buffers to exercise correct algorithmic behavior.
1399 mOutputLayer.uncacheBuffers({kBuffer1->getId(), kBuffer2->getId(), kBuffer3->getId()});
1400 Mock::VerifyAndClearExpectations(&mHwcLayer);
1401
1402 // Buffer1 becomes active again, and rather than allocating a new slot, or re-using slot 0,
1403 // the active buffer slot (slot 1 for Buffer2) is reused first, which allows HWC to free the
1404 // memory for the active buffer. Note: slot 1 is different from the first and last buffer slot
1405 // requested to be cleared in slotsToClear (slot 1), above, indicating that the algorithm
1406 // correctly identifies the active buffer as the buffer in slot 1, despite ping-ponging.
Brian Lindahl90553da2022-12-06 13:36:30 -07001407 mLayerFEState.buffer = kBuffer1;
1408 EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, kBuffer1, kFence));
1409 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1410 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1411 Mock::VerifyAndClearExpectations(&mHwcLayer);
Brian Lindahl90553da2022-12-06 13:36:30 -07001412}
1413
1414/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001415 * OutputLayer::writeCursorPositionToHWC()
1416 */
1417
1418struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1419 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -07001420 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001421
1422 static const Rect kDefaultDisplayViewport;
1423 static const Rect kDefaultCursorFrame;
1424
1425 OutputLayerWriteCursorPositionToHWCTest() {
1426 auto& outputLayerState = mOutputLayer.editState();
1427 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1428
Lloyd Pique9755fb72019-03-26 14:44:40 -07001429 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001430
Angel Aguayob084e0c2021-08-04 23:27:28 +00001431 mOutputState.layerStackSpace.setContent(kDefaultDisplayViewport);
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001432 mOutputState.transform = ui::Transform{kDefaultTransform};
1433 }
1434
1435 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1436};
1437
1438const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1439const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1440
Lloyd Piquede196652020-01-22 17:29:58 -08001441TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
Brian Lindahl90553da2022-12-06 13:36:30 -07001442 EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
Lloyd Piquede196652020-01-22 17:29:58 -08001443
1444 mOutputLayer.writeCursorPositionToHWC();
1445}
1446
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001447TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1448 mOutputLayer.editState().hwc.reset();
1449
1450 mOutputLayer.writeCursorPositionToHWC();
1451}
1452
1453TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1454 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1455
1456 mOutputLayer.writeCursorPositionToHWC();
1457}
1458
1459TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001460 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001461
1462 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1463
1464 mOutputLayer.writeCursorPositionToHWC();
1465}
1466
1467TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1468 mOutputState.transform = ui::Transform{TR_ROT_90};
1469
1470 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1471
1472 mOutputLayer.writeCursorPositionToHWC();
1473}
1474
1475/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001476 * OutputLayer::getHwcLayer()
1477 */
1478
1479TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1480 mOutputLayer.editState().hwc.reset();
1481
1482 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1483}
1484
1485TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1486 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1487
1488 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1489}
1490
1491TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1492 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1493 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1494
1495 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1496}
1497
1498/*
1499 * OutputLayer::requiresClientComposition()
1500 */
1501
1502TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1503 mOutputLayer.editState().hwc.reset();
1504
1505 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1506}
1507
1508TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1509 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001510 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Lloyd Pique66d68602019-02-13 14:23:31 -08001511
1512 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1513}
1514
1515TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1516 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001517 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001518
1519 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1520}
1521
1522/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001523 * OutputLayer::isHardwareCursor()
1524 */
1525
1526TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1527 mOutputLayer.editState().hwc.reset();
1528
1529 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1530}
1531
1532TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1533 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001534 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CURSOR;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001535
1536 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1537}
1538
1539TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1540 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001541 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001542
1543 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1544}
1545
1546/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001547 * OutputLayer::applyDeviceCompositionTypeChange()
1548 */
1549
1550TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1551 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001552 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001553
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001554 mOutputLayer.applyDeviceCompositionTypeChange(Composition::CLIENT);
Lloyd Pique66d68602019-02-13 14:23:31 -08001555
1556 ASSERT_TRUE(mOutputLayer.getState().hwc);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001557 EXPECT_EQ(Composition::CLIENT, mOutputLayer.getState().hwc->hwcCompositionType);
Lloyd Pique66d68602019-02-13 14:23:31 -08001558}
1559
1560/*
1561 * OutputLayer::prepareForDeviceLayerRequests()
1562 */
1563
1564TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1565 mOutputLayer.editState().clearClientTarget = true;
1566
1567 mOutputLayer.prepareForDeviceLayerRequests();
1568
1569 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1570}
1571
1572/*
1573 * OutputLayer::applyDeviceLayerRequest()
1574 */
1575
1576TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1577 mOutputLayer.editState().clearClientTarget = false;
1578
1579 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1580
1581 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1582}
1583
1584TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1585 mOutputLayer.editState().clearClientTarget = false;
1586
1587 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1588
1589 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1590}
1591
Lloyd Pique688abd42019-02-15 15:42:24 -08001592/*
1593 * OutputLayer::needsFiltering()
1594 */
1595
1596TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1597 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1598 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1599
1600 EXPECT_FALSE(mOutputLayer.needsFiltering());
1601}
1602
1603TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1604 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1605 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1606
1607 EXPECT_TRUE(mOutputLayer.needsFiltering());
1608}
1609
Lloyd Piquecc01a452018-12-04 17:24:00 -08001610} // namespace
1611} // namespace android::compositionengine