blob: 8eb1946b679cfbe8833981a59512f5aa74a76103 [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;
Lloyd Piquea83776c2019-01-29 18:42:32 -080045using testing::Return;
46using testing::ReturnRef;
Lloyd Piquecc01a452018-12-04 17:24:00 -080047using testing::StrictMock;
48
Lloyd Piquea83776c2019-01-29 18:42:32 -080049constexpr auto TR_IDENT = 0u;
50constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H;
51constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V;
52constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
53constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V;
54constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180;
55
56const std::string kOutputName{"Test Output"};
57
Lloyd Piquef5275482019-01-29 18:42:42 -080058MATCHER_P(ColorEq, expected, "") {
59 *result_listener << "Colors are not equal\n";
60 *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " "
61 << expected.a << "\n";
62 *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n";
63
64 return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a;
65}
66
Marin Shalamanov68933fb2020-09-10 17:58:12 +020067ui::Rotation toRotation(uint32_t rotationFlag) {
68 switch (rotationFlag) {
69 case ui::Transform::RotationFlags::ROT_0:
70 return ui::ROTATION_0;
71 case ui::Transform::RotationFlags::ROT_90:
72 return ui::ROTATION_90;
73 case ui::Transform::RotationFlags::ROT_180:
74 return ui::ROTATION_180;
75 case ui::Transform::RotationFlags::ROT_270:
76 return ui::ROTATION_270;
77 default:
78 LOG_FATAL("Unexpected rotation flag %d", rotationFlag);
79 return ui::Rotation(-1);
80 }
81}
82
Lloyd Pique66d68602019-02-13 14:23:31 -080083struct OutputLayerTest : public testing::Test {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070084 struct OutputLayer final : public impl::OutputLayer {
Lloyd Piquede196652020-01-22 17:29:58 -080085 OutputLayer(const compositionengine::Output& output, sp<compositionengine::LayerFE> layerFE)
86 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070087 ~OutputLayer() override = default;
88
89 // compositionengine::OutputLayer overrides
90 const compositionengine::Output& getOutput() const override { return mOutput; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070091 compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
92 const impl::OutputLayerCompositionState& getState() const override { return mState; }
93 impl::OutputLayerCompositionState& editState() override { return mState; }
94
95 // compositionengine::impl::OutputLayer overrides
96 void dumpState(std::string& out) const override { mState.dump(out); }
97
98 const compositionengine::Output& mOutput;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070099 sp<compositionengine::LayerFE> mLayerFE;
100 impl::OutputLayerCompositionState mState;
101 };
102
Lloyd Piquea83776c2019-01-29 18:42:32 -0800103 OutputLayerTest() {
104 EXPECT_CALL(*mLayerFE, getDebugName()).WillRepeatedly(Return("Test LayerFE"));
105 EXPECT_CALL(mOutput, getName()).WillRepeatedly(ReturnRef(kOutputName));
106
Lloyd Piquede196652020-01-22 17:29:58 -0800107 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800108 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
109 }
110
Lloyd Piquecc01a452018-12-04 17:24:00 -0800111 compositionengine::mock::Output mOutput;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800112 sp<StrictMock<compositionengine::mock::LayerFE>> mLayerFE =
113 sp<StrictMock<compositionengine::mock::LayerFE>>::make();
Lloyd Piquede196652020-01-22 17:29:58 -0800114 OutputLayer mOutputLayer{mOutput, mLayerFE};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800115
Lloyd Pique9755fb72019-03-26 14:44:40 -0700116 LayerFECompositionState mLayerFEState;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800117 impl::OutputCompositionState mOutputState;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800118};
119
Lloyd Piquea83776c2019-01-29 18:42:32 -0800120/*
Lloyd Piquecc01a452018-12-04 17:24:00 -0800121 * Basic construction
122 */
123
124TEST_F(OutputLayerTest, canInstantiateOutputLayer) {}
125
Lloyd Piquea83776c2019-01-29 18:42:32 -0800126/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800127 * OutputLayer::setHwcLayer()
Lloyd Pique07e33212018-12-18 16:33:37 -0800128 */
129
Lloyd Piquedf336d92019-03-07 21:38:42 -0800130TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) {
Lloyd Pique07e33212018-12-18 16:33:37 -0800131 StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
132
Lloyd Piquedf336d92019-03-07 21:38:42 -0800133 mOutputLayer.setHwcLayer(nullptr);
Lloyd Pique07e33212018-12-18 16:33:37 -0800134
135 EXPECT_FALSE(mOutputLayer.getState().hwc);
136}
137
Lloyd Piquedf336d92019-03-07 21:38:42 -0800138TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) {
139 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Pique07e33212018-12-18 16:33:37 -0800140
Lloyd Piquedf336d92019-03-07 21:38:42 -0800141 mOutputLayer.setHwcLayer(hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800142
Lloyd Piquea83776c2019-01-29 18:42:32 -0800143 const auto& outputLayerState = mOutputLayer.getState();
144 ASSERT_TRUE(outputLayerState.hwc);
Lloyd Pique07e33212018-12-18 16:33:37 -0800145
Lloyd Piquea83776c2019-01-29 18:42:32 -0800146 const auto& hwcState = *outputLayerState.hwc;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800147 EXPECT_EQ(hwcLayer, hwcState.hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800148}
149
Lloyd Piquea83776c2019-01-29 18:42:32 -0800150/*
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000151 * OutputLayer::calculateOutputSourceCrop()
152 */
153
154struct OutputLayerSourceCropTest : public OutputLayerTest {
155 OutputLayerSourceCropTest() {
156 // Set reasonable default values for a simple case. Each test will
157 // set one specific value to something different.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700158 mLayerFEState.geomUsesSourceCrop = true;
159 mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080};
160 mLayerFEState.transparentRegionHint = Region{};
161 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
162 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
163 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
164 mLayerFEState.geomBufferTransform = TR_IDENT;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000165
Angel Aguayob084e0c2021-08-04 23:27:28 +0000166 mOutputState.layerStackSpace.setContent(Rect{0, 0, 1920, 1080});
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000167 }
168
169 FloatRect calculateOutputSourceCrop() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700170 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000171
172 return mOutputLayer.calculateOutputSourceCrop();
173 }
174};
175
176TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700177 mLayerFEState.geomUsesSourceCrop = false;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000178
179 const FloatRect expected{};
Lloyd Piqueea629282019-12-03 15:57:10 -0800180 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000181}
182
183TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) {
184 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800185 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000186}
187
188TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700189 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000190
191 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800192 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000193}
194
195TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700196 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
197 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000198
199 const FloatRect expected{0.f, 0.f, 1080.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800200 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000201}
202
203TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) {
204 struct Entry {
205 uint32_t bufferInvDisplay;
206 uint32_t buffer;
207 uint32_t display;
208 FloatRect expected;
209 };
210 // Not an exhaustive list of cases, but hopefully enough.
211 const std::array<Entry, 12> testData = {
212 // clang-format off
213 // inv buffer display expected
214 /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
215 /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
216 /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
217 /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
218
219 /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
220 /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
221 /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
222 /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
223
224 /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
225 /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
226 /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
227 /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
228
229 // clang-format on
230 };
231
232 for (size_t i = 0; i < testData.size(); i++) {
233 const auto& entry = testData[i];
234
Lloyd Pique9755fb72019-03-26 14:44:40 -0700235 mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay;
236 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000237 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000238
Lloyd Piqueea629282019-12-03 15:57:10 -0800239 EXPECT_THAT(calculateOutputSourceCrop(), entry.expected) << "entry " << i;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000240 }
241}
242
243TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700244 mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000245
246 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800247 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000248}
249
250TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) {
Angel Aguayob084e0c2021-08-04 23:27:28 +0000251 mOutputState.layerStackSpace.setContent(Rect{0, 0, 960, 540});
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000252
253 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800254 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000255}
256
257/*
Lloyd Piquea83776c2019-01-29 18:42:32 -0800258 * OutputLayer::calculateOutputDisplayFrame()
259 */
260
261struct OutputLayerDisplayFrameTest : public OutputLayerTest {
262 OutputLayerDisplayFrameTest() {
263 // Set reasonable default values for a simple case. Each test will
264 // set one specific value to something different.
265
Lloyd Pique9755fb72019-03-26 14:44:40 -0700266 mLayerFEState.transparentRegionHint = Region{};
267 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
268 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
269 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
270 mLayerFEState.geomCrop = Rect{0, 0, 1920, 1080};
271 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800272
Angel Aguayob084e0c2021-08-04 23:27:28 +0000273 mOutputState.layerStackSpace.setContent(Rect{0, 0, 1920, 1080});
Lloyd Piquea83776c2019-01-29 18:42:32 -0800274 mOutputState.transform = ui::Transform{TR_IDENT};
275 }
276
277 Rect calculateOutputDisplayFrame() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700278 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800279
280 return mOutputLayer.calculateOutputDisplayFrame();
281 }
282};
283
284TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) {
285 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800286 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800287}
288
289TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700290 mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800291 const Rect expected{0, 0, 0, 0};
Lloyd Piqueea629282019-12-03 15:57:10 -0800292 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800293}
294
295TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700296 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800297 const Rect expected{100, 200, 300, 500};
Lloyd Piqueea629282019-12-03 15:57:10 -0800298 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800299}
300
301TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700302 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
303 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800304 const Rect expected{1420, 100, 1720, 300};
Lloyd Piqueea629282019-12-03 15:57:10 -0800305 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800306}
307
308TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700309 mLayerFEState.geomCrop = Rect{};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800310 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800311 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800312}
313
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000314TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700315 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800316 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800317 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800318}
319
320TEST_F(OutputLayerDisplayFrameTest, viewportAffectsFrame) {
Angel Aguayob084e0c2021-08-04 23:27:28 +0000321 mOutputState.layerStackSpace.setContent(Rect{0, 0, 960, 540});
Lloyd Piquea83776c2019-01-29 18:42:32 -0800322 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800323 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800324}
325
326TEST_F(OutputLayerDisplayFrameTest, outputTransformAffectsDisplayFrame) {
327 mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90};
328 const Rect expected{-1080, 0, 0, 1920};
Lloyd Piqueea629282019-12-03 15:57:10 -0800329 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800330}
331
Leon Scroggins IIId394d3c2021-06-24 11:30:32 -0400332TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame) {
333 const int kShadowRadius = 5;
334 mLayerFEState.shadowRadius = kShadowRadius;
335 mLayerFEState.forceClientComposition = true;
336
337 mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
338 Rect expected{mLayerFEState.geomLayerBounds};
339 expected.inset(-kShadowRadius, -kShadowRadius, -kShadowRadius, -kShadowRadius);
340 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
341}
342
343TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame_onlyIfForcingClientComposition) {
344 const int kShadowRadius = 5;
345 mLayerFEState.shadowRadius = kShadowRadius;
346 mLayerFEState.forceClientComposition = false;
347
348 mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
349 Rect expected{mLayerFEState.geomLayerBounds};
350 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
351}
352
Lloyd Piquea83776c2019-01-29 18:42:32 -0800353/*
354 * OutputLayer::calculateOutputRelativeBufferTransform()
355 */
356
357TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700358 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800359
360 struct Entry {
361 uint32_t layer;
362 uint32_t buffer;
363 uint32_t display;
364 uint32_t expected;
365 };
366 // Not an exhaustive list of cases, but hopefully enough.
367 const std::array<Entry, 24> testData = {
368 // clang-format off
369 // layer buffer display expected
370 /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
371 /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_90},
372 /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
373 /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270},
374
375 /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_IDENT},
376 /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_90},
377 /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_180},
378 /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_ROT_270},
379
380 /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V},
381 /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_180},
382 /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
383 /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_180},
384
385 /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_90},
386 /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_180},
387 /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT ^ TR_ROT_270},
388 /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_IDENT},
389
390 /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_ROT_180},
391 /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT ^ TR_ROT_270},
392 /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_IDENT},
393 /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_90},
394
395 /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_270},
396 /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_IDENT},
397 /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_90},
398 /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_180},
399 // clang-format on
400 };
401
402 for (size_t i = 0; i < testData.size(); i++) {
403 const auto& entry = testData[i];
404
Lloyd Pique9755fb72019-03-26 14:44:40 -0700405 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
406 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000407 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700408 mOutputState.transform = ui::Transform{entry.display};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800409
Snild Dolkow9e217d62020-04-22 15:53:42 +0200410 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.display);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800411 EXPECT_EQ(entry.expected, actual) << "entry " << i;
412 }
413}
414
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000415TEST_F(OutputLayerTest,
416 calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700417 mLayerFEState.geomBufferUsesDisplayInverseTransform = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000418
419 struct Entry {
Snild Dolkow9e217d62020-04-22 15:53:42 +0200420 uint32_t layer; /* shouldn't affect the result, so we just use arbitrary values */
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000421 uint32_t buffer;
422 uint32_t display;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200423 uint32_t internal;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000424 uint32_t expected;
425 };
Snild Dolkow9e217d62020-04-22 15:53:42 +0200426 const std::array<Entry, 64> testData = {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000427 // clang-format off
Snild Dolkow9e217d62020-04-22 15:53:42 +0200428 // layer buffer display internal expected
429 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
430 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_270},
431 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
432 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_90},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000433
Snild Dolkow9e217d62020-04-22 15:53:42 +0200434 Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT, TR_ROT_90},
435 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_90, TR_IDENT},
436 Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_180, TR_ROT_270},
437 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000438
Snild Dolkow9e217d62020-04-22 15:53:42 +0200439 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_180},
440 Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_90, TR_ROT_90},
441 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
442 Entry{TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000443
Snild Dolkow9e217d62020-04-22 15:53:42 +0200444 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270},
445 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_ROT_90, TR_ROT_180},
446 Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_180, TR_ROT_90},
447 Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000448
Snild Dolkow9e217d62020-04-22 15:53:42 +0200449 // layer buffer display internal expected
450 Entry{TR_IDENT, TR_ROT_90, TR_IDENT, TR_IDENT, TR_ROT_90},
451 Entry{TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_90, TR_IDENT},
452 Entry{TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_270},
453 Entry{TR_ROT_270, TR_ROT_90, TR_IDENT, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000454
Snild Dolkow9e217d62020-04-22 15:53:42 +0200455 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_180},
456 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90},
457 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_IDENT},
458 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270, TR_ROT_270},
459
460 Entry{TR_IDENT, TR_ROT_90, TR_ROT_180, TR_IDENT, TR_ROT_270},
461 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_180},
462 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_180, TR_ROT_90},
463 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_270, TR_IDENT},
464
465 Entry{TR_IDENT, TR_ROT_90, TR_ROT_270, TR_IDENT, TR_IDENT},
466 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270},
467 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_ROT_180, TR_ROT_180},
468 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90},
469
470 // layer buffer display internal expected
471 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_IDENT, TR_ROT_180},
472 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_90},
473 Entry{TR_ROT_180, TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT},
474 Entry{TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_270},
475
476 Entry{TR_IDENT, TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_270},
477 Entry{TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_90, TR_ROT_180},
478 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_90},
479 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_IDENT},
480
481 Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT, TR_IDENT},
482 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270},
483 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180},
484 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90},
485
486 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_IDENT, TR_ROT_90},
487 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_IDENT},
488 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_270},
489 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_270, TR_ROT_180},
490
491 // layer buffer display internal expected
492 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_IDENT, TR_ROT_270},
493 Entry{TR_ROT_90, TR_ROT_270, TR_IDENT, TR_ROT_90, TR_ROT_180},
494 Entry{TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_90},
495 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT},
496
497 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_IDENT, TR_IDENT},
498 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270},
499 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_ROT_180, TR_ROT_180},
500 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90},
501
502 Entry{TR_IDENT, TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_90},
503 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_90, TR_IDENT},
504 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270},
505 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_180},
506
507 Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180},
508 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_ROT_90},
509 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_IDENT},
510 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000511 // clang-format on
512 };
513
514 for (size_t i = 0; i < testData.size(); i++) {
515 const auto& entry = testData[i];
516
Snild Dolkow9e217d62020-04-22 15:53:42 +0200517 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
Lloyd Pique9755fb72019-03-26 14:44:40 -0700518 mLayerFEState.geomBufferTransform = entry.buffer;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000519 mOutputState.displaySpace.setOrientation(toRotation(entry.display));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700520 mOutputState.transform = ui::Transform{entry.display};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000521
Snild Dolkow9e217d62020-04-22 15:53:42 +0200522 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.internal);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000523 EXPECT_EQ(entry.expected, actual) << "entry " << i;
524 }
525}
526
527/*
528 * OutputLayer::updateCompositionState()
529 */
530
531struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer {
532 OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output,
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000533 sp<compositionengine::LayerFE> layerFE)
Lloyd Piquede196652020-01-22 17:29:58 -0800534 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000535 // Mock everything called by updateCompositionState to simplify testing it.
536 MOCK_CONST_METHOD0(calculateOutputSourceCrop, FloatRect());
537 MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect());
Snild Dolkow9e217d62020-04-22 15:53:42 +0200538 MOCK_CONST_METHOD1(calculateOutputRelativeBufferTransform, uint32_t(uint32_t));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700539
540 // compositionengine::OutputLayer overrides
541 const compositionengine::Output& getOutput() const override { return mOutput; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700542 compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
543 const impl::OutputLayerCompositionState& getState() const override { return mState; }
544 impl::OutputLayerCompositionState& editState() override { return mState; }
545
546 // These need implementations though are not expected to be called.
547 MOCK_CONST_METHOD1(dumpState, void(std::string&));
548
549 const compositionengine::Output& mOutput;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700550 sp<compositionengine::LayerFE> mLayerFE;
551 impl::OutputLayerCompositionState mState;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000552};
553
554struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest {
555public:
556 OutputLayerUpdateCompositionStateTest() {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000557 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
Lloyd Piquef5275482019-01-29 18:42:42 -0800558 EXPECT_CALL(mOutput, getDisplayColorProfile())
559 .WillRepeatedly(Return(&mDisplayColorProfile));
560 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000561 }
562
563 ~OutputLayerUpdateCompositionStateTest() = default;
564
Snild Dolkow9e217d62020-04-22 15:53:42 +0200565 void setupGeometryChildCallValues(ui::Transform::RotationFlags internalDisplayRotationFlags) {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000566 EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop()).WillOnce(Return(kSourceCrop));
567 EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200568 EXPECT_CALL(mOutputLayer,
569 calculateOutputRelativeBufferTransform(internalDisplayRotationFlags))
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000570 .WillOnce(Return(mBufferTransform));
571 }
572
573 void validateComputedGeometryState() {
574 const auto& state = mOutputLayer.getState();
575 EXPECT_EQ(kSourceCrop, state.sourceCrop);
576 EXPECT_EQ(kDisplayFrame, state.displayFrame);
577 EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform);
578 }
579
580 const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f};
581 const Rect kDisplayFrame{11, 12, 13, 14};
582 uint32_t mBufferTransform{21};
583
584 using OutputLayer = OutputLayerPartialMockForUpdateCompositionState;
Lloyd Piquede196652020-01-22 17:29:58 -0800585 StrictMock<OutputLayer> mOutputLayer{mOutput, mLayerFE};
Lloyd Piquef5275482019-01-29 18:42:42 -0800586 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000587};
588
Lloyd Piquede196652020-01-22 17:29:58 -0800589TEST_F(OutputLayerUpdateCompositionStateTest, doesNothingIfNoFECompositionState) {
590 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
591
Snild Dolkow9e217d62020-04-22 15:53:42 +0200592 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Piquede196652020-01-22 17:29:58 -0800593}
594
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000595TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700596 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000597 mOutputState.isSecure = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700598 mOutputLayer.editState().forceClientComposition = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000599
Snild Dolkow9e217d62020-04-22 15:53:42 +0200600 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000601
Snild Dolkow9e217d62020-04-22 15:53:42 +0200602 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000603
604 validateComputedGeometryState();
605
606 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
607}
608
609TEST_F(OutputLayerUpdateCompositionStateTest,
610 alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700611 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000612 mOutputState.isSecure = false;
613
Snild Dolkow9e217d62020-04-22 15:53:42 +0200614 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000615
Snild Dolkow9e217d62020-04-22 15:53:42 +0200616 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000617
618 validateComputedGeometryState();
619
620 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
621}
622
623TEST_F(OutputLayerUpdateCompositionStateTest,
624 alsoSetsForceCompositionIfUnsupportedBufferTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700625 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000626 mOutputState.isSecure = true;
627
628 mBufferTransform = ui::Transform::ROT_INVALID;
629
Snild Dolkow9e217d62020-04-22 15:53:42 +0200630 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000631
Snild Dolkow9e217d62020-04-22 15:53:42 +0200632 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000633
634 validateComputedGeometryState();
635
636 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
637}
638
Lloyd Piquef5275482019-01-29 18:42:42 -0800639TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700640 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
Lloyd Piquef5275482019-01-29 18:42:42 -0800641 mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB;
642
643 // If the layer is not colorspace agnostic, the output layer dataspace
644 // should use the layers requested colorspace.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700645 mLayerFEState.isColorspaceAgnostic = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800646
Snild Dolkow9e217d62020-04-22 15:53:42 +0200647 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800648
649 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
650
651 // If the layer is colorspace agnostic, the output layer dataspace
652 // should use the colorspace chosen for the whole output.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700653 mLayerFEState.isColorspaceAgnostic = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800654
Snild Dolkow9e217d62020-04-22 15:53:42 +0200655 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800656
657 EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace);
658}
659
Alec Mourie8dd3562022-02-11 14:18:57 -0800660TEST_F(OutputLayerUpdateCompositionStateTest, setsWhitePointNitsAndDimmingRatioCorrectly) {
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700661 mOutputState.sdrWhitePointNits = 200.f;
662 mOutputState.displayBrightnessNits = 800.f;
663
664 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
665 mLayerFEState.isColorspaceAgnostic = false;
666 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
667 EXPECT_EQ(mOutputState.sdrWhitePointNits, mOutputLayer.getState().whitePointNits);
Alec Mourie8dd3562022-02-11 14:18:57 -0800668 EXPECT_EQ(mOutputState.sdrWhitePointNits / mOutputState.displayBrightnessNits,
669 mOutputLayer.getState().dimmingRatio);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700670
671 mLayerFEState.dataspace = ui::Dataspace::BT2020_ITU_PQ;
672 mLayerFEState.isColorspaceAgnostic = false;
673 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
674
675 EXPECT_EQ(mOutputState.displayBrightnessNits, mOutputLayer.getState().whitePointNits);
Alec Mourie8dd3562022-02-11 14:18:57 -0800676 EXPECT_EQ(1.f, mOutputLayer.getState().dimmingRatio);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700677}
678
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000679TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700680 mOutputLayer.editState().forceClientComposition = false;
681
Snild Dolkow9e217d62020-04-22 15:53:42 +0200682 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000683
684 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
685}
686
Lloyd Piquefe671022019-09-24 10:43:03 -0700687TEST_F(OutputLayerUpdateCompositionStateTest,
688 doesNotClearForceClientCompositionIfNotDoingGeometry) {
689 mOutputLayer.editState().forceClientComposition = true;
690
Snild Dolkow9e217d62020-04-22 15:53:42 +0200691 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquefe671022019-09-24 10:43:03 -0700692
693 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
694}
695
Lloyd Piquef5275482019-01-29 18:42:42 -0800696TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700697 mLayerFEState.forceClientComposition = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700698 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800699
Snild Dolkow9e217d62020-04-22 15:53:42 +0200700 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800701
702 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
703}
704
705TEST_F(OutputLayerUpdateCompositionStateTest,
706 clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700707 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800708 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false));
709
Snild Dolkow9e217d62020-04-22 15:53:42 +0200710 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700711
712 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
713}
714
715TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromArgumentFlag) {
716 mLayerFEState.forceClientComposition = false;
717 mOutputLayer.editState().forceClientComposition = false;
718
Snild Dolkow9e217d62020-04-22 15:53:42 +0200719 mOutputLayer.updateCompositionState(false, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700720
721 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
722
723 mOutputLayer.editState().forceClientComposition = false;
724
Snild Dolkow9e217d62020-04-22 15:53:42 +0200725 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700726
Snild Dolkow9e217d62020-04-22 15:53:42 +0200727 mOutputLayer.updateCompositionState(true, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800728
729 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
730}
731
Lloyd Piquea83776c2019-01-29 18:42:32 -0800732/*
733 * OutputLayer::writeStateToHWC()
734 */
735
736struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
Peiyong Line9d809e2020-04-14 13:10:48 -0700737 static constexpr hal::Error kError = hal::Error::UNSUPPORTED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800738 static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800739 static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31);
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700740 static constexpr Hwc2::Transform kOverrideBufferTransform = static_cast<Hwc2::Transform>(0);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800741 static constexpr Hwc2::IComposerClient::BlendMode kBlendMode =
742 static_cast<Hwc2::IComposerClient::BlendMode>(41);
Alec Mouriee69a592021-03-23 15:00:45 -0700743 static constexpr Hwc2::IComposerClient::BlendMode kOverrideBlendMode =
744 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800745 static constexpr float kAlpha = 51.f;
Alec Mouriee69a592021-03-23 15:00:45 -0700746 static constexpr float kOverrideAlpha = 1.f;
Alec Mouri96ca45c2021-06-09 17:32:26 -0700747 static constexpr float kSkipAlpha = 0.f;
Lloyd Piquef5275482019-01-29 18:42:42 -0800748 static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
Alec Mourib7edfc22021-03-17 16:20:26 -0700749 static constexpr ui::Dataspace kOverrideDataspace = static_cast<ui::Dataspace>(72);
Lloyd Piquef5275482019-01-29 18:42:42 -0800750 static constexpr int kSupportedPerFrameMetadata = 101;
751 static constexpr int kExpectedHwcSlot = 0;
Alec Mourie7cc1c22021-04-27 15:23:26 -0700752 static constexpr int kOverrideHwcSlot = impl::HwcBufferCache::FLATTENER_CACHING_SLOT;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800753 static constexpr bool kLayerGenericMetadata1Mandatory = true;
754 static constexpr bool kLayerGenericMetadata2Mandatory = true;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700755 static constexpr float kWhitePointNits = 200.f;
Alec Mourie8dd3562022-02-11 14:18:57 -0800756 static constexpr float kSdrWhitePointNits = 100.f;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700757 static constexpr float kDisplayBrightnessNits = 400.f;
Alec Mouri6da0e272022-02-07 12:45:57 -0800758 static constexpr float kLayerBrightness = kWhitePointNits / kDisplayBrightnessNits;
Alec Mourie8dd3562022-02-11 14:18:57 -0800759 static constexpr float kOverrideLayerBrightness = kSdrWhitePointNits / kDisplayBrightnessNits;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800760
Lloyd Piquef5275482019-01-29 18:42:42 -0800761 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800762 static const Rect kDisplayFrame;
Alec Mourib7edfc22021-03-17 16:20:26 -0700763 static const Rect kOverrideDisplayFrame;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700764 static const FloatRect kOverrideSourceCrop;
Lloyd Piquea2468662019-03-07 21:31:06 -0800765 static const Region kOutputSpaceVisibleRegion;
Alec Mouri464352b2021-03-24 16:33:21 -0700766 static const Region kOverrideVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800767 static const mat4 kColorTransform;
768 static const Region kSurfaceDamage;
Alec Mouri464352b2021-03-24 16:33:21 -0700769 static const Region kOverrideSurfaceDamage;
Lloyd Piquef5275482019-01-29 18:42:42 -0800770 static const HdrMetadata kHdrMetadata;
771 static native_handle_t* kSidebandStreamHandle;
772 static const sp<GraphicBuffer> kBuffer;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700773 static const sp<GraphicBuffer> kOverrideBuffer;
Lloyd Piquef5275482019-01-29 18:42:42 -0800774 static const sp<Fence> kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700775 static const sp<Fence> kOverrideFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800776 static const std::string kLayerGenericMetadata1Key;
777 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
778 static const std::string kLayerGenericMetadata2Key;
779 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800780
781 OutputLayerWriteStateToHWCTest() {
782 auto& outputLayerState = mOutputLayer.editState();
783 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
784
785 outputLayerState.displayFrame = kDisplayFrame;
786 outputLayerState.sourceCrop = kSourceCrop;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800787 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800788 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800789 outputLayerState.dataspace = kDataspace;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700790 outputLayerState.whitePointNits = kWhitePointNits;
Alec Mouri6da0e272022-02-07 12:45:57 -0800791 outputLayerState.dimmingRatio = kLayerBrightness;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800792
Lloyd Pique9755fb72019-03-26 14:44:40 -0700793 mLayerFEState.blendMode = kBlendMode;
794 mLayerFEState.alpha = kAlpha;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700795 mLayerFEState.colorTransform = kColorTransform;
796 mLayerFEState.color = kColor;
797 mLayerFEState.surfaceDamage = kSurfaceDamage;
798 mLayerFEState.hdrMetadata = kHdrMetadata;
799 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
800 mLayerFEState.buffer = kBuffer;
801 mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
802 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800803
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700804 mOutputState.displayBrightnessNits = kDisplayBrightnessNits;
Alec Mourie8dd3562022-02-11 14:18:57 -0800805 mOutputState.sdrWhitePointNits = kSdrWhitePointNits;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700806
Lloyd Piquef5275482019-01-29 18:42:42 -0800807 EXPECT_CALL(mOutput, getDisplayColorProfile())
808 .WillRepeatedly(Return(&mDisplayColorProfile));
809 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
810 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800811 }
812
Lloyd Piquef5275482019-01-29 18:42:42 -0800813 // Some tests may need to simulate unsupported HWC calls
814 enum class SimulateUnsupported { None, ColorTransform };
815
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800816 void includeGenericLayerMetadataInState() {
817 mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory,
818 kLayerGenericMetadata1Value};
819 mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory,
820 kLayerGenericMetadata2Value};
821 }
822
Alec Mourib7edfc22021-03-17 16:20:26 -0700823 void includeOverrideInfo() {
824 auto& overrideInfo = mOutputLayer.editState().overrideInfo;
825
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700826 overrideInfo.buffer = std::make_shared<
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800827 renderengine::impl::ExternalTexture>(kOverrideBuffer, mRenderEngine,
828 renderengine::impl::ExternalTexture::Usage::
829 READABLE |
830 renderengine::impl::ExternalTexture::
831 Usage::WRITEABLE);
Alec Mourib7edfc22021-03-17 16:20:26 -0700832 overrideInfo.acquireFence = kOverrideFence;
833 overrideInfo.displayFrame = kOverrideDisplayFrame;
834 overrideInfo.dataspace = kOverrideDataspace;
Alec Mouri464352b2021-03-24 16:33:21 -0700835 overrideInfo.damageRegion = kOverrideSurfaceDamage;
836 overrideInfo.visibleRegion = kOverrideVisibleRegion;
Alec Mourib7edfc22021-03-17 16:20:26 -0700837 }
838
839 void expectGeometryCommonCalls(Rect displayFrame = kDisplayFrame,
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700840 FloatRect sourceCrop = kSourceCrop,
Alec Mouriee69a592021-03-23 15:00:45 -0700841 Hwc2::Transform bufferTransform = kBufferTransform,
842 Hwc2::IComposerClient::BlendMode blendMode = kBlendMode,
843 float alpha = kAlpha) {
Alec Mourib7edfc22021-03-17 16:20:26 -0700844 EXPECT_CALL(*mHwcLayer, setDisplayFrame(displayFrame)).WillOnce(Return(kError));
845 EXPECT_CALL(*mHwcLayer, setSourceCrop(sourceCrop)).WillOnce(Return(kError));
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400846 EXPECT_CALL(*mHwcLayer, setZOrder(_)).WillOnce(Return(kError));
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700847 EXPECT_CALL(*mHwcLayer, setTransform(bufferTransform)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800848
Alec Mouriee69a592021-03-23 15:00:45 -0700849 EXPECT_CALL(*mHwcLayer, setBlendMode(blendMode)).WillOnce(Return(kError));
850 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(alpha)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800851 }
852
Alec Mourib7edfc22021-03-17 16:20:26 -0700853 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None,
Alec Mouri464352b2021-03-24 16:33:21 -0700854 ui::Dataspace dataspace = kDataspace,
855 const Region& visibleRegion = kOutputSpaceVisibleRegion,
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700856 const Region& surfaceDamage = kSurfaceDamage,
Alec Mouri6da0e272022-02-07 12:45:57 -0800857 float brightness = kLayerBrightness,
Leon Scroggins III9a0afda2022-01-11 16:53:09 -0500858 const Region& blockingRegion = Region()) {
Alec Mouri464352b2021-03-24 16:33:21 -0700859 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(visibleRegion))).WillOnce(Return(kError));
Alec Mourib7edfc22021-03-17 16:20:26 -0700860 EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError));
Alec Mouri6da0e272022-02-07 12:45:57 -0800861 EXPECT_CALL(*mHwcLayer, setBrightness(brightness)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800862 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
863 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700864 ? hal::Error::UNSUPPORTED
865 : hal::Error::NONE));
Alec Mouri464352b2021-03-24 16:33:21 -0700866 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(surfaceDamage))).WillOnce(Return(kError));
Leon Scroggins III9a0afda2022-01-11 16:53:09 -0500867 EXPECT_CALL(*mHwcLayer, setBlockingRegion(RegionEq(blockingRegion)))
868 .WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800869 }
870
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500871 void expectSetCompositionTypeCall(Composition compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700872 EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800873 }
874
875 void expectNoSetCompositionTypeCall() {
876 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
877 }
878
879 void expectSetColorCall() {
Ady Abraham6e60b142022-01-06 18:10:35 -0800880 const aidl::android::hardware::graphics::composer3::Color color = {kColor.r, kColor.g,
881 kColor.b, 1.0f};
Lloyd Piquef5275482019-01-29 18:42:42 -0800882
883 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
884 }
885
886 void expectSetSidebandHandleCall() {
887 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
888 }
889
Alec Mourie7cc1c22021-04-27 15:23:26 -0700890 void expectSetHdrMetadataAndBufferCalls(uint32_t hwcSlot = kExpectedHwcSlot,
891 sp<GraphicBuffer> buffer = kBuffer,
Alec Mourib7edfc22021-03-17 16:20:26 -0700892 sp<Fence> fence = kFence) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800893 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
Alec Mourie7cc1c22021-04-27 15:23:26 -0700894 EXPECT_CALL(*mHwcLayer, setBuffer(hwcSlot, buffer, fence));
Lloyd Piquef5275482019-01-29 18:42:42 -0800895 }
896
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800897 void expectGenericLayerMetadataCalls() {
898 // Note: Can be in any order.
899 EXPECT_CALL(*mHwcLayer,
900 setLayerGenericMetadata(kLayerGenericMetadata1Key,
901 kLayerGenericMetadata1Mandatory,
902 kLayerGenericMetadata1Value));
903 EXPECT_CALL(*mHwcLayer,
904 setLayerGenericMetadata(kLayerGenericMetadata2Key,
905 kLayerGenericMetadata2Mandatory,
906 kLayerGenericMetadata2Value));
907 }
908
Lloyd Piquea83776c2019-01-29 18:42:32 -0800909 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800910 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Alec Mouria90a5702021-04-16 16:36:21 +0000911 renderengine::mock::RenderEngine mRenderEngine;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800912};
913
Lloyd Piquef5275482019-01-29 18:42:42 -0800914const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
915 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800916const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Alec Mourib7edfc22021-03-17 16:20:26 -0700917const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044};
Wiwit Rifa'ie30a5852021-06-25 19:20:48 +0800918const FloatRect OutputLayerWriteStateToHWCTest::kOverrideSourceCrop{1002, 1003, 1004, 20044};
Lloyd Piquea2468662019-03-07 21:31:06 -0800919const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
920 Rect{1005, 1006, 1007, 1008}};
Alec Mouri464352b2021-03-24 16:33:21 -0700921const Region OutputLayerWriteStateToHWCTest::kOverrideVisibleRegion{Rect{1006, 1007, 1008, 1009}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800922const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
923 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
924 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
925};
926const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
Alec Mouri464352b2021-03-24 16:33:21 -0700927const Region OutputLayerWriteStateToHWCTest::kOverrideSurfaceDamage{Rect{1026, 1027, 1028, 1029}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800928const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
929native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
930 reinterpret_cast<native_handle_t*>(1031);
931const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700932const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kOverrideBuffer =
933 new GraphicBuffer(4, 5, PIXEL_FORMAT_RGBA_8888,
934 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
935 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Lloyd Piquef5275482019-01-29 18:42:42 -0800936const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700937const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = new Fence();
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800938const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
939 "com.example.metadata.1";
940const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
941const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
942 "com.example.metadata.2";
943const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
944 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800945
Lloyd Piquede196652020-01-22 17:29:58 -0800946TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
947 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
948
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400949 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
950 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquede196652020-01-22 17:29:58 -0800951}
952
Lloyd Piquea83776c2019-01-29 18:42:32 -0800953TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
954 mOutputLayer.editState().hwc.reset();
955
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400956 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
957 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800958}
959
960TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
961 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
962
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400963 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
964 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800965}
966
Lloyd Piquef5275482019-01-29 18:42:42 -0800967TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800968 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -0800969 expectPerFrameCommonCalls();
970
971 expectNoSetCompositionTypeCall();
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400972 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800973
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400974 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
975 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800976}
977
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700978TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
979 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
980 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
981 // This test simulates a scenario where displayInstallOrientation is set to
982 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
983 // DisplayDevice::setProjection).
Angel Aguayob084e0c2021-08-04 23:27:28 +0000984 mOutputState.displaySpace.setOrientation(ui::ROTATION_0);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700985 mOutputState.transform = ui::Transform{TR_ROT_90};
986 // Buffers are pre-rotated based on the transform hint (ROT_90); their
987 // geomBufferTransform is set to the inverse transform.
988 mLayerFEState.geomBufferTransform = TR_ROT_270;
989
Snild Dolkow9e217d62020-04-22 15:53:42 +0200990 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700991}
992
Lloyd Piquef5275482019-01-29 18:42:42 -0800993TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500994 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800995
996 expectPerFrameCommonCalls();
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400997 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Pique46b72df2019-10-29 13:19:27 -0700998
999 // Setting the composition type should happen before setting the color. We
1000 // check this in this test only by setting up an testing::InSeqeuence
1001 // instance before setting up the two expectations.
1002 InSequence s;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001003 expectSetCompositionTypeCall(Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -07001004 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -08001005
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001006 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1007 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001008}
1009
1010TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001011 mLayerFEState.compositionType = Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -08001012
1013 expectPerFrameCommonCalls();
1014 expectSetSidebandHandleCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001015 expectSetCompositionTypeCall(Composition::SIDEBAND);
Lloyd Piquef5275482019-01-29 18:42:42 -08001016
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001017 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1018
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001019 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1020 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001021}
1022
1023TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001024 mLayerFEState.compositionType = Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001025
1026 expectPerFrameCommonCalls();
1027 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001028 expectSetCompositionTypeCall(Composition::CURSOR);
Lloyd Piquef5275482019-01-29 18:42:42 -08001029
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001030 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1031
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001032 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1033 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001034}
1035
1036TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001037 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -08001038
1039 expectPerFrameCommonCalls();
1040 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001041 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Piquef5275482019-01-29 18:42:42 -08001042
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001043 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1044
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, compositionTypeIsNotSetIfUnchanged) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001050 (*mOutputLayer.editState().hwc).hwcCompositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001051
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001052 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001053
1054 expectPerFrameCommonCalls();
1055 expectSetColorCall();
1056 expectNoSetCompositionTypeCall();
1057
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001058 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1059
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001060 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1061 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001062}
1063
1064TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001065 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001066
1067 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
1068 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001069 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001070
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001071 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1072 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001073}
1074
1075TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
1076 mOutputLayer.editState().forceClientComposition = true;
1077
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001078 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001079
1080 expectPerFrameCommonCalls();
1081 expectSetColorCall();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001082 expectSetCompositionTypeCall(Composition::CLIENT);
Lloyd Piquef5275482019-01-29 18:42:42 -08001083
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001084 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1085 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001086}
1087
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001088TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001089 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001090 includeGenericLayerMetadataInState();
1091
1092 expectGeometryCommonCalls();
1093 expectPerFrameCommonCalls();
1094 expectSetHdrMetadataAndBufferCalls();
1095 expectGenericLayerMetadataCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001096 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001097
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001098 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1099
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001100 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1101 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001102}
1103
1104TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001105 mLayerFEState.compositionType = Composition::DEVICE;
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001106 includeGenericLayerMetadataInState();
1107
1108 expectPerFrameCommonCalls();
1109 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001110 expectSetCompositionTypeCall(Composition::DEVICE);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001111
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001112 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1113
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001114 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1115 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001116}
1117
Alec Mouri96ca45c2021-06-09 17:32:26 -07001118TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001119 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mouri96ca45c2021-06-09 17:32:26 -07001120 includeOverrideInfo();
1121
1122 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1123 kOverrideBlendMode, kSkipAlpha);
1124 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001125 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001126 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001127 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri96ca45c2021-06-09 17:32:26 -07001128 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1129
1130 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1131 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1132}
1133
Alec Mouri2b1212b2021-12-09 12:02:39 -08001134TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerForSolidColorDoesNotSendBuffer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001135 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri2b1212b2021-12-09 12:02:39 -08001136 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 Mouri2b1212b2021-12-09 12:02:39 -08001142 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001143 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri2b1212b2021-12-09 12:02:39 -08001144 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1145
1146 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1147 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1148}
1149
Alec Mourib7edfc22021-03-17 16:20:26 -07001150TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001151 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourib7edfc22021-03-17 16:20:26 -07001152 includeOverrideInfo();
1153
Alec Mouri03bf0ff2021-04-19 14:17:31 -07001154 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1155 kOverrideBlendMode, kOverrideAlpha);
Alec Mouri464352b2021-03-24 16:33:21 -07001156 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001157 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mourie7cc1c22021-04-27 15:23:26 -07001158 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001159 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001160 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1161
1162 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1163 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1164}
1165
Alec Mouri028676a2021-12-02 15:01:48 -08001166TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoForSolidColorIfPresent) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001167 mLayerFEState.compositionType = Composition::SOLID_COLOR;
Alec Mouri028676a2021-12-02 15:01:48 -08001168 includeOverrideInfo();
1169
1170 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1171 kOverrideBlendMode, kOverrideAlpha);
1172 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
Alec Mourie8dd3562022-02-11 14:18:57 -08001173 kOverrideSurfaceDamage, kOverrideLayerBrightness);
Alec Mouri028676a2021-12-02 15:01:48 -08001174 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001175 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mouri028676a2021-12-02 15:01:48 -08001176 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1177
1178 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1179 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1180}
1181
Alec Mourid1bf1b52021-05-05 18:44:58 -07001182TEST_F(OutputLayerWriteStateToHWCTest, previousOverriddenLayerSendsSurfaceDamage) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001183 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001184 mOutputLayer.editState().hwc->stateOverridden = true;
1185
1186 expectGeometryCommonCalls();
1187 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1188 Region::INVALID_REGION);
1189 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001190 expectSetCompositionTypeCall(Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001191 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1192
1193 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1194 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1195}
1196
1197TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedDeviceCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001198 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001199 mOutputLayer.editState().hwc->stateOverridden = true;
1200 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001201 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001202
1203 expectGeometryCommonCalls();
1204 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1205 Region::INVALID_REGION);
1206 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001207 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001208 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1209
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001210 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1211 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Alec Mourib7edfc22021-03-17 16:20:26 -07001212}
1213
Alec Mourid1bf1b52021-05-05 18:44:58 -07001214TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedClientCompositionInfo) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001215 mLayerFEState.compositionType = Composition::DEVICE;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001216 mOutputLayer.editState().forceClientComposition = true;
1217 mOutputLayer.editState().hwc->stateOverridden = true;
1218 mOutputLayer.editState().hwc->layerSkipped = true;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001219 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Alec Mourid1bf1b52021-05-05 18:44:58 -07001220
1221 expectGeometryCommonCalls();
1222 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1223 Region::INVALID_REGION);
1224 expectSetHdrMetadataAndBufferCalls();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001225 expectSetCompositionTypeCall(Composition::CLIENT);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001226 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1227
1228 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1229 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1230}
1231
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001232TEST_F(OutputLayerWriteStateToHWCTest, peekThroughChangesBlendMode) {
1233 auto peekThroughLayerFE = sp<compositionengine::mock::LayerFE>::make();
1234 OutputLayer peekThroughLayer{mOutput, peekThroughLayerFE};
1235
1236 mOutputLayer.mState.overrideInfo.peekThroughLayer = &peekThroughLayer;
1237
1238 expectGeometryCommonCalls(kDisplayFrame, kSourceCrop, kBufferTransform,
1239 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED);
1240 expectPerFrameCommonCalls();
1241 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1242
1243 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1244 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1245}
1246
1247TEST_F(OutputLayerWriteStateToHWCTest, isPeekingThroughSetsOverride) {
1248 expectGeometryCommonCalls();
1249 expectPerFrameCommonCalls();
1250
1251 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1252 /*zIsOverridden*/ false, /*isPeekingThrough*/ true);
1253 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1254}
1255
1256TEST_F(OutputLayerWriteStateToHWCTest, zIsOverriddenSetsOverride) {
1257 expectGeometryCommonCalls();
1258 expectPerFrameCommonCalls();
1259 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1260
1261 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1262 /*zIsOverridden*/ true, /*isPeekingThrough*/
1263 false);
1264 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1265}
1266
1267TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersForceClientComposition) {
1268 expectGeometryCommonCalls();
1269 expectPerFrameCommonCalls();
1270 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001271 expectSetCompositionTypeCall(Composition::CLIENT);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001272
1273 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1274 /*zIsOverridden*/ false, /*isPeekingThrough*/
1275 false);
1276}
1277
1278TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersPeekingThroughAllowsDeviceComposition) {
1279 expectGeometryCommonCalls();
1280 expectPerFrameCommonCalls();
1281 expectSetHdrMetadataAndBufferCalls();
1282 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(true));
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001283 expectSetCompositionTypeCall(Composition::DEVICE);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001284
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001285 mLayerFEState.compositionType = Composition::DEVICE;
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001286 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1287 /*zIsOverridden*/ false, /*isPeekingThrough*/
1288 true);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001289 EXPECT_EQ(Composition::DEVICE, mOutputLayer.getState().hwc->hwcCompositionType);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001290}
1291
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001292TEST_F(OutputLayerWriteStateToHWCTest, setBlockingRegion) {
1293 mLayerFEState.compositionType = Composition::DISPLAY_DECORATION;
1294 const auto blockingRegion = Region(Rect(0, 0, 1000, 1000));
1295 mOutputLayer.editState().outputSpaceBlockingRegionHint = blockingRegion;
1296
1297 expectGeometryCommonCalls();
1298 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
Alec Mouri6da0e272022-02-07 12:45:57 -08001299 kSurfaceDamage, kLayerBrightness, blockingRegion);
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001300 expectSetHdrMetadataAndBufferCalls();
1301 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1302 expectSetCompositionTypeCall(Composition::DISPLAY_DECORATION);
1303
1304 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1305 /*zIsOverridden*/ false, /*isPeekingThrough*/
1306 false);
1307}
1308
Lloyd Pique66d68602019-02-13 14:23:31 -08001309/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001310 * OutputLayer::writeCursorPositionToHWC()
1311 */
1312
1313struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1314 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -07001315 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001316
1317 static const Rect kDefaultDisplayViewport;
1318 static const Rect kDefaultCursorFrame;
1319
1320 OutputLayerWriteCursorPositionToHWCTest() {
1321 auto& outputLayerState = mOutputLayer.editState();
1322 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1323
Lloyd Pique9755fb72019-03-26 14:44:40 -07001324 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001325
Angel Aguayob084e0c2021-08-04 23:27:28 +00001326 mOutputState.layerStackSpace.setContent(kDefaultDisplayViewport);
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001327 mOutputState.transform = ui::Transform{kDefaultTransform};
1328 }
1329
1330 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1331};
1332
1333const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1334const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1335
Lloyd Piquede196652020-01-22 17:29:58 -08001336TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
1337 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
1338
1339 mOutputLayer.writeCursorPositionToHWC();
1340}
1341
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001342TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1343 mOutputLayer.editState().hwc.reset();
1344
1345 mOutputLayer.writeCursorPositionToHWC();
1346}
1347
1348TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1349 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1350
1351 mOutputLayer.writeCursorPositionToHWC();
1352}
1353
1354TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001355 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001356
1357 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1358
1359 mOutputLayer.writeCursorPositionToHWC();
1360}
1361
1362TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1363 mOutputState.transform = ui::Transform{TR_ROT_90};
1364
1365 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1366
1367 mOutputLayer.writeCursorPositionToHWC();
1368}
1369
1370/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001371 * OutputLayer::getHwcLayer()
1372 */
1373
1374TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1375 mOutputLayer.editState().hwc.reset();
1376
1377 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1378}
1379
1380TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1381 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1382
1383 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1384}
1385
1386TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1387 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1388 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1389
1390 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1391}
1392
1393/*
1394 * OutputLayer::requiresClientComposition()
1395 */
1396
1397TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1398 mOutputLayer.editState().hwc.reset();
1399
1400 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1401}
1402
1403TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1404 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001405 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
Lloyd Pique66d68602019-02-13 14:23:31 -08001406
1407 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1408}
1409
1410TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1411 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001412 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001413
1414 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1415}
1416
1417/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001418 * OutputLayer::isHardwareCursor()
1419 */
1420
1421TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1422 mOutputLayer.editState().hwc.reset();
1423
1424 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1425}
1426
1427TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1428 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001429 mOutputLayer.editState().hwc->hwcCompositionType = Composition::CURSOR;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001430
1431 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1432}
1433
1434TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1435 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001436 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001437
1438 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1439}
1440
1441/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001442 * OutputLayer::applyDeviceCompositionTypeChange()
1443 */
1444
1445TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1446 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001447 mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
Lloyd Pique66d68602019-02-13 14:23:31 -08001448
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001449 mOutputLayer.applyDeviceCompositionTypeChange(Composition::CLIENT);
Lloyd Pique66d68602019-02-13 14:23:31 -08001450
1451 ASSERT_TRUE(mOutputLayer.getState().hwc);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001452 EXPECT_EQ(Composition::CLIENT, mOutputLayer.getState().hwc->hwcCompositionType);
Lloyd Pique66d68602019-02-13 14:23:31 -08001453}
1454
1455/*
1456 * OutputLayer::prepareForDeviceLayerRequests()
1457 */
1458
1459TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1460 mOutputLayer.editState().clearClientTarget = true;
1461
1462 mOutputLayer.prepareForDeviceLayerRequests();
1463
1464 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1465}
1466
1467/*
1468 * OutputLayer::applyDeviceLayerRequest()
1469 */
1470
1471TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1472 mOutputLayer.editState().clearClientTarget = false;
1473
1474 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1475
1476 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1477}
1478
1479TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1480 mOutputLayer.editState().clearClientTarget = false;
1481
1482 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1483
1484 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1485}
1486
Lloyd Pique688abd42019-02-15 15:42:24 -08001487/*
1488 * OutputLayer::needsFiltering()
1489 */
1490
1491TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1492 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1493 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1494
1495 EXPECT_FALSE(mOutputLayer.needsFiltering());
1496}
1497
1498TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1499 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1500 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1501
1502 EXPECT_TRUE(mOutputLayer.needsFiltering());
1503}
1504
Lloyd Piquecc01a452018-12-04 17:24:00 -08001505} // namespace
1506} // namespace android::compositionengine