~mir-team/mir/trunk

« back to all changes in this revision

Viewing changes to src/server/graphics/gbm/gbm_buffer_allocator.cpp

gbm: Don't try to allocate buffers with unsupported formats. Fixes: https://bugs.launchpad.net/bugs/1124948.

Approved by PS Jenkins bot, Alan Griffiths.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <GLES2/gl2.h>
32
32
#include <GLES2/gl2ext.h>
33
33
 
 
34
#include <algorithm>
34
35
#include <stdexcept>
35
36
#include <gbm.h>
36
37
#include <cassert>
119
120
{
120
121
    uint32_t bo_flags{GBM_BO_USE_RENDERING};
121
122
 
 
123
    uint32_t gbm_format = mgg::mir_format_to_gbm_format(buffer_properties.format);
 
124
 
 
125
    if (!is_pixel_format_supported(buffer_properties.format) ||
 
126
        gbm_format == mgg::invalid_gbm_format)
 
127
    {
 
128
        BOOST_THROW_EXCEPTION(
 
129
            std::runtime_error("Trying to create GBM buffer with unsupported pixel format"));
 
130
    }
 
131
 
122
132
    /* Create the GBM buffer object */
123
133
    if (buffer_properties.usage == BufferUsage::software)
124
134
        bo_flags |= GBM_BO_USE_WRITE;
127
137
        platform->gbm.device,
128
138
        buffer_properties.size.width.as_uint32_t(),
129
139
        buffer_properties.size.height.as_uint32_t(),
130
 
        mgg::mir_format_to_gbm_format(buffer_properties.format),
 
140
        gbm_format,
131
141
        bo_flags);
132
142
 
133
143
    if (!bo_raw)
155
165
 
156
166
    return pixel_formats;
157
167
}
 
168
 
 
169
bool mgg::GBMBufferAllocator::is_pixel_format_supported(geom::PixelFormat format)
 
170
{
 
171
    auto formats = supported_pixel_formats();
 
172
 
 
173
    auto iter = std::find(formats.begin(), formats.end(), format);
 
174
 
 
175
    return iter != formats.end();
 
176
}