2
* Copyright © 2014 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3,
6
* as 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 "screencast_display_buffer.h"
20
#include "mir/graphics/buffer.h"
22
#include <boost/throw_exception.hpp>
24
namespace mc = mir::compositor;
25
namespace mg = mir::graphics;
26
namespace geom = mir::geometry;
28
mc::ScreencastDisplayBuffer::ScreencastDisplayBuffer(
29
geom::Rectangle const& rect,
31
: rect(rect), buffer(buffer), old_fbo(), old_viewport()
33
glGetIntegerv(GL_VIEWPORT, old_viewport);
34
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo);
36
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
38
/* Set up the color buffer... */
39
glBindTexture(GL_TEXTURE_2D, color_tex);
40
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
41
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
42
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
43
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
45
/* and the depth buffer */
46
glBindRenderbuffer(GL_RENDERBUFFER, depth_rbo);
47
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16,
48
rect.size.width.as_uint32_t(),
49
rect.size.height.as_uint32_t());
50
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
51
GL_RENDERBUFFER, depth_rbo);
53
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
54
BOOST_THROW_EXCEPTION(std::runtime_error("Failed to create FBO for buffer"));
57
mc::ScreencastDisplayBuffer::~ScreencastDisplayBuffer()
62
geom::Rectangle mc::ScreencastDisplayBuffer::view_area() const
67
void mc::ScreencastDisplayBuffer::make_current()
69
glBindTexture(GL_TEXTURE_2D, color_tex);
70
buffer.bind_to_texture();
71
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
72
GL_TEXTURE_2D, color_tex, 0);
74
auto const buf_size = buffer.size();
76
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
77
glViewport(0, 0, buf_size.width.as_uint32_t(), buf_size.height.as_uint32_t());
80
void mc::ScreencastDisplayBuffer::release_current()
82
glBindFramebuffer(GL_FRAMEBUFFER, old_fbo);
83
glViewport(old_viewport[0], old_viewport[1],
84
old_viewport[2], old_viewport[3]);
87
void mc::ScreencastDisplayBuffer::render_and_post_update(
88
std::list<std::shared_ptr<mg::Renderable>> const& renderables,
89
std::function<void(mg::Renderable const&)> const& render)
91
for (auto const& renderable : renderables)
97
void mc::ScreencastDisplayBuffer::post_update()
102
bool mc::ScreencastDisplayBuffer::can_bypass() const
107
MirOrientation mc::ScreencastDisplayBuffer::orientation() const
109
return mir_orientation_normal;