• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #undef LOG_TAG
18 #define LOG_TAG "LibSurfaceFlingerUnittests"
19 
20 #include <gtest/gtest.h>
21 #include <ui/FloatRect.h>
22 #include <ui/Transform.h>
23 #include <limits>
24 
25 #include "LayerTestUtils.h"
26 #include "TestableSurfaceFlinger.h"
27 
28 namespace android {
29 namespace {
30 
31 class LayerTest : public BaseLayerTest {
32 protected:
33     static constexpr const float MIN_FLOAT = std::numeric_limits<float>::min();
34     static constexpr const float MAX_FLOAT = std::numeric_limits<float>::max();
35     static constexpr const FloatRect LARGE_FLOAT_RECT{MIN_FLOAT, MIN_FLOAT, MAX_FLOAT, MAX_FLOAT};
36 };
37 
38 INSTANTIATE_TEST_SUITE_P(PerLayerType, LayerTest,
39                          testing::Values(std::make_shared<BufferStateLayerFactory>(),
40                                          std::make_shared<EffectLayerFactory>()),
41                          PrintToStringParamName);
42 
TEST_P(LayerTest,layerVisibleByDefault)43 TEST_P(LayerTest, layerVisibleByDefault) {
44     sp<Layer> layer = GetParam()->createLayer(mFlinger);
45     layer->updateGeometry();
46     layer->computeBounds(LARGE_FLOAT_RECT, ui::Transform(), 0.f);
47     ASSERT_FALSE(layer->isHiddenByPolicy());
48 }
49 
TEST_P(LayerTest,hideLayerWithZeroMatrix)50 TEST_P(LayerTest, hideLayerWithZeroMatrix) {
51     sp<Layer> layer = GetParam()->createLayer(mFlinger);
52 
53     layer_state_t::matrix22_t matrix{0, 0, 0, 0};
54     layer->setMatrix(matrix);
55     layer->updateGeometry();
56     layer->computeBounds(LARGE_FLOAT_RECT, ui::Transform(), 0.f);
57 
58     ASSERT_TRUE(layer->isHiddenByPolicy());
59 }
60 
TEST_P(LayerTest,hideLayerWithInfMatrix)61 TEST_P(LayerTest, hideLayerWithInfMatrix) {
62     sp<Layer> layer = GetParam()->createLayer(mFlinger);
63 
64     constexpr const float INF = std::numeric_limits<float>::infinity();
65     layer_state_t::matrix22_t matrix{INF, 0, 0, INF};
66     layer->setMatrix(matrix);
67     layer->updateGeometry();
68     layer->computeBounds(LARGE_FLOAT_RECT, ui::Transform(), 0.f);
69 
70     ASSERT_TRUE(layer->isHiddenByPolicy());
71 }
72 
TEST_P(LayerTest,hideLayerWithNanMatrix)73 TEST_P(LayerTest, hideLayerWithNanMatrix) {
74     sp<Layer> layer = GetParam()->createLayer(mFlinger);
75 
76     constexpr const float QUIET_NAN = std::numeric_limits<float>::quiet_NaN();
77     layer_state_t::matrix22_t matrix{QUIET_NAN, 0, 0, QUIET_NAN};
78     layer->setMatrix(matrix);
79     layer->updateGeometry();
80     layer->computeBounds(LARGE_FLOAT_RECT, ui::Transform(), 0.f);
81 
82     ASSERT_TRUE(layer->isHiddenByPolicy());
83 }
84 
85 } // namespace
86 } // namespace android
87