blob: 7d77abcef1ea0752ab8cd701bf7fb6c509ebc9be [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
Marin Shalamanov23c44202020-12-22 19:09:20 +010036#include "DisplayHardware/DisplayMode.h"
Lloyd Pique4603f3c2020-02-11 12:06:56 -080037#include "DisplayHardware/HWComposer.h"
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +010038#include "DisplayHardware/Hal.h"
Lloyd Pique4603f3c2020-02-11 12:06:56 -080039#include "mock/DisplayHardware/MockComposer.h"
40
41// TODO(b/129481165): remove the #pragma below and fix conversion issues
42#pragma clang diagnostic pop // ignored "-Wconversion"
43
44namespace android {
45namespace {
46
Marin Shalamanov6e840172020-12-14 22:13:28 +010047namespace V2_1 = hardware::graphics::composer::V2_1;
48namespace V2_4 = hardware::graphics::composer::V2_4;
49
50using Hwc2::Config;
Peiyong Line9d809e2020-04-14 13:10:48 -070051
Lloyd Pique4603f3c2020-02-11 12:06:56 -080052using ::testing::_;
53using ::testing::DoAll;
54using ::testing::ElementsAreArray;
55using ::testing::Return;
56using ::testing::SetArgPointee;
57using ::testing::StrictMock;
58
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070059struct MockHWC2ComposerCallback final : StrictMock<HWC2::ComposerCallback> {
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070060 MOCK_METHOD2(onComposerHalHotplug, void(hal::HWDisplayId, hal::Connection));
61 MOCK_METHOD1(onComposerHalRefresh, void(hal::HWDisplayId));
62 MOCK_METHOD3(onComposerHalVsync,
63 void(hal::HWDisplayId, int64_t timestamp, std::optional<hal::VsyncPeriodNanos>));
64 MOCK_METHOD2(onComposerHalVsyncPeriodTimingChanged,
65 void(hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline&));
66 MOCK_METHOD1(onComposerHalSeamlessPossible, void(hal::HWDisplayId));
Lloyd Pique4603f3c2020-02-11 12:06:56 -080067};
68
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070069struct HWComposerSetCallbackTest : testing::Test {
Lloyd Pique4603f3c2020-02-11 12:06:56 -080070 Hwc2::mock::Composer* mHal = new StrictMock<Hwc2::mock::Composer>();
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070071 MockHWC2ComposerCallback mCallback;
Lloyd Pique4603f3c2020-02-11 12:06:56 -080072};
73
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070074TEST_F(HWComposerSetCallbackTest, loadsLayerMetadataSupport) {
Lloyd Pique4603f3c2020-02-11 12:06:56 -080075 const std::string kMetadata1Name = "com.example.metadata.1";
76 constexpr bool kMetadata1Mandatory = false;
77 const std::string kMetadata2Name = "com.example.metadata.2";
78 constexpr bool kMetadata2Mandatory = true;
79
Peiyong Line9d809e2020-04-14 13:10:48 -070080 EXPECT_CALL(*mHal, getCapabilities()).WillOnce(Return(std::vector<hal::Capability>{}));
Lloyd Pique4603f3c2020-02-11 12:06:56 -080081 EXPECT_CALL(*mHal, getLayerGenericMetadataKeys(_))
Peiyong Line9d809e2020-04-14 13:10:48 -070082 .WillOnce(DoAll(SetArgPointee<0>(std::vector<hal::LayerGenericMetadataKey>{
83 {kMetadata1Name, kMetadata1Mandatory},
84 {kMetadata2Name, kMetadata2Mandatory},
85 }),
Lloyd Pique4603f3c2020-02-11 12:06:56 -080086 Return(hardware::graphics::composer::V2_4::Error::NONE)));
87 EXPECT_CALL(*mHal, registerCallback(_));
88 EXPECT_CALL(*mHal, isVsyncPeriodSwitchSupported()).WillOnce(Return(false));
89
90 impl::HWComposer hwc{std::unique_ptr<Hwc2::Composer>(mHal)};
Dominik Laskowski0deb06e2021-04-16 23:18:31 -070091 hwc.setCallback(&mCallback);
Lloyd Pique4603f3c2020-02-11 12:06:56 -080092
93 const auto& supported = hwc.getSupportedLayerGenericMetadata();
94 EXPECT_EQ(2u, supported.size());
95 EXPECT_EQ(1u, supported.count(kMetadata1Name));
96 EXPECT_EQ(kMetadata1Mandatory, supported.find(kMetadata1Name)->second);
97 EXPECT_EQ(1u, supported.count(kMetadata2Name));
98 EXPECT_EQ(kMetadata2Mandatory, supported.find(kMetadata2Name)->second);
99}
100
Dominik Laskowski0deb06e2021-04-16 23:18:31 -0700101TEST_F(HWComposerSetCallbackTest, handlesUnsupportedCallToGetLayerGenericMetadataKeys) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700102 EXPECT_CALL(*mHal, getCapabilities()).WillOnce(Return(std::vector<hal::Capability>{}));
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800103 EXPECT_CALL(*mHal, getLayerGenericMetadataKeys(_))
104 .WillOnce(Return(hardware::graphics::composer::V2_4::Error::UNSUPPORTED));
105 EXPECT_CALL(*mHal, registerCallback(_));
106 EXPECT_CALL(*mHal, isVsyncPeriodSwitchSupported()).WillOnce(Return(false));
107
108 impl::HWComposer hwc{std::unique_ptr<Hwc2::Composer>(mHal)};
Dominik Laskowski0deb06e2021-04-16 23:18:31 -0700109 hwc.setCallback(&mCallback);
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800110
111 const auto& supported = hwc.getSupportedLayerGenericMetadata();
112 EXPECT_EQ(0u, supported.size());
113}
114
115struct HWComposerLayerTest : public testing::Test {
Peiyong Line9d809e2020-04-14 13:10:48 -0700116 static constexpr hal::HWDisplayId kDisplayId = static_cast<hal::HWDisplayId>(1001);
117 static constexpr hal::HWLayerId kLayerId = static_cast<hal::HWLayerId>(1002);
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800118
Peiyong Line9d809e2020-04-14 13:10:48 -0700119 HWComposerLayerTest(const std::unordered_set<hal::Capability>& capabilities)
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800120 : mCapabilies(capabilities) {}
121
122 ~HWComposerLayerTest() override { EXPECT_CALL(*mHal, destroyLayer(kDisplayId, kLayerId)); }
123
124 std::unique_ptr<Hwc2::mock::Composer> mHal{new StrictMock<Hwc2::mock::Composer>()};
Peiyong Line9d809e2020-04-14 13:10:48 -0700125 const std::unordered_set<hal::Capability> mCapabilies;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800126 HWC2::impl::Layer mLayer{*mHal, mCapabilies, kDisplayId, kLayerId};
127};
128
129struct HWComposerLayerGenericMetadataTest : public HWComposerLayerTest {
130 static const std::string kLayerGenericMetadata1Name;
131 static constexpr bool kLayerGenericMetadata1Mandatory = false;
132 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
133 static const std::string kLayerGenericMetadata2Name;
134 static constexpr bool kLayerGenericMetadata2Mandatory = true;
135 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
136
137 HWComposerLayerGenericMetadataTest() : HWComposerLayerTest({}) {}
138};
139
140const std::string HWComposerLayerGenericMetadataTest::kLayerGenericMetadata1Name =
141 "com.example.metadata.1";
142
143const std::vector<uint8_t> HWComposerLayerGenericMetadataTest::kLayerGenericMetadata1Value = {1u,
144 2u,
145 3u};
146
147const std::string HWComposerLayerGenericMetadataTest::kLayerGenericMetadata2Name =
148 "com.example.metadata.2";
149
150const std::vector<uint8_t> HWComposerLayerGenericMetadataTest::kLayerGenericMetadata2Value = {45u,
151 67u};
152
153TEST_F(HWComposerLayerGenericMetadataTest, forwardsSupportedMetadata) {
154 EXPECT_CALL(*mHal,
155 setLayerGenericMetadata(kDisplayId, kLayerId, kLayerGenericMetadata1Name,
156 kLayerGenericMetadata1Mandatory,
157 kLayerGenericMetadata1Value))
158 .WillOnce(Return(hardware::graphics::composer::V2_4::Error::NONE));
159 auto result = mLayer.setLayerGenericMetadata(kLayerGenericMetadata1Name,
160 kLayerGenericMetadata1Mandatory,
161 kLayerGenericMetadata1Value);
Peiyong Line9d809e2020-04-14 13:10:48 -0700162 EXPECT_EQ(hal::Error::NONE, result);
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800163
164 EXPECT_CALL(*mHal,
165 setLayerGenericMetadata(kDisplayId, kLayerId, kLayerGenericMetadata2Name,
166 kLayerGenericMetadata2Mandatory,
167 kLayerGenericMetadata2Value))
168 .WillOnce(Return(hardware::graphics::composer::V2_4::Error::UNSUPPORTED));
169 result = mLayer.setLayerGenericMetadata(kLayerGenericMetadata2Name,
170 kLayerGenericMetadata2Mandatory,
171 kLayerGenericMetadata2Value);
Peiyong Line9d809e2020-04-14 13:10:48 -0700172 EXPECT_EQ(hal::Error::UNSUPPORTED, result);
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800173}
174
175} // namespace
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800176} // namespace android