• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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/HwcBufferCache.h>
18 #include <compositionengine/impl/OutputLayer.h>
19 #include <compositionengine/impl/OutputLayerCompositionState.h>
20 #include <compositionengine/mock/CompositionEngine.h>
21 #include <compositionengine/mock/DisplayColorProfile.h>
22 #include <compositionengine/mock/LayerFE.h>
23 #include <compositionengine/mock/Output.h>
24 #include <gtest/gtest.h>
25 #include <log/log.h>
26 
27 #include <renderengine/impl/ExternalTexture.h>
28 #include <renderengine/mock/RenderEngine.h>
29 #include <ui/PixelFormat.h>
30 #include "MockHWC2.h"
31 #include "MockHWComposer.h"
32 #include "RegionMatcher.h"
33 
34 #include <aidl/android/hardware/graphics/composer3/Composition.h>
35 
36 using aidl::android::hardware::graphics::composer3::Composition;
37 
38 namespace android::compositionengine {
39 namespace {
40 
41 namespace hal = android::hardware::graphics::composer::hal;
42 
43 using testing::_;
44 using testing::InSequence;
45 using testing::Return;
46 using testing::ReturnRef;
47 using testing::StrictMock;
48 
49 constexpr auto TR_IDENT = 0u;
50 constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H;
51 constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V;
52 constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
53 constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V;
54 constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180;
55 
56 const std::string kOutputName{"Test Output"};
57 
58 MATCHER_P(ColorEq, expected, "") {
59     *result_listener << "Colors are not equal\n";
60     *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " "
61                      << expected.a << "\n";
62     *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n";
63 
64     return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a;
65 }
66 
toRotation(uint32_t rotationFlag)67 ui::Rotation toRotation(uint32_t rotationFlag) {
68     switch (rotationFlag) {
69         case ui::Transform::RotationFlags::ROT_0:
70             return ui::ROTATION_0;
71         case ui::Transform::RotationFlags::ROT_90:
72             return ui::ROTATION_90;
73         case ui::Transform::RotationFlags::ROT_180:
74             return ui::ROTATION_180;
75         case ui::Transform::RotationFlags::ROT_270:
76             return ui::ROTATION_270;
77         default:
78             LOG_FATAL("Unexpected rotation flag %d", rotationFlag);
79             return ui::Rotation(-1);
80     }
81 }
82 
83 struct OutputLayerTest : public testing::Test {
84     struct OutputLayer final : public impl::OutputLayer {
OutputLayerandroid::compositionengine::__anon89706d5d0111::OutputLayerTest::OutputLayer85         OutputLayer(const compositionengine::Output& output, sp<compositionengine::LayerFE> layerFE)
86               : mOutput(output), mLayerFE(layerFE) {}
87         ~OutputLayer() override = default;
88 
89         // compositionengine::OutputLayer overrides
getOutputandroid::compositionengine::__anon89706d5d0111::OutputLayerTest::OutputLayer90         const compositionengine::Output& getOutput() const override { return mOutput; }
getLayerFEandroid::compositionengine::__anon89706d5d0111::OutputLayerTest::OutputLayer91         compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
getStateandroid::compositionengine::__anon89706d5d0111::OutputLayerTest::OutputLayer92         const impl::OutputLayerCompositionState& getState() const override { return mState; }
editStateandroid::compositionengine::__anon89706d5d0111::OutputLayerTest::OutputLayer93         impl::OutputLayerCompositionState& editState() override { return mState; }
94 
95         // compositionengine::impl::OutputLayer overrides
dumpStateandroid::compositionengine::__anon89706d5d0111::OutputLayerTest::OutputLayer96         void dumpState(std::string& out) const override { mState.dump(out); }
97 
98         const compositionengine::Output& mOutput;
99         sp<compositionengine::LayerFE> mLayerFE;
100         impl::OutputLayerCompositionState mState;
101     };
102 
OutputLayerTestandroid::compositionengine::__anon89706d5d0111::OutputLayerTest103     OutputLayerTest() {
104         EXPECT_CALL(*mLayerFE, getDebugName()).WillRepeatedly(Return("Test LayerFE"));
105         EXPECT_CALL(mOutput, getName()).WillRepeatedly(ReturnRef(kOutputName));
106 
107         EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
108         EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
109     }
110 
111     compositionengine::mock::Output mOutput;
112     sp<StrictMock<compositionengine::mock::LayerFE>> mLayerFE =
113             sp<StrictMock<compositionengine::mock::LayerFE>>::make();
114     OutputLayer mOutputLayer{mOutput, mLayerFE};
115 
116     LayerFECompositionState mLayerFEState;
117     impl::OutputCompositionState mOutputState;
118 };
119 
120 /*
121  * Basic construction
122  */
123 
TEST_F(OutputLayerTest,canInstantiateOutputLayer)124 TEST_F(OutputLayerTest, canInstantiateOutputLayer) {}
125 
126 /*
127  * OutputLayer::setHwcLayer()
128  */
129 
TEST_F(OutputLayerTest,settingNullHwcLayerSetsEmptyHwcState)130 TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) {
131     StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
132 
133     mOutputLayer.setHwcLayer(nullptr);
134 
135     EXPECT_FALSE(mOutputLayer.getState().hwc);
136 }
137 
TEST_F(OutputLayerTest,settingHwcLayerSetsHwcState)138 TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) {
139     auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
140 
141     mOutputLayer.setHwcLayer(hwcLayer);
142 
143     const auto& outputLayerState = mOutputLayer.getState();
144     ASSERT_TRUE(outputLayerState.hwc);
145 
146     const auto& hwcState = *outputLayerState.hwc;
147     EXPECT_EQ(hwcLayer, hwcState.hwcLayer);
148 }
149 
150 /*
151  * OutputLayer::calculateOutputSourceCrop()
152  */
153 
154 struct OutputLayerSourceCropTest : public OutputLayerTest {
OutputLayerSourceCropTestandroid::compositionengine::__anon89706d5d0111::OutputLayerSourceCropTest155     OutputLayerSourceCropTest() {
156         // Set reasonable default values for a simple case. Each test will
157         // set one specific value to something different.
158         mLayerFEState.geomUsesSourceCrop = true;
159         mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080};
160         mLayerFEState.transparentRegionHint = Region{};
161         mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
162         mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
163         mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
164         mLayerFEState.geomBufferTransform = TR_IDENT;
165 
166         mOutputState.layerStackSpace.setContent(Rect{0, 0, 1920, 1080});
167     }
168 
calculateOutputSourceCropandroid::compositionengine::__anon89706d5d0111::OutputLayerSourceCropTest169     FloatRect calculateOutputSourceCrop() {
170         mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
171 
172         return mOutputLayer.calculateOutputSourceCrop(ui::Transform::RotationFlags::ROT_0);
173     }
174 };
175 
TEST_F(OutputLayerSourceCropTest,computesEmptyIfSourceCropNotUsed)176 TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) {
177     mLayerFEState.geomUsesSourceCrop = false;
178 
179     const FloatRect expected{};
180     EXPECT_THAT(calculateOutputSourceCrop(), expected);
181 }
182 
TEST_F(OutputLayerSourceCropTest,correctForSimpleDefaultCase)183 TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) {
184     const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
185     EXPECT_THAT(calculateOutputSourceCrop(), expected);
186 }
187 
TEST_F(OutputLayerSourceCropTest,handlesBoundsOutsideViewport)188 TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) {
189     mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
190 
191     const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
192     EXPECT_THAT(calculateOutputSourceCrop(), expected);
193 }
194 
TEST_F(OutputLayerSourceCropTest,handlesBoundsOutsideViewportRotated)195 TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) {
196     mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
197     mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
198 
199     const FloatRect expected{0.f, 0.f, 1080.f, 1080.f};
200     EXPECT_THAT(calculateOutputSourceCrop(), expected);
201 }
202 
TEST_F(OutputLayerSourceCropTest,calculateOutputSourceCropWorksWithATransformedBuffer)203 TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) {
204     struct Entry {
205         uint32_t bufferInvDisplay;
206         uint32_t buffer;
207         uint32_t display;
208         FloatRect expected;
209     };
210     // Not an exhaustive list of cases, but hopefully enough.
211     const std::array<Entry, 12> testData = {
212             // clang-format off
213             //             inv      buffer      display     expected
214             /*  0 */ Entry{false,   TR_IDENT,   TR_IDENT,   FloatRect{0.f, 0.f, 1920.f, 1080.f}},
215             /*  1 */ Entry{false,   TR_IDENT,   TR_ROT_90,  FloatRect{0.f, 0.f, 1920.f, 1080.f}},
216             /*  2 */ Entry{false,   TR_IDENT,   TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
217             /*  3 */ Entry{false,   TR_IDENT,   TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
218 
219             /*  4 */ Entry{true,    TR_IDENT,   TR_IDENT,   FloatRect{0.f, 0.f, 1920.f, 1080.f}},
220             /*  5 */ Entry{true,    TR_IDENT,   TR_ROT_90,  FloatRect{0.f, 0.f, 1920.f, 1080.f}},
221             /*  6 */ Entry{true,    TR_IDENT,   TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
222             /*  7 */ Entry{true,    TR_IDENT,   TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
223 
224             /*  8 */ Entry{false,   TR_IDENT,   TR_IDENT,   FloatRect{0.f, 0.f, 1920.f, 1080.f}},
225             /*  9 */ Entry{false,   TR_ROT_90,  TR_ROT_90,  FloatRect{0.f, 0.f, 1920.f, 1080.f}},
226             /* 10 */ Entry{false,   TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
227             /* 11 */ Entry{false,   TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
228 
229             // clang-format on
230     };
231 
232     for (size_t i = 0; i < testData.size(); i++) {
233         const auto& entry = testData[i];
234 
235         mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay;
236         mLayerFEState.geomBufferTransform = entry.buffer;
237         mOutputState.displaySpace.setOrientation(toRotation(entry.display));
238 
239         EXPECT_THAT(calculateOutputSourceCrop(), entry.expected) << "entry " << i;
240     }
241 }
242 
TEST_F(OutputLayerSourceCropTest,geomContentCropAffectsCrop)243 TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) {
244     mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540};
245 
246     const FloatRect expected{0.f, 0.f, 960.f, 540.f};
247     EXPECT_THAT(calculateOutputSourceCrop(), expected);
248 }
249 
TEST_F(OutputLayerSourceCropTest,viewportAffectsCrop)250 TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) {
251     mOutputState.layerStackSpace.setContent(Rect{0, 0, 960, 540});
252 
253     const FloatRect expected{0.f, 0.f, 960.f, 540.f};
254     EXPECT_THAT(calculateOutputSourceCrop(), expected);
255 }
256 
257 /*
258  * OutputLayer::calculateOutputDisplayFrame()
259  */
260 
261 struct OutputLayerDisplayFrameTest : public OutputLayerTest {
OutputLayerDisplayFrameTestandroid::compositionengine::__anon89706d5d0111::OutputLayerDisplayFrameTest262     OutputLayerDisplayFrameTest() {
263         // Set reasonable default values for a simple case. Each test will
264         // set one specific value to something different.
265 
266         mLayerFEState.transparentRegionHint = Region{};
267         mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
268         mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080};
269         mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
270         mLayerFEState.geomCrop = Rect{0, 0, 1920, 1080};
271         mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
272 
273         mOutputState.layerStackSpace.setContent(Rect{0, 0, 1920, 1080});
274         mOutputState.transform = ui::Transform{TR_IDENT};
275     }
276 
calculateOutputDisplayFrameandroid::compositionengine::__anon89706d5d0111::OutputLayerDisplayFrameTest277     Rect calculateOutputDisplayFrame() {
278         mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse();
279 
280         return mOutputLayer.calculateOutputDisplayFrame();
281     }
282 };
283 
TEST_F(OutputLayerDisplayFrameTest,correctForSimpleDefaultCase)284 TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) {
285     const Rect expected{0, 0, 1920, 1080};
286     EXPECT_THAT(calculateOutputDisplayFrame(), expected);
287 }
288 
TEST_F(OutputLayerDisplayFrameTest,fullActiveTransparentRegionReturnsEmptyFrame)289 TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) {
290     mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}};
291     const Rect expected{0, 0, 0, 0};
292     EXPECT_THAT(calculateOutputDisplayFrame(), expected);
293 }
294 
TEST_F(OutputLayerDisplayFrameTest,cropAffectsDisplayFrame)295 TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) {
296     mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
297     const Rect expected{100, 200, 300, 500};
298     EXPECT_THAT(calculateOutputDisplayFrame(), expected);
299 }
300 
TEST_F(OutputLayerDisplayFrameTest,cropAffectsDisplayFrameRotated)301 TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) {
302     mLayerFEState.geomCrop = Rect{100, 200, 300, 500};
303     mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
304     const Rect expected{1420, 100, 1720, 300};
305     EXPECT_THAT(calculateOutputDisplayFrame(), expected);
306 }
307 
TEST_F(OutputLayerDisplayFrameTest,emptyGeomCropIsNotUsedToComputeFrame)308 TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) {
309     mLayerFEState.geomCrop = Rect{};
310     const Rect expected{0, 0, 1920, 1080};
311     EXPECT_THAT(calculateOutputDisplayFrame(), expected);
312 }
313 
TEST_F(OutputLayerDisplayFrameTest,geomLayerBoundsAffectsFrame)314 TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) {
315     mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f};
316     const Rect expected{0, 0, 960, 540};
317     EXPECT_THAT(calculateOutputDisplayFrame(), expected);
318 }
319 
TEST_F(OutputLayerDisplayFrameTest,viewportAffectsFrame)320 TEST_F(OutputLayerDisplayFrameTest, viewportAffectsFrame) {
321     mOutputState.layerStackSpace.setContent(Rect{0, 0, 960, 540});
322     const Rect expected{0, 0, 960, 540};
323     EXPECT_THAT(calculateOutputDisplayFrame(), expected);
324 }
325 
TEST_F(OutputLayerDisplayFrameTest,outputTransformAffectsDisplayFrame)326 TEST_F(OutputLayerDisplayFrameTest, outputTransformAffectsDisplayFrame) {
327     mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90};
328     const Rect expected{-1080, 0, 0, 1920};
329     EXPECT_THAT(calculateOutputDisplayFrame(), expected);
330 }
331 
TEST_F(OutputLayerDisplayFrameTest,shadowExpandsDisplayFrame)332 TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame) {
333     const int kShadowRadius = 5;
334     mLayerFEState.shadowRadius = kShadowRadius;
335     mLayerFEState.forceClientComposition = true;
336 
337     mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
338     Rect expected{mLayerFEState.geomLayerBounds};
339     expected.inset(-kShadowRadius, -kShadowRadius, -kShadowRadius, -kShadowRadius);
340     EXPECT_THAT(calculateOutputDisplayFrame(), expected);
341 }
342 
TEST_F(OutputLayerDisplayFrameTest,shadowExpandsDisplayFrame_onlyIfForcingClientComposition)343 TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame_onlyIfForcingClientComposition) {
344     const int kShadowRadius = 5;
345     mLayerFEState.shadowRadius = kShadowRadius;
346     mLayerFEState.forceClientComposition = false;
347 
348     mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
349     Rect expected{mLayerFEState.geomLayerBounds};
350     EXPECT_THAT(calculateOutputDisplayFrame(), expected);
351 }
352 
353 /*
354  * OutputLayer::calculateOutputRelativeBufferTransform()
355  */
356 
TEST_F(OutputLayerTest,calculateOutputRelativeBufferTransformTestsNeeded)357 TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) {
358     mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
359 
360     struct Entry {
361         uint32_t layer;
362         uint32_t buffer;
363         uint32_t display;
364         uint32_t expected;
365     };
366     // Not an exhaustive list of cases, but hopefully enough.
367     const std::array<Entry, 24> testData = {
368             // clang-format off
369             //             layer       buffer      display     expected
370             /*  0 */ Entry{TR_IDENT,   TR_IDENT,   TR_IDENT,   TR_IDENT},
371             /*  1 */ Entry{TR_IDENT,   TR_IDENT,   TR_ROT_90,  TR_ROT_90},
372             /*  2 */ Entry{TR_IDENT,   TR_IDENT,   TR_ROT_180, TR_ROT_180},
373             /*  3 */ Entry{TR_IDENT,   TR_IDENT,   TR_ROT_270, TR_ROT_270},
374 
375             /*  4 */ Entry{TR_IDENT,   TR_FLP_H,   TR_IDENT,   TR_FLP_H ^ TR_IDENT},
376             /*  5 */ Entry{TR_IDENT,   TR_FLP_H,   TR_ROT_90,  TR_FLP_H ^ TR_ROT_90},
377             /*  6 */ Entry{TR_IDENT,   TR_FLP_H,   TR_ROT_180, TR_FLP_H ^ TR_ROT_180},
378             /*  7 */ Entry{TR_IDENT,   TR_FLP_H,   TR_ROT_270, TR_FLP_H ^ TR_ROT_270},
379 
380             /*  8 */ Entry{TR_IDENT,   TR_FLP_V,   TR_IDENT,   TR_FLP_V},
381             /*  9 */ Entry{TR_IDENT,   TR_ROT_90,  TR_ROT_90,  TR_ROT_180},
382             /* 10 */ Entry{TR_IDENT,   TR_ROT_180, TR_ROT_180, TR_IDENT},
383             /* 11 */ Entry{TR_IDENT,   TR_ROT_270, TR_ROT_270, TR_ROT_180},
384 
385             /* 12 */ Entry{TR_ROT_90,  TR_IDENT,   TR_IDENT,   TR_IDENT ^ TR_ROT_90},
386             /* 13 */ Entry{TR_ROT_90,  TR_FLP_H,   TR_ROT_90,  TR_FLP_H ^ TR_ROT_180},
387             /* 14 */ Entry{TR_ROT_90,  TR_IDENT,   TR_ROT_180, TR_IDENT ^ TR_ROT_270},
388             /* 15 */ Entry{TR_ROT_90,  TR_FLP_H,   TR_ROT_270, TR_FLP_H ^ TR_IDENT},
389 
390             /* 16 */ Entry{TR_ROT_180, TR_FLP_H,   TR_IDENT,   TR_FLP_H ^ TR_ROT_180},
391             /* 17 */ Entry{TR_ROT_180, TR_IDENT,   TR_ROT_90,  TR_IDENT ^ TR_ROT_270},
392             /* 18 */ Entry{TR_ROT_180, TR_FLP_H,   TR_ROT_180, TR_FLP_H ^ TR_IDENT},
393             /* 19 */ Entry{TR_ROT_180, TR_IDENT,   TR_ROT_270, TR_IDENT ^ TR_ROT_90},
394 
395             /* 20 */ Entry{TR_ROT_270, TR_IDENT,   TR_IDENT,   TR_IDENT ^ TR_ROT_270},
396             /* 21 */ Entry{TR_ROT_270, TR_FLP_H,   TR_ROT_90,  TR_FLP_H ^ TR_IDENT},
397             /* 22 */ Entry{TR_ROT_270, TR_FLP_H,   TR_ROT_180, TR_FLP_H ^ TR_ROT_90},
398             /* 23 */ Entry{TR_ROT_270, TR_IDENT,   TR_ROT_270, TR_IDENT ^ TR_ROT_180},
399             // clang-format on
400     };
401 
402     for (size_t i = 0; i < testData.size(); i++) {
403         const auto& entry = testData[i];
404 
405         mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
406         mLayerFEState.geomBufferTransform = entry.buffer;
407         mOutputState.displaySpace.setOrientation(toRotation(entry.display));
408         mOutputState.transform = ui::Transform{entry.display};
409 
410         const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.display);
411         EXPECT_EQ(entry.expected, actual) << "entry " << i;
412     }
413 }
414 
TEST_F(OutputLayerTest,calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform)415 TEST_F(OutputLayerTest,
416        calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) {
417     mLayerFEState.geomBufferUsesDisplayInverseTransform = true;
418 
419     struct Entry {
420         uint32_t layer; /* shouldn't affect the result, so we just use arbitrary values */
421         uint32_t buffer;
422         uint32_t display;
423         uint32_t internal;
424         uint32_t expected;
425     };
426     const std::array<Entry, 64> testData = {
427             // clang-format off
428             //    layer       buffer      display     internal    expected
429             Entry{TR_IDENT,   TR_IDENT,   TR_IDENT,   TR_IDENT,   TR_IDENT},
430             Entry{TR_IDENT,   TR_IDENT,   TR_IDENT,   TR_ROT_90,  TR_ROT_270},
431             Entry{TR_IDENT,   TR_IDENT,   TR_IDENT,   TR_ROT_180, TR_ROT_180},
432             Entry{TR_IDENT,   TR_IDENT,   TR_IDENT,   TR_ROT_270, TR_ROT_90},
433 
434             Entry{TR_IDENT,   TR_IDENT,   TR_ROT_90,  TR_IDENT,   TR_ROT_90},
435             Entry{TR_ROT_90,  TR_IDENT,   TR_ROT_90,  TR_ROT_90,  TR_IDENT},
436             Entry{TR_ROT_180, TR_IDENT,   TR_ROT_90,  TR_ROT_180, TR_ROT_270},
437             Entry{TR_ROT_90,  TR_IDENT,   TR_ROT_90,  TR_ROT_270, TR_ROT_180},
438 
439             Entry{TR_ROT_180, TR_IDENT,   TR_ROT_180, TR_IDENT,   TR_ROT_180},
440             Entry{TR_ROT_90,  TR_IDENT,   TR_ROT_180, TR_ROT_90,  TR_ROT_90},
441             Entry{TR_ROT_180, TR_IDENT,   TR_ROT_180, TR_ROT_180, TR_IDENT},
442             Entry{TR_ROT_270, TR_IDENT,   TR_ROT_180, TR_ROT_270, TR_ROT_270},
443 
444             Entry{TR_ROT_270, TR_IDENT,   TR_ROT_270, TR_IDENT,   TR_ROT_270},
445             Entry{TR_ROT_270, TR_IDENT,   TR_ROT_270, TR_ROT_90,  TR_ROT_180},
446             Entry{TR_ROT_180, TR_IDENT,   TR_ROT_270, TR_ROT_180, TR_ROT_90},
447             Entry{TR_IDENT,   TR_IDENT,   TR_ROT_270, TR_ROT_270, TR_IDENT},
448 
449             //    layer       buffer      display     internal    expected
450             Entry{TR_IDENT,   TR_ROT_90,  TR_IDENT,   TR_IDENT,   TR_ROT_90},
451             Entry{TR_ROT_90,  TR_ROT_90,  TR_IDENT,   TR_ROT_90,  TR_IDENT},
452             Entry{TR_ROT_180, TR_ROT_90,  TR_IDENT,   TR_ROT_180, TR_ROT_270},
453             Entry{TR_ROT_270, TR_ROT_90,  TR_IDENT,   TR_ROT_270, TR_ROT_180},
454 
455             Entry{TR_ROT_90,  TR_ROT_90,  TR_ROT_90,  TR_IDENT,   TR_ROT_180},
456             Entry{TR_ROT_90,  TR_ROT_90,  TR_ROT_90,  TR_ROT_90,  TR_ROT_90},
457             Entry{TR_ROT_90,  TR_ROT_90,  TR_ROT_90,  TR_ROT_180, TR_IDENT},
458             Entry{TR_ROT_270, TR_ROT_90,  TR_ROT_90,  TR_ROT_270, TR_ROT_270},
459 
460             Entry{TR_IDENT,   TR_ROT_90,  TR_ROT_180, TR_IDENT,   TR_ROT_270},
461             Entry{TR_ROT_90,  TR_ROT_90,  TR_ROT_180, TR_ROT_90,  TR_ROT_180},
462             Entry{TR_ROT_180, TR_ROT_90,  TR_ROT_180, TR_ROT_180, TR_ROT_90},
463             Entry{TR_ROT_90,  TR_ROT_90,  TR_ROT_180, TR_ROT_270, TR_IDENT},
464 
465             Entry{TR_IDENT,   TR_ROT_90,  TR_ROT_270, TR_IDENT,   TR_IDENT},
466             Entry{TR_ROT_270, TR_ROT_90,  TR_ROT_270, TR_ROT_90,  TR_ROT_270},
467             Entry{TR_ROT_180, TR_ROT_90,  TR_ROT_270, TR_ROT_180, TR_ROT_180},
468             Entry{TR_ROT_270, TR_ROT_90,  TR_ROT_270, TR_ROT_270, TR_ROT_90},
469 
470             //    layer       buffer      display     internal    expected
471             Entry{TR_IDENT,   TR_ROT_180, TR_IDENT,   TR_IDENT,   TR_ROT_180},
472             Entry{TR_IDENT,   TR_ROT_180, TR_IDENT,   TR_ROT_90,  TR_ROT_90},
473             Entry{TR_ROT_180, TR_ROT_180, TR_IDENT,   TR_ROT_180, TR_IDENT},
474             Entry{TR_ROT_270, TR_ROT_180, TR_IDENT,   TR_ROT_270, TR_ROT_270},
475 
476             Entry{TR_IDENT,   TR_ROT_180, TR_ROT_90,  TR_IDENT,   TR_ROT_270},
477             Entry{TR_ROT_90,  TR_ROT_180, TR_ROT_90,  TR_ROT_90,  TR_ROT_180},
478             Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90,  TR_ROT_180, TR_ROT_90},
479             Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90,  TR_ROT_270, TR_IDENT},
480 
481             Entry{TR_IDENT,   TR_ROT_180, TR_ROT_180, TR_IDENT,   TR_IDENT},
482             Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_90,  TR_ROT_270},
483             Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180},
484             Entry{TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90},
485 
486             Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_IDENT,   TR_ROT_90},
487             Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90,  TR_IDENT},
488             Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_270},
489             Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_270, TR_ROT_180},
490 
491             //    layer       buffer      display     internal    expected
492             Entry{TR_IDENT,   TR_ROT_270, TR_IDENT,   TR_IDENT,   TR_ROT_270},
493             Entry{TR_ROT_90,  TR_ROT_270, TR_IDENT,   TR_ROT_90,  TR_ROT_180},
494             Entry{TR_ROT_270, TR_ROT_270, TR_IDENT,   TR_ROT_180, TR_ROT_90},
495             Entry{TR_IDENT,   TR_ROT_270, TR_IDENT,   TR_ROT_270, TR_IDENT},
496 
497             Entry{TR_ROT_270, TR_ROT_270, TR_ROT_90,  TR_IDENT,   TR_IDENT},
498             Entry{TR_ROT_90,  TR_ROT_270, TR_ROT_90,  TR_ROT_90,  TR_ROT_270},
499             Entry{TR_ROT_180, TR_ROT_270, TR_ROT_90,  TR_ROT_180, TR_ROT_180},
500             Entry{TR_ROT_90,  TR_ROT_270, TR_ROT_90,  TR_ROT_270, TR_ROT_90},
501 
502             Entry{TR_IDENT,   TR_ROT_270, TR_ROT_180, TR_IDENT,   TR_ROT_90},
503             Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_90,  TR_IDENT},
504             Entry{TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270},
505             Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_180},
506 
507             Entry{TR_IDENT,   TR_ROT_270, TR_ROT_270, TR_IDENT,   TR_ROT_180},
508             Entry{TR_ROT_90,  TR_ROT_270, TR_ROT_270, TR_ROT_90,  TR_ROT_90},
509             Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_IDENT},
510             Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270},
511             // clang-format on
512     };
513 
514     for (size_t i = 0; i < testData.size(); i++) {
515         const auto& entry = testData[i];
516 
517         mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080);
518         mLayerFEState.geomBufferTransform = entry.buffer;
519         mOutputState.displaySpace.setOrientation(toRotation(entry.display));
520         mOutputState.transform = ui::Transform{entry.display};
521 
522         const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.internal);
523         EXPECT_EQ(entry.expected, actual) << "entry " << i;
524     }
525 }
526 
527 /*
528  * OutputLayer::updateCompositionState()
529  */
530 
531 struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer {
OutputLayerPartialMockForUpdateCompositionStateandroid::compositionengine::__anon89706d5d0111::OutputLayerPartialMockForUpdateCompositionState532     OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output,
533                                                     sp<compositionengine::LayerFE> layerFE)
534           : mOutput(output), mLayerFE(layerFE) {}
535     // Mock everything called by updateCompositionState to simplify testing it.
536     MOCK_CONST_METHOD1(calculateOutputSourceCrop, FloatRect(uint32_t));
537     MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect());
538     MOCK_CONST_METHOD1(calculateOutputRelativeBufferTransform, uint32_t(uint32_t));
539 
540     // compositionengine::OutputLayer overrides
getOutputandroid::compositionengine::__anon89706d5d0111::OutputLayerPartialMockForUpdateCompositionState541     const compositionengine::Output& getOutput() const override { return mOutput; }
getLayerFEandroid::compositionengine::__anon89706d5d0111::OutputLayerPartialMockForUpdateCompositionState542     compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; }
getStateandroid::compositionengine::__anon89706d5d0111::OutputLayerPartialMockForUpdateCompositionState543     const impl::OutputLayerCompositionState& getState() const override { return mState; }
editStateandroid::compositionengine::__anon89706d5d0111::OutputLayerPartialMockForUpdateCompositionState544     impl::OutputLayerCompositionState& editState() override { return mState; }
545 
546     // These need implementations though are not expected to be called.
547     MOCK_CONST_METHOD1(dumpState, void(std::string&));
548 
549     const compositionengine::Output& mOutput;
550     sp<compositionengine::LayerFE> mLayerFE;
551     impl::OutputLayerCompositionState mState;
552 };
553 
554 struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest {
555 public:
OutputLayerUpdateCompositionStateTestandroid::compositionengine::__anon89706d5d0111::OutputLayerUpdateCompositionStateTest556     OutputLayerUpdateCompositionStateTest() {
557         EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
558         EXPECT_CALL(mOutput, getDisplayColorProfile())
559                 .WillRepeatedly(Return(&mDisplayColorProfile));
560         EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true));
561     }
562 
563     ~OutputLayerUpdateCompositionStateTest() = default;
564 
setupGeometryChildCallValuesandroid::compositionengine::__anon89706d5d0111::OutputLayerUpdateCompositionStateTest565     void setupGeometryChildCallValues(ui::Transform::RotationFlags internalDisplayRotationFlags) {
566         EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop(internalDisplayRotationFlags))
567                 .WillOnce(Return(kSourceCrop));
568         EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame));
569         EXPECT_CALL(mOutputLayer,
570                     calculateOutputRelativeBufferTransform(internalDisplayRotationFlags))
571                 .WillOnce(Return(mBufferTransform));
572     }
573 
validateComputedGeometryStateandroid::compositionengine::__anon89706d5d0111::OutputLayerUpdateCompositionStateTest574     void validateComputedGeometryState() {
575         const auto& state = mOutputLayer.getState();
576         EXPECT_EQ(kSourceCrop, state.sourceCrop);
577         EXPECT_EQ(kDisplayFrame, state.displayFrame);
578         EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform);
579     }
580 
581     const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f};
582     const Rect kDisplayFrame{11, 12, 13, 14};
583     uint32_t mBufferTransform{21};
584 
585     using OutputLayer = OutputLayerPartialMockForUpdateCompositionState;
586     StrictMock<OutputLayer> mOutputLayer{mOutput, mLayerFE};
587     StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
588 };
589 
TEST_F(OutputLayerUpdateCompositionStateTest,doesNothingIfNoFECompositionState)590 TEST_F(OutputLayerUpdateCompositionStateTest, doesNothingIfNoFECompositionState) {
591     EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
592 
593     mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
594 }
595 
TEST_F(OutputLayerUpdateCompositionStateTest,setsStateNormally)596 TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) {
597     mLayerFEState.isSecure = true;
598     mOutputState.isSecure = true;
599     mOutputLayer.editState().forceClientComposition = true;
600 
601     setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_90);
602 
603     mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90);
604 
605     validateComputedGeometryState();
606 
607     EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
608 }
609 
TEST_F(OutputLayerUpdateCompositionStateTest,alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput)610 TEST_F(OutputLayerUpdateCompositionStateTest,
611        alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) {
612     mLayerFEState.isSecure = true;
613     mOutputState.isSecure = false;
614 
615     setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
616 
617     mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
618 
619     validateComputedGeometryState();
620 
621     EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
622 }
623 
TEST_F(OutputLayerUpdateCompositionStateTest,alsoSetsForceCompositionIfUnsupportedBufferTransform)624 TEST_F(OutputLayerUpdateCompositionStateTest,
625        alsoSetsForceCompositionIfUnsupportedBufferTransform) {
626     mLayerFEState.isSecure = true;
627     mOutputState.isSecure = true;
628 
629     mBufferTransform = ui::Transform::ROT_INVALID;
630 
631     setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
632 
633     mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0);
634 
635     validateComputedGeometryState();
636 
637     EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
638 }
639 
TEST_F(OutputLayerUpdateCompositionStateTest,setsOutputLayerColorspaceCorrectly)640 TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) {
641     mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
642     mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB;
643 
644     // If the layer is not colorspace agnostic, the output layer dataspace
645     // should use the layers requested colorspace.
646     mLayerFEState.isColorspaceAgnostic = false;
647 
648     mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
649 
650     EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace);
651 
652     // If the layer is colorspace agnostic, the output layer dataspace
653     // should use the colorspace chosen for the whole output.
654     mLayerFEState.isColorspaceAgnostic = true;
655 
656     mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
657 
658     EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace);
659 }
660 
TEST_F(OutputLayerUpdateCompositionStateTest,setsOutputLayerColorspaceWith170mReplacement)661 TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceWith170mReplacement) {
662     mLayerFEState.dataspace = ui::Dataspace::TRANSFER_SMPTE_170M;
663     mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB;
664     mOutputState.treat170mAsSrgb = false;
665     mLayerFEState.isColorspaceAgnostic = false;
666 
667     mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
668 
669     EXPECT_EQ(ui::Dataspace::TRANSFER_SMPTE_170M, mOutputLayer.getState().dataspace);
670 
671     // Rewrite SMPTE 170M as sRGB
672     mOutputState.treat170mAsSrgb = true;
673     mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
674 
675     EXPECT_EQ(ui::Dataspace::TRANSFER_SRGB, mOutputLayer.getState().dataspace);
676 }
677 
TEST_F(OutputLayerUpdateCompositionStateTest,setsWhitePointNitsAndDimmingRatioCorrectly)678 TEST_F(OutputLayerUpdateCompositionStateTest, setsWhitePointNitsAndDimmingRatioCorrectly) {
679     mOutputState.sdrWhitePointNits = 200.f;
680     mOutputState.displayBrightnessNits = 800.f;
681 
682     mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3;
683     mLayerFEState.isColorspaceAgnostic = false;
684     mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
685     EXPECT_EQ(mOutputState.sdrWhitePointNits, mOutputLayer.getState().whitePointNits);
686     EXPECT_EQ(mOutputState.sdrWhitePointNits / mOutputState.displayBrightnessNits,
687               mOutputLayer.getState().dimmingRatio);
688 
689     mLayerFEState.dimmingEnabled = false;
690     mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
691     EXPECT_EQ(mOutputState.displayBrightnessNits, mOutputLayer.getState().whitePointNits);
692     EXPECT_EQ(1.f, mOutputLayer.getState().dimmingRatio);
693 
694     // change dimmingEnabled back to true.
695     mLayerFEState.dimmingEnabled = true;
696     mLayerFEState.dataspace = ui::Dataspace::BT2020_ITU_PQ;
697     mLayerFEState.isColorspaceAgnostic = false;
698     mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
699 
700     EXPECT_EQ(mOutputState.displayBrightnessNits, mOutputLayer.getState().whitePointNits);
701     EXPECT_EQ(1.f, mOutputLayer.getState().dimmingRatio);
702 }
703 
TEST_F(OutputLayerUpdateCompositionStateTest,doesNotRecomputeGeometryIfNotRequested)704 TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
705     mOutputLayer.editState().forceClientComposition = false;
706 
707     mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
708 
709     EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
710 }
711 
TEST_F(OutputLayerUpdateCompositionStateTest,doesNotClearForceClientCompositionIfNotDoingGeometry)712 TEST_F(OutputLayerUpdateCompositionStateTest,
713        doesNotClearForceClientCompositionIfNotDoingGeometry) {
714     mOutputLayer.editState().forceClientComposition = true;
715 
716     mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
717 
718     EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
719 }
720 
TEST_F(OutputLayerUpdateCompositionStateTest,clientCompositionForcedFromFrontEndFlagAtAnyTime)721 TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) {
722     mLayerFEState.forceClientComposition = true;
723     mOutputLayer.editState().forceClientComposition = false;
724 
725     mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
726 
727     EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
728 }
729 
TEST_F(OutputLayerUpdateCompositionStateTest,clientCompositionForcedFromUnsupportedDataspaceAtAnyTime)730 TEST_F(OutputLayerUpdateCompositionStateTest,
731        clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) {
732     mOutputLayer.editState().forceClientComposition = false;
733     EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false));
734 
735     mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0);
736 
737     EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
738 }
739 
TEST_F(OutputLayerUpdateCompositionStateTest,clientCompositionForcedFromArgumentFlag)740 TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromArgumentFlag) {
741     mLayerFEState.forceClientComposition = false;
742     mOutputLayer.editState().forceClientComposition = false;
743 
744     mOutputLayer.updateCompositionState(false, true, ui::Transform::RotationFlags::ROT_0);
745 
746     EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
747 
748     mOutputLayer.editState().forceClientComposition = false;
749 
750     setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0);
751 
752     mOutputLayer.updateCompositionState(true, true, ui::Transform::RotationFlags::ROT_0);
753 
754     EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
755 }
756 
757 /*
758  * OutputLayer::writeStateToHWC()
759  */
760 
761 struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
762     static constexpr hal::Error kError = hal::Error::UNSUPPORTED;
763     static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f};
764     static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31);
765     static constexpr Hwc2::Transform kOverrideBufferTransform = static_cast<Hwc2::Transform>(0);
766     static constexpr Hwc2::IComposerClient::BlendMode kBlendMode =
767             static_cast<Hwc2::IComposerClient::BlendMode>(41);
768     static constexpr Hwc2::IComposerClient::BlendMode kOverrideBlendMode =
769             Hwc2::IComposerClient::BlendMode::PREMULTIPLIED;
770     static constexpr float kAlpha = 51.f;
771     static constexpr float kOverrideAlpha = 1.f;
772     static constexpr float kSkipAlpha = 0.f;
773     static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71);
774     static constexpr ui::Dataspace kOverrideDataspace = static_cast<ui::Dataspace>(72);
775     static constexpr int kSupportedPerFrameMetadata = 101;
776     static constexpr int kExpectedHwcSlot = 0;
777     static constexpr int kOverrideHwcSlot = impl::HwcBufferCache::FLATTENER_CACHING_SLOT;
778     static constexpr bool kLayerGenericMetadata1Mandatory = true;
779     static constexpr bool kLayerGenericMetadata2Mandatory = true;
780     static constexpr float kWhitePointNits = 200.f;
781     static constexpr float kSdrWhitePointNits = 100.f;
782     static constexpr float kDisplayBrightnessNits = 400.f;
783     static constexpr float kLayerBrightness = kWhitePointNits / kDisplayBrightnessNits;
784     static constexpr float kOverrideLayerBrightness = kSdrWhitePointNits / kDisplayBrightnessNits;
785 
786     static const half4 kColor;
787     static const Rect kDisplayFrame;
788     static const Rect kOverrideDisplayFrame;
789     static const FloatRect kOverrideSourceCrop;
790     static const Region kOutputSpaceVisibleRegion;
791     static const Region kOverrideVisibleRegion;
792     static const mat4 kColorTransform;
793     static const Region kSurfaceDamage;
794     static const Region kOverrideSurfaceDamage;
795     static const HdrMetadata kHdrMetadata;
796     static native_handle_t* kSidebandStreamHandle;
797     static const sp<GraphicBuffer> kBuffer;
798     static const sp<GraphicBuffer> kOverrideBuffer;
799     static const sp<Fence> kFence;
800     static const sp<Fence> kOverrideFence;
801     static const std::string kLayerGenericMetadata1Key;
802     static const std::vector<uint8_t> kLayerGenericMetadata1Value;
803     static const std::string kLayerGenericMetadata2Key;
804     static const std::vector<uint8_t> kLayerGenericMetadata2Value;
805 
OutputLayerWriteStateToHWCTestandroid::compositionengine::__anon89706d5d0111::OutputLayerWriteStateToHWCTest806     OutputLayerWriteStateToHWCTest() {
807         auto& outputLayerState = mOutputLayer.editState();
808         outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
809 
810         outputLayerState.displayFrame = kDisplayFrame;
811         outputLayerState.sourceCrop = kSourceCrop;
812         outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
813         outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
814         outputLayerState.dataspace = kDataspace;
815         outputLayerState.whitePointNits = kWhitePointNits;
816         outputLayerState.dimmingRatio = kLayerBrightness;
817 
818         mLayerFEState.blendMode = kBlendMode;
819         mLayerFEState.alpha = kAlpha;
820         mLayerFEState.colorTransform = kColorTransform;
821         mLayerFEState.color = kColor;
822         mLayerFEState.surfaceDamage = kSurfaceDamage;
823         mLayerFEState.hdrMetadata = kHdrMetadata;
824         mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false);
825         mLayerFEState.buffer = kBuffer;
826         mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
827         mLayerFEState.acquireFence = kFence;
828 
829         mOutputState.displayBrightnessNits = kDisplayBrightnessNits;
830         mOutputState.sdrWhitePointNits = kSdrWhitePointNits;
831 
832         EXPECT_CALL(mOutput, getDisplayColorProfile())
833                 .WillRepeatedly(Return(&mDisplayColorProfile));
834         EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata())
835                 .WillRepeatedly(Return(kSupportedPerFrameMetadata));
836     }
837 
838     // Some tests may need to simulate unsupported HWC calls
839     enum class SimulateUnsupported { None, ColorTransform };
840 
includeGenericLayerMetadataInStateandroid::compositionengine::__anon89706d5d0111::OutputLayerWriteStateToHWCTest841     void includeGenericLayerMetadataInState() {
842         mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory,
843                                                              kLayerGenericMetadata1Value};
844         mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory,
845                                                              kLayerGenericMetadata2Value};
846     }
847 
includeOverrideInfoandroid::compositionengine::__anon89706d5d0111::OutputLayerWriteStateToHWCTest848     void includeOverrideInfo() {
849         auto& overrideInfo = mOutputLayer.editState().overrideInfo;
850 
851         overrideInfo.buffer = std::make_shared<
852                 renderengine::impl::ExternalTexture>(kOverrideBuffer, mRenderEngine,
853                                                      renderengine::impl::ExternalTexture::Usage::
854                                                                      READABLE |
855                                                              renderengine::impl::ExternalTexture::
856                                                                      Usage::WRITEABLE);
857         overrideInfo.acquireFence = kOverrideFence;
858         overrideInfo.displayFrame = kOverrideDisplayFrame;
859         overrideInfo.dataspace = kOverrideDataspace;
860         overrideInfo.damageRegion = kOverrideSurfaceDamage;
861         overrideInfo.visibleRegion = kOverrideVisibleRegion;
862     }
863 
expectGeometryCommonCallsandroid::compositionengine::__anon89706d5d0111::OutputLayerWriteStateToHWCTest864     void expectGeometryCommonCalls(Rect displayFrame = kDisplayFrame,
865                                    FloatRect sourceCrop = kSourceCrop,
866                                    Hwc2::Transform bufferTransform = kBufferTransform,
867                                    Hwc2::IComposerClient::BlendMode blendMode = kBlendMode,
868                                    float alpha = kAlpha) {
869         EXPECT_CALL(*mHwcLayer, setDisplayFrame(displayFrame)).WillOnce(Return(kError));
870         EXPECT_CALL(*mHwcLayer, setSourceCrop(sourceCrop)).WillOnce(Return(kError));
871         EXPECT_CALL(*mHwcLayer, setZOrder(_)).WillOnce(Return(kError));
872         EXPECT_CALL(*mHwcLayer, setTransform(bufferTransform)).WillOnce(Return(kError));
873 
874         EXPECT_CALL(*mHwcLayer, setBlendMode(blendMode)).WillOnce(Return(kError));
875         EXPECT_CALL(*mHwcLayer, setPlaneAlpha(alpha)).WillOnce(Return(kError));
876     }
877 
expectPerFrameCommonCallsandroid::compositionengine::__anon89706d5d0111::OutputLayerWriteStateToHWCTest878     void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None,
879                                    ui::Dataspace dataspace = kDataspace,
880                                    const Region& visibleRegion = kOutputSpaceVisibleRegion,
881                                    const Region& surfaceDamage = kSurfaceDamage,
882                                    float brightness = kLayerBrightness,
883                                    const Region& blockingRegion = Region()) {
884         EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(visibleRegion))).WillOnce(Return(kError));
885         EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError));
886         EXPECT_CALL(*mHwcLayer, setBrightness(brightness)).WillOnce(Return(kError));
887         EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
888                 .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
889                                          ? hal::Error::UNSUPPORTED
890                                          : hal::Error::NONE));
891         EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(surfaceDamage))).WillOnce(Return(kError));
892         EXPECT_CALL(*mHwcLayer, setBlockingRegion(RegionEq(blockingRegion)))
893                 .WillOnce(Return(kError));
894     }
895 
expectSetCompositionTypeCallandroid::compositionengine::__anon89706d5d0111::OutputLayerWriteStateToHWCTest896     void expectSetCompositionTypeCall(Composition compositionType) {
897         EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError));
898     }
899 
expectNoSetCompositionTypeCallandroid::compositionengine::__anon89706d5d0111::OutputLayerWriteStateToHWCTest900     void expectNoSetCompositionTypeCall() {
901         EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0);
902     }
903 
expectSetColorCallandroid::compositionengine::__anon89706d5d0111::OutputLayerWriteStateToHWCTest904     void expectSetColorCall() {
905         const aidl::android::hardware::graphics::composer3::Color color = {kColor.r, kColor.g,
906                                                                            kColor.b, 1.0f};
907 
908         EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError));
909     }
910 
expectSetSidebandHandleCallandroid::compositionengine::__anon89706d5d0111::OutputLayerWriteStateToHWCTest911     void expectSetSidebandHandleCall() {
912         EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle));
913     }
914 
expectSetHdrMetadataAndBufferCallsandroid::compositionengine::__anon89706d5d0111::OutputLayerWriteStateToHWCTest915     void expectSetHdrMetadataAndBufferCalls(uint32_t hwcSlot = kExpectedHwcSlot,
916                                             sp<GraphicBuffer> buffer = kBuffer,
917                                             sp<Fence> fence = kFence) {
918         EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata));
919         EXPECT_CALL(*mHwcLayer, setBuffer(hwcSlot, buffer, fence));
920     }
921 
expectGenericLayerMetadataCallsandroid::compositionengine::__anon89706d5d0111::OutputLayerWriteStateToHWCTest922     void expectGenericLayerMetadataCalls() {
923         // Note: Can be in any order.
924         EXPECT_CALL(*mHwcLayer,
925                     setLayerGenericMetadata(kLayerGenericMetadata1Key,
926                                             kLayerGenericMetadata1Mandatory,
927                                             kLayerGenericMetadata1Value));
928         EXPECT_CALL(*mHwcLayer,
929                     setLayerGenericMetadata(kLayerGenericMetadata2Key,
930                                             kLayerGenericMetadata2Mandatory,
931                                             kLayerGenericMetadata2Value));
932     }
933 
934     std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
935     StrictMock<mock::DisplayColorProfile> mDisplayColorProfile;
936     renderengine::mock::RenderEngine mRenderEngine;
937 };
938 
939 const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
940                                                    84.f / 255.f};
941 const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
942 const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044};
943 const FloatRect OutputLayerWriteStateToHWCTest::kOverrideSourceCrop{0.f, 0.f, 4.f, 5.f};
944 const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
945         Rect{1005, 1006, 1007, 1008}};
946 const Region OutputLayerWriteStateToHWCTest::kOverrideVisibleRegion{Rect{1006, 1007, 1008, 1009}};
947 const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
948         1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
949         1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
950 };
951 const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}};
952 const Region OutputLayerWriteStateToHWCTest::kOverrideSurfaceDamage{Rect{1026, 1027, 1028, 1029}};
953 const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029};
954 native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle =
955         reinterpret_cast<native_handle_t*>(1031);
956 const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer;
957 const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kOverrideBuffer =
958         new GraphicBuffer(4, 5, PIXEL_FORMAT_RGBA_8888,
959                           AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
960                                   AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
961 const sp<Fence> OutputLayerWriteStateToHWCTest::kFence;
962 const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = new Fence();
963 const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key =
964         "com.example.metadata.1";
965 const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}};
966 const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key =
967         "com.example.metadata.2";
968 const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{
969         {4, 5, 6, 7}};
970 
TEST_F(OutputLayerWriteStateToHWCTest,doesNothingIfNoFECompositionState)971 TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) {
972     EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
973 
974     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
975                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
976 }
977 
TEST_F(OutputLayerWriteStateToHWCTest,doesNothingIfNoHWCState)978 TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) {
979     mOutputLayer.editState().hwc.reset();
980 
981     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
982                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
983 }
984 
TEST_F(OutputLayerWriteStateToHWCTest,doesNothingIfNoHWCLayer)985 TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) {
986     mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr);
987 
988     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
989                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
990 }
991 
TEST_F(OutputLayerWriteStateToHWCTest,canSetAllState)992 TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) {
993     expectGeometryCommonCalls();
994     expectPerFrameCommonCalls();
995 
996     expectNoSetCompositionTypeCall();
997     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
998 
999     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1000                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1001 }
1002 
TEST_F(OutputLayerTest,displayInstallOrientationBufferTransformSetTo90)1003 TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) {
1004     mLayerFEState.geomBufferUsesDisplayInverseTransform = false;
1005     mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT};
1006     // This test simulates a scenario where displayInstallOrientation is set to
1007     // ROT_90. This only has an effect on the transform; orientation stays 0 (see
1008     // DisplayDevice::setProjection).
1009     mOutputState.displaySpace.setOrientation(ui::ROTATION_0);
1010     mOutputState.transform = ui::Transform{TR_ROT_90};
1011     // Buffers are pre-rotated based on the transform hint (ROT_90); their
1012     // geomBufferTransform is set to the inverse transform.
1013     mLayerFEState.geomBufferTransform = TR_ROT_270;
1014 
1015     EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90));
1016 }
1017 
TEST_F(OutputLayerWriteStateToHWCTest,canSetPerFrameStateForSolidColor)1018 TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) {
1019     mLayerFEState.compositionType = Composition::SOLID_COLOR;
1020 
1021     expectPerFrameCommonCalls();
1022     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1023 
1024     // Setting the composition type should happen before setting the color. We
1025     // check this in this test only by setting up an testing::InSeqeuence
1026     // instance before setting up the two expectations.
1027     InSequence s;
1028     expectSetCompositionTypeCall(Composition::SOLID_COLOR);
1029     expectSetColorCall();
1030 
1031     mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1032                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1033 }
1034 
TEST_F(OutputLayerWriteStateToHWCTest,canSetPerFrameStateForSideband)1035 TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) {
1036     mLayerFEState.compositionType = Composition::SIDEBAND;
1037 
1038     expectPerFrameCommonCalls();
1039     expectSetSidebandHandleCall();
1040     expectSetCompositionTypeCall(Composition::SIDEBAND);
1041 
1042     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1043 
1044     mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1045                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1046 }
1047 
TEST_F(OutputLayerWriteStateToHWCTest,canSetPerFrameStateForCursor)1048 TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) {
1049     mLayerFEState.compositionType = Composition::CURSOR;
1050 
1051     expectPerFrameCommonCalls();
1052     expectSetHdrMetadataAndBufferCalls();
1053     expectSetCompositionTypeCall(Composition::CURSOR);
1054 
1055     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1056 
1057     mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1058                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1059 }
1060 
TEST_F(OutputLayerWriteStateToHWCTest,canSetPerFrameStateForDevice)1061 TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) {
1062     mLayerFEState.compositionType = Composition::DEVICE;
1063 
1064     expectPerFrameCommonCalls();
1065     expectSetHdrMetadataAndBufferCalls();
1066     expectSetCompositionTypeCall(Composition::DEVICE);
1067 
1068     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1069 
1070     mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1071                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1072 }
1073 
TEST_F(OutputLayerWriteStateToHWCTest,compositionTypeIsNotSetIfUnchanged)1074 TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) {
1075     (*mOutputLayer.editState().hwc).hwcCompositionType = Composition::SOLID_COLOR;
1076 
1077     mLayerFEState.compositionType = Composition::SOLID_COLOR;
1078 
1079     expectPerFrameCommonCalls();
1080     expectSetColorCall();
1081     expectNoSetCompositionTypeCall();
1082 
1083     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1084 
1085     mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1086                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1087 }
1088 
TEST_F(OutputLayerWriteStateToHWCTest,compositionTypeIsSetToClientIfColorTransformNotSupported)1089 TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) {
1090     mLayerFEState.compositionType = Composition::SOLID_COLOR;
1091 
1092     expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform);
1093     expectSetColorCall();
1094     expectSetCompositionTypeCall(Composition::CLIENT);
1095 
1096     mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1097                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1098 }
1099 
TEST_F(OutputLayerWriteStateToHWCTest,compositionTypeIsSetToClientIfClientCompositionForced)1100 TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) {
1101     mOutputLayer.editState().forceClientComposition = true;
1102 
1103     mLayerFEState.compositionType = Composition::SOLID_COLOR;
1104 
1105     expectPerFrameCommonCalls();
1106     expectSetColorCall();
1107     expectSetCompositionTypeCall(Composition::CLIENT);
1108 
1109     mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1110                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1111 }
1112 
TEST_F(OutputLayerWriteStateToHWCTest,allStateIncludesMetadataIfPresent)1113 TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) {
1114     mLayerFEState.compositionType = Composition::DEVICE;
1115     includeGenericLayerMetadataInState();
1116 
1117     expectGeometryCommonCalls();
1118     expectPerFrameCommonCalls();
1119     expectSetHdrMetadataAndBufferCalls();
1120     expectGenericLayerMetadataCalls();
1121     expectSetCompositionTypeCall(Composition::DEVICE);
1122 
1123     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1124 
1125     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1126                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1127 }
1128 
TEST_F(OutputLayerWriteStateToHWCTest,perFrameStateDoesNotIncludeMetadataIfPresent)1129 TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) {
1130     mLayerFEState.compositionType = Composition::DEVICE;
1131     includeGenericLayerMetadataInState();
1132 
1133     expectPerFrameCommonCalls();
1134     expectSetHdrMetadataAndBufferCalls();
1135     expectSetCompositionTypeCall(Composition::DEVICE);
1136 
1137     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1138 
1139     mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
1140                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1141 }
1142 
TEST_F(OutputLayerWriteStateToHWCTest,overriddenSkipLayerDoesNotSendBuffer)1143 TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerDoesNotSendBuffer) {
1144     mLayerFEState.compositionType = Composition::DEVICE;
1145     includeOverrideInfo();
1146 
1147     expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1148                               kOverrideBlendMode, kSkipAlpha);
1149     expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
1150                               kOverrideSurfaceDamage, kOverrideLayerBrightness);
1151     expectSetHdrMetadataAndBufferCalls();
1152     expectSetCompositionTypeCall(Composition::DEVICE);
1153     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1154 
1155     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1156                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1157 }
1158 
TEST_F(OutputLayerWriteStateToHWCTest,overriddenSkipLayerForSolidColorDoesNotSendBuffer)1159 TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerForSolidColorDoesNotSendBuffer) {
1160     mLayerFEState.compositionType = Composition::SOLID_COLOR;
1161     includeOverrideInfo();
1162 
1163     expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1164                               kOverrideBlendMode, kSkipAlpha);
1165     expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
1166                               kOverrideSurfaceDamage, kOverrideLayerBrightness);
1167     expectSetHdrMetadataAndBufferCalls();
1168     expectSetCompositionTypeCall(Composition::DEVICE);
1169     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1170 
1171     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0,
1172                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1173 }
1174 
TEST_F(OutputLayerWriteStateToHWCTest,includesOverrideInfoIfPresent)1175 TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
1176     mLayerFEState.compositionType = Composition::DEVICE;
1177     includeOverrideInfo();
1178 
1179     expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1180                               kOverrideBlendMode, kOverrideAlpha);
1181     expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
1182                               kOverrideSurfaceDamage, kOverrideLayerBrightness);
1183     expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
1184     expectSetCompositionTypeCall(Composition::DEVICE);
1185     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1186 
1187     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1188                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1189 }
1190 
TEST_F(OutputLayerWriteStateToHWCTest,includesOverrideInfoForSolidColorIfPresent)1191 TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoForSolidColorIfPresent) {
1192     mLayerFEState.compositionType = Composition::SOLID_COLOR;
1193     includeOverrideInfo();
1194 
1195     expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
1196                               kOverrideBlendMode, kOverrideAlpha);
1197     expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
1198                               kOverrideSurfaceDamage, kOverrideLayerBrightness);
1199     expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
1200     expectSetCompositionTypeCall(Composition::DEVICE);
1201     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1202 
1203     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1204                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1205 }
1206 
TEST_F(OutputLayerWriteStateToHWCTest,previousOverriddenLayerSendsSurfaceDamage)1207 TEST_F(OutputLayerWriteStateToHWCTest, previousOverriddenLayerSendsSurfaceDamage) {
1208     mLayerFEState.compositionType = Composition::DEVICE;
1209     mOutputLayer.editState().hwc->stateOverridden = true;
1210 
1211     expectGeometryCommonCalls();
1212     expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1213                               Region::INVALID_REGION);
1214     expectSetHdrMetadataAndBufferCalls();
1215     expectSetCompositionTypeCall(Composition::DEVICE);
1216     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1217 
1218     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1219                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1220 }
1221 
TEST_F(OutputLayerWriteStateToHWCTest,previousSkipLayerSendsUpdatedDeviceCompositionInfo)1222 TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedDeviceCompositionInfo) {
1223     mLayerFEState.compositionType = Composition::DEVICE;
1224     mOutputLayer.editState().hwc->stateOverridden = true;
1225     mOutputLayer.editState().hwc->layerSkipped = true;
1226     mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
1227 
1228     expectGeometryCommonCalls();
1229     expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1230                               Region::INVALID_REGION);
1231     expectSetHdrMetadataAndBufferCalls();
1232     expectSetCompositionTypeCall(Composition::DEVICE);
1233     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1234 
1235     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1236                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1237 }
1238 
TEST_F(OutputLayerWriteStateToHWCTest,previousSkipLayerSendsUpdatedClientCompositionInfo)1239 TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedClientCompositionInfo) {
1240     mLayerFEState.compositionType = Composition::DEVICE;
1241     mOutputLayer.editState().forceClientComposition = true;
1242     mOutputLayer.editState().hwc->stateOverridden = true;
1243     mOutputLayer.editState().hwc->layerSkipped = true;
1244     mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
1245 
1246     expectGeometryCommonCalls();
1247     expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1248                               Region::INVALID_REGION);
1249     expectSetHdrMetadataAndBufferCalls();
1250     expectSetCompositionTypeCall(Composition::CLIENT);
1251     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1252 
1253     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1254                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1255 }
1256 
TEST_F(OutputLayerWriteStateToHWCTest,peekThroughChangesBlendMode)1257 TEST_F(OutputLayerWriteStateToHWCTest, peekThroughChangesBlendMode) {
1258     auto peekThroughLayerFE = sp<compositionengine::mock::LayerFE>::make();
1259     OutputLayer peekThroughLayer{mOutput, peekThroughLayerFE};
1260 
1261     mOutputLayer.mState.overrideInfo.peekThroughLayer = &peekThroughLayer;
1262 
1263     expectGeometryCommonCalls(kDisplayFrame, kSourceCrop, kBufferTransform,
1264                               Hwc2::IComposerClient::BlendMode::PREMULTIPLIED);
1265     expectPerFrameCommonCalls();
1266     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1267 
1268     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1269                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ false);
1270 }
1271 
TEST_F(OutputLayerWriteStateToHWCTest,isPeekingThroughSetsOverride)1272 TEST_F(OutputLayerWriteStateToHWCTest, isPeekingThroughSetsOverride) {
1273     expectGeometryCommonCalls();
1274     expectPerFrameCommonCalls();
1275 
1276     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1277                                  /*zIsOverridden*/ false, /*isPeekingThrough*/ true);
1278     EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1279 }
1280 
TEST_F(OutputLayerWriteStateToHWCTest,zIsOverriddenSetsOverride)1281 TEST_F(OutputLayerWriteStateToHWCTest, zIsOverriddenSetsOverride) {
1282     expectGeometryCommonCalls();
1283     expectPerFrameCommonCalls();
1284     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(false));
1285 
1286     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1287                                  /*zIsOverridden*/ true, /*isPeekingThrough*/
1288                                  false);
1289     EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden);
1290 }
1291 
TEST_F(OutputLayerWriteStateToHWCTest,roundedCornersForceClientComposition)1292 TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersForceClientComposition) {
1293     expectGeometryCommonCalls();
1294     expectPerFrameCommonCalls();
1295     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillOnce(Return(true));
1296     expectSetCompositionTypeCall(Composition::CLIENT);
1297 
1298     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1299                                  /*zIsOverridden*/ false, /*isPeekingThrough*/
1300                                  false);
1301 }
1302 
TEST_F(OutputLayerWriteStateToHWCTest,roundedCornersPeekingThroughAllowsDeviceComposition)1303 TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersPeekingThroughAllowsDeviceComposition) {
1304     expectGeometryCommonCalls();
1305     expectPerFrameCommonCalls();
1306     expectSetHdrMetadataAndBufferCalls();
1307     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(true));
1308     expectSetCompositionTypeCall(Composition::DEVICE);
1309 
1310     mLayerFEState.compositionType = Composition::DEVICE;
1311     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1312                                  /*zIsOverridden*/ false, /*isPeekingThrough*/
1313                                  true);
1314     EXPECT_EQ(Composition::DEVICE, mOutputLayer.getState().hwc->hwcCompositionType);
1315 }
1316 
TEST_F(OutputLayerWriteStateToHWCTest,setBlockingRegion)1317 TEST_F(OutputLayerWriteStateToHWCTest, setBlockingRegion) {
1318     mLayerFEState.compositionType = Composition::DISPLAY_DECORATION;
1319     const auto blockingRegion = Region(Rect(0, 0, 1000, 1000));
1320     mOutputLayer.editState().outputSpaceBlockingRegionHint = blockingRegion;
1321 
1322     expectGeometryCommonCalls();
1323     expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
1324                               kSurfaceDamage, kLayerBrightness, blockingRegion);
1325     expectSetHdrMetadataAndBufferCalls();
1326     EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
1327     expectSetCompositionTypeCall(Composition::DISPLAY_DECORATION);
1328 
1329     mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
1330                                  /*zIsOverridden*/ false, /*isPeekingThrough*/
1331                                  false);
1332 }
1333 
1334 /*
1335  * OutputLayer::writeCursorPositionToHWC()
1336  */
1337 
1338 struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
1339     static constexpr int kDefaultTransform = TR_IDENT;
1340     static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED;
1341 
1342     static const Rect kDefaultDisplayViewport;
1343     static const Rect kDefaultCursorFrame;
1344 
OutputLayerWriteCursorPositionToHWCTestandroid::compositionengine::__anon89706d5d0111::OutputLayerWriteCursorPositionToHWCTest1345     OutputLayerWriteCursorPositionToHWCTest() {
1346         auto& outputLayerState = mOutputLayer.editState();
1347         outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
1348 
1349         mLayerFEState.cursorFrame = kDefaultCursorFrame;
1350 
1351         mOutputState.layerStackSpace.setContent(kDefaultDisplayViewport);
1352         mOutputState.transform = ui::Transform{kDefaultTransform};
1353     }
1354 
1355     std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
1356 };
1357 
1358 const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
1359 const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
1360 
TEST_F(OutputLayerWriteCursorPositionToHWCTest,doesNothingIfNoFECompositionState)1361 TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) {
1362     EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr));
1363 
1364     mOutputLayer.writeCursorPositionToHWC();
1365 }
1366 
TEST_F(OutputLayerWriteCursorPositionToHWCTest,writeCursorPositionToHWCHandlesNoHwcState)1367 TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
1368     mOutputLayer.editState().hwc.reset();
1369 
1370     mOutputLayer.writeCursorPositionToHWC();
1371 }
1372 
TEST_F(OutputLayerWriteCursorPositionToHWCTest,writeCursorPositionToHWCWritesStateToHWC)1373 TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
1374     EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
1375 
1376     mOutputLayer.writeCursorPositionToHWC();
1377 }
1378 
TEST_F(OutputLayerWriteCursorPositionToHWCTest,writeCursorPositionToHWCIntersectedWithViewport)1379 TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
1380     mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016};
1381 
1382     EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
1383 
1384     mOutputLayer.writeCursorPositionToHWC();
1385 }
1386 
TEST_F(OutputLayerWriteCursorPositionToHWCTest,writeCursorPositionToHWCRotatedByTransform)1387 TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
1388     mOutputState.transform = ui::Transform{TR_ROT_90};
1389 
1390     EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
1391 
1392     mOutputLayer.writeCursorPositionToHWC();
1393 }
1394 
1395 /*
1396  * OutputLayer::getHwcLayer()
1397  */
1398 
TEST_F(OutputLayerTest,getHwcLayerHandlesNoHwcState)1399 TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) {
1400     mOutputLayer.editState().hwc.reset();
1401 
1402     EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1403 }
1404 
TEST_F(OutputLayerTest,getHwcLayerHandlesNoHwcLayer)1405 TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) {
1406     mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1407 
1408     EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr);
1409 }
1410 
TEST_F(OutputLayerTest,getHwcLayerReturnsHwcLayer)1411 TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) {
1412     auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
1413     mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer};
1414 
1415     EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer());
1416 }
1417 
1418 /*
1419  * OutputLayer::requiresClientComposition()
1420  */
1421 
TEST_F(OutputLayerTest,requiresClientCompositionReturnsTrueIfNoHWC2State)1422 TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) {
1423     mOutputLayer.editState().hwc.reset();
1424 
1425     EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1426 }
1427 
TEST_F(OutputLayerTest,requiresClientCompositionReturnsTrueIfSetToClientComposition)1428 TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) {
1429     mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1430     mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT;
1431 
1432     EXPECT_TRUE(mOutputLayer.requiresClientComposition());
1433 }
1434 
TEST_F(OutputLayerTest,requiresClientCompositionReturnsFalseIfSetToDeviceComposition)1435 TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) {
1436     mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1437     mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
1438 
1439     EXPECT_FALSE(mOutputLayer.requiresClientComposition());
1440 }
1441 
1442 /*
1443  * OutputLayer::isHardwareCursor()
1444  */
1445 
TEST_F(OutputLayerTest,isHardwareCursorReturnsFalseIfNoHWC2State)1446 TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
1447     mOutputLayer.editState().hwc.reset();
1448 
1449     EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1450 }
1451 
TEST_F(OutputLayerTest,isHardwareCursorReturnsTrueIfSetToCursorComposition)1452 TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
1453     mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1454     mOutputLayer.editState().hwc->hwcCompositionType = Composition::CURSOR;
1455 
1456     EXPECT_TRUE(mOutputLayer.isHardwareCursor());
1457 }
1458 
TEST_F(OutputLayerTest,isHardwareCursorReturnsFalseIfSetToDeviceComposition)1459 TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
1460     mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1461     mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
1462 
1463     EXPECT_FALSE(mOutputLayer.isHardwareCursor());
1464 }
1465 
1466 /*
1467  * OutputLayer::applyDeviceCompositionTypeChange()
1468  */
1469 
TEST_F(OutputLayerTest,applyDeviceCompositionTypeChangeSetsNewType)1470 TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) {
1471     mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
1472     mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE;
1473 
1474     mOutputLayer.applyDeviceCompositionTypeChange(Composition::CLIENT);
1475 
1476     ASSERT_TRUE(mOutputLayer.getState().hwc);
1477     EXPECT_EQ(Composition::CLIENT, mOutputLayer.getState().hwc->hwcCompositionType);
1478 }
1479 
1480 /*
1481  * OutputLayer::prepareForDeviceLayerRequests()
1482  */
1483 
TEST_F(OutputLayerTest,prepareForDeviceLayerRequestsResetsRequestState)1484 TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) {
1485     mOutputLayer.editState().clearClientTarget = true;
1486 
1487     mOutputLayer.prepareForDeviceLayerRequests();
1488 
1489     EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1490 }
1491 
1492 /*
1493  * OutputLayer::applyDeviceLayerRequest()
1494  */
1495 
TEST_F(OutputLayerTest,applyDeviceLayerRequestHandlesClearClientTarget)1496 TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) {
1497     mOutputLayer.editState().clearClientTarget = false;
1498 
1499     mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET);
1500 
1501     EXPECT_TRUE(mOutputLayer.getState().clearClientTarget);
1502 }
1503 
TEST_F(OutputLayerTest,applyDeviceLayerRequestHandlesUnknownRequest)1504 TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) {
1505     mOutputLayer.editState().clearClientTarget = false;
1506 
1507     mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0));
1508 
1509     EXPECT_FALSE(mOutputLayer.getState().clearClientTarget);
1510 }
1511 
1512 /*
1513  * OutputLayer::needsFiltering()
1514  */
1515 
TEST_F(OutputLayerTest,needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize)1516 TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) {
1517     mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1518     mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f};
1519 
1520     EXPECT_FALSE(mOutputLayer.needsFiltering());
1521 }
1522 
TEST_F(OutputLayerTest,needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize)1523 TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) {
1524     mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200);
1525     mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f};
1526 
1527     EXPECT_TRUE(mOutputLayer.needsFiltering());
1528 }
1529 
1530 } // namespace
1531 } // namespace android::compositionengine
1532