render/pixel_format: introduce pixel format info table

This commit is contained in:
Simon Zeni 2021-03-15 12:29:29 -04:00 committed by Simon Ser
parent d9cae04ffc
commit 5fd82c6f54
3 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,23 @@
#ifndef RENDER_PIXEL_FORMAT_H
#define RENDER_PIXEL_FORMAT_H
#include <wayland-server-protocol.h>
struct wlr_pixel_format_info {
uint32_t drm_format;
/* Equivalent of the format if it has an alpha channel,
* DRM_FORMAT_INVALID (0) if NA
*/
uint32_t opaque_substitute;
/* Bits per pixels */
uint32_t bpp;
/* True if the format has an alpha channel */
bool has_alpha;
};
const struct wlr_pixel_format_info *drm_get_pixel_format_info(uint32_t fmt);
#endif

View File

@ -5,6 +5,7 @@ wlr_files += files(
'drm_format_set.c', 'drm_format_set.c',
'gbm_allocator.c', 'gbm_allocator.c',
'shm_format.c', 'shm_format.c',
'pixel_format.c',
'swapchain.c', 'swapchain.c',
'wlr_renderer.c', 'wlr_renderer.c',
'wlr_texture.c', 'wlr_texture.c',

30
render/pixel_format.c Normal file
View File

@ -0,0 +1,30 @@
#include <drm_fourcc.h>
#include "render/pixel_format.h"
static const struct wlr_pixel_format_info pixel_format_info[] = {
{
.drm_format = DRM_FORMAT_XRGB8888,
.opaque_substitute = DRM_FORMAT_INVALID,
.bpp = 32,
.has_alpha = false,
},
{
.drm_format = DRM_FORMAT_ARGB8888,
.opaque_substitute = DRM_FORMAT_XRGB8888,
.bpp = 32,
.has_alpha = true,
}
};
static const size_t pixel_format_info_size =
sizeof(pixel_format_info) / sizeof(pixel_format_info[0]);
const struct wlr_pixel_format_info *drm_get_pixel_format_info(uint32_t fmt) {
for (size_t i = 0; i < pixel_format_info_size; ++i) {
if (pixel_format_info[i].drm_format == fmt) {
return &pixel_format_info[i];
}
}
return NULL;
}