blob: d9fb0982f2fbb3195ab58814384d4d34536fd2c0 [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>
24
Lloyd Pique07e33212018-12-18 16:33:37 -080025#include "MockHWC2.h"
26#include "MockHWComposer.h"
Lloyd Piquef5275482019-01-29 18:42:42 -080027#include "RegionMatcher.h"
Lloyd Pique07e33212018-12-18 16:33:37 -080028
Lloyd Piquecc01a452018-12-04 17:24:00 -080029namespace android::compositionengine {
30namespace {
31
Peiyong Line9d809e2020-04-14 13:10:48 -070032namespace hal = android::hardware::graphics::composer::hal;
33
Lloyd Piquea83776c2019-01-29 18:42:32 -080034using testing::_;
Lloyd Pique46b72df2019-10-29 13:19:27 -070035using testing::InSequence;
Lloyd Piquea83776c2019-01-29 18:42:32 -080036using testing::Return;
37using testing::ReturnRef;
Lloyd Piquecc01a452018-12-04 17:24:00 -080038using testing::StrictMock;
39
Lloyd Piquea83776c2019-01-29 18:42:32 -080040constexpr auto TR_IDENT = 0u;
41constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H;
42constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V;
43constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
44constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V;
45constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180;
46
47const std::string kOutputName{"Test Output"};
48
Lloyd Piquef5275482019-01-29 18:42:42 -080049MATCHER_P(ColorEq, expected, "") {
50 *result_listener << "Colors are not equal\n";
51 *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " "
52 << expected.a << "\n";
53 *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n";
54
55 return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a;
56}
57
Lloyd Pique66d68602019-02-13 14:23:31 -080058struct OutputLayerTest : public testing::Test {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070059 struct OutputLayer final : public impl::OutputLayer {
Lloyd Piquede196652020-01-22 17:29:58 -080060 OutputLayer(const compositionengine::Output& output, sp<compositionengine::LayerFE> layerFE)
61 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070062 ~OutputLayer() override = default;
63
64 // compositionengine::OutputLayer overrides
65 const compositionengine::Output& getOutput() const override { return mOutput; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070066 compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
67 const impl::OutputLayerCompositionState& getState() const override { return mState; }
68 impl::OutputLayerCompositionState& editState() override { return mState; }
69
70 // compositionengine::impl::OutputLayer overrides
71 void dumpState(std::string& out) const override { mState.dump(out); }
72
73 const compositionengine::Output& mOutput;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070074 sp<compositionengine::LayerFE> mLayerFE;
75 impl::OutputLayerCompositionState mState;
76 };
77
Lloyd Piquea83776c2019-01-29 18:42:32 -080078 OutputLayerTest() {
79 EXPECT_CALL(*mLayerFE, getDebugName()).WillRepeatedly(Return("Test LayerFE"));
80 EXPECT_CALL(mOutput, getName()).WillRepeatedly(ReturnRef(kOutputName));
81
Lloyd Piquede196652020-01-22 17:29:58 -080082 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
Lloyd Piquea83776c2019-01-29 18:42:32 -080083 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
84 }
85
Lloyd Piquecc01a452018-12-04 17:24:00 -080086 compositionengine::mock::Output mOutput;
Lloyd Piquecc01a452018-12-04 17:24:00 -080087 sp<compositionengine::mock::LayerFE> mLayerFE{
88 new StrictMock<compositionengine::mock::LayerFE>()};
Lloyd Piquede196652020-01-22 17:29:58 -080089 OutputLayer mOutputLayer{mOutput, mLayerFE};
Lloyd Piquea83776c2019-01-29 18:42:32 -080090
Lloyd Pique9755fb72019-03-26 14:44:40 -070091 LayerFECompositionState mLayerFEState;
Lloyd Piquea83776c2019-01-29 18:42:32 -080092 impl::OutputCompositionState mOutputState;
Lloyd Piquecc01a452018-12-04 17:24:00 -080093};
94
Lloyd Piquea83776c2019-01-29 18:42:32 -080095/*
Lloyd Piquecc01a452018-12-04 17:24:00 -080096 * Basic construction
97 */
98
99TEST_F(OutputLayerTest, canInstantiateOutputLayer) {}
100
Lloyd Piquea83776c2019-01-29 18:42:32 -0800101/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800102 * OutputLayer::setHwcLayer()
Lloyd Pique07e33212018-12-18 16:33:37 -0800103 */
104
Lloyd Piquedf336d92019-03-07 21:38:42 -0800105TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) {
Lloyd Pique07e33212018-12-18 16:33:37 -0800106 StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
107
Lloyd Piquedf336d92019-03-07 21:38:42 -0800108 mOutputLayer.setHwcLayer(nullptr);
Lloyd Pique07e33212018-12-18 16:33:37 -0800109
110 EXPECT_FALSE(mOutputLayer.getState().hwc);
111}
112
Lloyd Piquedf336d92019-03-07 21:38:42 -0800113TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) {
114 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Pique07e33212018-12-18 16:33:37 -0800115
Lloyd Piquedf336d92019-03-07 21:38:42 -0800116 mOutputLayer.setHwcLayer(hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800117
Lloyd Piquea83776c2019-01-29 18:42:32 -0800118 const auto& outputLayerState = mOutputLayer.getState();
119 ASSERT_TRUE(outputLayerState.hwc);
Lloyd Pique07e33212018-12-18 16:33:37 -0800120
Lloyd Piquea83776c2019-01-29 18:42:32 -0800121 const auto& hwcState = *outputLayerState.hwc;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800122 EXPECT_EQ(hwcLayer, hwcState.hwcLayer);
Lloyd Pique07e33212018-12-18 16:33:37 -0800123}
124
Lloyd Piquea83776c2019-01-29 18:42:32 -0800125/*
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000126 * OutputLayer::calculateOutputSourceCrop()
127 */
128
129struct OutputLayerSourceCropTest : public OutputLayerTest {
130 OutputLayerSourceCropTest() {
131 // Set reasonable default values for a simple case. Each test will
132 // set one specific value to something different.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700133 mLayerFEState.geomUsesSourceCrop = true;
134 mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080};
135 mLayerFEState.transparentRegionHint = Region{};
136 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
137 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
138 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
139 mLayerFEState.geomBufferTransform = TR_IDENT;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000140
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200141 mOutputState.layerStackSpace.content = Rect{0, 0, 1920, 1080};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000142 }
143
144 FloatRect calculateOutputSourceCrop() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700145 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000146
147 return mOutputLayer.calculateOutputSourceCrop();
148 }
149};
150
151TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700152 mLayerFEState.geomUsesSourceCrop = false;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000153
154 const FloatRect expected{};
Lloyd Piqueea629282019-12-03 15:57:10 -0800155 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000156}
157
158TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) {
159 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800160 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000161}
162
163TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700164 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000165
166 const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800167 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000168}
169
170TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700171 mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
172 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000173
174 const FloatRect expected{0.f, 0.f, 1080.f, 1080.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800175 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000176}
177
178TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) {
179 struct Entry {
180 uint32_t bufferInvDisplay;
181 uint32_t buffer;
182 uint32_t display;
183 FloatRect expected;
184 };
185 // Not an exhaustive list of cases, but hopefully enough.
186 const std::array<Entry, 12> testData = {
187 // clang-format off
188 // inv buffer display expected
189 /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
190 /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
191 /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
192 /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
193
194 /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
195 /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
196 /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
197 /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
198
199 /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
200 /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
201 /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
202 /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
203
204 // clang-format on
205 };
206
207 for (size_t i = 0; i < testData.size(); i++) {
208 const auto& entry = testData[i];
209
Lloyd Pique9755fb72019-03-26 14:44:40 -0700210 mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay;
211 mLayerFEState.geomBufferTransform = entry.buffer;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000212 mOutputState.orientation = entry.display;
213
Lloyd Piqueea629282019-12-03 15:57:10 -0800214 EXPECT_THAT(calculateOutputSourceCrop(), entry.expected) << "entry " << i;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000215 }
216}
217
218TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700219 mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000220
221 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800222 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000223}
224
225TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200226 mOutputState.layerStackSpace.content = Rect{0, 0, 960, 540};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000227
228 const FloatRect expected{0.f, 0.f, 960.f, 540.f};
Lloyd Piqueea629282019-12-03 15:57:10 -0800229 EXPECT_THAT(calculateOutputSourceCrop(), expected);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000230}
231
232/*
Lloyd Piquea83776c2019-01-29 18:42:32 -0800233 * OutputLayer::calculateOutputDisplayFrame()
234 */
235
236struct OutputLayerDisplayFrameTest : public OutputLayerTest {
237 OutputLayerDisplayFrameTest() {
238 // Set reasonable default values for a simple case. Each test will
239 // set one specific value to something different.
240
Lloyd Pique9755fb72019-03-26 14:44:40 -0700241 mLayerFEState.transparentRegionHint = Region{};
242 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
243 mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
244 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
245 mLayerFEState.geomCrop = Rect{0, 0, 1920, 1080};
246 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800247
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200248 mOutputState.layerStackSpace.content = Rect{0, 0, 1920, 1080};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800249 mOutputState.transform = ui::Transform{TR_IDENT};
250 }
251
252 Rect calculateOutputDisplayFrame() {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700253 mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800254
255 return mOutputLayer.calculateOutputDisplayFrame();
256 }
257};
258
259TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) {
260 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800261 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800262}
263
264TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700265 mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800266 const Rect expected{0, 0, 0, 0};
Lloyd Piqueea629282019-12-03 15:57:10 -0800267 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800268}
269
270TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700271 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800272 const Rect expected{100, 200, 300, 500};
Lloyd Piqueea629282019-12-03 15:57:10 -0800273 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800274}
275
276TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700277 mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
278 mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800279 const Rect expected{1420, 100, 1720, 300};
Lloyd Piqueea629282019-12-03 15:57:10 -0800280 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800281}
282
283TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700284 mLayerFEState.geomCrop = Rect{};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800285 const Rect expected{0, 0, 1920, 1080};
Lloyd Piqueea629282019-12-03 15:57:10 -0800286 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800287}
288
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000289TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700290 mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800291 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800292 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800293}
294
295TEST_F(OutputLayerDisplayFrameTest, viewportAffectsFrame) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200296 mOutputState.layerStackSpace.content = Rect{0, 0, 960, 540};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800297 const Rect expected{0, 0, 960, 540};
Lloyd Piqueea629282019-12-03 15:57:10 -0800298 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800299}
300
301TEST_F(OutputLayerDisplayFrameTest, outputTransformAffectsDisplayFrame) {
302 mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90};
303 const Rect expected{-1080, 0, 0, 1920};
Lloyd Piqueea629282019-12-03 15:57:10 -0800304 EXPECT_THAT(calculateOutputDisplayFrame(), expected);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800305}
306
307/*
308 * OutputLayer::calculateOutputRelativeBufferTransform()
309 */
310
311TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700312 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800313
314 struct Entry {
315 uint32_t layer;
316 uint32_t buffer;
317 uint32_t display;
318 uint32_t expected;
319 };
320 // Not an exhaustive list of cases, but hopefully enough.
321 const std::array<Entry, 24> testData = {
322 // clang-format off
323 // layer buffer display expected
324 /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
325 /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_90},
326 /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
327 /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270},
328
329 /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_IDENT},
330 /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_90},
331 /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_180},
332 /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_ROT_270},
333
334 /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V},
335 /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_180},
336 /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
337 /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_180},
338
339 /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_90},
340 /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_180},
341 /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT ^ TR_ROT_270},
342 /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_IDENT},
343
344 /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_ROT_180},
345 /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT ^ TR_ROT_270},
346 /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_IDENT},
347 /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_90},
348
349 /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_270},
350 /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_IDENT},
351 /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_90},
352 /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_180},
353 // clang-format on
354 };
355
356 for (size_t i = 0; i < testData.size(); i++) {
357 const auto& entry = testData[i];
358
Lloyd Pique9755fb72019-03-26 14:44:40 -0700359 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
360 mLayerFEState.geomBufferTransform = entry.buffer;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800361 mOutputState.orientation = entry.display;
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700362 mOutputState.transform = ui::Transform{entry.display};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800363
Snild Dolkow9e217d62020-04-22 15:53:42 +0200364 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.display);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800365 EXPECT_EQ(entry.expected, actual) << "entry " << i;
366 }
367}
368
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000369TEST_F(OutputLayerTest,
370 calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700371 mLayerFEState.geomBufferUsesDisplayInverseTransform = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000372
373 struct Entry {
Snild Dolkow9e217d62020-04-22 15:53:42 +0200374 uint32_t layer; /* shouldn't affect the result, so we just use arbitrary values */
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000375 uint32_t buffer;
376 uint32_t display;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200377 uint32_t internal;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000378 uint32_t expected;
379 };
Snild Dolkow9e217d62020-04-22 15:53:42 +0200380 const std::array<Entry, 64> testData = {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000381 // clang-format off
Snild Dolkow9e217d62020-04-22 15:53:42 +0200382 // layer buffer display internal expected
383 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
384 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_270},
385 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180},
386 Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_90},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000387
Snild Dolkow9e217d62020-04-22 15:53:42 +0200388 Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT, TR_ROT_90},
389 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_90, TR_IDENT},
390 Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_180, TR_ROT_270},
391 Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000392
Snild Dolkow9e217d62020-04-22 15:53:42 +0200393 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_180},
394 Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_90, TR_ROT_90},
395 Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT},
396 Entry{TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000397
Snild Dolkow9e217d62020-04-22 15:53:42 +0200398 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270},
399 Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_ROT_90, TR_ROT_180},
400 Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_180, TR_ROT_90},
401 Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000402
Snild Dolkow9e217d62020-04-22 15:53:42 +0200403 // layer buffer display internal expected
404 Entry{TR_IDENT, TR_ROT_90, TR_IDENT, TR_IDENT, TR_ROT_90},
405 Entry{TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_90, TR_IDENT},
406 Entry{TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_270},
407 Entry{TR_ROT_270, TR_ROT_90, TR_IDENT, TR_ROT_270, TR_ROT_180},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000408
Snild Dolkow9e217d62020-04-22 15:53:42 +0200409 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_180},
410 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90},
411 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_IDENT},
412 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270, TR_ROT_270},
413
414 Entry{TR_IDENT, TR_ROT_90, TR_ROT_180, TR_IDENT, TR_ROT_270},
415 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_180},
416 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_180, TR_ROT_90},
417 Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_270, TR_IDENT},
418
419 Entry{TR_IDENT, TR_ROT_90, TR_ROT_270, TR_IDENT, TR_IDENT},
420 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270},
421 Entry{TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_ROT_180, TR_ROT_180},
422 Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90},
423
424 // layer buffer display internal expected
425 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_IDENT, TR_ROT_180},
426 Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_90},
427 Entry{TR_ROT_180, TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT},
428 Entry{TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_270},
429
430 Entry{TR_IDENT, TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_270},
431 Entry{TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_90, TR_ROT_180},
432 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_90},
433 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_IDENT},
434
435 Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT, TR_IDENT},
436 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270},
437 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180},
438 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90},
439
440 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_IDENT, TR_ROT_90},
441 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_IDENT},
442 Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_270},
443 Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_270, TR_ROT_180},
444
445 // layer buffer display internal expected
446 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_IDENT, TR_ROT_270},
447 Entry{TR_ROT_90, TR_ROT_270, TR_IDENT, TR_ROT_90, TR_ROT_180},
448 Entry{TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_90},
449 Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT},
450
451 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_IDENT, TR_IDENT},
452 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270},
453 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_ROT_180, TR_ROT_180},
454 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90},
455
456 Entry{TR_IDENT, TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_90},
457 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_90, TR_IDENT},
458 Entry{TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270},
459 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_180},
460
461 Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180},
462 Entry{TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_ROT_90},
463 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_IDENT},
464 Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270},
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000465 // clang-format on
466 };
467
468 for (size_t i = 0; i < testData.size(); i++) {
469 const auto& entry = testData[i];
470
Snild Dolkow9e217d62020-04-22 15:53:42 +0200471 mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
Lloyd Pique9755fb72019-03-26 14:44:40 -0700472 mLayerFEState.geomBufferTransform = entry.buffer;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000473 mOutputState.orientation = entry.display;
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700474 mOutputState.transform = ui::Transform{entry.display};
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000475
Snild Dolkow9e217d62020-04-22 15:53:42 +0200476 const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.internal);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000477 EXPECT_EQ(entry.expected, actual) << "entry " << i;
478 }
479}
480
481/*
482 * OutputLayer::updateCompositionState()
483 */
484
485struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer {
486 OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output,
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000487 sp<compositionengine::LayerFE> layerFE)
Lloyd Piquede196652020-01-22 17:29:58 -0800488 : mOutput(output), mLayerFE(layerFE) {}
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000489 // Mock everything called by updateCompositionState to simplify testing it.
490 MOCK_CONST_METHOD0(calculateOutputSourceCrop, FloatRect());
491 MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect());
Snild Dolkow9e217d62020-04-22 15:53:42 +0200492 MOCK_CONST_METHOD1(calculateOutputRelativeBufferTransform, uint32_t(uint32_t));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700493
494 // compositionengine::OutputLayer overrides
495 const compositionengine::Output& getOutput() const override { return mOutput; }
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700496 compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
497 const impl::OutputLayerCompositionState& getState() const override { return mState; }
498 impl::OutputLayerCompositionState& editState() override { return mState; }
499
500 // These need implementations though are not expected to be called.
501 MOCK_CONST_METHOD1(dumpState, void(std::string&));
502
503 const compositionengine::Output& mOutput;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700504 sp<compositionengine::LayerFE> mLayerFE;
505 impl::OutputLayerCompositionState mState;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000506};
507
508struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest {
509public:
510 OutputLayerUpdateCompositionStateTest() {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000511 EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
Lloyd Piquef5275482019-01-29 18:42:42 -0800512 EXPECT_CALL(mOutput, getDisplayColorProfile())
513 .WillRepeatedly(Return(&mDisplayColorProfile));
514 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true));
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000515 }
516
517 ~OutputLayerUpdateCompositionStateTest() = default;
518
Snild Dolkow9e217d62020-04-22 15:53:42 +0200519 void setupGeometryChildCallValues(ui::Transform::RotationFlags internalDisplayRotationFlags) {
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000520 EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop()).WillOnce(Return(kSourceCrop));
521 EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200522 EXPECT_CALL(mOutputLayer,
523 calculateOutputRelativeBufferTransform(internalDisplayRotationFlags))
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000524 .WillOnce(Return(mBufferTransform));
525 }
526
527 void validateComputedGeometryState() {
528 const auto& state = mOutputLayer.getState();
529 EXPECT_EQ(kSourceCrop, state.sourceCrop);
530 EXPECT_EQ(kDisplayFrame, state.displayFrame);
531 EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform);
532 }
533
534 const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f};
535 const Rect kDisplayFrame{11, 12, 13, 14};
536 uint32_t mBufferTransform{21};
537
538 using OutputLayer = OutputLayerPartialMockForUpdateCompositionState;
Lloyd Piquede196652020-01-22 17:29:58 -0800539 StrictMock<OutputLayer> mOutputLayer{mOutput, mLayerFE};
Lloyd Piquef5275482019-01-29 18:42:42 -0800540 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000541};
542
Lloyd Piquede196652020-01-22 17:29:58 -0800543TEST_F(OutputLayerUpdateCompositionStateTest, doesNothingIfNoFECompositionState) {
544 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
545
Snild Dolkow9e217d62020-04-22 15:53:42 +0200546 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Piquede196652020-01-22 17:29:58 -0800547}
548
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000549TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700550 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000551 mOutputState.isSecure = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700552 mOutputLayer.editState().forceClientComposition = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000553
Snild Dolkow9e217d62020-04-22 15:53:42 +0200554 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000555
Snild Dolkow9e217d62020-04-22 15:53:42 +0200556 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000557
558 validateComputedGeometryState();
559
560 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
561}
562
563TEST_F(OutputLayerUpdateCompositionStateTest,
564 alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700565 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000566 mOutputState.isSecure = false;
567
Snild Dolkow9e217d62020-04-22 15:53:42 +0200568 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000569
Snild Dolkow9e217d62020-04-22 15:53:42 +0200570 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000571
572 validateComputedGeometryState();
573
574 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
575}
576
577TEST_F(OutputLayerUpdateCompositionStateTest,
578 alsoSetsForceCompositionIfUnsupportedBufferTransform) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700579 mLayerFEState.isSecure = true;
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000580 mOutputState.isSecure = true;
581
582 mBufferTransform = ui::Transform::ROT_INVALID;
583
Snild Dolkow9e217d62020-04-22 15:53:42 +0200584 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000585
Snild Dolkow9e217d62020-04-22 15:53:42 +0200586 mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000587
588 validateComputedGeometryState();
589
590 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
591}
592
Lloyd Piquef5275482019-01-29 18:42:42 -0800593TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700594 mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
Lloyd Piquef5275482019-01-29 18:42:42 -0800595 mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB;
596
597 // If the layer is not colorspace agnostic, the output layer dataspace
598 // should use the layers requested colorspace.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700599 mLayerFEState.isColorspaceAgnostic = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800600
Snild Dolkow9e217d62020-04-22 15:53:42 +0200601 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800602
603 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
604
605 // If the layer is colorspace agnostic, the output layer dataspace
606 // should use the colorspace chosen for the whole output.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700607 mLayerFEState.isColorspaceAgnostic = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800608
Snild Dolkow9e217d62020-04-22 15:53:42 +0200609 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800610
611 EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace);
612}
613
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000614TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700615 mOutputLayer.editState().forceClientComposition = false;
616
Snild Dolkow9e217d62020-04-22 15:53:42 +0200617 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique67e3d9b2019-03-22 23:09:28 +0000618
619 EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
620}
621
Lloyd Piquefe671022019-09-24 10:43:03 -0700622TEST_F(OutputLayerUpdateCompositionStateTest,
623 doesNotClearForceClientCompositionIfNotDoingGeometry) {
624 mOutputLayer.editState().forceClientComposition = true;
625
Snild Dolkow9e217d62020-04-22 15:53:42 +0200626 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquefe671022019-09-24 10:43:03 -0700627
628 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
629}
630
Lloyd Piquef5275482019-01-29 18:42:42 -0800631TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700632 mLayerFEState.forceClientComposition = true;
Lloyd Piquefe671022019-09-24 10:43:03 -0700633 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800634
Snild Dolkow9e217d62020-04-22 15:53:42 +0200635 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800636
637 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
638}
639
640TEST_F(OutputLayerUpdateCompositionStateTest,
641 clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700642 mOutputLayer.editState().forceClientComposition = false;
Lloyd Piquef5275482019-01-29 18:42:42 -0800643 EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false));
644
Snild Dolkow9e217d62020-04-22 15:53:42 +0200645 mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700646
647 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
648}
649
650TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromArgumentFlag) {
651 mLayerFEState.forceClientComposition = false;
652 mOutputLayer.editState().forceClientComposition = false;
653
Snild Dolkow9e217d62020-04-22 15:53:42 +0200654 mOutputLayer.updateCompositionState(false, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700655
656 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
657
658 mOutputLayer.editState().forceClientComposition = false;
659
Snild Dolkow9e217d62020-04-22 15:53:42 +0200660 setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
Lloyd Pique7a234912019-10-03 11:54:27 -0700661
Snild Dolkow9e217d62020-04-22 15:53:42 +0200662 mOutputLayer.updateCompositionState(true, true, ui::Transform::RotationFlags::ROT_0);
Lloyd Piquef5275482019-01-29 18:42:42 -0800663
664 EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
665}
666
Lloyd Piquea83776c2019-01-29 18:42:32 -0800667/*
668 * OutputLayer::writeStateToHWC()
669 */
670
671struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
Peiyong Line9d809e2020-04-14 13:10:48 -0700672 static constexpr hal::Error kError = hal::Error::UNSUPPORTED;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800673 static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f};
674 static constexpr uint32_t kZOrder = 21u;
675 static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31);
676 static constexpr Hwc2::IComposerClient::BlendMode kBlendMode =
677 static_cast<Hwc2::IComposerClient::BlendMode>(41);
678 static constexpr float kAlpha = 51.f;
Lloyd Piquef5275482019-01-29 18:42:42 -0800679 static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
680 static constexpr int kSupportedPerFrameMetadata = 101;
681 static constexpr int kExpectedHwcSlot = 0;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800682 static constexpr bool kLayerGenericMetadata1Mandatory = true;
683 static constexpr bool kLayerGenericMetadata2Mandatory = true;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800684
Lloyd Piquef5275482019-01-29 18:42:42 -0800685 static const half4 kColor;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800686 static const Rect kDisplayFrame;
Lloyd Piquea2468662019-03-07 21:31:06 -0800687 static const Region kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800688 static const mat4 kColorTransform;
689 static const Region kSurfaceDamage;
690 static const HdrMetadata kHdrMetadata;
691 static native_handle_t* kSidebandStreamHandle;
692 static const sp<GraphicBuffer> kBuffer;
693 static const sp<Fence> kFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800694 static const std::string kLayerGenericMetadata1Key;
695 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
696 static const std::string kLayerGenericMetadata2Key;
697 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800698
699 OutputLayerWriteStateToHWCTest() {
700 auto& outputLayerState = mOutputLayer.editState();
701 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
702
703 outputLayerState.displayFrame = kDisplayFrame;
704 outputLayerState.sourceCrop = kSourceCrop;
705 outputLayerState.z = kZOrder;
706 outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
Lloyd Piquea2468662019-03-07 21:31:06 -0800707 outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
Lloyd Piquef5275482019-01-29 18:42:42 -0800708 outputLayerState.dataspace = kDataspace;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800709
Lloyd Pique9755fb72019-03-26 14:44:40 -0700710 mLayerFEState.blendMode = kBlendMode;
711 mLayerFEState.alpha = kAlpha;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700712 mLayerFEState.colorTransform = kColorTransform;
713 mLayerFEState.color = kColor;
714 mLayerFEState.surfaceDamage = kSurfaceDamage;
715 mLayerFEState.hdrMetadata = kHdrMetadata;
716 mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
717 mLayerFEState.buffer = kBuffer;
718 mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
719 mLayerFEState.acquireFence = kFence;
Lloyd Piquef5275482019-01-29 18:42:42 -0800720
721 EXPECT_CALL(mOutput, getDisplayColorProfile())
722 .WillRepeatedly(Return(&mDisplayColorProfile));
723 EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
724 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800725 }
726
Lloyd Piquef5275482019-01-29 18:42:42 -0800727 // Some tests may need to simulate unsupported HWC calls
728 enum class SimulateUnsupported { None, ColorTransform };
729
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800730 void includeGenericLayerMetadataInState() {
731 mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory,
732 kLayerGenericMetadata1Value};
733 mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory,
734 kLayerGenericMetadata2Value};
735 }
736
Lloyd Piquea83776c2019-01-29 18:42:32 -0800737 void expectGeometryCommonCalls() {
738 EXPECT_CALL(*mHwcLayer, setDisplayFrame(kDisplayFrame)).WillOnce(Return(kError));
739 EXPECT_CALL(*mHwcLayer, setSourceCrop(kSourceCrop)).WillOnce(Return(kError));
740 EXPECT_CALL(*mHwcLayer, setZOrder(kZOrder)).WillOnce(Return(kError));
Peiyong Line9d809e2020-04-14 13:10:48 -0700741 EXPECT_CALL(*mHwcLayer, setTransform(kBufferTransform)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800742
Peiyong Line9d809e2020-04-14 13:10:48 -0700743 EXPECT_CALL(*mHwcLayer, setBlendMode(kBlendMode)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800744 EXPECT_CALL(*mHwcLayer, setPlaneAlpha(kAlpha)).WillOnce(Return(kError));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800745 }
746
Lloyd Piquef5275482019-01-29 18:42:42 -0800747 void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None) {
Lloyd Piquea2468662019-03-07 21:31:06 -0800748 EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(kOutputSpaceVisibleRegion)))
Lloyd Piquef5275482019-01-29 18:42:42 -0800749 .WillOnce(Return(kError));
750 EXPECT_CALL(*mHwcLayer, setDataspace(kDataspace)).WillOnce(Return(kError));
751 EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
752 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700753 ? hal::Error::UNSUPPORTED
754 : hal::Error::NONE));
Lloyd Piquef5275482019-01-29 18:42:42 -0800755 EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(kSurfaceDamage)))
756 .WillOnce(Return(kError));
757 }
758
759 void expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700760 EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
Lloyd Piquef5275482019-01-29 18:42:42 -0800761 }
762
763 void expectNoSetCompositionTypeCall() {
764 EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
765 }
766
767 void expectSetColorCall() {
Peiyong Lin65248e02020-04-18 21:15:07 -0700768 const hal::Color color = {static_cast<uint8_t>(std::round(kColor.r * 255)),
769 static_cast<uint8_t>(std::round(kColor.g * 255)),
770 static_cast<uint8_t>(std::round(kColor.b * 255)), 255};
Lloyd Piquef5275482019-01-29 18:42:42 -0800771
772 EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
773 }
774
775 void expectSetSidebandHandleCall() {
776 EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
777 }
778
779 void expectSetHdrMetadataAndBufferCalls() {
780 EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
781 EXPECT_CALL(*mHwcLayer, setBuffer(kExpectedHwcSlot, kBuffer, kFence));
782 }
783
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800784 void expectGenericLayerMetadataCalls() {
785 // Note: Can be in any order.
786 EXPECT_CALL(*mHwcLayer,
787 setLayerGenericMetadata(kLayerGenericMetadata1Key,
788 kLayerGenericMetadata1Mandatory,
789 kLayerGenericMetadata1Value));
790 EXPECT_CALL(*mHwcLayer,
791 setLayerGenericMetadata(kLayerGenericMetadata2Key,
792 kLayerGenericMetadata2Mandatory,
793 kLayerGenericMetadata2Value));
794 }
795
Lloyd Piquea83776c2019-01-29 18:42:32 -0800796 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
Lloyd Piquef5275482019-01-29 18:42:42 -0800797 StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800798};
799
Lloyd Piquef5275482019-01-29 18:42:42 -0800800const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
801 84.f / 255.f};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800802const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
Lloyd Piquea2468662019-03-07 21:31:06 -0800803const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
804 Rect{1005, 1006, 1007, 1008}};
Lloyd Piquef5275482019-01-29 18:42:42 -0800805const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
806 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
807 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
808};
809const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
810const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
811native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
812 reinterpret_cast<native_handle_t*>(1031);
813const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer;
814const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800815const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
816 "com.example.metadata.1";
817const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
818const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
819 "com.example.metadata.2";
820const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
821 {4, 5, 6, 7}};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800822
Lloyd Piquede196652020-01-22 17:29:58 -0800823TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
824 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
825
826 mOutputLayer.writeStateToHWC(true);
827}
828
Lloyd Piquea83776c2019-01-29 18:42:32 -0800829TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
830 mOutputLayer.editState().hwc.reset();
831
832 mOutputLayer.writeStateToHWC(true);
833}
834
835TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
836 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
837
838 mOutputLayer.writeStateToHWC(true);
839}
840
Lloyd Piquef5275482019-01-29 18:42:42 -0800841TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800842 expectGeometryCommonCalls();
Lloyd Piquef5275482019-01-29 18:42:42 -0800843 expectPerFrameCommonCalls();
844
845 expectNoSetCompositionTypeCall();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800846
847 mOutputLayer.writeStateToHWC(true);
848}
849
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700850TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
851 mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
852 mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
853 // This test simulates a scenario where displayInstallOrientation is set to
854 // ROT_90. This only has an effect on the transform; orientation stays 0 (see
855 // DisplayDevice::setProjection).
856 mOutputState.orientation = TR_IDENT;
857 mOutputState.transform = ui::Transform{TR_ROT_90};
858 // Buffers are pre-rotated based on the transform hint (ROT_90); their
859 // geomBufferTransform is set to the inverse transform.
860 mLayerFEState.geomBufferTransform = TR_ROT_270;
861
Snild Dolkow9e217d62020-04-22 15:53:42 +0200862 EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700863}
864
Lloyd Piquef5275482019-01-29 18:42:42 -0800865TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700866 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800867
868 expectPerFrameCommonCalls();
Lloyd Pique46b72df2019-10-29 13:19:27 -0700869
870 // Setting the composition type should happen before setting the color. We
871 // check this in this test only by setting up an testing::InSeqeuence
872 // instance before setting up the two expectations.
873 InSequence s;
Lloyd Piquef5275482019-01-29 18:42:42 -0800874 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SOLID_COLOR);
Lloyd Pique46b72df2019-10-29 13:19:27 -0700875 expectSetColorCall();
Lloyd Piquef5275482019-01-29 18:42:42 -0800876
877 mOutputLayer.writeStateToHWC(false);
878}
879
880TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700881 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SIDEBAND;
Lloyd Piquef5275482019-01-29 18:42:42 -0800882
883 expectPerFrameCommonCalls();
884 expectSetSidebandHandleCall();
885 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SIDEBAND);
886
887 mOutputLayer.writeStateToHWC(false);
888}
889
890TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700891 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::CURSOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800892
893 expectPerFrameCommonCalls();
894 expectSetHdrMetadataAndBufferCalls();
895 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CURSOR);
896
897 mOutputLayer.writeStateToHWC(false);
898}
899
900TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700901 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
Lloyd Piquef5275482019-01-29 18:42:42 -0800902
903 expectPerFrameCommonCalls();
904 expectSetHdrMetadataAndBufferCalls();
905 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
906
907 mOutputLayer.writeStateToHWC(false);
908}
909
910TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
911 (*mOutputLayer.editState().hwc).hwcCompositionType =
912 Hwc2::IComposerClient::Composition::SOLID_COLOR;
913
Lloyd Pique9755fb72019-03-26 14:44:40 -0700914 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800915
916 expectPerFrameCommonCalls();
917 expectSetColorCall();
918 expectNoSetCompositionTypeCall();
919
920 mOutputLayer.writeStateToHWC(false);
921}
922
923TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
Lloyd Pique9755fb72019-03-26 14:44:40 -0700924 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800925
926 expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
927 expectSetColorCall();
928 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
929
930 mOutputLayer.writeStateToHWC(false);
931}
932
933TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
934 mOutputLayer.editState().forceClientComposition = true;
935
Lloyd Pique9755fb72019-03-26 14:44:40 -0700936 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
Lloyd Piquef5275482019-01-29 18:42:42 -0800937
938 expectPerFrameCommonCalls();
939 expectSetColorCall();
940 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT);
941
942 mOutputLayer.writeStateToHWC(false);
943}
944
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800945TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
946 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
947 includeGenericLayerMetadataInState();
948
949 expectGeometryCommonCalls();
950 expectPerFrameCommonCalls();
951 expectSetHdrMetadataAndBufferCalls();
952 expectGenericLayerMetadataCalls();
953 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
954
955 mOutputLayer.writeStateToHWC(true);
956}
957
958TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
959 mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE;
960 includeGenericLayerMetadataInState();
961
962 expectPerFrameCommonCalls();
963 expectSetHdrMetadataAndBufferCalls();
964 expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE);
965
966 mOutputLayer.writeStateToHWC(false);
967}
968
Lloyd Pique66d68602019-02-13 14:23:31 -0800969/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800970 * OutputLayer::writeCursorPositionToHWC()
971 */
972
973struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
974 static constexpr int kDefaultTransform = TR_IDENT;
Peiyong Line9d809e2020-04-14 13:10:48 -0700975 static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800976
977 static const Rect kDefaultDisplayViewport;
978 static const Rect kDefaultCursorFrame;
979
980 OutputLayerWriteCursorPositionToHWCTest() {
981 auto& outputLayerState = mOutputLayer.editState();
982 outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
983
Lloyd Pique9755fb72019-03-26 14:44:40 -0700984 mLayerFEState.cursorFrame = kDefaultCursorFrame;
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800985
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200986 mOutputState.layerStackSpace.content = kDefaultDisplayViewport;
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800987 mOutputState.transform = ui::Transform{kDefaultTransform};
988 }
989
990 std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
991};
992
993const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
994const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
995
Lloyd Piquede196652020-01-22 17:29:58 -0800996TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
997 EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
998
999 mOutputLayer.writeCursorPositionToHWC();
1000}
1001
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001002TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1003 mOutputLayer.editState().hwc.reset();
1004
1005 mOutputLayer.writeCursorPositionToHWC();
1006}
1007
1008TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1009 EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1010
1011 mOutputLayer.writeCursorPositionToHWC();
1012}
1013
1014TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
Lloyd Pique9755fb72019-03-26 14:44:40 -07001015 mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001016
1017 EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1018
1019 mOutputLayer.writeCursorPositionToHWC();
1020}
1021
1022TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1023 mOutputState.transform = ui::Transform{TR_ROT_90};
1024
1025 EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1026
1027 mOutputLayer.writeCursorPositionToHWC();
1028}
1029
1030/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001031 * OutputLayer::getHwcLayer()
1032 */
1033
1034TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1035 mOutputLayer.editState().hwc.reset();
1036
1037 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1038}
1039
1040TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1041 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1042
1043 EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1044}
1045
1046TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1047 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1048 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1049
1050 EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1051}
1052
1053/*
1054 * OutputLayer::requiresClientComposition()
1055 */
1056
1057TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1058 mOutputLayer.editState().hwc.reset();
1059
1060 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1061}
1062
1063TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1064 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1065 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CLIENT;
1066
1067 EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1068}
1069
1070TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1071 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1072 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1073
1074 EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1075}
1076
1077/*
Lloyd Piquec7b0c752019-03-07 20:59:59 -08001078 * OutputLayer::isHardwareCursor()
1079 */
1080
1081TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1082 mOutputLayer.editState().hwc.reset();
1083
1084 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1085}
1086
1087TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1088 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1089 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CURSOR;
1090
1091 EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1092}
1093
1094TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1095 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1096 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1097
1098 EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1099}
1100
1101/*
Lloyd Pique66d68602019-02-13 14:23:31 -08001102 * OutputLayer::applyDeviceCompositionTypeChange()
1103 */
1104
1105TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1106 mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1107 mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
1108
1109 mOutputLayer.applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT);
1110
1111 ASSERT_TRUE(mOutputLayer.getState().hwc);
1112 EXPECT_EQ(Hwc2::IComposerClient::Composition::CLIENT,
1113 mOutputLayer.getState().hwc->hwcCompositionType);
1114}
1115
1116/*
1117 * OutputLayer::prepareForDeviceLayerRequests()
1118 */
1119
1120TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1121 mOutputLayer.editState().clearClientTarget = true;
1122
1123 mOutputLayer.prepareForDeviceLayerRequests();
1124
1125 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1126}
1127
1128/*
1129 * OutputLayer::applyDeviceLayerRequest()
1130 */
1131
1132TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1133 mOutputLayer.editState().clearClientTarget = false;
1134
1135 mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1136
1137 EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1138}
1139
1140TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1141 mOutputLayer.editState().clearClientTarget = false;
1142
1143 mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1144
1145 EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1146}
1147
Lloyd Pique688abd42019-02-15 15:42:24 -08001148/*
1149 * OutputLayer::needsFiltering()
1150 */
1151
1152TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1153 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1154 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1155
1156 EXPECT_FALSE(mOutputLayer.needsFiltering());
1157}
1158
1159TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1160 mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1161 mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1162
1163 EXPECT_TRUE(mOutputLayer.needsFiltering());
1164}
1165
Lloyd Piquecc01a452018-12-04 17:24:00 -08001166} // namespace
1167} // namespace android::compositionengine