blob: e9ecf3ecc5c35583551f4099a705b4edfdb61d45 [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
Alec Mouri03bf0ff2021-04-19 14:17:31 -070027#include <renderengine/mock/RenderEngine.h>
28#include <ui/PixelFormat.h>
Lloyd Pique07e33212018-12-18 16:33:37 -080029#include "MockHWC2.h"
30#include "MockHWComposer.h"
Lloyd Piquef5275482019-01-29 18:42:42 -080031#include "RegionMatcher.h"
Lloyd Pique07e33212018-12-18 16:33:37 -080032
Lloyd Piquecc01a452018-12-04 17:24:00 -080033namespace android::compositionengine {
34namespace {
35
Peiyong Line9d809e2020-04-14 13:10:48 -070036namespace hal = android::hardware::graphics::composer::hal;
37
Lloyd Piquea83776c2019-01-29 18:42:32 -080038using testing::_;
Lloyd Pique46b72df2019-10-29 13:19:27 -070039using testing::InSequence;
Lloyd Piquea83776c2019-01-29 18:42:32 -080040using testing::Return;
41using testing::ReturnRef;
Lloyd Piquecc01a452018-12-04 17:24:00 -080042using testing::StrictMock;
43
Lloyd Piquea83776c2019-01-29 18:42:32 -080044constexpr auto TR_IDENT = 0u;
45constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H;
46constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V;
47constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
48constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V;
49constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180;
50
51const std::string kOutputName{"Test Output"};
52
Lloyd Piquef5275482019-01-29 18:42:42 -080053MATCHER_P(ColorEq, expected, "") {
54 *result_listener << "Colors are not equal\n";
55 *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " "
56 << expected.a << "\n";
57 *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n";
58
59 return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a;
60}
61
Marin Shalamanov68933fb2020-09-10 17:58:12 +020062ui::Rotation toRotation(uint32_t rotationFlag) {
63 switch (rotationFlag) {
64 case ui::Transform::RotationFlags::ROT_0:
65 return ui::ROTATION_0;
66 case ui::Transform::RotationFlags::ROT_90:
67 return ui::ROTATION_90;
68 case ui::Transform::RotationFlags::ROT_180:
69 return ui::ROTATION_180;
70 case ui::Transform::RotationFlags::ROT_270:
71 return ui::ROTATION_270;
72 default:
73 LOG_FATAL("Unexpected rotation flag %d", rotationFlag);
74 return ui::Rotation(-1);
75 }
76}
77
Lloyd Pique66d68602019-02-13 14:23:31 -080078struct OutputLayerTest : public testing::Test {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070079 struct OutputLayer final : public impl::OutputLayer {
Lloyd Piquede196652020-01-22 17:29:58 -080080 OutputLayer(const compositionengine::Output& output, sp<compositionengine::LayerFE> layerFE)
81 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070082 ~OutputLayer() override = default;
83
84 // compositionengine::OutputLayer overrides
85 const compositionengine::Output& getOutput() const override { return mOutput; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070086 compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
87 const impl::OutputLayerCompositionState& getState() const override { return mState; }
88 impl::OutputLayerCompositionState& editState() override { return mState; }
89
90 // compositionengine::impl::OutputLayer overrides
91 void dumpState(std::string& out) const override { mState.dump(out); }
92
93 const compositionengine::Output& mOutput;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070094 sp<compositionengine::LayerFE> mLayerFE;
95 impl::OutputLayerCompositionState mState;
96 };
97
Lloyd Piquea83776c2019-01-29 18:42:32 -080098 OutputLayerTest() {
99 EXPECT_CALL(*mLayerFE, getDebugName()).WillRepeatedly(Return("Test LayerFE"));
100 EXPECT_CALL(mOutput, getName()).WillRepeatedly(ReturnRef(kOutputName));
101
Lloyd Piquede196652020-01-22 17:29:58 -0800102 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800103 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
104 }
105
Lloyd Piquecc01a452018-12-04 17:24:00 -0800106 compositionengine::mock::Output mOutput;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800107 sp<compositionengine::mock::LayerFE> mLayerFE{
108 new StrictMock<compositionengine::mock::LayerFE>()};
Lloyd Piquede196652020-01-22 17:29:58 -0800109 OutputLayer mOutputLayer{mOutput, mLayerFE};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800110
Lloyd Pique9755fb72019-03-26 14:44:40 -0700111 LayerFECompositionState mLayerFEState;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800112 impl::OutputCompositionState mOutputState;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800113};
114
Lloyd Piquea83776c2019-01-29 18:42:32 -0800115/*
Lloyd Piquecc01a452018-12-04 17:24:00 -0800116 * Basic construction
117 */
118
119TEST_F(OutputLayerTest, canInstantiateOutputLayer) {}
120
Lloyd Piquea83776c2019-01-29 18:42:32 -0800121/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800122 * OutputLayer::setHwcLayer()
Lloyd Pique07e33212018-12-18 16:33:37 -0800123 */
124
Lloyd Piquedf336d92019-03-07 21:38:42 -0800125TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) {
Lloyd Pique07e33212018-12-18 16:33:37 -0800126 StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
127
Lloyd Piquedf336d92019-03-07 21:38:42 -0800128 mOutputLayer.setHwcLayer(nullptr);
Lloyd Pique07e33212018-12-18 16:33:37 -0800129
130 EXPECT_FALSE(mOutputLayer.getState().hwc);
131}
132
Lloyd Piquedf336d92019-03-07 21:38:42 -0800133TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) {
134 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Pique07e33212018-12-18 16:33:37 -0800135
Lloyd Piquedf336d92019-03-07 21:38:42 -0800136 mOutputLayer.setHwcLayer(hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800137
Lloyd Piquea83776c2019-01-29 18:42:32 -0800138 const auto& outputLayerState = mOutputLayer.getState();
139 ASSERT_TRUE(outputLayerState.hwc);
Lloyd Pique07e33212018-12-18 16:33:37 -0800140
Lloyd Piquea83776c2019-01-29 18:42:32 -0800141 const auto& hwcState = *outputLayerState.hwc;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800142 EXPECT_EQ(hwcLayer, hwcState.hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800143}
144
Lloyd Piquea83776c2019-01-29 18:42:32 -0800145/*
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000146 * OutputLayer::calculateOutputSourceCrop()
147 */
148
149struct OutputLayerSourceCropTest : public OutputLayerTest {
150 OutputLayerSourceCropTest() {
151 // Set reasonable default values for a simple case. Each test will
152 // set one specific value to something different.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700153 mLayerFEState.geomUsesSourceCrop = true;
154 mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080};
155 mLayerFEState.transparentRegionHint = Region{};
156 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
157 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
158 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
159 mLayerFEState.geomBufferTransform = TR_IDENT;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000160
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200161 mOutputState.layerStackSpace.content = Rect{0, 0, 1920, 1080};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000162 }
163
164 FloatRect calculateOutputSourceCrop() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700165 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000166
167 return mOutputLayer.calculateOutputSourceCrop();
168 }
169};
170
171TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700172 mLayerFEState.geomUsesSourceCrop = false;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000173
174 const FloatRect expected{};
Lloyd Piqueea629282019-12-03 15:57:10 -0800175 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000176}
177
178TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) {
179 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800180 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000181}
182
183TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700184 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000185
186 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800187 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000188}
189
190TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700191 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
192 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000193
194 const FloatRect expected{0.f, 0.f, 1080.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800195 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000196}
197
198TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) {
199 struct Entry {
200 uint32_t bufferInvDisplay;
201 uint32_t buffer;
202 uint32_t display;
203 FloatRect expected;
204 };
205 // Not an exhaustive list of cases, but hopefully enough.
206 const std::array<Entry, 12> testData = {
207 // clang-format off
208 // inv buffer display expected
209 /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
210 /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
211 /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
212 /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
213
214 /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
215 /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
216 /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
217 /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
218
219 /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
220 /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
221 /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
222 /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
223
224 // clang-format on
225 };
226
227 for (size_t i = 0; i < testData.size(); i++) {
228 const auto& entry = testData[i];
229
Lloyd Pique9755fb72019-03-26 14:44:40 -0700230 mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay;
231 mLayerFEState.geomBufferTransform = entry.buffer;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200232 mOutputState.displaySpace.orientation = toRotation(entry.display);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000233
Lloyd Piqueea629282019-12-03 15:57:10 -0800234 EXPECT_THAT(calculateOutputSourceCrop(), entry.expected) << "entry " << i;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000235 }
236}
237
238TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700239 mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000240
241 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800242 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000243}
244
245TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200246 mOutputState.layerStackSpace.content = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000247
248 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800249 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000250}
251
252/*
Lloyd Piquea83776c2019-01-29 18:42:32 -0800253 * OutputLayer::calculateOutputDisplayFrame()
254 */
255
256struct OutputLayerDisplayFrameTest : public OutputLayerTest {
257 OutputLayerDisplayFrameTest() {
258 // Set reasonable default values for a simple case. Each test will
259 // set one specific value to something different.
260
Lloyd Pique9755fb72019-03-26 14:44:40 -0700261 mLayerFEState.transparentRegionHint = Region{};
262 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
263 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
264 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
265 mLayerFEState.geomCrop = Rect{0, 0, 1920, 1080};
266 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800267
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200268 mOutputState.layerStackSpace.content = Rect{0, 0, 1920, 1080};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800269 mOutputState.transform = ui::Transform{TR_IDENT};
270 }
271
272 Rect calculateOutputDisplayFrame() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700273 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800274
275 return mOutputLayer.calculateOutputDisplayFrame();
276 }
277};
278
279TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) {
280 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800281 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800282}
283
284TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700285 mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800286 const Rect expected{0, 0, 0, 0};
Lloyd Piqueea629282019-12-03 15:57:10 -0800287 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800288}
289
290TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700291 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800292 const Rect expected{100, 200, 300, 500};
Lloyd Piqueea629282019-12-03 15:57:10 -0800293 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800294}
295
296TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700297 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
298 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800299 const Rect expected{1420, 100, 1720, 300};
Lloyd Piqueea629282019-12-03 15:57:10 -0800300 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800301}
302
303TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700304 mLayerFEState.geomCrop = Rect{};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800305 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800306 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800307}
308
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000309TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700310 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800311 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800312 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800313}
314
315TEST_F(OutputLayerDisplayFrameTest, viewportAffectsFrame) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200316 mOutputState.layerStackSpace.content = Rect{0, 0, 960, 540};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800317 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800318 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800319}
320
321TEST_F(OutputLayerDisplayFrameTest, outputTransformAffectsDisplayFrame) {
322 mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90};
323 const Rect expected{-1080, 0, 0, 1920};
Lloyd Piqueea629282019-12-03 15:57:10 -0800324 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800325}
326
327/*
328 * OutputLayer::calculateOutputRelativeBufferTransform()
329 */
330
331TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700332 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800333
334 struct Entry {
335 uint32_t layer;
336 uint32_t buffer;
337 uint32_t display;
338 uint32_t expected;
339 };
340 // Not an exhaustive list of cases, but hopefully enough.
341 const std::array<Entry, 24> testData = {
342 // clang-format off
343 // layer buffer display expected
344 /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
345 /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_90},
346 /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
347 /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270},
348
349 /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_IDENT},
350 /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_90},
351 /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_180},
352 /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_ROT_270},
353
354 /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V},
355 /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_180},
356 /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
357 /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_180},
358
359 /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_90},
360 /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_180},
361 /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT ^ TR_ROT_270},
362 /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_IDENT},
363
364 /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_ROT_180},
365 /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT ^ TR_ROT_270},
366 /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_IDENT},
367 /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_90},
368
369 /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_270},
370 /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_IDENT},
371 /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_90},
372 /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_180},
373 // clang-format on
374 };
375
376 for (size_t i = 0; i < testData.size(); i++) {
377 const auto& entry = testData[i];
378
Lloyd Pique9755fb72019-03-26 14:44:40 -0700379 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
380 mLayerFEState.geomBufferTransform = entry.buffer;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200381 mOutputState.displaySpace.orientation = toRotation(entry.display);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700382 mOutputState.transform = ui::Transform{entry.display};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800383
Snild Dolkow9e217d62020-04-22 15:53:42 +0200384 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.display);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800385 EXPECT_EQ(entry.expected, actual) << "entry " << i;
386 }
387}
388
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000389TEST_F(OutputLayerTest,
390 calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700391 mLayerFEState.geomBufferUsesDisplayInverseTransform = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000392
393 struct Entry {
Snild Dolkow9e217d62020-04-22 15:53:42 +0200394 uint32_t layer; /* shouldn't affect the result, so we just use arbitrary values */
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000395 uint32_t buffer;
396 uint32_t display;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200397 uint32_t internal;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000398 uint32_t expected;
399 };
Snild Dolkow9e217d62020-04-22 15:53:42 +0200400 const std::array<Entry, 64> testData = {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000401 // clang-format off
Snild Dolkow9e217d62020-04-22 15:53:42 +0200402 // layer buffer display internal expected
403 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
404 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_270},
405 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
406 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_90},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000407
Snild Dolkow9e217d62020-04-22 15:53:42 +0200408 Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT, TR_ROT_90},
409 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_90, TR_IDENT},
410 Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_180, TR_ROT_270},
411 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000412
Snild Dolkow9e217d62020-04-22 15:53:42 +0200413 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_180},
414 Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_90, TR_ROT_90},
415 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
416 Entry{TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000417
Snild Dolkow9e217d62020-04-22 15:53:42 +0200418 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270},
419 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_ROT_90, TR_ROT_180},
420 Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_180, TR_ROT_90},
421 Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000422
Snild Dolkow9e217d62020-04-22 15:53:42 +0200423 // layer buffer display internal expected
424 Entry{TR_IDENT, TR_ROT_90, TR_IDENT, TR_IDENT, TR_ROT_90},
425 Entry{TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_90, TR_IDENT},
426 Entry{TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_270},
427 Entry{TR_ROT_270, TR_ROT_90, TR_IDENT, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000428
Snild Dolkow9e217d62020-04-22 15:53:42 +0200429 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_180},
430 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90},
431 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_IDENT},
432 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270, TR_ROT_270},
433
434 Entry{TR_IDENT, TR_ROT_90, TR_ROT_180, TR_IDENT, TR_ROT_270},
435 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_180},
436 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_180, TR_ROT_90},
437 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_270, TR_IDENT},
438
439 Entry{TR_IDENT, TR_ROT_90, TR_ROT_270, TR_IDENT, TR_IDENT},
440 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270},
441 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_ROT_180, TR_ROT_180},
442 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90},
443
444 // layer buffer display internal expected
445 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_IDENT, TR_ROT_180},
446 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_90},
447 Entry{TR_ROT_180, TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT},
448 Entry{TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_270},
449
450 Entry{TR_IDENT, TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_270},
451 Entry{TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_90, TR_ROT_180},
452 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_90},
453 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_IDENT},
454
455 Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT, TR_IDENT},
456 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270},
457 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180},
458 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90},
459
460 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_IDENT, TR_ROT_90},
461 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_IDENT},
462 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_270},
463 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_270, TR_ROT_180},
464
465 // layer buffer display internal expected
466 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_IDENT, TR_ROT_270},
467 Entry{TR_ROT_90, TR_ROT_270, TR_IDENT, TR_ROT_90, TR_ROT_180},
468 Entry{TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_90},
469 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT},
470
471 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_IDENT, TR_IDENT},
472 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270},
473 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_ROT_180, TR_ROT_180},
474 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90},
475
476 Entry{TR_IDENT, TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_90},
477 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_90, TR_IDENT},
478 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270},
479 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_180},
480
481 Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180},
482 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_ROT_90},
483 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_IDENT},
484 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000485 // clang-format on
486 };
487
488 for (size_t i = 0; i < testData.size(); i++) {
489 const auto& entry = testData[i];
490
Snild Dolkow9e217d62020-04-22 15:53:42 +0200491 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
Lloyd Pique9755fb72019-03-26 14:44:40 -0700492 mLayerFEState.geomBufferTransform = entry.buffer;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200493 mOutputState.displaySpace.orientation = toRotation(entry.display);
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700494 mOutputState.transform = ui::Transform{entry.display};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000495
Snild Dolkow9e217d62020-04-22 15:53:42 +0200496 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.internal);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000497 EXPECT_EQ(entry.expected, actual) << "entry " << i;
498 }
499}
500
501/*
502 * OutputLayer::updateCompositionState()
503 */
504
505struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer {
506 OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output,
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000507 sp<compositionengine::LayerFE> layerFE)
Lloyd Piquede196652020-01-22 17:29:58 -0800508 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000509 // Mock everything called by updateCompositionState to simplify testing it.
510 MOCK_CONST_METHOD0(calculateOutputSourceCrop, FloatRect());
511 MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect());
Snild Dolkow9e217d62020-04-22 15:53:42 +0200512 MOCK_CONST_METHOD1(calculateOutputRelativeBufferTransform, uint32_t(uint32_t));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700513
514 // compositionengine::OutputLayer overrides
515 const compositionengine::Output& getOutput() const override { return mOutput; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700516 compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
517 const impl::OutputLayerCompositionState& getState() const override { return mState; }
518 impl::OutputLayerCompositionState& editState() override { return mState; }
519
520 // These need implementations though are not expected to be called.
521 MOCK_CONST_METHOD1(dumpState, void(std::string&));
522
523 const compositionengine::Output& mOutput;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700524 sp<compositionengine::LayerFE> mLayerFE;
525 impl::OutputLayerCompositionState mState;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000526};
527
528struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest {
529public:
530 OutputLayerUpdateCompositionStateTest() {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000531 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
Lloyd Piquef5275482019-01-29 18:42:42 -0800532 EXPECT_CALL(mOutput, getDisplayColorProfile())
533 .WillRepeatedly(Return(&mDisplayColorProfile));
534 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000535 }
536
537 ~OutputLayerUpdateCompositionStateTest() = default;
538
Snild Dolkow9e217d62020-04-22 15:53:42 +0200539 void setupGeometryChildCallValues(ui::Transform::RotationFlags internalDisplayRotationFlags) {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000540 EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop()).WillOnce(Return(kSourceCrop));
541 EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200542 EXPECT_CALL(mOutputLayer,
543 calculateOutputRelativeBufferTransform(internalDisplayRotationFlags))
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000544 .WillOnce(Return(mBufferTransform));
545 }
546
547 void validateComputedGeometryState() {
548 const auto& state = mOutputLayer.getState();
549 EXPECT_EQ(kSourceCrop, state.sourceCrop);
550 EXPECT_EQ(kDisplayFrame, state.displayFrame);
551 EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform);
552 }
553
554 const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f};
555 const Rect kDisplayFrame{11, 12, 13, 14};
556 uint32_t mBufferTransform{21};
557
558 using OutputLayer = OutputLayerPartialMockForUpdateCompositionState;
Lloyd Piquede196652020-01-22 17:29:58 -0800559 StrictMock<OutputLayer> mOutputLayer{mOutput, mLayerFE};
Lloyd Piquef5275482019-01-29 18:42:42 -0800560 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000561};
562
Lloyd Piquede196652020-01-22 17:29:58 -0800563TEST_F(OutputLayerUpdateCompositionStateTest, doesNothingIfNoFECompositionState) {
564 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
565
Snild Dolkow9e217d62020-04-22 15:53:42 +0200566 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Piquede196652020-01-22 17:29:58 -0800567}
568
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000569TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700570 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000571 mOutputState.isSecure = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700572 mOutputLayer.editState().forceClientComposition = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000573
Snild Dolkow9e217d62020-04-22 15:53:42 +0200574 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000575
Snild Dolkow9e217d62020-04-22 15:53:42 +0200576 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000577
578 validateComputedGeometryState();
579
580 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
581}
582
583TEST_F(OutputLayerUpdateCompositionStateTest,
584 alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700585 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000586 mOutputState.isSecure = false;
587
Snild Dolkow9e217d62020-04-22 15:53:42 +0200588 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000589
Snild Dolkow9e217d62020-04-22 15:53:42 +0200590 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000591
592 validateComputedGeometryState();
593
594 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
595}
596
597TEST_F(OutputLayerUpdateCompositionStateTest,
598 alsoSetsForceCompositionIfUnsupportedBufferTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700599 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000600 mOutputState.isSecure = true;
601
602 mBufferTransform = ui::Transform::ROT_INVALID;
603
Snild Dolkow9e217d62020-04-22 15:53:42 +0200604 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000605
Snild Dolkow9e217d62020-04-22 15:53:42 +0200606 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000607
608 validateComputedGeometryState();
609
610 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
611}
612
Lloyd Piquef5275482019-01-29 18:42:42 -0800613TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700614 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
Lloyd Piquef5275482019-01-29 18:42:42 -0800615 mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB;
616
617 // If the layer is not colorspace agnostic, the output layer dataspace
618 // should use the layers requested colorspace.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700619 mLayerFEState.isColorspaceAgnostic = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800620
Snild Dolkow9e217d62020-04-22 15:53:42 +0200621 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800622
623 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
624
625 // If the layer is colorspace agnostic, the output layer dataspace
626 // should use the colorspace chosen for the whole output.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700627 mLayerFEState.isColorspaceAgnostic = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800628
Snild Dolkow9e217d62020-04-22 15:53:42 +0200629 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800630
631 EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace);
632}
633
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000634TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700635 mOutputLayer.editState().forceClientComposition = false;
636
Snild Dolkow9e217d62020-04-22 15:53:42 +0200637 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000638
639 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
640}
641
Lloyd Piquefe671022019-09-24 10:43:03 -0700642TEST_F(OutputLayerUpdateCompositionStateTest,
643 doesNotClearForceClientCompositionIfNotDoingGeometry) {
644 mOutputLayer.editState().forceClientComposition = true;
645
Snild Dolkow9e217d62020-04-22 15:53:42 +0200646 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquefe671022019-09-24 10:43:03 -0700647
648 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
649}
650
Lloyd Piquef5275482019-01-29 18:42:42 -0800651TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700652 mLayerFEState.forceClientComposition = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700653 mOutputLayer.editState().forceClientComposition = false;
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(true, mOutputLayer.getState().forceClientComposition);
658}
659
660TEST_F(OutputLayerUpdateCompositionStateTest,
661 clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700662 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800663 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false));
664
Snild Dolkow9e217d62020-04-22 15:53:42 +0200665 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700666
667 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
668}
669
670TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromArgumentFlag) {
671 mLayerFEState.forceClientComposition = false;
672 mOutputLayer.editState().forceClientComposition = false;
673
Snild Dolkow9e217d62020-04-22 15:53:42 +0200674 mOutputLayer.updateCompositionState(false, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700675
676 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
677
678 mOutputLayer.editState().forceClientComposition = false;
679
Snild Dolkow9e217d62020-04-22 15:53:42 +0200680 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700681
Snild Dolkow9e217d62020-04-22 15:53:42 +0200682 mOutputLayer.updateCompositionState(true, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800683
684 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
685}
686
Lloyd Piquea83776c2019-01-29 18:42:32 -0800687/*
688 * OutputLayer::writeStateToHWC()
689 */
690
691struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
Peiyong Line9d809e2020-04-14 13:10:48 -0700692 static constexpr hal::Error kError = hal::Error::UNSUPPORTED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800693 static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800694 static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31);
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700695 static constexpr Hwc2::Transform kOverrideBufferTransform = static_cast<Hwc2::Transform>(0);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800696 static constexpr Hwc2::IComposerClient::BlendMode kBlendMode =
697 static_cast<Hwc2::IComposerClient::BlendMode>(41);
Alec Mouriee69a592021-03-23 15:00:45 -0700698 static constexpr Hwc2::IComposerClient::BlendMode kOverrideBlendMode =
699 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800700 static constexpr float kAlpha = 51.f;
Alec Mouriee69a592021-03-23 15:00:45 -0700701 static constexpr float kOverrideAlpha = 1.f;
Alec Mouri96ca45c2021-06-09 17:32:26 -0700702 static constexpr float kSkipAlpha = 0.f;
Lloyd Piquef5275482019-01-29 18:42:42 -0800703 static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
Alec Mourib7edfc22021-03-17 16:20:26 -0700704 static constexpr ui::Dataspace kOverrideDataspace = static_cast<ui::Dataspace>(72);
Lloyd Piquef5275482019-01-29 18:42:42 -0800705 static constexpr int kSupportedPerFrameMetadata = 101;
706 static constexpr int kExpectedHwcSlot = 0;
Alec Mourie7cc1c22021-04-27 15:23:26 -0700707 static constexpr int kOverrideHwcSlot = impl::HwcBufferCache::FLATTENER_CACHING_SLOT;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800708 static constexpr bool kLayerGenericMetadata1Mandatory = true;
709 static constexpr bool kLayerGenericMetadata2Mandatory = true;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800710
Lloyd Piquef5275482019-01-29 18:42:42 -0800711 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800712 static const Rect kDisplayFrame;
Alec Mourib7edfc22021-03-17 16:20:26 -0700713 static const Rect kOverrideDisplayFrame;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700714 static const FloatRect kOverrideSourceCrop;
Lloyd Piquea2468662019-03-07 21:31:06 -0800715 static const Region kOutputSpaceVisibleRegion;
Alec Mouri464352b2021-03-24 16:33:21 -0700716 static const Region kOverrideVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800717 static const mat4 kColorTransform;
718 static const Region kSurfaceDamage;
Alec Mouri464352b2021-03-24 16:33:21 -0700719 static const Region kOverrideSurfaceDamage;
Lloyd Piquef5275482019-01-29 18:42:42 -0800720 static const HdrMetadata kHdrMetadata;
721 static native_handle_t* kSidebandStreamHandle;
722 static const sp<GraphicBuffer> kBuffer;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700723 static const sp<GraphicBuffer> kOverrideBuffer;
Lloyd Piquef5275482019-01-29 18:42:42 -0800724 static const sp<Fence> kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700725 static const sp<Fence> kOverrideFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800726 static const std::string kLayerGenericMetadata1Key;
727 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
728 static const std::string kLayerGenericMetadata2Key;
729 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800730
731 OutputLayerWriteStateToHWCTest() {
732 auto& outputLayerState = mOutputLayer.editState();
733 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
734
735 outputLayerState.displayFrame = kDisplayFrame;
736 outputLayerState.sourceCrop = kSourceCrop;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800737 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800738 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800739 outputLayerState.dataspace = kDataspace;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800740
Lloyd Pique9755fb72019-03-26 14:44:40 -0700741 mLayerFEState.blendMode = kBlendMode;
742 mLayerFEState.alpha = kAlpha;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700743 mLayerFEState.colorTransform = kColorTransform;
744 mLayerFEState.color = kColor;
745 mLayerFEState.surfaceDamage = kSurfaceDamage;
746 mLayerFEState.hdrMetadata = kHdrMetadata;
747 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
748 mLayerFEState.buffer = kBuffer;
749 mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
750 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800751
752 EXPECT_CALL(mOutput, getDisplayColorProfile())
753 .WillRepeatedly(Return(&mDisplayColorProfile));
754 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
755 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800756 }
757
Lloyd Piquef5275482019-01-29 18:42:42 -0800758 // Some tests may need to simulate unsupported HWC calls
759 enum class SimulateUnsupported { None, ColorTransform };
760
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800761 void includeGenericLayerMetadataInState() {
762 mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory,
763 kLayerGenericMetadata1Value};
764 mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory,
765 kLayerGenericMetadata2Value};
766 }
767
Alec Mourib7edfc22021-03-17 16:20:26 -0700768 void includeOverrideInfo() {
769 auto& overrideInfo = mOutputLayer.editState().overrideInfo;
770
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700771 overrideInfo.buffer = std::make_shared<
772 renderengine::ExternalTexture>(kOverrideBuffer, mRenderEngine,
773 renderengine::ExternalTexture::Usage::READABLE |
774 renderengine::ExternalTexture::Usage::
775 WRITEABLE);
Alec Mourib7edfc22021-03-17 16:20:26 -0700776 overrideInfo.acquireFence = kOverrideFence;
777 overrideInfo.displayFrame = kOverrideDisplayFrame;
778 overrideInfo.dataspace = kOverrideDataspace;
Alec Mouri464352b2021-03-24 16:33:21 -0700779 overrideInfo.damageRegion = kOverrideSurfaceDamage;
780 overrideInfo.visibleRegion = kOverrideVisibleRegion;
Alec Mourib7edfc22021-03-17 16:20:26 -0700781 }
782
783 void expectGeometryCommonCalls(Rect displayFrame = kDisplayFrame,
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700784 FloatRect sourceCrop = kSourceCrop,
Alec Mouriee69a592021-03-23 15:00:45 -0700785 Hwc2::Transform bufferTransform = kBufferTransform,
786 Hwc2::IComposerClient::BlendMode blendMode = kBlendMode,
787 float alpha = kAlpha) {
Alec Mourib7edfc22021-03-17 16:20:26 -0700788 EXPECT_CALL(*mHwcLayer, setDisplayFrame(displayFrame)).WillOnce(Return(kError));
789 EXPECT_CALL(*mHwcLayer, setSourceCrop(sourceCrop)).WillOnce(Return(kError));
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400790 EXPECT_CALL(*mHwcLayer, setZOrder(_)).WillOnce(Return(kError));
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700791 EXPECT_CALL(*mHwcLayer, setTransform(bufferTransform)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800792
Alec Mouriee69a592021-03-23 15:00:45 -0700793 EXPECT_CALL(*mHwcLayer, setBlendMode(blendMode)).WillOnce(Return(kError));
794 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(alpha)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800795 }
796
Alec Mourib7edfc22021-03-17 16:20:26 -0700797 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None,
Alec Mouri464352b2021-03-24 16:33:21 -0700798 ui::Dataspace dataspace = kDataspace,
799 const Region& visibleRegion = kOutputSpaceVisibleRegion,
800 const Region& surfaceDamage = kSurfaceDamage) {
801 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(visibleRegion))).WillOnce(Return(kError));
Alec Mourib7edfc22021-03-17 16:20:26 -0700802 EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800803 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
804 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700805 ? hal::Error::UNSUPPORTED
806 : hal::Error::NONE));
Alec Mouri464352b2021-03-24 16:33:21 -0700807 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(surfaceDamage))).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800808 }
809
810 void expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700811 EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800812 }
813
814 void expectNoSetCompositionTypeCall() {
815 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
816 }
817
818 void expectSetColorCall() {
Peiyong Lin65248e02020-04-18 21:15:07 -0700819 const hal::Color color = {static_cast<uint8_t>(std::round(kColor.r * 255)),
820 static_cast<uint8_t>(std::round(kColor.g * 255)),
821 static_cast<uint8_t>(std::round(kColor.b * 255)), 255};
Lloyd Piquef5275482019-01-29 18:42:42 -0800822
823 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
824 }
825
826 void expectSetSidebandHandleCall() {
827 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
828 }
829
Alec Mourie7cc1c22021-04-27 15:23:26 -0700830 void expectSetHdrMetadataAndBufferCalls(uint32_t hwcSlot = kExpectedHwcSlot,
831 sp<GraphicBuffer> buffer = kBuffer,
Alec Mourib7edfc22021-03-17 16:20:26 -0700832 sp<Fence> fence = kFence) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800833 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
Alec Mourie7cc1c22021-04-27 15:23:26 -0700834 EXPECT_CALL(*mHwcLayer, setBuffer(hwcSlot, buffer, fence));
Lloyd Piquef5275482019-01-29 18:42:42 -0800835 }
836
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800837 void expectGenericLayerMetadataCalls() {
838 // Note: Can be in any order.
839 EXPECT_CALL(*mHwcLayer,
840 setLayerGenericMetadata(kLayerGenericMetadata1Key,
841 kLayerGenericMetadata1Mandatory,
842 kLayerGenericMetadata1Value));
843 EXPECT_CALL(*mHwcLayer,
844 setLayerGenericMetadata(kLayerGenericMetadata2Key,
845 kLayerGenericMetadata2Mandatory,
846 kLayerGenericMetadata2Value));
847 }
848
Lloyd Piquea83776c2019-01-29 18:42:32 -0800849 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800850 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Alec Mouria90a5702021-04-16 16:36:21 +0000851 renderengine::mock::RenderEngine mRenderEngine;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800852};
853
Lloyd Piquef5275482019-01-29 18:42:42 -0800854const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
855 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800856const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Alec Mourib7edfc22021-03-17 16:20:26 -0700857const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044};
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700858const FloatRect OutputLayerWriteStateToHWCTest::kOverrideSourceCrop{0.f, 0.f, 4.f, 5.f};
Lloyd Piquea2468662019-03-07 21:31:06 -0800859const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
860 Rect{1005, 1006, 1007, 1008}};
Alec Mouri464352b2021-03-24 16:33:21 -0700861const Region OutputLayerWriteStateToHWCTest::kOverrideVisibleRegion{Rect{1006, 1007, 1008, 1009}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800862const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
863 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
864 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
865};
866const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
Alec Mouri464352b2021-03-24 16:33:21 -0700867const Region OutputLayerWriteStateToHWCTest::kOverrideSurfaceDamage{Rect{1026, 1027, 1028, 1029}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800868const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
869native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
870 reinterpret_cast<native_handle_t*>(1031);
871const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700872const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kOverrideBuffer =
873 new GraphicBuffer(4, 5, PIXEL_FORMAT_RGBA_8888,
874 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
875 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
Lloyd Piquef5275482019-01-29 18:42:42 -0800876const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Alec Mourib7edfc22021-03-17 16:20:26 -0700877const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = new Fence();
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800878const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
879 "com.example.metadata.1";
880const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
881const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
882 "com.example.metadata.2";
883const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
884 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800885
Lloyd Piquede196652020-01-22 17:29:58 -0800886TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
887 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
888
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400889 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
890 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquede196652020-01-22 17:29:58 -0800891}
892
Lloyd Piquea83776c2019-01-29 18:42:32 -0800893TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
894 mOutputLayer.editState().hwc.reset();
895
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400896 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
897 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800898}
899
900TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
901 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
902
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400903 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
904 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800905}
906
Lloyd Piquef5275482019-01-29 18:42:42 -0800907TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800908 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -0800909 expectPerFrameCommonCalls();
910
911 expectNoSetCompositionTypeCall();
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400912 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800913
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400914 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
915 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800916}
917
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700918TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
919 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
920 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
921 // This test simulates a scenario where displayInstallOrientation is set to
922 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
923 // DisplayDevice::setProjection).
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200924 mOutputState.displaySpace.orientation = ui::ROTATION_0;
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700925 mOutputState.transform = ui::Transform{TR_ROT_90};
926 // Buffers are pre-rotated based on the transform hint (ROT_90); their
927 // geomBufferTransform is set to the inverse transform.
928 mLayerFEState.geomBufferTransform = TR_ROT_270;
929
Snild Dolkow9e217d62020-04-22 15:53:42 +0200930 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700931}
932
Lloyd Piquef5275482019-01-29 18:42:42 -0800933TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700934 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800935
936 expectPerFrameCommonCalls();
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400937 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
Lloyd Pique46b72df2019-10-29 13:19:27 -0700938
939 // Setting the composition type should happen before setting the color. We
940 // check this in this test only by setting up an testing::InSeqeuence
941 // instance before setting up the two expectations.
942 InSequence s;
Lloyd Piquef5275482019-01-29 18:42:42 -0800943 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -0700944 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -0800945
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400946 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
947 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800948}
949
950TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700951 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -0800952
953 expectPerFrameCommonCalls();
954 expectSetSidebandHandleCall();
955 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SIDEBAND);
956
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400957 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
958
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400959 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
960 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800961}
962
963TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700964 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800965
966 expectPerFrameCommonCalls();
967 expectSetHdrMetadataAndBufferCalls();
968 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CURSOR);
969
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400970 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
971
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400972 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
973 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800974}
975
976TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700977 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -0800978
979 expectPerFrameCommonCalls();
980 expectSetHdrMetadataAndBufferCalls();
981 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
982
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400983 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
984
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400985 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
986 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -0800987}
988
989TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
990 (*mOutputLayer.editState().hwc).hwcCompositionType =
991 Hwc2::IComposerClient::Composition::SOLID_COLOR;
992
Lloyd Pique9755fb72019-03-26 14:44:40 -0700993 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800994
995 expectPerFrameCommonCalls();
996 expectSetColorCall();
997 expectNoSetCompositionTypeCall();
998
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400999 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1000
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001001 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1002 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001003}
1004
1005TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001006 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001007
1008 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
1009 expectSetColorCall();
1010 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
1011
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001012 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1013 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001014}
1015
1016TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
1017 mOutputLayer.editState().forceClientComposition = true;
1018
Lloyd Pique9755fb72019-03-26 14:44:40 -07001019 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -08001020
1021 expectPerFrameCommonCalls();
1022 expectSetColorCall();
1023 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
1024
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001025 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1026 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Piquef5275482019-01-29 18:42:42 -08001027}
1028
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001029TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
1030 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1031 includeGenericLayerMetadataInState();
1032
1033 expectGeometryCommonCalls();
1034 expectPerFrameCommonCalls();
1035 expectSetHdrMetadataAndBufferCalls();
1036 expectGenericLayerMetadataCalls();
1037 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1038
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001039 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1040
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001041 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1042 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001043}
1044
1045TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
1046 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1047 includeGenericLayerMetadataInState();
1048
1049 expectPerFrameCommonCalls();
1050 expectSetHdrMetadataAndBufferCalls();
1051 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1052
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001053 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1054
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001055 mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1056 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Lloyd Pique8d9f8362020-02-11 19:13:09 -08001057}
1058
Alec Mouri96ca45c2021-06-09 17:32:26 -07001059TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerDoesNotSendBuffer) {
1060 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1061 includeOverrideInfo();
1062
1063 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1064 kOverrideBlendMode, kSkipAlpha);
1065 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
1066 kOverrideSurfaceDamage);
1067 expectSetHdrMetadataAndBufferCalls();
1068 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1069 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1070
1071 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1072 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1073}
1074
Alec Mourib7edfc22021-03-17 16:20:26 -07001075TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
1076 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1077 includeOverrideInfo();
1078
Alec Mouri03bf0ff2021-04-19 14:17:31 -07001079 expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1080 kOverrideBlendMode, kOverrideAlpha);
Alec Mouri464352b2021-03-24 16:33:21 -07001081 expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
1082 kOverrideSurfaceDamage);
Alec Mourie7cc1c22021-04-27 15:23:26 -07001083 expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
Alec Mourib7edfc22021-03-17 16:20:26 -07001084 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
Alec Mourid1bf1b52021-05-05 18:44:58 -07001085 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1086
1087 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1088 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1089}
1090
1091TEST_F(OutputLayerWriteStateToHWCTest, previousOverriddenLayerSendsSurfaceDamage) {
1092 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1093 mOutputLayer.editState().hwc->stateOverridden = true;
1094
1095 expectGeometryCommonCalls();
1096 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1097 Region::INVALID_REGION);
1098 expectSetHdrMetadataAndBufferCalls();
1099 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1100 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1101
1102 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1103 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1104}
1105
1106TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedDeviceCompositionInfo) {
1107 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1108 mOutputLayer.editState().hwc->stateOverridden = true;
1109 mOutputLayer.editState().hwc->layerSkipped = true;
1110 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1111
1112 expectGeometryCommonCalls();
1113 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1114 Region::INVALID_REGION);
1115 expectSetHdrMetadataAndBufferCalls();
1116 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001117 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1118
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04001119 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1120 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
Alec Mourib7edfc22021-03-17 16:20:26 -07001121}
1122
Alec Mourid1bf1b52021-05-05 18:44:58 -07001123TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedClientCompositionInfo) {
1124 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1125 mOutputLayer.editState().forceClientComposition = true;
1126 mOutputLayer.editState().hwc->stateOverridden = true;
1127 mOutputLayer.editState().hwc->layerSkipped = true;
1128 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CLIENT;
1129
1130 expectGeometryCommonCalls();
1131 expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1132 Region::INVALID_REGION);
1133 expectSetHdrMetadataAndBufferCalls();
1134 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
1135 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1136
1137 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1138 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1139}
1140
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -04001141TEST_F(OutputLayerWriteStateToHWCTest, peekThroughChangesBlendMode) {
1142 auto peekThroughLayerFE = sp<compositionengine::mock::LayerFE>::make();
1143 OutputLayer peekThroughLayer{mOutput, peekThroughLayerFE};
1144
1145 mOutputLayer.mState.overrideInfo.peekThroughLayer = &peekThroughLayer;
1146
1147 expectGeometryCommonCalls(kDisplayFrame, kSourceCrop, kBufferTransform,
1148 Hwc2::IComposerClient::BlendMode::PREMULTIPLIED);
1149 expectPerFrameCommonCalls();
1150 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1151
1152 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1153 /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1154}
1155
1156TEST_F(OutputLayerWriteStateToHWCTest, isPeekingThroughSetsOverride) {
1157 expectGeometryCommonCalls();
1158 expectPerFrameCommonCalls();
1159
1160 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1161 /*zIsOverridden*/ false, /*isPeekingThrough*/ true);
1162 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1163}
1164
1165TEST_F(OutputLayerWriteStateToHWCTest, zIsOverriddenSetsOverride) {
1166 expectGeometryCommonCalls();
1167 expectPerFrameCommonCalls();
1168 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1169
1170 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1171 /*zIsOverridden*/ true, /*isPeekingThrough*/
1172 false);
1173 EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1174}
1175
1176TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersForceClientComposition) {
1177 expectGeometryCommonCalls();
1178 expectPerFrameCommonCalls();
1179 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(true));
1180 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
1181
1182 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1183 /*zIsOverridden*/ false, /*isPeekingThrough*/
1184 false);
1185}
1186
1187TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersPeekingThroughAllowsDeviceComposition) {
1188 expectGeometryCommonCalls();
1189 expectPerFrameCommonCalls();
1190 expectSetHdrMetadataAndBufferCalls();
1191 EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(true));
1192 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
1193
1194 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
1195 mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1196 /*zIsOverridden*/ false, /*isPeekingThrough*/
1197 true);
1198 EXPECT_EQ(Hwc2::IComposerClient::Composition::DEVICE,
1199 mOutputLayer.getState().hwc->hwcCompositionType);
1200}
1201
Lloyd Pique66d68602019-02-13 14:23:31 -08001202/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001203 * OutputLayer::writeCursorPositionToHWC()
1204 */
1205
1206struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1207 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -07001208 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001209
1210 static const Rect kDefaultDisplayViewport;
1211 static const Rect kDefaultCursorFrame;
1212
1213 OutputLayerWriteCursorPositionToHWCTest() {
1214 auto& outputLayerState = mOutputLayer.editState();
1215 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1216
Lloyd Pique9755fb72019-03-26 14:44:40 -07001217 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001218
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001219 mOutputState.layerStackSpace.content = kDefaultDisplayViewport;
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001220 mOutputState.transform = ui::Transform{kDefaultTransform};
1221 }
1222
1223 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1224};
1225
1226const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1227const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1228
Lloyd Piquede196652020-01-22 17:29:58 -08001229TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
1230 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
1231
1232 mOutputLayer.writeCursorPositionToHWC();
1233}
1234
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001235TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1236 mOutputLayer.editState().hwc.reset();
1237
1238 mOutputLayer.writeCursorPositionToHWC();
1239}
1240
1241TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1242 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1243
1244 mOutputLayer.writeCursorPositionToHWC();
1245}
1246
1247TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001248 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001249
1250 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1251
1252 mOutputLayer.writeCursorPositionToHWC();
1253}
1254
1255TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1256 mOutputState.transform = ui::Transform{TR_ROT_90};
1257
1258 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1259
1260 mOutputLayer.writeCursorPositionToHWC();
1261}
1262
1263/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001264 * OutputLayer::getHwcLayer()
1265 */
1266
1267TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1268 mOutputLayer.editState().hwc.reset();
1269
1270 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1271}
1272
1273TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1274 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1275
1276 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1277}
1278
1279TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1280 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1281 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1282
1283 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1284}
1285
1286/*
1287 * OutputLayer::requiresClientComposition()
1288 */
1289
1290TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1291 mOutputLayer.editState().hwc.reset();
1292
1293 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1294}
1295
1296TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1297 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1298 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CLIENT;
1299
1300 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1301}
1302
1303TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1304 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1305 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1306
1307 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1308}
1309
1310/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001311 * OutputLayer::isHardwareCursor()
1312 */
1313
1314TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1315 mOutputLayer.editState().hwc.reset();
1316
1317 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1318}
1319
1320TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1321 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1322 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CURSOR;
1323
1324 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1325}
1326
1327TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1328 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1329 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1330
1331 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1332}
1333
1334/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001335 * OutputLayer::applyDeviceCompositionTypeChange()
1336 */
1337
1338TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1339 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1340 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1341
1342 mOutputLayer.applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT);
1343
1344 ASSERT_TRUE(mOutputLayer.getState().hwc);
1345 EXPECT_EQ(Hwc2::IComposerClient::Composition::CLIENT,
1346 mOutputLayer.getState().hwc->hwcCompositionType);
1347}
1348
1349/*
1350 * OutputLayer::prepareForDeviceLayerRequests()
1351 */
1352
1353TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1354 mOutputLayer.editState().clearClientTarget = true;
1355
1356 mOutputLayer.prepareForDeviceLayerRequests();
1357
1358 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1359}
1360
1361/*
1362 * OutputLayer::applyDeviceLayerRequest()
1363 */
1364
1365TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1366 mOutputLayer.editState().clearClientTarget = false;
1367
1368 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1369
1370 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1371}
1372
1373TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1374 mOutputLayer.editState().clearClientTarget = false;
1375
1376 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1377
1378 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1379}
1380
Lloyd Pique688abd42019-02-15 15:42:24 -08001381/*
1382 * OutputLayer::needsFiltering()
1383 */
1384
1385TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1386 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1387 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1388
1389 EXPECT_FALSE(mOutputLayer.needsFiltering());
1390}
1391
1392TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1393 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1394 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1395
1396 EXPECT_TRUE(mOutputLayer.needsFiltering());
1397}
1398
Lloyd Piquecc01a452018-12-04 17:24:00 -08001399} // namespace
1400} // namespace android::compositionengine