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
|
/*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 2 or 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by:
* Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
*/
#include "buffer_allocator.h"
#include "buffer_texture_binder.h"
#include "anonymous_shm_file.h"
#include "shm_buffer.h"
#include "mir/graphics/buffer_properties.h"
#include "software_buffer.h"
#include <boost/throw_exception.hpp>
#include <boost/exception/errinfo_errno.hpp>
#include <system_error>
#include <cassert>
namespace mg = mir::graphics;
namespace mge = mg::eglstream;
namespace mgc = mg::common;
namespace geom = mir::geometry;
mge::BufferAllocator::BufferAllocator()
{
}
std::shared_ptr<mg::Buffer> mge::BufferAllocator::alloc_buffer(
BufferProperties const& buffer_properties)
{
if (buffer_properties.usage == mg::BufferUsage::software)
return alloc_software_buffer(buffer_properties.size, buffer_properties.format);
BOOST_THROW_EXCEPTION(std::runtime_error("platform incapable of creating hardware buffers"));
}
std::shared_ptr<mg::Buffer> mge::BufferAllocator::alloc_software_buffer(geom::Size size, MirPixelFormat format)
{
if (!mgc::ShmBuffer::supports(format))
{
BOOST_THROW_EXCEPTION(
std::runtime_error(
"Trying to create SHM buffer with unsupported pixel format"));
}
auto const stride = geom::Stride{ MIR_BYTES_PER_PIXEL(format) * size.width.as_uint32_t() };
size_t const size_in_bytes = stride.as_int() * size.height.as_int();
return std::make_shared<mge::SoftwareBuffer>(
std::make_unique<mgc::AnonymousShmFile>(size_in_bytes), size, format);
}
std::vector<MirPixelFormat> mge::BufferAllocator::supported_pixel_formats()
{
// Lazy
return {mir_pixel_format_argb_8888, mir_pixel_format_xrgb_8888};
}
std::shared_ptr<mg::Buffer> mge::BufferAllocator::alloc_buffer(geometry::Size, uint32_t, uint32_t)
{
BOOST_THROW_EXCEPTION(std::runtime_error("platform incapable of creating buffers"));
}
|