~hikiko/mir/mir.unity8-desktop-session

« back to all changes in this revision

Viewing changes to src/platform/graphics/mesa/shm_buffer.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Daniel van Vugt, Ubuntu daily release
  • Date: 2014-01-08 02:04:38 UTC
  • mfrom: (1.1.54)
  • Revision ID: package-import@ubuntu.com-20140108020438-ikbu7qqm9v2l026y
Tags: 0.1.3+14.04.20140108-0ubuntu1
[ Daniel van Vugt ]
* Preparing for release 0.1.3

[ Ubuntu daily release ]
* Automatic snapshot from revision 1170

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2013 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser 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 Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by:
 
17
 *   Alexandros Frantzis <alexandros.frantzis@canonical.com>
 
18
 */
 
19
 
 
20
#include "shm_file.h"
 
21
#include "shm_buffer.h"
 
22
#include "buffer_texture_binder.h"
 
23
#include <GLES2/gl2.h>
 
24
#include <GLES2/gl2ext.h>
 
25
 
 
26
namespace mgm = mir::graphics::mesa;
 
27
namespace geom = mir::geometry;
 
28
 
 
29
mgm::ShmBuffer::ShmBuffer(
 
30
    std::shared_ptr<ShmFile> const& shm_file,
 
31
    geom::Size const& size,
 
32
    MirPixelFormat const& pixel_format)
 
33
    : shm_file{shm_file},
 
34
      size_{size},
 
35
      pixel_format_{pixel_format},
 
36
      stride_{MIR_BYTES_PER_PIXEL(pixel_format_) * size_.width.as_uint32_t()},
 
37
      pixels{shm_file->base_ptr()}
 
38
{
 
39
}
 
40
 
 
41
mgm::ShmBuffer::~ShmBuffer() noexcept
 
42
{
 
43
}
 
44
 
 
45
geom::Size mgm::ShmBuffer::size() const
 
46
{
 
47
    return size_;
 
48
}
 
49
 
 
50
geom::Stride mgm::ShmBuffer::stride() const
 
51
{
 
52
    return stride_;
 
53
}
 
54
 
 
55
MirPixelFormat mgm::ShmBuffer::pixel_format() const
 
56
{
 
57
    return pixel_format_;
 
58
}
 
59
 
 
60
void mgm::ShmBuffer::bind_to_texture()
 
61
{
 
62
    glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT,
 
63
                 size_.width.as_int(), size_.height.as_int(),
 
64
                 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE,
 
65
                 pixels);
 
66
}
 
67
 
 
68
std::shared_ptr<MirNativeBuffer> mgm::ShmBuffer::native_buffer_handle() const
 
69
{
 
70
    auto native_buffer = std::make_shared<MirNativeBuffer>();
 
71
 
 
72
    native_buffer->fd_items = 1;
 
73
    native_buffer->fd[0] = shm_file->fd();
 
74
    native_buffer->stride = stride().as_uint32_t();
 
75
    native_buffer->flags = 0;
 
76
 
 
77
    auto const& dim = size();
 
78
    native_buffer->width = dim.width.as_int();
 
79
    native_buffer->height = dim.height.as_int();
 
80
 
 
81
    return native_buffer;
 
82
}
 
83
 
 
84
bool mgm::ShmBuffer::can_bypass() const
 
85
{
 
86
    return false;
 
87
}