~robertcarr/mir/client-focus-notifications

« back to all changes in this revision

Viewing changes to tests/unit-tests/graphics/android/test_android_fb.cpp

  • Committer: Robert Carr
  • Date: 2013-08-01 22:01:20 UTC
  • mfrom: (706.2.208 trunk)
  • Revision ID: robert.carr@canonical.com-20130801220120-6m230b3g6x0xflzd
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
 
19
19
#include "mir/graphics/display_buffer.h"
 
20
#include "mir/graphics/display_configuration.h"
20
21
#include "src/server/graphics/android/android_display.h"
21
22
#include "src/server/graphics/android/gpu_android_display_buffer_factory.h"
22
23
#include "src/server/graphics/android/hwc_android_display_buffer_factory.h"
36
37
namespace mg=mir::graphics;
37
38
namespace mga=mir::graphics::android;
38
39
namespace mtd=mir::test::doubles;
 
40
namespace geom=mir::geometry;
39
41
 
40
42
struct DummyGPUDisplayType {};
41
43
struct DummyHWCDisplayType {};
42
44
 
43
 
template<class T>
44
 
std::shared_ptr<mg::Display> make_display(
45
 
   std::shared_ptr<mtd::MockAndroidFramebufferWindow> const& fbwin,
46
 
   std::shared_ptr<mg::DisplayReport> const& listener);
47
 
 
48
 
template <>
49
 
std::shared_ptr<mg::Display> make_display<DummyGPUDisplayType>(
50
 
    std::shared_ptr<mtd::MockAndroidFramebufferWindow> const& fbwin,
51
 
    std::shared_ptr<mg::DisplayReport> const& listener)
52
 
{
53
 
    auto db_factory = std::make_shared<mga::GPUAndroidDisplayBufferFactory>();
54
 
    return std::make_shared<mga::AndroidDisplay>(fbwin, db_factory, listener);
55
 
}
56
 
 
57
 
template <>
58
 
std::shared_ptr<mg::Display> make_display<DummyHWCDisplayType>(
59
 
    std::shared_ptr<mtd::MockAndroidFramebufferWindow> const& fbwin,
60
 
    std::shared_ptr<mg::DisplayReport> const& listener)
61
 
{
62
 
    auto mock_hwc_device = std::make_shared<mtd::MockHWCInterface>();
63
 
    auto db_factory = std::make_shared<mga::HWCAndroidDisplayBufferFactory>(mock_hwc_device);
64
 
    return std::make_shared<mga::AndroidDisplay>(fbwin, db_factory, listener);
65
 
}
 
45
static geom::Size const display_size{433,232};
66
46
 
67
47
template<typename T>
68
48
class AndroidTestFramebufferInit : public ::testing::Test
82
62
        EXPECT_CALL(*native_win, android_display_egl_config(_))
83
63
        .Times(AtLeast(0));
84
64
 
85
 
        width = 435;
86
 
        height = 477;
 
65
        ON_CALL(mock_egl, eglQuerySurface(_,_,EGL_WIDTH,_))
 
66
            .WillByDefault(DoAll(
 
67
                SetArgPointee<3>(display_size.width.as_uint32_t()),
 
68
                Return(EGL_TRUE)));
 
69
        ON_CALL(mock_egl, eglQuerySurface(_,_,EGL_HEIGHT,_))
 
70
            .WillByDefault(DoAll(
 
71
                SetArgPointee<3>(display_size.height.as_uint32_t()),
 
72
                Return(EGL_TRUE)));
 
73
 
87
74
 
88
75
        mock_display_report = std::make_shared<NiceMock<mtd::MockDisplayReport>>();
89
76
    }
91
78
    std::shared_ptr<mtd::MockDisplayReport> mock_display_report;
92
79
    std::shared_ptr<mtd::MockAndroidFramebufferWindow> native_win;
93
80
    mtd::MockEGL mock_egl;
94
 
    int width, height;
95
81
};
96
82
 
 
83
template<class T>
 
84
std::shared_ptr<mg::Display> make_display(
 
85
   std::shared_ptr<mtd::MockAndroidFramebufferWindow> const& fbwin,
 
86
   std::shared_ptr<mg::DisplayReport> const& listener);
 
87
 
 
88
template <>
 
