19
19
#include "mir/graphics/android/sync_fence.h"
20
#include "src/platform/graphics/android/hwc_fb_device.h"
21
#include "src/platform/graphics/android/hwc_device.h"
22
#include "src/platform/graphics/android/hwc_wrapper.h"
23
#include "src/platform/graphics/android/hwc_layerlist.h"
24
#include "src/platform/graphics/android/hwc_vsync_coordinator.h"
20
#include "src/platforms/android/hwc_fb_device.h"
21
#include "src/platforms/android/hwc_device.h"
22
#include "src/platforms/android/hwc_wrapper.h"
23
#include "src/platforms/android/hwc_layerlist.h"
24
#include "src/platforms/android/hwc_vsync_coordinator.h"
25
#include "src/platforms/android/hwc_configuration.h"
25
26
#include "mir_test_doubles/mock_hwc_composer_device_1.h"
26
27
#include "mir_test_doubles/mock_hwc_vsync_coordinator.h"
27
28
#include "mir_test_doubles/mock_hwc_device_wrapper.h"
40
41
namespace mtd=mir::test::doubles;
41
42
namespace geom=mir::geometry;
44
std::shared_ptr<mga::HWCCommonDevice> make_hwc_device(
45
std::shared_ptr<mga::HwcWrapper> const& hwc_device,
46
std::shared_ptr<framebuffer_device_t> const& fb_device,
47
std::shared_ptr<mga::HWCVsyncCoordinator> const& coordinator);
50
std::shared_ptr<mga::HWCCommonDevice> make_hwc_device<mga::HwcFbDevice>(
51
std::shared_ptr<mga::HwcWrapper> const& hwc_device,
52
std::shared_ptr<framebuffer_device_t> const& fb_device,
53
std::shared_ptr<mga::HWCVsyncCoordinator> const& coordinator)
55
return std::make_shared<mga::HwcFbDevice>(hwc_device, fb_device, coordinator);
59
std::shared_ptr<mga::HWCCommonDevice> make_hwc_device<mga::HwcDevice>(
60
std::shared_ptr<mga::HwcWrapper> const& hwc_device,
61
std::shared_ptr<framebuffer_device_t> const&,
62
std::shared_ptr<mga::HWCVsyncCoordinator> const& coordinator)
64
auto file_ops = std::make_shared<mga::RealSyncFileOps>();
65
return std::make_shared<mga::HwcDevice>(hwc_device, coordinator, file_ops);
46
struct MockDisplayConfiguration : mga::HwcConfiguration
48
MOCK_METHOD2(power_mode, void(mga::DisplayName, MirPowerMode));
49
MOCK_METHOD1(active_attribs_for, mga::DisplayAttribs(mga::DisplayName));
68
53
template<typename T>
72
57
virtual void SetUp()
74
using namespace testing;
76
59
mock_fbdev = std::make_shared<mtd::MockFBHalDevice>();
77
60
mock_device = std::make_shared<testing::NiceMock<mtd::MockHWCDeviceWrapper>>();
78
61
mock_vsync = std::make_shared<testing::NiceMock<mtd::MockVsyncCoordinator>>();
62
mock_config = std::make_shared<testing::NiceMock<MockDisplayConfiguration>>();
65
std::shared_ptr<mga::DisplayDevice> make_display_device();
81
67
testing::NiceMock<mtd::MockEGL> mock_egl;
82
68
std::shared_ptr<mtd::MockVsyncCoordinator> mock_vsync;
83
69
std::shared_ptr<mtd::MockHWCDeviceWrapper> mock_device;
84
70
std::shared_ptr<mtd::MockFBHalDevice> mock_fbdev;
71
std::shared_ptr<MockDisplayConfiguration> mock_config;
75
std::shared_ptr<mga::DisplayDevice> HWCCommon<mga::HwcFbDevice>::make_display_device()
77
return std::make_shared<mga::HwcFbDevice>(mock_device, mock_fbdev, mock_config, mock_vsync);
81
std::shared_ptr<mga::DisplayDevice> HWCCommon<mga::HwcDevice>::make_display_device()
83
return std::make_shared<mga::HwcDevice>(mock_device, mock_config, mock_vsync, std::make_shared<mga::IntegerSourceCrop>());
87
86
typedef ::testing::Types<mga::HwcFbDevice, mga::HwcDevice> HWCDeviceTestTypes;
88
87
TYPED_TEST_CASE(HWCCommon, HWCDeviceTestTypes);
96
95
.WillOnce(SaveArg<0>(&callbacks));
98
auto device = make_hwc_device<TypeParam>(this->mock_device, this->mock_fbdev, this->mock_vsync);
97
auto device = this->make_display_device();
100
99
ASSERT_THAT(callbacks, Ne(nullptr));
101
100
EXPECT_THAT(callbacks->hooks.invalidate, Ne(nullptr));
112
111
.WillOnce(SaveArg<0>(&callbacks));
114
auto device = make_hwc_device<TypeParam>(this->mock_device, this->mock_fbdev, this->mock_vsync);
113
auto device = this->make_display_device();
116
115
ASSERT_THAT(callbacks, Ne(nullptr));
117
116
EXPECT_THAT(callbacks->self, Eq(device.get()));
119
118
EXPECT_THAT(callbacks->self, Eq(nullptr));
122
TYPED_TEST(HWCCommon, registerst_hooks_and_turns_on_display)
121
TYPED_TEST(HWCCommon, registers_hooks_before_turning_on_display)
124
123
using namespace testing;
127
126
EXPECT_CALL(*this->mock_device, register_hooks(_))
128
127
.InSequence(seq);
129
EXPECT_CALL(*this->mock_device, display_on())
131
EXPECT_CALL(*this->mock_device, vsync_signal_on())
134
auto device = make_hwc_device<TypeParam>(this->mock_device, this->mock_fbdev, this->mock_vsync);
135
testing::Mock::VerifyAndClearExpectations(this->mock_device.get());
138
TYPED_TEST(HWCCommon, test_hwc_suspend_standby_throw)
140
using namespace testing;
141
auto device = make_hwc_device<TypeParam>(this->mock_device, this->mock_fbdev, this->mock_vsync);
144
device->mode(mir_power_mode_suspend);
145
}, std::runtime_error);
147
device->mode(mir_power_mode_standby);
148
}, std::runtime_error);
151
TYPED_TEST(HWCCommon, test_hwc_deactivates_vsync_on_blank)
153
using namespace testing;
156
EXPECT_CALL(*this->mock_device, display_on())
158
EXPECT_CALL(*this->mock_device, vsync_signal_on())
160
EXPECT_CALL(*this->mock_device, vsync_signal_off())
162
EXPECT_CALL(*this->mock_device, display_off())
165
auto device = make_hwc_device<TypeParam>(this->mock_device, this->mock_fbdev, this->mock_vsync);
166
device->mode(mir_power_mode_off);
128
EXPECT_CALL(*this->mock_config, power_mode(mga::DisplayName::primary, mir_power_mode_on))
131
auto device = this->make_display_device();
132
testing::Mock::VerifyAndClearExpectations(this->mock_config.get());
169
135
TYPED_TEST(HWCCommon, test_hwc_display_is_deactivated_on_destroy)
171
auto device = make_hwc_device<TypeParam>(this->mock_device, this->mock_fbdev, this->mock_vsync);
173
testing::InSequence seq;
174
EXPECT_CALL(*this->mock_device, vsync_signal_off())
176
EXPECT_CALL(*this->mock_device, display_off())
137
auto device = this->make_display_device();
138
EXPECT_CALL(*this->mock_config, power_mode(mga::DisplayName::primary, mir_power_mode_off));
181
142
TYPED_TEST(HWCCommon, catches_exception_during_destruction)
183
auto device = make_hwc_device<TypeParam>(this->mock_device, this->mock_fbdev, this->mock_vsync);
184
EXPECT_CALL(*this->mock_device, display_off())
144
auto device = this->make_display_device();
145
EXPECT_CALL(*this->mock_config, power_mode(mga::DisplayName::primary, mir_power_mode_off))
185
146
.WillOnce(testing::Throw(std::runtime_error("")));
205
166
callbacks->hooks.vsync(&callbacks->hooks, 0, 0);
208
TYPED_TEST(HWCCommon, set_orientation)
210
auto device = make_hwc_device<TypeParam>(this->mock_device, this->mock_fbdev, this->mock_vsync);
211
EXPECT_FALSE(device->apply_orientation(mir_orientation_left));
214
TYPED_TEST(HWCCommon, first_unblank_failure_is_not_fatal) //lp:1345533
216
ON_CALL(*this->mock_device, display_on())
217
.WillByDefault(testing::Throw(std::runtime_error("error")));
219
auto device = make_hwc_device<TypeParam>(this->mock_device, this->mock_fbdev, this->mock_vsync);
223
TYPED_TEST(HWCCommon, first_vsync_failure_is_not_fatal) //lp:1345533
225
ON_CALL(*this->mock_device, vsync_signal_on())
226
.WillByDefault(testing::Throw(std::runtime_error("error")));
228
auto device = make_hwc_device<TypeParam>(this->mock_device, this->mock_fbdev, this->mock_vsync);
169
TYPED_TEST(HWCCommon, first_power_on_is_not_fatal) //lp:1345533
171
ON_CALL(*this->mock_config, power_mode(testing::_, mir_power_mode_on))
172
.WillByDefault(testing::Throw(std::runtime_error("error")));
174
auto device = this->make_display_device();