2
* Copyright © 2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
19
#include "mir/shell/graphics_display_layout.h"
21
#include "mir_test_doubles/null_display.h"
22
#include "mir_test_doubles/stub_display_buffer.h"
27
#include <gtest/gtest.h>
29
namespace msh = mir::shell;
30
namespace mg = mir::graphics;
31
namespace mtd = mir::test::doubles;
32
namespace geom = mir::geometry;
37
class StubDisplay : public mtd::NullDisplay
42
mtd::StubDisplayBuffer{geom::Rectangle{geom::Point{0,0}, geom::Size{800,600}}},
43
mtd::StubDisplayBuffer{geom::Rectangle{geom::Point{0,600}, geom::Size{100,100}}},
44
mtd::StubDisplayBuffer{geom::Rectangle{geom::Point{800,0}, geom::Size{100,100}}}}
49
void for_each_display_buffer(std::function<void(mg::DisplayBuffer&)> const& f) override
51
for (auto& db : display_buffers)
56
std::vector<mtd::StubDisplayBuffer> display_buffers;
61
TEST(GraphicsDisplayLayoutTest, clips_correctly)
63
auto stub_display = std::make_shared<StubDisplay>();
65
msh::GraphicsDisplayLayout display_layout{stub_display};
67
std::vector<std::tuple<geom::Rectangle,geom::Rectangle>> rect_tuples{
69
geom::Rectangle{geom::Point{0,0}, geom::Size{800,600}},
70
geom::Rectangle{geom::Point{0,0}, geom::Size{800,600}}),
72
geom::Rectangle{geom::Point{750,50}, geom::Size{100,100}},
73
geom::Rectangle{geom::Point{750,50}, geom::Size{50,100}}),
75
geom::Rectangle{geom::Point{899,99}, geom::Size{100,100}},
76
geom::Rectangle{geom::Point{899,99}, geom::Size{1,1}}),
78
geom::Rectangle{geom::Point{-1,-1}, geom::Size{100,100}},
79
geom::Rectangle{geom::Point{-1,-1}, geom::Size{0,0}})
82
for (auto const& t : rect_tuples)
84
auto clipped_rect = std::get<0>(t);
85
auto const expected_rect = std::get<1>(t);
86
display_layout.clip_to_output(clipped_rect);
87
EXPECT_EQ(expected_rect, clipped_rect);
91
TEST(GraphicsDisplayLayoutTest, makes_fullscreen_in_correct_screen)
93
auto stub_display = std::make_shared<StubDisplay>();
95
msh::GraphicsDisplayLayout display_layout{stub_display};
97
std::vector<std::tuple<geom::Rectangle,geom::Rectangle>> rect_tuples{
99
geom::Rectangle{geom::Point{0,0}, geom::Size{800,600}},
100
geom::Rectangle{geom::Point{0,0}, geom::Size{800,600}}),
102
geom::Rectangle{geom::Point{750,50}, geom::Size{150,130}},
103
geom::Rectangle{geom::Point{0,0}, geom::Size{800,600}}),
105
geom::Rectangle{geom::Point{899,99}, geom::Size{30,40}},
106
geom::Rectangle{geom::Point{800,0}, geom::Size{100,100}}),
108
geom::Rectangle{geom::Point{-1,-1}, geom::Size{100,100}},
109
geom::Rectangle{geom::Point{0,0}, geom::Size{0,0}})
112
for (auto const& t : rect_tuples)
114
auto fullscreen_rect = std::get<0>(t);
115
auto const expected_rect = std::get<1>(t);
116
display_layout.size_to_output(fullscreen_rect);
117
EXPECT_EQ(expected_rect, fullscreen_rect);