~ubuntu-branches/ubuntu/vivid/mir/vivid

« back to all changes in this revision

Viewing changes to examples/demo-shell/demo_compositor.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-10-10 14:01:26 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20141010140126-n1czko8na1kuz4ll
Tags: upstream-0.8.0+14.10.20141010
Import upstream version 0.8.0+14.10.20141010

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 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/graphics/display_buffer.h"
20
 
#include "mir/compositor/compositor_report.h"
21
 
#include "mir/compositor/scene.h"
22
 
#include "mir/compositor/scene_element.h"
23
 
#include "mir/compositor/destination_alpha.h"
24
 
#include "demo_compositor.h"
25
 
 
26
 
namespace me = mir::examples;
27
 
namespace mg = mir::graphics;
28
 
namespace mc = mir::compositor;
29
 
namespace geom = mir::geometry;
30
 
 
31
 
namespace
32
 
{
33
 
mc::DestinationAlpha destination_alpha(mg::DisplayBuffer const& db)
34
 
{
35
 
    return db.uses_alpha() ? mc::DestinationAlpha::generate_from_source : mc::DestinationAlpha::opaque;
36
 
}
37
 
}
38
 
 
39
 
me::DemoCompositor::DemoCompositor(
40
 
    mg::DisplayBuffer& display_buffer,
41
 
    std::shared_ptr<mc::Scene> const& scene,
42
 
    mg::GLProgramFactory const& factory,
43
 
    std::shared_ptr<mc::CompositorReport> const& report) :
44
 
    display_buffer(display_buffer),
45
 
    scene(scene),
46
 
    report(report),
47
 
    renderer(
48
 
        factory,
49
 
        display_buffer.view_area(),
50
 
        destination_alpha(display_buffer),
51
 
        30.0f, //titlebar_height
52
 
        80.0f) //shadow_radius
53
 
{
54
 
    scene->register_compositor(this);
55
 
}
56
 
 
57
 
me::DemoCompositor::~DemoCompositor()
58
 
{
59
 
    scene->unregister_compositor(this);
60
 
}
61
 
 
62
 
void me::DemoCompositor::composite()
63
 
{
64
 
    report->began_frame(this);
65
 
    //a simple filtering out of renderables that shouldn't be drawn
66
 
    //the elements should be notified if they are rendered or not
67
 
    bool nonrenderlist_elements{false};
68
 
    mg::RenderableList renderable_list;
69
 
    auto elements = scene->scene_elements_for(this);
70
 
    for(auto const& it : elements)
71
 
    {
72
 
        auto const& renderable = it->renderable();
73
 
        auto const& view_area = display_buffer.view_area();
74
 
        auto embellished = renderer.would_embellish(*renderable, view_area);
75
 
        auto any_part_drawn = (view_area.overlaps(renderable->screen_position()) || embellished);
76
 
        if (renderable->visible() && any_part_drawn)
77
 
        {
78
 
            renderable_list.push_back(renderable);
79
 
            it->rendered_in(this);
80
 
        }
81
 
        else
82
 
        {
83
 
            it->occluded_in(this);
84
 
        }
85
 
        nonrenderlist_elements |= embellished;
86
 
    }
87
 
 
88
 
    if (!nonrenderlist_elements &&
89
 
        display_buffer.post_renderables_if_optimizable(renderable_list))
90
 
    {
91
 
        renderer.suspend();
92
 
        report->finished_frame(true, this);
93
 
    }
94
 
    else
95
 
    {
96
 
        display_buffer.make_current();
97
 
 
98
 
        renderer.set_rotation(display_buffer.orientation());
99
 
        renderer.begin();
100
 
        renderer.render(renderable_list);
101
 
        display_buffer.post_update();
102
 
        renderer.end();
103
 
        report->finished_frame(false, this);
104
 
    }
105
 
}