89
std::shared_ptr<mg::Display> make_display<DummyGPUDisplayType>(
 
90
    std::shared_ptr<mtd::MockAndroidFramebufferWindow> const& fbwin,
 
91
    std::shared_ptr<mg::DisplayReport> const& listener)
 
92
{
 
93
    auto db_factory = std::make_shared<mga::GPUAndroidDisplayBufferFactory>();
 
94
    return std::make_shared<mga::AndroidDisplay>(fbwin, db_factory, listener);
 
95
}
 
96
 
 
97
template <>
 
98
std::shared_ptr<mg::Display> make_display<DummyHWCDisplayType>(
 
99
    std::shared_ptr<mtd::MockAndroidFramebufferWindow> const& fbwin,
 
100
    std::shared_ptr<mg::DisplayReport> const& listener)
 
101
{
 
102
    auto mock_hwc_device = std::make_shared<mtd::MockHWCInterface>();
 
103
    ON_CALL(*mock_hwc_device, display_size())
 
104
        .WillByDefault(testing::Return(display_size)); 
 
105
    auto db_factory = std::make_shared<mga::HWCAndroidDisplayBufferFactory>(mock_hwc_device);
 
106
    return std::make_shared<mga::AndroidDisplay>(fbwin, db_factory, listener);
 
107
}
 
108
 
 
109
 
97
110
typedef ::testing::Types<DummyGPUDisplayType, DummyHWCDisplayType> FramebufferTestTypes;
98
111
TYPED_TEST_CASE(AndroidTestFramebufferInit, FramebufferTestTypes);
99
112
 
115
128
    .Times(Exactly(1))
116
129
    .WillOnce(Return((EGLDisplay)EGL_NO_DISPLAY));
117
130
 
118
 
    EXPECT_THROW(
119
 
    {
 
131
    EXPECT_THROW({
120
132
        auto display = make_display<TypeParam>(this->native_win, this->mock_display_report);
121
133
    }, std::runtime_error   );
122
134
}
590
602
        auto display = make_display<TypeParam>(this->native_win, this->mock_display_report);
591
603
    }, std::runtime_error);
592
604
}
 
605
 
 
606
//we only have single display and single mode on android for the time being
 
607
TYPED_TEST(AndroidTestFramebufferInit, android_display_configuration_info)
 
608
{
 
609
    auto display = make_display<TypeParam>(this->native_win, this->mock_display_report);
 
610
    auto config = display->configuration();
 
611
 
 
612
    std::vector<mg::DisplayConfigurationOutput> configurations;
 
613
    config->for_each_output([&](mg::DisplayConfigurationOutput const& config)
 
614
    {
 
615
        configurations.push_back(config);
 
616
    });
 
617
 
 
618
    ASSERT_EQ(1u, configurations.size());
 
619
    auto& disp_conf = configurations[0];
 
620
    ASSERT_EQ(1u, disp_conf.modes.size());
 
621
    auto& disp_mode = disp_conf.modes[0];
 
622
    EXPECT_EQ(display_size, disp_mode.size);
 
623
    //TODO fill refresh rate accordingly
 
624
 
 
625
    EXPECT_EQ(mg::DisplayConfigurationOutputId{0}, disp_conf.id); 
 
626
    EXPECT_EQ(mg::DisplayConfigurationCardId{0}, disp_conf.card_id); 
 
627
    EXPECT_TRUE(disp_conf.connected);
 
628
    EXPECT_TRUE(disp_conf.used);
 
629
    auto origin = geom::Point{0,0}; 
 
630
    EXPECT_EQ(origin, disp_conf.top_left);
 
631
    EXPECT_EQ(0, disp_conf.current_mode_index);
 
632
    //TODO fill physical_size_mm fields accordingly;
 
633
}
 
634
 
 
635
//Cannot configure android displays at this time
 
636
TYPED_TEST(AndroidTestFramebufferInit, android_display_configure_output)
 
637
{
 
638
    auto display = make_display<TypeParam>(this->native_win, this->mock_display_report);
 
639
    auto config = display->configuration();
 
640
 
 
641
    mg::DisplayConfigurationOutputId id{0};
 
642
    EXPECT_THROW({
 
643
        config->configure_output(id, true, geom::Point{0,0}, 0);
 
644
    }, std::runtime_error);
 
645
}