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