~ubuntu-branches/ubuntu/utopic/mir/utopic-proposed

« back to all changes in this revision

Viewing changes to examples/render_overlays.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-03-10 19:28:46 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: package-import@ubuntu.com-20140310192846-rq9qm3ec26yrelo2
Tags: upstream-0.1.6+14.04.20140310
Import upstream version 0.1.6+14.04.20140310

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2012, 2014 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
 
17
 */
 
18
 
 
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"
 
27
 
 
28
#include "graphics_region_factory.h"
 
29
#include "patterns.h"
 
30
 
 
31
#include <csignal>
 
32
#include <iostream>
 
33
 
 
34
namespace mg=mir::graphics;
 
35
namespace ml=mir::logging;
 
36
namespace mo=mir::options;
 
37
namespace geom=mir::geometry;
 
38
 
 
39
namespace
 
40
{
 
41
volatile std::sig_atomic_t running = true;
 
42
 
 
43
void signal_handler(int /*signum*/)
 
44
{
 
45
    running = false;
 
46
}
 
47
}
 
48
 
 
49
class DemoRenderable : public mg::Renderable
 
50
{
 
51
public:
 
52
    DemoRenderable(std::shared_ptr<mg::Buffer> const& buffer, geom::Rectangle rect)
 
53
        : renderable_buffer(buffer),
 
54
          position(rect)
 
55
    {
 
56
    }
 
57
 
 
58
    std::shared_ptr<mg::Buffer> buffer() const
 
59
    {
 
60
        return renderable_buffer;
 
61
    }
 
62
 
 
63
    bool alpha_enabled() const
 
64
    {
 
65
        return false;
 
66
    }
 
67
 
 
68
    geom::Rectangle screen_position() const
 
69
    {
 
70
        return position;
 
71
    }
 
72
 
 
73
private:
 
74
    std::shared_ptr<mg::Buffer> const renderable_buffer;
 
75
    geom::Rectangle const position;
 
76
};
 
77
 
 
78
int main(int argc, char const** argv)
 
79
try
 
80
{
 
81
    mir::test::draw::DrawPatternSolid fill_with_green(0x00FF00FF);
 
82
    mir::test::draw::DrawPatternSolid fill_with_blue(0x0000FFFF);
 
83
 
 
84
    /* Set up graceful exit on SIGINT and SIGTERM */
 
85
    struct sigaction sa;
 
86
    sa.sa_handler = signal_handler;
 
87
    sa.sa_flags = 0;
 
88
    sigemptyset(&sa.sa_mask);
 
89
 
 
90
    sigaction(SIGINT, &sa, NULL);
 
91
    sigaction(SIGTERM, &sa, NULL);
 
92
 
 
93
    mir::DefaultServerConfiguration conf{argc, argv};
 
94
 
 
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();
 
99
 
 
100
     mg::BufferProperties buffer_properties{
 
101
        geom::Size{512, 512},
 
102
        mir_pixel_format_abgr_8888,
 
103
        mg::BufferUsage::hardware
 
104
    };
 
105
 
 
106
    auto buffer1 = buffer_allocator->alloc_buffer(buffer_properties);
 
107
    auto buffer2 = buffer_allocator->alloc_buffer(buffer_properties);
 
108
 
 
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()));
 
111
 
 
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
 
115
    {
 
116
        std::make_shared<DemoRenderable>(buffer2, screen_pos2),
 
117
        std::make_shared<DemoRenderable>(buffer1, screen_pos1)
 
118
    };
 
119
 
 
120
    while (running)
 
121
    {
 
122
        display->for_each_display_buffer([&](mg::DisplayBuffer& buffer)
 
123
        {
 
124
            buffer.make_current();
 
125
            auto render_fn = [](mg::Renderable const&) {};
 
126
            buffer.render_and_post_update(renderlist, render_fn);
 
127
        });
 
128
    }
 
129
   return 0;
 
130
}
 
131
catch (...)
 
132
{
 
133
    mir::report_exception(std::cerr);
 
134
    return 1;
 
135
}