2
* Copyright © 2013 Canonical Ltd.
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.
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.
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/>.
17
* Alexandros Frantzis <alexandros.frantzis@canonical.com>
21
#include "shm_buffer.h"
22
#include "buffer_texture_binder.h"
23
#include <GLES2/gl2.h>
24
#include <GLES2/gl2ext.h>
26
namespace mgm = mir::graphics::mesa;
27
namespace geom = mir::geometry;
29
mgm::ShmBuffer::ShmBuffer(
30
std::shared_ptr<ShmFile> const& shm_file,
31
geom::Size const& size,
32
MirPixelFormat const& pixel_format)
35
pixel_format_{pixel_format},
36
stride_{MIR_BYTES_PER_PIXEL(pixel_format_) * size_.width.as_uint32_t()},
37
pixels{shm_file->base_ptr()}
41
mgm::ShmBuffer::~ShmBuffer() noexcept
45
geom::Size mgm::ShmBuffer::size() const
50
geom::Stride mgm::ShmBuffer::stride() const
55
MirPixelFormat mgm::ShmBuffer::pixel_format() const
60
void mgm::ShmBuffer::bind_to_texture()
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,
68
std::shared_ptr<MirNativeBuffer> mgm::ShmBuffer::native_buffer_handle() const
70
auto native_buffer = std::make_shared<MirNativeBuffer>();
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;
77
auto const& dim = size();
78
native_buffer->width = dim.width.as_int();
79
native_buffer->height = dim.height.as_int();
84
bool mgm::ShmBuffer::can_bypass() const