blob: e876a61c4f8327141311377e5b673a0b0819982f [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
17#include <compositionengine/impl/OutputLayer.h>
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070018#include <compositionengine/impl/OutputLayerCompositionState.h>
Lloyd Pique07e33212018-12-18 16:33:37 -080019#include <compositionengine/mock/CompositionEngine.h>
Lloyd Piquef5275482019-01-29 18:42:42 -080020#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080021#include <compositionengine/mock/LayerFE.h>
22#include <compositionengine/mock/Output.h>
23#include <gtest/gtest.h>
Marin Shalamanov68933fb2020-09-10 17:58:12 +020024#include <log/log.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080025
Alec Mouri03bf0ff2021-04-19 14:17:31 -070026#include <renderengine/mock/RenderEngine.h>
27#include <ui/PixelFormat.h>
Lloyd Pique07e33212018-12-18 16:33:37 -080028#include "MockHWC2.h"
29#include "MockHWComposer.h"
Lloyd Piquef5275482019-01-29 18:42:42 -080030#include "RegionMatcher.h"
Lloyd Pique07e33212018-12-18 16:33:37 -080031
Lloyd Piquecc01a452018-12-04 17:24:00 -080032namespace android::compositionengine {
33namespace {
34
Peiyong Line9d809e2020-04-14 13:10:48 -070035namespace hal = android::hardware::graphics::composer::hal;
36
Lloyd Piquea83776c2019-01-29 18:42:32 -080037using testing::_;
Lloyd Pique46b72df2019-10-29 13:19:27 -070038using testing::InSequence;
Lloyd Piquea83776c2019-01-29 18:42:32 -080039using testing::Return;
40using testing::ReturnRef;
Lloyd Piquecc01a452018-12-04 17:24:00 -080041using testing::StrictMock;
42
Lloyd Piquea83776c2019-01-29 18:42:32 -080043constexpr auto TR_IDENT = 0u;
44constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H;
45constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V;
46constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
47constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V;
48constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180;
49
50const std::string kOutputName{"Test Output"};
51
Lloyd Piquef5275482019-01-29 18:42:42 -080052MATCHER_P(ColorEq, expected, "") {
53 *result_listener << "Colors are not equal\n";
54 *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " "
55 << expected.a << "\n";
56 *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n";
57
58 return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a;
59}
60
Marin Shalamanov68933fb2020-09-10 17:58:12 +020061ui::Rotation toRotation(uint32_t rotationFlag) {
62 switch (rotationFlag) {
63 case ui::Transform::RotationFlags::ROT_0:
64 return ui::ROTATION_0;
65 case ui::Transform::RotationFlags::ROT_90:
66 return ui::ROTATION_90;
67 case ui::Transform::RotationFlags::ROT_180:
68 return ui::ROTATION_180;
69 case ui::Transform::RotationFlags::ROT_270:
70 return ui::ROTATION_270;
71 default:
72 LOG_FATAL("Unexpected rotation flag %d", rotationFlag);
73 return ui::Rotation(-1);
74 }
75}
76
Lloyd Pique66d68602019-02-13 14:23:31 -080077struct OutputLayerTest : public testing::Test {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070078 struct OutputLayer final : public impl::OutputLayer {
Lloyd Piquede196652020-01-22 17:29:58 -080079 OutputLayer(const compositionengine::Output& output, sp<compositionengine::LayerFE> layerFE)
80 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070081 ~OutputLayer() override = default;
82
83 // compositionengine::OutputLayer overrides
84 const compositionengine::Output& getOutput() const override { return mOutput; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070085 compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
86 const impl::OutputLayerCompositionState& getState() const override { return mState; }
87 impl::OutputLayerCompositionState& editState() override { return mState; }
88
89 // compositionengine::impl::OutputLayer overrides
90 void dumpState(std::string& out) const override { mState.dump(out); }
91
92 const compositionengine::Output& mOutput;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070093 sp<compositionengine::LayerFE> mLayerFE;
94 impl::OutputLayerCompositionState mState;
95 };
96
Lloyd Piquea83776c2019-01-29 18:42:32 -080097 OutputLayerTest() {
98 EXPECT_CALL(*mLayerFE, getDebugName()).WillRepeatedly(Return("Test LayerFE"));
99 EXPECT_CALL(mOutput, getName()).WillRepeatedly(ReturnRef(kOutputName));
100
Lloyd Piquede196652020-01-22 17:29:58 -0800101 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800102 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
103 }
104
Lloyd Piquecc01a452018-12-04 17:24:00 -0800105 compositionengine::mock::Output mOutput;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800106 sp<compositionengine::mock::LayerFE> mLayerFE{
107 new StrictMock<compositionengine::mock::LayerFE>()};
Lloyd Piquede196652020-01-22 17:29:58 -0800108 OutputLayer mOutputLayer{mOutput, mLayerFE};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800109
Lloyd Pique9755fb72019-03-26 14:44:40 -0700110 LayerFECompositionState mLayerFEState;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800111 impl::OutputCompositionState mOutputState;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800112};
113
Lloyd Piquea83776c2019-01-29 18:42:32 -0800114/*
Lloyd Piquecc01a452018-12-04 17:24:00 -0800115 * Basic construction
116 */
117
118TEST_F(OutputLayerTest, canInstantiateOutputLayer) {}
119
Lloyd Piquea83776c2019-01-29 18:42:32 -0800120/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800121 * OutputLayer::setHwcLayer()
Lloyd Pique07e33212018-12-18 16:33:37 -0800122 */
123
Lloyd Piquedf336d92019-03-07 21:38:42 -0800124TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) {
Lloyd Pique07e33212018-12-18 16:33:37 -0800125 StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
126
Lloyd Piquedf336d92019-03-07 21:38:42 -0800127 mOutputLayer.setHwcLayer(nullptr);
Lloyd Pique07e33212018-12-18 16:33:37 -0800128
129 EXPECT_FALSE(mOutputLayer.getState().hwc);
130}
131
Lloyd Piquedf336d92019-03-07 21:38:42 -0800132TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) {
133 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Pique07e33212018-12-18 16:33:37 -0800134
Lloyd Piquedf336d92019-03-07 21:38:42 -0800135 mOutputLayer.setHwcLayer(hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800136
Lloyd Piquea83776c2019-01-29 18:42:32 -0800137 const auto& outputLayerState = mOutputLayer.getState();
138 ASSERT_TRUE(outputLayerState.hwc);
Lloyd Pique07e33212018-12-18 16:33:37 -0800139
Lloyd Piquea83776c2019-01-29 18:42:32 -0800140 const auto& hwcState = *outputLayerState.hwc;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800141 EXPECT_EQ(hwcLayer, hwcState.hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800142}
143
Lloyd Piquea83776c2019-01-29 18:42:32 -0800144/*
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000145 * OutputLayer::calculateOutputSourceCrop()
146 */
147
148struct OutputLayerSourceCropTest : public OutputLayerTest {
149 OutputLayerSourceCropTest() {
150 // Set reasonable default values for a simple case. Each test will
151 // set one specific value to something different.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700152 mLayerFEState.geomUsesSourceCrop = true;
153 mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080};
154 mLayerFEState.transparentRegionHint = Region{};
155 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
156 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
157 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
158 mLayerFEState.geomBufferTransform = TR_IDENT;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000159
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200160 mOutputState.layerStackSpace.content = Rect{0, 0, 1920, 1080};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000161 }
162
163 FloatRect calculateOutputSourceCrop() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700164 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000165
166 return mOutputLayer.calculateOutputSourceCrop();
167 }
168};
169
170TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700171 mLayerFEState.geomUsesSourceCrop = false;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000172
173 const FloatRect expected{};
Lloyd Piqueea629282019-12-03 15:57:10 -0800174 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000175}
176
177TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) {
178 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800179 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000180}
181
182TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700183 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000184
185 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800186 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000187}
188
189TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700190 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
191 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000192
193 const FloatRect expected{0.f, 0.f, 1080.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800194 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000195}
196
197TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) {
198 struct Entry {
199 uint32_t bufferInvDisplay;
200 uint32_t buffer;
201 uint32_t display;
202 FloatRect expected;
203 };
204 // Not an exhaustive list of cases, but hopefully enough.
205 const std::array<Entry, 12> testData = {
206 // clang-format off
207 // inv buffer display expected
208 /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
209 /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
210 /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
211 /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
212
213 /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
214 /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
215 /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
216 /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
217
218 /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
219 /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
220 /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
221 /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
222
223 // clang-format on
224 };
225
226 for (size_t i = 0; i < testData.size(); i++) {
227 const auto& entry = testData[i];
228
Lloyd Pique9755fb72019-03-26 14:44:40 -0700229 mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay;
230 mLayerFEState.geomBufferTransform = entry.buffer;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200231 mOutputState.displaySpace.orientation = toRotation(entry.display);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000232
Lloyd Piqueea629282019-12-03 15:57:10 -0800233 EXPECT_THAT(calculateOutputSourceCrop(), entry.expected) << "entry " << i;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000234 }
235}
236
237TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700238 mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000239
240 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800241 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000242}
243
244TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200245 mOutputState.layerStackSpace.content = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000246
247 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800248 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000249}
250
251/*
Lloyd Piquea83776c2019-01-29 18:42:32 -0800252 * OutputLayer::calculateOutputDisplayFrame()
253 */
254
255struct OutputLayerDisplayFrameTest : public OutputLayerTest {
256 OutputLayerDisplayFrameTest() {
257 // Set reasonable default values for a simple case. Each test will
258 // set one specific value to something different.
259
Lloyd Pique9755fb72019-03-26 14:44:40 -0700260 mLayerFEState.transparentRegionHint = Region{};
261 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
262 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
263 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
264 mLayerFEState.geomCrop = Rect{0, 0, 1920, 1080};
265 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800266
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200267 mOutputState.layerStackSpace.content = Rect{0, 0, 1920, 1080};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800268 mOutputState.transform = ui::Transform{TR_IDENT};
269 }
270
271 Rect calculateOutputDisplayFrame() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700272 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800273
274 return mOutputLayer.calculateOutputDisplayFrame();
275 }
276};
277
278TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) {
279 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800280 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800281}
282
283TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700284 mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800285 const Rect expected{0, 0, 0, 0};
Lloyd Piqueea629282019-12-03 15:57:10 -0800286 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800287}
288
289TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700290 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800291 const Rect expected{100, 200, 300, 500};
Lloyd Piqueea629282019-12-03 15:57:10 -0800292 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800293}
294
295TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700296 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
297 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800298 const Rect expected{1420, 100, 1720, 300};
Lloyd Piqueea629282019-12-03 15:57:10 -0800299 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800300}
301
302TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700303 mLayerFEState.geomCrop = Rect{};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800304 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800305 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800306}
307
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000308TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700309 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800310 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800311 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800312}
313
314TEST_F(OutputLayerDisplayFrameTest, viewportAffectsFrame) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200315 mOutputState.layerStackSpace.content = Rect{0, 0, 960, 540};
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, outputTransformAffectsDisplayFrame) {
321 mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90};
322 const Rect expected{-1080, 0, 0, 1920};
Lloyd Piqueea629282019-12-03 15:57:10 -0800323 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800324}
325
326/*
327 * OutputLayer::calculateOutputRelativeBufferTransform()
328 */
329
330TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700331 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800332
333 struct Entry {
334 uint32_t layer;
335 uint32_t buffer;
336 uint32_t display;
337 uint32_t expected;
338 };
339 // Not an exhaustive list of cases, but hopefully enough.
340 const std::array<Entry, 24> testData = {
341 // clang-format off
342 // layer buffer display expected
343 /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
344 /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_90},
345 /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
346 /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270},
347
348 /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_IDENT},
349 /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_90},
350 /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_180},
351 /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_ROT_270},
352
353 /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V},
354 /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_180},
355 /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
356 /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_180},
357
358 /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_90},
359 /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_180},
360 /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT ^ TR_ROT_270},
361 /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_IDENT},
362
363 /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_ROT_180},
364 /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT ^ TR_ROT_270},
365 /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_IDENT},
366 /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_90},
367
368 /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_270},
369 /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_IDENT},
370 /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_90},
371 /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_180},
372 // clang-format on
373 };
374
375 for (size_t i = 0; i < testData.size(); i++) {
376 const auto& entry = testData[i];
377
Lloyd Pique9755fb72019-03-26 14:44:40 -0700378 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
379 mLayerFEState.geomBufferTransform = entry.buffer;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200380 mOutputState.displaySpace.orientation = toRotation(entry.display);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700381 mOutputState.transform = ui::Transform{entry.display};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800382
Snild Dolkow9e217d62020-04-22 15:53:42 +0200383 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.display);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800384 EXPECT_EQ(entry.expected, actual) << "entry " << i;
385 }
386}
387
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000388TEST_F(OutputLayerTest,
389 calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700390 mLayerFEState.geomBufferUsesDisplayInverseTransform = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000391
392 struct Entry {
Snild Dolkow9e217d62020-04-22 15:53:42 +0200393 uint32_t layer; /* shouldn't affect the result, so we just use arbitrary values */
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000394 uint32_t buffer;
395 uint32_t display;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200396 uint32_t internal;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000397 uint32_t expected;
398 };
Snild Dolkow9e217d62020-04-22 15:53:42 +0200399 const std::array<Entry, 64> testData = {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000400 // clang-format off
Snild Dolkow9e217d62020-04-22 15:53:42 +0200401 // layer buffer display internal expected
402 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
403 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_270},
404 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
405 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_90},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000406
Snild Dolkow9e217d62020-04-22 15:53:42 +0200407 Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT, TR_ROT_90},
408 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_90, TR_IDENT},
409 Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_180, TR_ROT_270},
410 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000411
Snild Dolkow9e217d62020-04-22 15:53:42 +0200412 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_180},
413 Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_90, TR_ROT_90},
414 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
415 Entry{TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000416
Snild Dolkow9e217d62020-04-22 15:53:42 +0200417 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270},
418 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_ROT_90, TR_ROT_180},
419 Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_180, TR_ROT_90},
420 Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000421
Snild Dolkow9e217d62020-04-22 15:53:42 +0200422 // layer buffer display internal expected
423 Entry{TR_IDENT, TR_ROT_90, TR_IDENT, TR_IDENT, TR_ROT_90},
424 Entry{TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_90, TR_IDENT},
425 Entry{TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_270},
426 Entry{TR_ROT_270, TR_ROT_90, TR_IDENT, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000427
Snild Dolkow9e217d62020-04-22 15:53:42 +0200428 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_180},
429 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90},
430 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_IDENT},
431 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270, TR_ROT_270},
432
433 Entry{TR_IDENT, TR_ROT_90, TR_ROT_180, TR_IDENT, TR_ROT_270},
434 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_180},
435 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_180, TR_ROT_90},
436 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_270, TR_IDENT},
437
438 Entry{TR_IDENT, TR_ROT_90, TR_ROT_270, TR_IDENT, TR_IDENT},
439 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270},
440 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_ROT_180, TR_ROT_180},
441 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90},
442
443 // layer buffer display internal expected
444 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_IDENT, TR_ROT_180},
445 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_90},
446 Entry{TR_ROT_180, TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT},
447 Entry{TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_270},
448
449 Entry{TR_IDENT, TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_270},
450 Entry{TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_90, TR_ROT_180},
451 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_90},
452 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_IDENT},
453
454 Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT, TR_IDENT},
455 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270},
456 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180},
457 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90},
458
459 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_IDENT, TR_ROT_90},
460 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_IDENT},
461 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_270},
462 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_270, TR_ROT_180},
463
464 // layer buffer display internal expected
465 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_IDENT, TR_ROT_270},
466 Entry{TR_ROT_90, TR_ROT_270, TR_IDENT, TR_ROT_90, TR_ROT_180},
467 Entry{TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_90},
468 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT},
469
470 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_IDENT, TR_IDENT},
471 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270},
472 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_ROT_180, TR_ROT_180},
473 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90},
474
475 Entry{TR_IDENT, TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_90},
476 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_90, TR_IDENT},
477 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270},
478 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_180},
479
480 Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180},
481 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_ROT_90},
482 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_IDENT},
483 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000484 // clang-format on
485 };
486
487 for (size_t i = 0; i < testData.size(); i++) {
488 const auto& entry = testData[i];
489
Snild Dolkow9e217d62020-04-22 15:53:42 +0200490 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
Lloyd Pique9755fb72019-03-26 14:44:40 -0700491 mLayerFEState.geomBufferTransform = entry.buffer;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200492 mOutputState.displaySpace.orientation = toRotation(entry.display);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700493 mOutputState.transform = ui::Transform{entry.display};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000494
Snild Dolkow9e217d62020-04-22 15:53:42 +0200495 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.internal);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000496 EXPECT_EQ(entry.expected, actual) << "entry " << i;
497 }
498}
499
500/*
501 * OutputLayer::updateCompositionState()
502 */
503
504struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer {
505 OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output,
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000506 sp<compositionengine::LayerFE> layerFE)
Lloyd Piquede196652020-01-22 17:29:58 -0800507 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000508 // Mock everything called by updateCompositionState to simplify testing it.
509 MOCK_CONST_METHOD0(calculateOutputSourceCrop, FloatRect());
510 MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect());
Snild Dolkow9e217d62020-04-22 15:53:42 +0200511 MOCK_CONST_METHOD1(calculateOutputRelativeBufferTransform, uint32_t(uint32_t));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700512
513 // compositionengine::OutputLayer overrides
514 const compositionengine::Output& getOutput() const override { return mOutput; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700515 compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
516 const impl::OutputLayerCompositionState& getState() const override { return mState; }
517 impl::OutputLayerCompositionState& editState() override { return mState; }
518
519 // These need implementations though are not expected to be called.
520 MOCK_CONST_METHOD1(dumpState, void(std::string&));
521
522 const compositionengine::Output& mOutput;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700523 sp<compositionengine::LayerFE> mLayerFE;
524 impl::OutputLayerCompositionState mState;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000525};
526
527struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest {
528public:
529 OutputLayerUpdateCompositionStateTest() {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000530 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
Lloyd Piquef5275482019-01-29 18:42:42 -0800531 EXPECT_CALL(mOutput, getDisplayColorProfile())
532 .WillRepeatedly(Return(&mDisplayColorProfile));
533 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000534 }
535
536 ~OutputLayerUpdateCompositionStateTest() = default;
537
Snild Dolkow9e217d62020-04-22 15:53:42 +0200538 void setupGeometryChildCallValues(ui::Transform::RotationFlags internalDisplayRotationFlags) {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000539 EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop()).WillOnce(Return(kSourceCrop));
540 EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200541 EXPECT_CALL(mOutputLayer,
542 calculateOutputRelativeBufferTransform(internalDisplayRotationFlags))
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000543 .WillOnce(Return(mBufferTransform));
544 }
545
546 void validateComputedGeometryState() {
547 const auto& state = mOutputLayer.getState();
548 EXPECT_EQ(kSourceCrop, state.sourceCrop);
549 EXPECT_EQ(kDisplayFrame, state.displayFrame);
550 EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform);
551 }
552
553 const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f};
554 const Rect kDisplayFrame{11, 12, 13, 14};
555 uint32_t mBufferTransform{21};
556
557 using OutputLayer = OutputLayerPartialMockForUpdateCompositionState;
Lloyd Piquede196652020-01-22 17:29:58 -0800558 StrictMock<OutputLayer> mOutputLayer{mOutput, mLayerFE};
Lloyd Piquef5275482019-01-29 18:42:42 -0800559 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000560};
561
Lloyd Piquede196652020-01-22 17:29:58 -0800562TEST_F(OutputLayerUpdateCompositionStateTest, doesNothingIfNoFECompositionState) {
563 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
564
Snild Dolkow9e217d62020-04-22 15:53:42 +0200565 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Piquede196652020-01-22 17:29:58 -0800566}
567
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000568TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700569 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000570 mOutputState.isSecure = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700571 mOutputLayer.editState().forceClientComposition = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000572
Snild Dolkow9e217d62020-04-22 15:53:42 +0200573 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000574
Snild Dolkow9e217d62020-04-22 15:53:42 +0200575 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000576
577 validateComputedGeometryState();
578
579 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
580}
581
582TEST_F(OutputLayerUpdateCompositionStateTest,
583 alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700584 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000585 mOutputState.isSecure = false;
586
Snild Dolkow9e217d62020-04-22 15:53:42 +0200587 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000588
Snild Dolkow9e217d62020-04-22 15:53:42 +0200589 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000590
591 validateComputedGeometryState();
592
593 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
594}
595
596TEST_F(OutputLayerUpdateCompositionStateTest,
597 alsoSetsForceCompositionIfUnsupportedBufferTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700598 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000599 mOutputState.isSecure = true;
600
601 mBufferTransform = ui::Transform::ROT_INVALID;
602
Snild Dolkow9e217d62020-04-22 15:53:42 +0200603 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000604
Snild Dolkow9e217d62020-04-22 15:53:42 +0200605 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000606
607 validateComputedGeometryState();
608
609 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
610}
611
Lloyd Piquef5275482019-01-29 18:42:42 -0800612TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700613 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
Lloyd Piquef5275482019-01-29 18:42:42 -0800614 mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB;
615
616 // If the layer is not colorspace agnostic, the output layer dataspace
617 // should use the layers requested colorspace.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700618 mLayerFEState.isColorspaceAgnostic = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800619
Snild Dolkow9e217d62020-04-22 15:53:42 +0200620 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800621
622 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
623
624 // If the layer is colorspace agnostic, the output layer dataspace
625 // should use the colorspace chosen for the whole output.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700626 mLayerFEState.isColorspaceAgnostic = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800627
Snild Dolkow9e217d62020-04-22 15:53:42 +0200628 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800629
630 EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace);
631}
632
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000633TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700634 mOutputLayer.editState().forceClientComposition = false;
635
Snild Dolkow9e217d62020-04-22 15:53:42 +0200636 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000637
638 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
639}
640
Lloyd Piquefe671022019-09-24 10:43:03 -0700641TEST_F(OutputLayerUpdateCompositionStateTest,
642 doesNotClearForceClientCompositionIfNotDoingGeometry) {
643 mOutputLayer.editState().forceClientComposition = true;
644
Snild Dolkow9e217d62020-04-22 15:53:42 +0200645 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquefe671022019-09-24 10:43:03 -0700646
647 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
648}
649
Lloyd Piquef5275482019-01-29 18:42:42 -0800650TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700651 mLayerFEState.forceClientComposition = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700652 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800653
Snild Dolkow9e217d62020-04-22 15:53:42 +0200654 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800655
656 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
657}
658
659TEST_F(OutputLayerUpdateCompositionStateTest,
660 clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700661 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800662 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false));
663
Snild Dolkow9e217d62020-04-22 15:53:42 +0200664 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700665
666 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
667}
668
669TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromArgumentFlag) {
670 mLayerFEState.forceClientComposition = false;
671 mOutputLayer.editState().forceClientComposition = false;
672
Snild Dolkow9e217d62020-04-22 15:53:42 +0200673 mOutputLayer.updateCompositionState(false, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700674
675 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
676
677 mOutputLayer.editState().forceClientComposition = false;
678
Snild Dolkow9e217d62020-04-22 15:53:42 +0200679 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700680
Snild Dolkow9e217d62020-04-22 15:53:42 +0200681 mOutputLayer.updateCompositionState(true, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800682
683 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
684}
685
Lloyd Piquea83776c2019-01-29 18:42:32 -0800686/*
687 * OutputLayer::writeStateToHWC()
688 */
689
690struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
Peiyong Line9d809e2020-04-14 13:10:48 -0700691 static constexpr hal::Error kError = hal::Error::UNSUPPORTED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800692 static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800693 static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31);
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700694 static constexpr Hwc2::Transform kOverrideBufferTransform = static_cast<Hwc2::Transform>(0);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800695 static constexpr Hwc2::IComposerClient::BlendMode kBlendMode =
696 static_cast<Hwc2::IComposerClient::BlendMode>(41);
Alec Mouriee69a592021-03-23 15:00:45 -0700697 static constexpr Hwc2::IComposerClient::BlendMode kOverrideBlendMode =
698 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800699 static constexpr float kAlpha = 51.f;
Alec Mouriee69a592021-03-23 15:00:45 -0700700 static constexpr float kOverrideAlpha = 1.f;
Lloyd Piquef5275482019-01-29 18:42:42 -0800701 static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
Alec Mourib7edfc22021-03-17 16:20:26 -0700702 static constexpr ui::Dataspace kOverrideDataspace = static_cast<ui::Dataspace>(72);
Lloyd Piquef5275482019-01-29 18:42:42 -0800703 static constexpr int kSupportedPerFrameMetadata = 101;
704 static constexpr int kExpectedHwcSlot = 0;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800705 static constexpr bool kLayerGenericMetadata1Mandatory = true;
706 static constexpr bool kLayerGenericMetadata2Mandatory = true;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800707
Lloyd Piquef5275482019-01-29 18:42:42 -0800708 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800709 static const Rect kDisplayFrame;
Alec Mourib7edfc22021-03-17 16:20:26 -0700710 static const Rect kOverrideDisplayFrame;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700711 static const FloatRect kOverrideSourceCrop;
Lloyd Piquea2468662019-03-07 21:31:06 -0800712 static const Region kOutputSpaceVisibleRegion;
Alec Mouri464352b2021-03-24 16:33:21 -0700713 static const Region kOverrideVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800714 static const mat4 kColorTransform;
715 static const Region kSurfaceDamage;
Alec Mouri464352b2021-03-24 16:33:21 -0700716 static const Region kOverrideSurfaceDamage;
Lloyd Piquef5275482019-01-29 18:42:42 -0800717 static const HdrMetadata kHdrMetadata;
718 static native_handle_t* kSidebandStreamHandle;
719 static const sp<GraphicBuffer> kBuffer;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700720 static const sp<GraphicBuffer> kOverrideBuffer;
Lloyd Piquef5275482019-01-29 18:42:42 -0800721 static const sp<Fence> kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700722 static const sp<Fence> kOverrideFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800723 static const std::string kLayerGenericMetadata1Key;
724 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
725 static const std::string kLayerGenericMetadata2Key;
726 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800727
728 OutputLayerWriteStateToHWCTest() {
729 auto& outputLayerState = mOutputLayer.editState();
730 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
731
732 outputLayerState.displayFrame = kDisplayFrame;
733 outputLayerState.sourceCrop = kSourceCrop;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800734 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800735 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800736 outputLayerState.dataspace = kDataspace;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800737
Lloyd Pique9755fb72019-03-26 14:44:40 -0700738 mLayerFEState.blendMode = kBlendMode;
739 mLayerFEState.alpha = kAlpha;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700740 mLayerFEState.colorTransform = kColorTransform;
741 mLayerFEState.color = kColor;
742 mLayerFEState.surfaceDamage = kSurfaceDamage;
743 mLayerFEState.hdrMetadata = kHdrMetadata;
744 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
745 mLayerFEState.buffer = kBuffer;
746 mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
747 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800748
749 EXPECT_CALL(mOutput, getDisplayColorProfile())
750 .WillRepeatedly(Return(&mDisplayColorProfile));
751 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
752 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800753 }
754
Lloyd Piquef5275482019-01-29 18:42:42 -0800755 // Some tests may need to simulate unsupported HWC calls
756 enum class SimulateUnsupported { None, ColorTransform };
757
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800758 void includeGenericLayerMetadataInState() {
759 mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory,
760 kLayerGenericMetadata1Value};
761 mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory,
762 kLayerGenericMetadata2Value};
763 }
764
Alec Mourib7edfc22021-03-17 16:20:26 -0700765 void includeOverrideInfo() {
766 auto& overrideInfo = mOutputLayer.editState().overrideInfo;
767
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700768 overrideInfo.buffer = std::make_shared<
769 renderengine::ExternalTexture>(kOverrideBuffer, mRenderEngine,
770 renderengine::ExternalTexture::Usage::READABLE |
771 renderengine::ExternalTexture::Usage::
772 WRITEABLE);
Alec Mourib7edfc22021-03-17 16:20:26 -0700773 overrideInfo.acquireFence = kOverrideFence;
774 overrideInfo.displayFrame = kOverrideDisplayFrame;
775 overrideInfo.dataspace = kOverrideDataspace;
Alec Mouri464352b2021-03-24 16:33:21 -0700776 overrideInfo.damageRegion = kOverrideSurfaceDamage;
777 overrideInfo.visibleRegion = kOverrideVisibleRegion;
Alec Mourib7edfc22021-03-17 16:20:26 -0700778 }
779
780 void expectGeometryCommonCalls(Rect displayFrame = kDisplayFrame,
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700781 FloatRect sourceCrop = kSourceCrop,
Alec Mouriee69a592021-03-23 15:00:45 -0700782 Hwc2::Transform bufferTransform = kBufferTransform,
783 Hwc2::IComposerClient::BlendMode blendMode = kBlendMode,
784 float alpha = kAlpha) {
Alec Mourib7edfc22021-03-17 16:20:26 -0700785 EXPECT_CALL(*mHwcLayer, setDisplayFrame(displayFrame)).WillOnce(Return(kError));
786 EXPECT_CALL(*mHwcLayer, setSourceCrop(sourceCrop)).WillOnce(Return(kError));
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400787 EXPECT_CALL(*mHwcLayer, setZOrder(_)).WillOnce(Return(kError));
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700788 EXPECT_CALL(*mHwcLayer, setTransform(bufferTransform)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800789
Alec Mouriee69a592021-03-23 15:00:45 -0700790 EXPECT_CALL(*mHwcLayer, setBlendMode(blendMode)).WillOnce(Return(kError));
791 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(alpha)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800792 }
793
Alec Mourib7edfc22021-03-17 16:20:26 -0700794 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None,
Alec Mouri464352b2021-03-24 16:33:21 -0700795 ui::Dataspace dataspace = kDataspace,
796 const Region& visibleRegion = kOutputSpaceVisibleRegion,
797 const Region& surfaceDamage = kSurfaceDamage) {
798 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(visibleRegion))).WillOnce(Return(kError));
Alec Mourib7edfc22021-03-17 16:20:26 -0700799 EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800800 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
801 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700802 ? hal::Error::UNSUPPORTED
803 : hal::Error::NONE));
Alec Mouri464352b2021-03-24 16:33:21 -0700804 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(surfaceDamage))).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800805 }
806
807 void expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700808 EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800809 }
810
811 void expectNoSetCompositionTypeCall() {
812 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
813 }
814
815 void expectSetColorCall() {
Peiyong Lin65248e02020-04-18 21:15:07 -0700816 const hal::Color color = {static_cast<uint8_t>(std::round(kColor.r * 255)),
817 static_cast<uint8_t>(std::round(kColor.g * 255)),
818 static_cast<uint8_t>(std::round(kColor.b * 255)), 255};
Lloyd Piquef5275482019-01-29 18:42:42 -0800819
820 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
821 }
822
823 void expectSetSidebandHandleCall() {
824 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
825 }
826
Alec Mourib7edfc22021-03-17 16:20:26 -0700827 void expectSetHdrMetadataAndBufferCalls(sp<GraphicBuffer> buffer = kBuffer,
828 sp<Fence> fence = kFence) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800829 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
Alec Mourib7edfc22021-03-17 16:20:26 -0700830 EXPECT_CALL(*mHwcLayer, setBuffer(kExpectedHwcSlot, buffer, fence));
Lloyd Piquef5275482019-01-29 18:42:42 -0800831 }
832
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800833 void expectGenericLayerMetadataCalls() {
834 // Note: Can be in any order.
835 EXPECT_CALL(*mHwcLayer,
836 setLayerGenericMetadata(kLayerGenericMetadata1Key,
837 kLayerGenericMetadata1Mandatory,
838 kLayerGenericMetadata1Value));
839 EXPECT_CALL(*mHwcLayer,
840 setLayerGenericMetadata(kLayerGenericMetadata2Key,
841 kLayerGenericMetadata2Mandatory,
842 kLayerGenericMetadata2Value));
843 }
844
Lloyd Piquea83776c2019-01-29 18:42:32 -0800845 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800846 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Alec Mouria90a5702021-04-16 16:36:21 +0000847 renderengine::mock::RenderEngine mRenderEngine;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800848};
849
Lloyd Piquef5275482019-01-29 18:42:42 -0800850const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
851 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800852const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Alec Mourib7edfc22021-03-17 16:20:26 -0700853const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044};
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700854const FloatRect OutputLayerWriteStateToHWCTest::kOverrideSourceCrop{0.f, 0.f, 4.f, 5.f};
Lloyd Piquea2468662019-03-07 21:31:06 -0800855const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
856 Rect{1005, 1006, 1007, 1008}};
Alec Mouri464352b2021-03-24 16:33:21 -0700857const Region OutputLayerWriteStateToHWCTest::kOverrideVisibleRegion{Rect{1006, 1007, 1008, 1009}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800858const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
859 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
860 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
861};
862const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
Alec Mouri464352b2021-03-24 16:33:21 -0700863const Region OutputLayerWriteStateToHWCTest::kOverrideSurfaceDamage{Rect{1026, 1027, 1028, 1029}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800864const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
865native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
866 reinterpret_cast<native_handle_t*>(1031);
867const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700868const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kOverrideBuffer =
869 new GraphicBuffer(4, 5, PIXEL_FORMAT_RGBA_8888,
870 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
871 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Lloyd Piquef5275482019-01-29 18:42:42 -0800872const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700873const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = new Fence();
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800874const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
875 "com.example.metadata.1";
876const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
877const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
878 "com.example.metadata.2";
879const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
880 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800881
Lloyd Piquede196652020-01-22 17:29:58 -0800882TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
883 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
884
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400885 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
886 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquede196652020-01-22 17:29:58 -0800887}
888
Lloyd Piquea83776c2019-01-29 18:42:32 -0800889TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
890 mOutputLayer.editState().hwc.reset();
891
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400892 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
893 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800894}
895
896TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
897 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
898
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400899 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
900 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800901}
902
Lloyd Piquef5275482019-01-29 18:42:42 -0800903TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800904 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -0800905 expectPerFrameCommonCalls();
906
907 expectNoSetCompositionTypeCall();
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400908 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800909
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400910 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
911 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800912}
913
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700914TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
915 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
916 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
917 // This test simulates a scenario where displayInstallOrientation is set to
918 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
919 // DisplayDevice::setProjection).
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200920 mOutputState.displaySpace.orientation = ui::ROTATION_0;
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700921 mOutputState.transform = ui::Transform{TR_ROT_90};
922 // Buffers are pre-rotated based on the transform hint (ROT_90); their
923 // geomBufferTransform is set to the inverse transform.
924 mLayerFEState.geomBufferTransform = TR_ROT_270;
925
Snild Dolkow9e217d62020-04-22 15:53:42 +0200926 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700927}
928
Lloyd Piquef5275482019-01-29 18:42:42 -0800929TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700930 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800931
932 expectPerFrameCommonCalls();
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400933 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Pique46b72df2019-10-29 13:19:27 -0700934
935 // Setting the composition type should happen before setting the color. We
936 // check this in this test only by setting up an testing::InSeqeuence
937 // instance before setting up the two expectations.
938 InSequence s;
Lloyd Piquef5275482019-01-29 18:42:42 -0800939 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -0700940 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -0800941
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400942 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
943 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800944}
945
946TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700947 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -0800948
949 expectPerFrameCommonCalls();
950 expectSetSidebandHandleCall();
951 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SIDEBAND);
952
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400953 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
954
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400955 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
956 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800957}
958
959TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700960 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800961
962 expectPerFrameCommonCalls();
963 expectSetHdrMetadataAndBufferCalls();
964 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CURSOR);
965
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400966 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
967
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400968 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
969 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800970}
971
972TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700973 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -0800974
975 expectPerFrameCommonCalls();
976 expectSetHdrMetadataAndBufferCalls();
977 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
978
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400979 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
980
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400981 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
982 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800983}
984
985TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
986 (*mOutputLayer.editState().hwc).hwcCompositionType =
987 Hwc2::IComposerClient::Composition::SOLID_COLOR;
988
Lloyd Pique9755fb72019-03-26 14:44:40 -0700989 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800990
991 expectPerFrameCommonCalls();
992 expectSetColorCall();
993 expectNoSetCompositionTypeCall();
994
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400995 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
996
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400997 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
998 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800999}
1000
1001TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001002 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001003
1004 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
1005 expectSetColorCall();
1006 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
1007
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001008 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1009 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001010}
1011
1012TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
1013 mOutputLayer.editState().forceClientComposition = true;
1014
Lloyd Pique9755fb72019-03-26 14:44:40 -07001015 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001016
1017 expectPerFrameCommonCalls();
1018 expectSetColorCall();
1019 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
1020
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001021 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1022 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001023}
1024
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001025TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
1026 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1027 includeGenericLayerMetadataInState();
1028
1029 expectGeometryCommonCalls();
1030 expectPerFrameCommonCalls();
1031 expectSetHdrMetadataAndBufferCalls();
1032 expectGenericLayerMetadataCalls();
1033 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1034
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001035 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1036
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001037 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1038 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001039}
1040
1041TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
1042 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1043 includeGenericLayerMetadataInState();
1044
1045 expectPerFrameCommonCalls();
1046 expectSetHdrMetadataAndBufferCalls();
1047 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1048
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001049 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1050
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001051 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1052 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001053}
1054
Alec Mourib7edfc22021-03-17 16:20:26 -07001055TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
1056 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1057 includeOverrideInfo();
1058
Alec Mouri03bf0ff2021-04-19 14:17:31 -07001059 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1060 kOverrideBlendMode, kOverrideAlpha);
Alec Mouri464352b2021-03-24 16:33:21 -07001061 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
1062 kOverrideSurfaceDamage);
Alec Mouri03bf0ff2021-04-19 14:17:31 -07001063 expectSetHdrMetadataAndBufferCalls(kOverrideBuffer, kOverrideFence);
Alec Mourib7edfc22021-03-17 16:20:26 -07001064 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001065 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1066
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001067 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1068 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Alec Mourib7edfc22021-03-17 16:20:26 -07001069}
1070
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001071TEST_F(OutputLayerWriteStateToHWCTest, peekThroughChangesBlendMode) {
1072 auto peekThroughLayerFE = sp<compositionengine::mock::LayerFE>::make();
1073 OutputLayer peekThroughLayer{mOutput, peekThroughLayerFE};
1074
1075 mOutputLayer.mState.overrideInfo.peekThroughLayer = &peekThroughLayer;
1076
1077 expectGeometryCommonCalls(kDisplayFrame, kSourceCrop, kBufferTransform,
1078 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED);
1079 expectPerFrameCommonCalls();
1080 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1081
1082 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1083 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1084}
1085
1086TEST_F(OutputLayerWriteStateToHWCTest, isPeekingThroughSetsOverride) {
1087 expectGeometryCommonCalls();
1088 expectPerFrameCommonCalls();
1089
1090 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1091 /*zIsOverridden*/ false, /*isPeekingThrough*/ true);
1092 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1093}
1094
1095TEST_F(OutputLayerWriteStateToHWCTest, zIsOverriddenSetsOverride) {
1096 expectGeometryCommonCalls();
1097 expectPerFrameCommonCalls();
1098 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1099
1100 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1101 /*zIsOverridden*/ true, /*isPeekingThrough*/
1102 false);
1103 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1104}
1105
1106TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersForceClientComposition) {
1107 expectGeometryCommonCalls();
1108 expectPerFrameCommonCalls();
1109 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(true));
1110 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
1111
1112 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1113 /*zIsOverridden*/ false, /*isPeekingThrough*/
1114 false);
1115}
1116
1117TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersPeekingThroughAllowsDeviceComposition) {
1118 expectGeometryCommonCalls();
1119 expectPerFrameCommonCalls();
1120 expectSetHdrMetadataAndBufferCalls();
1121 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(true));
1122 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1123
1124 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1125 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1126 /*zIsOverridden*/ false, /*isPeekingThrough*/
1127 true);
1128 EXPECT_EQ(Hwc2::IComposerClient::Composition::DEVICE,
1129 mOutputLayer.getState().hwc->hwcCompositionType);
1130}
1131
Lloyd Pique66d68602019-02-13 14:23:31 -08001132/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001133 * OutputLayer::writeCursorPositionToHWC()
1134 */
1135
1136struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1137 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -07001138 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001139
1140 static const Rect kDefaultDisplayViewport;
1141 static const Rect kDefaultCursorFrame;
1142
1143 OutputLayerWriteCursorPositionToHWCTest() {
1144 auto& outputLayerState = mOutputLayer.editState();
1145 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1146
Lloyd Pique9755fb72019-03-26 14:44:40 -07001147 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001148
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001149 mOutputState.layerStackSpace.content = kDefaultDisplayViewport;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001150 mOutputState.transform = ui::Transform{kDefaultTransform};
1151 }
1152
1153 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1154};
1155
1156const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1157const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1158
Lloyd Piquede196652020-01-22 17:29:58 -08001159TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
1160 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
1161
1162 mOutputLayer.writeCursorPositionToHWC();
1163}
1164
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001165TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1166 mOutputLayer.editState().hwc.reset();
1167
1168 mOutputLayer.writeCursorPositionToHWC();
1169}
1170
1171TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1172 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1173
1174 mOutputLayer.writeCursorPositionToHWC();
1175}
1176
1177TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001178 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001179
1180 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1181
1182 mOutputLayer.writeCursorPositionToHWC();
1183}
1184
1185TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1186 mOutputState.transform = ui::Transform{TR_ROT_90};
1187
1188 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1189
1190 mOutputLayer.writeCursorPositionToHWC();
1191}
1192
1193/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001194 * OutputLayer::getHwcLayer()
1195 */
1196
1197TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1198 mOutputLayer.editState().hwc.reset();
1199
1200 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1201}
1202
1203TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1204 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1205
1206 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1207}
1208
1209TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1210 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1211 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1212
1213 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1214}
1215
1216/*
1217 * OutputLayer::requiresClientComposition()
1218 */
1219
1220TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1221 mOutputLayer.editState().hwc.reset();
1222
1223 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1224}
1225
1226TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1227 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1228 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CLIENT;
1229
1230 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1231}
1232
1233TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1234 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1235 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1236
1237 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1238}
1239
1240/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001241 * OutputLayer::isHardwareCursor()
1242 */
1243
1244TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1245 mOutputLayer.editState().hwc.reset();
1246
1247 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1248}
1249
1250TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1251 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1252 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CURSOR;
1253
1254 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1255}
1256
1257TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1258 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1259 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1260
1261 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1262}
1263
1264/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001265 * OutputLayer::applyDeviceCompositionTypeChange()
1266 */
1267
1268TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1269 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1270 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1271
1272 mOutputLayer.applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT);
1273
1274 ASSERT_TRUE(mOutputLayer.getState().hwc);
1275 EXPECT_EQ(Hwc2::IComposerClient::Composition::CLIENT,
1276 mOutputLayer.getState().hwc->hwcCompositionType);
1277}
1278
1279/*
1280 * OutputLayer::prepareForDeviceLayerRequests()
1281 */
1282
1283TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1284 mOutputLayer.editState().clearClientTarget = true;
1285
1286 mOutputLayer.prepareForDeviceLayerRequests();
1287
1288 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1289}
1290
1291/*
1292 * OutputLayer::applyDeviceLayerRequest()
1293 */
1294
1295TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1296 mOutputLayer.editState().clearClientTarget = false;
1297
1298 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1299
1300 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1301}
1302
1303TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1304 mOutputLayer.editState().clearClientTarget = false;
1305
1306 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1307
1308 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1309}
1310
Lloyd Pique688abd42019-02-15 15:42:24 -08001311/*
1312 * OutputLayer::needsFiltering()
1313 */
1314
1315TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1316 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1317 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1318
1319 EXPECT_FALSE(mOutputLayer.needsFiltering());
1320}
1321
1322TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1323 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1324 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1325
1326 EXPECT_TRUE(mOutputLayer.needsFiltering());
1327}
1328
Lloyd Piquecc01a452018-12-04 17:24:00 -08001329} // namespace
1330} // namespace android::compositionengine