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

« back to all changes in this revision

Viewing changes to src/server/compositor/screencast_display_buffer.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 © 2014 Canonical Ltd.
 
3
 *
 
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.
 
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: Alexandros Frantzis <alexandros.frantzis@canonical.com>
 
17
 */
 
18
 
 
19
#include "screencast_display_buffer.h"
 
20
#include "mir/graphics/buffer.h"
 
21
 
 
22
#include <boost/throw_exception.hpp>
 
23
 
 
24
namespace mc = mir::compositor;
 
25
namespace mg = mir::graphics;
 
26
namespace geom = mir::geometry;
 
27
 
 
28
mc::ScreencastDisplayBuffer::ScreencastDisplayBuffer(
 
29
    geom::Rectangle const& rect,
 
30
    mg::Buffer& buffer)
 
31
    : rect(rect), buffer(buffer), old_fbo(), old_viewport()
 
32
{
 
33
    glGetIntegerv(GL_VIEWPORT, old_viewport);
 
34
    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo);
 
35
 
 
36
    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
 
37
 
 
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);
 
44
 
 
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);
 
52
 
 
53
    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
 
54
        BOOST_THROW_EXCEPTION(std::runtime_error("Failed to create FBO for buffer"));
 
55
}
 
56
 
 
57
mc::ScreencastDisplayBuffer::~ScreencastDisplayBuffer()
 
58
{
 
59
    release_current();
 
60
}
 
61
 
 
62
geom::Rectangle mc::ScreencastDisplayBuffer::view_area() const
 
63
{
 
64
    return rect;
 
65
}
 
66
 
 
67
void mc::ScreencastDisplayBuffer::make_current()
 
68
{
 
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);
 
73
 
 
74
    auto const buf_size = buffer.size();
 
75
 
 
76
    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
 
77
    glViewport(0, 0, buf_size.width.as_uint32_t(), buf_size.height.as_uint32_t());
 
78
}
 
79
 
 
80
void mc::ScreencastDisplayBuffer::release_current()
 
81
{
 
82
    glBindFramebuffer(GL_FRAMEBUFFER, old_fbo);
 
83
    glViewport(old_viewport[0], old_viewport[1],
 
84
               old_viewport[2], old_viewport[3]);
 
85
}
 
86
 
 
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)
 
90
{
 
91
    for (auto const& renderable : renderables)
 
92
        render(*renderable);
 
93
 
 
94
    post_update();
 
95
}
 
96
 
 
97
void mc::ScreencastDisplayBuffer::post_update()
 
98
{
 
99
    glFinish();
 
100
}
 
101
 
 
102
bool mc::ScreencastDisplayBuffer::can_bypass() const
 
103
{
 
104
    return false;
 
105
}
 
106
 
 
107
MirOrientation mc::ScreencastDisplayBuffer::orientation() const
 
108
{
 
109
    return mir_orientation_normal;
 
110
}