blob: fa12315a9103891f424642ff604cd110390b0216 [file] [log] [blame]
Lloyd Pique4603f3c2020-02-11 12:06:56 -08001/*
2 * Copyright 2020 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// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
21#undef LOG_TAG
22#define LOG_TAG "LibSurfaceFlingerUnittests"
23
24#include <vector>
25
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070026// StrictMock<T> derives from T and is not marked final, so the destructor of T is expected to be
27// virtual in case StrictMock<T> is used as a polymorphic base class. That is not the case here.
28#pragma clang diagnostic push
29#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
Lloyd Pique4603f3c2020-02-11 12:06:56 -080030#include <gmock/gmock.h>
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070031#pragma clang diagnostic pop
32
Lloyd Pique4603f3c2020-02-11 12:06:56 -080033#include <gui/LayerMetadata.h>
34#include <log/log.h>
35
36#include "DisplayHardware/HWComposer.h"
37#include "mock/DisplayHardware/MockComposer.h"
38
39// TODO(b/129481165): remove the #pragma below and fix conversion issues
40#pragma clang diagnostic pop // ignored "-Wconversion"
41
42namespace android {
43namespace {
44
Peiyong Line9d809e2020-04-14 13:10:48 -070045namespace hal = android::hardware::graphics::composer::hal;
46
Lloyd Pique4603f3c2020-02-11 12:06:56 -080047using ::testing::_;
48using ::testing::DoAll;
49using ::testing::ElementsAreArray;
50using ::testing::Return;
51using ::testing::SetArgPointee;
52using ::testing::StrictMock;
53
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070054struct MockHWC2ComposerCallback final : StrictMock<HWC2::ComposerCallback> {
55 MOCK_METHOD3(onHotplugReceived, void(int32_t sequenceId, hal::HWDisplayId, hal::Connection));
56 MOCK_METHOD2(onRefreshReceived, void(int32_t sequenceId, hal::HWDisplayId));
Lloyd Pique4603f3c2020-02-11 12:06:56 -080057 MOCK_METHOD4(onVsyncReceived,
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070058 void(int32_t sequenceId, hal::HWDisplayId, int64_t timestamp,
59 std::optional<hal::VsyncPeriodNanos>));
Lloyd Pique4603f3c2020-02-11 12:06:56 -080060 MOCK_METHOD3(onVsyncPeriodTimingChangedReceived,
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070061 void(int32_t sequenceId, hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline&));
62 MOCK_METHOD2(onSeamlessPossible, void(int32_t sequenceId, hal::HWDisplayId));
Lloyd Pique4603f3c2020-02-11 12:06:56 -080063};
64
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070065struct HWComposerSetConfigurationTest : testing::Test {
Lloyd Pique4603f3c2020-02-11 12:06:56 -080066 Hwc2::mock::Composer* mHal = new StrictMock<Hwc2::mock::Composer>();
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070067 MockHWC2ComposerCallback mCallback;
Lloyd Pique4603f3c2020-02-11 12:06:56 -080068};
69
70TEST_F(HWComposerSetConfigurationTest, loadsLayerMetadataSupport) {
71 const std::string kMetadata1Name = "com.example.metadata.1";
72 constexpr bool kMetadata1Mandatory = false;
73 const std::string kMetadata2Name = "com.example.metadata.2";
74 constexpr bool kMetadata2Mandatory = true;
75
76 EXPECT_CALL(*mHal, getMaxVirtualDisplayCount()).WillOnce(Return(0));
Peiyong Line9d809e2020-04-14 13:10:48 -070077 EXPECT_CALL(*mHal, getCapabilities()).WillOnce(Return(std::vector<hal::Capability>{}));
Lloyd Pique4603f3c2020-02-11 12:06:56 -080078 EXPECT_CALL(*mHal, getLayerGenericMetadataKeys(_))
Peiyong Line9d809e2020-04-14 13:10:48 -070079 .WillOnce(DoAll(SetArgPointee<0>(std::vector<hal::LayerGenericMetadataKey>{
80 {kMetadata1Name, kMetadata1Mandatory},
81 {kMetadata2Name, kMetadata2Mandatory},
82 }),
Lloyd Pique4603f3c2020-02-11 12:06:56 -080083 Return(hardware::graphics::composer::V2_4::Error::NONE)));
84 EXPECT_CALL(*mHal, registerCallback(_));
85 EXPECT_CALL(*mHal, isVsyncPeriodSwitchSupported()).WillOnce(Return(false));
86
87 impl::HWComposer hwc{std::unique_ptr<Hwc2::Composer>(mHal)};
88 hwc.setConfiguration(&mCallback, 123);
89
90 const auto& supported = hwc.getSupportedLayerGenericMetadata();
91 EXPECT_EQ(2u, supported.size());
92 EXPECT_EQ(1u, supported.count(kMetadata1Name));
93 EXPECT_EQ(kMetadata1Mandatory, supported.find(kMetadata1Name)->second);
94 EXPECT_EQ(1u, supported.count(kMetadata2Name));
95 EXPECT_EQ(kMetadata2Mandatory, supported.find(kMetadata2Name)->second);
96}
97
98TEST_F(HWComposerSetConfigurationTest, handlesUnsupportedCallToGetLayerGenericMetadataKeys) {
99 EXPECT_CALL(*mHal, getMaxVirtualDisplayCount()).WillOnce(Return(0));
Peiyong Line9d809e2020-04-14 13:10:48 -0700100 EXPECT_CALL(*mHal, getCapabilities()).WillOnce(Return(std::vector<hal::Capability>{}));
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800101 EXPECT_CALL(*mHal, getLayerGenericMetadataKeys(_))
102 .WillOnce(Return(hardware::graphics::composer::V2_4::Error::UNSUPPORTED));
103 EXPECT_CALL(*mHal, registerCallback(_));
104 EXPECT_CALL(*mHal, isVsyncPeriodSwitchSupported()).WillOnce(Return(false));
105
106 impl::HWComposer hwc{std::unique_ptr<Hwc2::Composer>(mHal)};
107 hwc.setConfiguration(&mCallback, 123);
108
109 const auto& supported = hwc.getSupportedLayerGenericMetadata();
110 EXPECT_EQ(0u, supported.size());
111}
112
113struct HWComposerLayerTest : public testing::Test {
Peiyong Line9d809e2020-04-14 13:10:48 -0700114 static constexpr hal::HWDisplayId kDisplayId = static_cast<hal::HWDisplayId>(1001);
115 static constexpr hal::HWLayerId kLayerId = static_cast<hal::HWLayerId>(1002);
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800116
Peiyong Line9d809e2020-04-14 13:10:48 -0700117 HWComposerLayerTest(const std::unordered_set<hal::Capability>& capabilities)
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800118 : mCapabilies(capabilities) {}
119
120 ~HWComposerLayerTest() override { EXPECT_CALL(*mHal, destroyLayer(kDisplayId, kLayerId)); }
121
122 std::unique_ptr<Hwc2::mock::Composer> mHal{new StrictMock<Hwc2::mock::Composer>()};
Peiyong Line9d809e2020-04-14 13:10:48 -0700123 const std::unordered_set<hal::Capability> mCapabilies;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800124 HWC2::impl::Layer mLayer{*mHal, mCapabilies, kDisplayId, kLayerId};
125};
126
127struct HWComposerLayerGenericMetadataTest : public HWComposerLayerTest {
128 static const std::string kLayerGenericMetadata1Name;
129 static constexpr bool kLayerGenericMetadata1Mandatory = false;
130 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
131 static const std::string kLayerGenericMetadata2Name;
132 static constexpr bool kLayerGenericMetadata2Mandatory = true;
133 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
134
135 HWComposerLayerGenericMetadataTest() : HWComposerLayerTest({}) {}
136};
137
138const std::string HWComposerLayerGenericMetadataTest::kLayerGenericMetadata1Name =
139 "com.example.metadata.1";
140
141const std::vector<uint8_t> HWComposerLayerGenericMetadataTest::kLayerGenericMetadata1Value = {1u,
142 2u,
143 3u};
144
145const std::string HWComposerLayerGenericMetadataTest::kLayerGenericMetadata2Name =
146 "com.example.metadata.2";
147
148const std::vector<uint8_t> HWComposerLayerGenericMetadataTest::kLayerGenericMetadata2Value = {45u,
149 67u};
150
151TEST_F(HWComposerLayerGenericMetadataTest, forwardsSupportedMetadata) {
152 EXPECT_CALL(*mHal,
153 setLayerGenericMetadata(kDisplayId, kLayerId, kLayerGenericMetadata1Name,
154 kLayerGenericMetadata1Mandatory,
155 kLayerGenericMetadata1Value))
156 .WillOnce(Return(hardware::graphics::composer::V2_4::Error::NONE));
157 auto result = mLayer.setLayerGenericMetadata(kLayerGenericMetadata1Name,
158 kLayerGenericMetadata1Mandatory,
159 kLayerGenericMetadata1Value);
Peiyong Line9d809e2020-04-14 13:10:48 -0700160 EXPECT_EQ(hal::Error::NONE, result);
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800161
162 EXPECT_CALL(*mHal,
163 setLayerGenericMetadata(kDisplayId, kLayerId, kLayerGenericMetadata2Name,
164 kLayerGenericMetadata2Mandatory,
165 kLayerGenericMetadata2Value))
166 .WillOnce(Return(hardware::graphics::composer::V2_4::Error::UNSUPPORTED));
167 result = mLayer.setLayerGenericMetadata(kLayerGenericMetadata2Name,
168 kLayerGenericMetadata2Mandatory,
169 kLayerGenericMetadata2Value);
Peiyong Line9d809e2020-04-14 13:10:48 -0700170 EXPECT_EQ(hal::Error::UNSUPPORTED, result);
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800171}
172
173} // namespace
174} // namespace android