2
* Copyright © 2012, 2014 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: Kevin DuBois <kevin.dubois@canonical.com>
19
#include "mir/default_server_configuration.h"
20
#include "mir/graphics/display.h"
21
#include "mir/graphics/renderable.h"
22
#include "mir/graphics/display_buffer.h"
23
#include "mir/graphics/platform.h"
24
#include "mir/graphics/graphic_buffer_allocator.h"
25
#include "mir/graphics/buffer_properties.h"
26
#include "mir/report_exception.h"
28
#include "graphics_region_factory.h"
34
namespace mg=mir::graphics;
35
namespace ml=mir::logging;
36
namespace mo=mir::options;
37
namespace geom=mir::geometry;
41
volatile std::sig_atomic_t running = true;
43
void signal_handler(int /*signum*/)
49
class DemoRenderable : public mg::Renderable
52
DemoRenderable(std::shared_ptr<mg::Buffer> const& buffer, geom::Rectangle rect)
53
: renderable_buffer(buffer),
58
std::shared_ptr<mg::Buffer> buffer() const
60
return renderable_buffer;
63
bool alpha_enabled() const
68
geom::Rectangle screen_position() const
74
std::shared_ptr<mg::Buffer> const renderable_buffer;
75
geom::Rectangle const position;
78
int main(int argc, char const** argv)
81
mir::test::draw::DrawPatternSolid fill_with_green(0x00FF00FF);
82
mir::test::draw::DrawPatternSolid fill_with_blue(0x0000FFFF);
84
/* Set up graceful exit on SIGINT and SIGTERM */
86
sa.sa_handler = signal_handler;
88
sigemptyset(&sa.sa_mask);
90
sigaction(SIGINT, &sa, NULL);
91
sigaction(SIGTERM, &sa, NULL);
93
mir::DefaultServerConfiguration conf{argc, argv};
95
auto platform = conf.the_graphics_platform();
96
auto display = platform->create_display(conf.the_display_configuration_policy());
97
auto buffer_allocator = platform->create_buffer_allocator(conf.the_buffer_initializer());
98
auto region_factory = mir::test::draw::create_graphics_region_factory();
100
mg::BufferProperties buffer_properties{
101
geom::Size{512, 512},
102
mir_pixel_format_abgr_8888,
103
mg::BufferUsage::hardware
106
auto buffer1 = buffer_allocator->alloc_buffer(buffer_properties);
107
auto buffer2 = buffer_allocator->alloc_buffer(buffer_properties);
109
fill_with_green.draw(*region_factory->graphic_region_from_handle(*buffer1->native_buffer_handle()));
110
fill_with_blue.draw(*region_factory->graphic_region_from_handle(*buffer2->native_buffer_handle()));
112
geom::Rectangle screen_pos1{{0,0} , {512, 512}};
113
geom::Rectangle screen_pos2{{80,80} , {592,592}};
114
std::list<std::shared_ptr<mg::Renderable>> renderlist
116
std::make_shared<DemoRenderable>(buffer2, screen_pos2),
117
std::make_shared<DemoRenderable>(buffer1, screen_pos1)
122
display->for_each_display_buffer([&](mg::DisplayBuffer& buffer)
124
buffer.make_current();
125
auto render_fn = [](mg::Renderable const&) {};
126
buffer.render_and_post_update(renderlist, render_fn);
133
mir::report_exception(std::cerr);