1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*
* Copyright © 2012 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Alan Griffiths <alan@octopull.co.uk>
* Daniel van Vugt <daniel.van.vugt@canonical.com>
*/
#include "default_display_buffer_compositor.h"
#include "mir/compositor/scene.h"
#include "mir/compositor/scene_element.h"
#include "mir/compositor/renderer.h"
#include "mir/graphics/renderable.h"
#include "mir/graphics/display_buffer.h"
#include "mir/graphics/buffer.h"
#include "mir/compositor/buffer_stream.h"
#include "occlusion.h"
#include <mutex>
#include <cstdlib>
#include <algorithm>
namespace mc = mir::compositor;
namespace mg = mir::graphics;
mc::DefaultDisplayBufferCompositor::DefaultDisplayBufferCompositor(
mg::DisplayBuffer& display_buffer,
std::shared_ptr<mc::Renderer> const& renderer,
std::shared_ptr<mc::CompositorReport> const& report) :
display_buffer{display_buffer},
renderer{renderer},
report{report}
{
}
void mc::DefaultDisplayBufferCompositor::composite(mc::SceneElementSequence&& scene_elements)
{
report->began_frame(this);
auto const& view_area = display_buffer.view_area();
auto const& occlusions = mc::filter_occlusions_from(scene_elements, view_area);
for (auto const& element : occlusions)
{
if (element->renderable()->visible())
element->occluded();
}
mg::RenderableList renderable_list;
for (auto const& element : scene_elements)
{
element->rendered();
renderable_list.push_back(element->renderable());
}
/*
* Note: Buffer lifetimes are ensured by the two objects holding
* references to them; scene_elements and renderable_list.
* So no buffer is going to be released back to the client till
* both of those containers get destroyed (end of the function).
* Actually, there's a third reference held by the texture cache
* in GLRenderer, but that gets released earlier in render().
*/
scene_elements.clear(); // Those in use are still in renderable_list
if (display_buffer.post_renderables_if_optimizable(renderable_list))
{
renderer->suspend();
report->finished_frame(true, this);
}
else
{
display_buffer.make_current();
renderer->set_rotation(display_buffer.orientation());
renderer->render(renderable_list);
display_buffer.gl_swap_buffers();
report->finished_frame(false, this);
// Release the buffers we did use back to the clients, before starting
// on the potentially slow flip().
// FIXME: This clear() call is blocking a little (LP: #1395421)
renderable_list.clear();
display_buffer.flip();
}
}
|