mirror of
https://github.com/brl/mutter.git
synced 2024-12-28 05:42:14 +00:00
multi-texture-format: Expose immutable fields directly
Split the struct into mutable and immutable parts. Access the mutable parts via getters and the immutable parts via a single struct. This avoids copying around the immutable parts. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3280>
This commit is contained in:
parent
6f1edfc776
commit
dbdc821ca7
@ -25,19 +25,20 @@
|
|||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
typedef struct _MetaMultiTextureFormatInfo
|
||||||
|
{
|
||||||
|
uint8_t n_planes;
|
||||||
|
|
||||||
|
/* Per plane-information */
|
||||||
|
CoglPixelFormat subformats[COGL_PIXEL_FORMAT_MAX_PLANES]; /* influences how we deal with it on a GL level */
|
||||||
|
uint8_t plane_indices[COGL_PIXEL_FORMAT_MAX_PLANES]; /* source plane */
|
||||||
|
uint8_t hsub[COGL_PIXEL_FORMAT_MAX_PLANES]; /* horizontal subsampling */
|
||||||
|
uint8_t vsub[COGL_PIXEL_FORMAT_MAX_PLANES]; /* vertical subsampling */
|
||||||
|
} MetaMultiTextureFormatInfo;
|
||||||
|
|
||||||
const char * meta_multi_texture_format_to_string (MetaMultiTextureFormat format);
|
const char * meta_multi_texture_format_to_string (MetaMultiTextureFormat format);
|
||||||
|
|
||||||
int meta_multi_texture_format_get_n_planes (MetaMultiTextureFormat format);
|
const MetaMultiTextureFormatInfo * meta_multi_texture_format_get_info (MetaMultiTextureFormat format);
|
||||||
|
|
||||||
void meta_multi_texture_format_get_subformats (MetaMultiTextureFormat format,
|
|
||||||
CoglPixelFormat *formats_out);
|
|
||||||
|
|
||||||
void meta_multi_texture_format_get_plane_indices (MetaMultiTextureFormat format,
|
|
||||||
uint8_t *plane_indices);
|
|
||||||
|
|
||||||
void meta_multi_texture_format_get_subsampling_factors (MetaMultiTextureFormat format,
|
|
||||||
uint8_t *horizontal_factors,
|
|
||||||
uint8_t *vertical_factors);
|
|
||||||
|
|
||||||
gboolean meta_multi_texture_format_get_snippets (MetaMultiTextureFormat format,
|
gboolean meta_multi_texture_format_get_snippets (MetaMultiTextureFormat format,
|
||||||
CoglSnippet **fragment_globals_snippet,
|
CoglSnippet **fragment_globals_snippet,
|
||||||
|
@ -79,82 +79,86 @@ static const char y_u_v_shader[] =
|
|||||||
"yuva.z = texture2D(cogl_sampler2, cogl_tex_coord2_in.st).x; \n"
|
"yuva.z = texture2D(cogl_sampler2, cogl_tex_coord2_in.st).x; \n"
|
||||||
"cogl_color_out = yuv_to_rgb(yuva); \n";
|
"cogl_color_out = yuv_to_rgb(yuva); \n";
|
||||||
|
|
||||||
typedef struct _MetaMultiTextureFormatInfo
|
typedef struct _MetaMultiTextureFormatFullInfo
|
||||||
{
|
{
|
||||||
MetaMultiTextureFormat multi_format;
|
MetaMultiTextureFormatInfo info;
|
||||||
|
|
||||||
|
/* Name */
|
||||||
const char *name;
|
const char *name;
|
||||||
uint8_t n_planes;
|
/* Shader to convert to RGBA (or NULL) */
|
||||||
|
const char *rgb_shader;
|
||||||
/* Per plane-information */
|
/* Cached snippet */
|
||||||
CoglPixelFormat subformats[COGL_PIXEL_FORMAT_MAX_PLANES]; /* influences how we deal with it on a GL level */
|
|
||||||
uint8_t plane_indices[COGL_PIXEL_FORMAT_MAX_PLANES]; /* source plane */
|
|
||||||
uint8_t hsub[COGL_PIXEL_FORMAT_MAX_PLANES]; /* horizontal subsampling */
|
|
||||||
uint8_t vsub[COGL_PIXEL_FORMAT_MAX_PLANES]; /* vertical subsampling */
|
|
||||||
|
|
||||||
/* Shaders */
|
|
||||||
const char *rgb_shader; /* Shader to convert to RGBA (or NULL) */
|
|
||||||
|
|
||||||
GOnce snippet_once;
|
GOnce snippet_once;
|
||||||
} MetaMultiTextureFormatInfo;
|
} MetaMultiTextureFormatFullInfo;
|
||||||
|
|
||||||
/* NOTE: The actual enum values are used as the index, so you don't need to
|
/* NOTE: The actual enum values are used as the index, so you don't need to
|
||||||
* loop over the table */
|
* loop over the table */
|
||||||
static MetaMultiTextureFormatInfo multi_format_table[] = {
|
static MetaMultiTextureFormatFullInfo multi_format_table[] = {
|
||||||
/* Invalid */
|
/* Invalid */
|
||||||
[META_MULTI_TEXTURE_FORMAT_INVALID] = {},
|
[META_MULTI_TEXTURE_FORMAT_INVALID] = {},
|
||||||
/* Simple */
|
/* Simple */
|
||||||
[META_MULTI_TEXTURE_FORMAT_SIMPLE] = {
|
[META_MULTI_TEXTURE_FORMAT_SIMPLE] = {
|
||||||
.name = "",
|
.name = "",
|
||||||
.n_planes = 1,
|
|
||||||
.subformats = { COGL_PIXEL_FORMAT_ANY },
|
|
||||||
.plane_indices = { 0 },
|
|
||||||
.hsub = { 1 },
|
|
||||||
.vsub = { 1 },
|
|
||||||
.rgb_shader = rgba_shader,
|
.rgb_shader = rgba_shader,
|
||||||
.snippet_once = G_ONCE_INIT,
|
.snippet_once = G_ONCE_INIT,
|
||||||
|
.info = {
|
||||||
|
.n_planes = 1,
|
||||||
|
.subformats = { COGL_PIXEL_FORMAT_ANY },
|
||||||
|
.plane_indices = { 0 },
|
||||||
|
.hsub = { 1 },
|
||||||
|
.vsub = { 1 },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
/* Packed YUV */
|
/* Packed YUV */
|
||||||
[META_MULTI_TEXTURE_FORMAT_YUYV] = {
|
[META_MULTI_TEXTURE_FORMAT_YUYV] = {
|
||||||
.name = "YUYV",
|
.name = "YUYV",
|
||||||
.n_planes = 2,
|
|
||||||
.subformats = { COGL_PIXEL_FORMAT_RG_88, COGL_PIXEL_FORMAT_BGRA_8888_PRE },
|
|
||||||
.plane_indices = { 0, 0 },
|
|
||||||
.hsub = { 1, 2 },
|
|
||||||
.vsub = { 1, 1 },
|
|
||||||
.rgb_shader = y_xuxv_shader,
|
.rgb_shader = y_xuxv_shader,
|
||||||
.snippet_once = G_ONCE_INIT,
|
.snippet_once = G_ONCE_INIT,
|
||||||
|
.info = {
|
||||||
|
.n_planes = 2,
|
||||||
|
.subformats = { COGL_PIXEL_FORMAT_RG_88, COGL_PIXEL_FORMAT_BGRA_8888_PRE },
|
||||||
|
.plane_indices = { 0, 0 },
|
||||||
|
.hsub = { 1, 2 },
|
||||||
|
.vsub = { 1, 1 },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
/* 2 plane YUV */
|
/* 2 plane YUV */
|
||||||
[META_MULTI_TEXTURE_FORMAT_NV12] = {
|
[META_MULTI_TEXTURE_FORMAT_NV12] = {
|
||||||
.name = "NV12",
|
.name = "NV12",
|
||||||
.n_planes = 2,
|
|
||||||
.subformats = { COGL_PIXEL_FORMAT_R_8, COGL_PIXEL_FORMAT_RG_88 },
|
|
||||||
.plane_indices = { 0, 1 },
|
|
||||||
.hsub = { 1, 2 },
|
|
||||||
.vsub = { 1, 2 },
|
|
||||||
.rgb_shader = y_uv_shader,
|
.rgb_shader = y_uv_shader,
|
||||||
.snippet_once = G_ONCE_INIT,
|
.snippet_once = G_ONCE_INIT,
|
||||||
|
.info = {
|
||||||
|
.n_planes = 2,
|
||||||
|
.subformats = { COGL_PIXEL_FORMAT_R_8, COGL_PIXEL_FORMAT_RG_88 },
|
||||||
|
.plane_indices = { 0, 1 },
|
||||||
|
.hsub = { 1, 2 },
|
||||||
|
.vsub = { 1, 2 },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
[META_MULTI_TEXTURE_FORMAT_P010] = {
|
[META_MULTI_TEXTURE_FORMAT_P010] = {
|
||||||
.name = "P010",
|
.name = "P010",
|
||||||
.n_planes = 2,
|
|
||||||
.subformats = { COGL_PIXEL_FORMAT_R_16, COGL_PIXEL_FORMAT_RG_1616 },
|
|
||||||
.plane_indices = { 0, 1 },
|
|
||||||
.hsub = { 1, 2 },
|
|
||||||
.vsub = { 1, 2 },
|
|
||||||
.rgb_shader = y_uv_shader,
|
.rgb_shader = y_uv_shader,
|
||||||
.snippet_once = G_ONCE_INIT,
|
.snippet_once = G_ONCE_INIT,
|
||||||
|
.info = {
|
||||||
|
.n_planes = 2,
|
||||||
|
.subformats = { COGL_PIXEL_FORMAT_R_16, COGL_PIXEL_FORMAT_RG_1616 },
|
||||||
|
.plane_indices = { 0, 1 },
|
||||||
|
.hsub = { 1, 2 },
|
||||||
|
.vsub = { 1, 2 },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
/* 3 plane YUV */
|
/* 3 plane YUV */
|
||||||
[META_MULTI_TEXTURE_FORMAT_YUV420] = {
|
[META_MULTI_TEXTURE_FORMAT_YUV420] = {
|
||||||
.name = "YUV420",
|
.name = "YUV420",
|
||||||
.n_planes = 3,
|
|
||||||
.subformats = { COGL_PIXEL_FORMAT_R_8, COGL_PIXEL_FORMAT_R_8, COGL_PIXEL_FORMAT_R_8 },
|
|
||||||
.plane_indices = { 0, 1, 2 },
|
|
||||||
.hsub = { 1, 2, 2 },
|
|
||||||
.vsub = { 1, 2, 2 },
|
|
||||||
.rgb_shader = y_u_v_shader,
|
.rgb_shader = y_u_v_shader,
|
||||||
.snippet_once = G_ONCE_INIT,
|
.snippet_once = G_ONCE_INIT,
|
||||||
|
.info = {
|
||||||
|
.n_planes = 3,
|
||||||
|
.subformats = { COGL_PIXEL_FORMAT_R_8, COGL_PIXEL_FORMAT_R_8, COGL_PIXEL_FORMAT_R_8 },
|
||||||
|
.plane_indices = { 0, 1, 2 },
|
||||||
|
.hsub = { 1, 2, 2 },
|
||||||
|
.vsub = { 1, 2, 2 },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -166,52 +170,12 @@ meta_multi_texture_format_to_string (MetaMultiTextureFormat format)
|
|||||||
return multi_format_table[format].name;
|
return multi_format_table[format].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
const MetaMultiTextureFormatInfo *
|
||||||
meta_multi_texture_format_get_n_planes (MetaMultiTextureFormat format)
|
meta_multi_texture_format_get_info (MetaMultiTextureFormat format)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (format < G_N_ELEMENTS (multi_format_table), 0);
|
g_return_val_if_fail (format < G_N_ELEMENTS (multi_format_table), NULL);
|
||||||
|
|
||||||
return multi_format_table[format].n_planes;
|
return &multi_format_table[format].info;
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
meta_multi_texture_format_get_subformats (MetaMultiTextureFormat format,
|
|
||||||
CoglPixelFormat *formats_out)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
g_return_if_fail (format < G_N_ELEMENTS (multi_format_table));
|
|
||||||
|
|
||||||
for (i = 0; i < multi_format_table[format].n_planes; i++)
|
|
||||||
formats_out[i] = multi_format_table[format].subformats[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
meta_multi_texture_format_get_plane_indices (MetaMultiTextureFormat format,
|
|
||||||
uint8_t *plane_indices)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
g_return_if_fail (format < G_N_ELEMENTS (multi_format_table));
|
|
||||||
|
|
||||||
for (i = 0; i < multi_format_table[format].n_planes; i++)
|
|
||||||
plane_indices[i] = multi_format_table[format].plane_indices[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
meta_multi_texture_format_get_subsampling_factors (MetaMultiTextureFormat format,
|
|
||||||
uint8_t *horizontal_factors,
|
|
||||||
uint8_t *vertical_factors)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
g_return_if_fail (format < G_N_ELEMENTS (multi_format_table));
|
|
||||||
|
|
||||||
for (i = 0; i < multi_format_table[format].n_planes; i++)
|
|
||||||
{
|
|
||||||
horizontal_factors[i] = multi_format_table[format].hsub[i];
|
|
||||||
vertical_factors[i] = multi_format_table[format].vsub[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gpointer
|
static gpointer
|
||||||
|
@ -437,21 +437,14 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer,
|
|||||||
{
|
{
|
||||||
CoglTexture **textures;
|
CoglTexture **textures;
|
||||||
g_autoptr (GPtrArray) planes = NULL;
|
g_autoptr (GPtrArray) planes = NULL;
|
||||||
CoglPixelFormat subformats[META_WAYLAND_DMA_BUF_MAX_FDS];
|
|
||||||
uint8_t horizontal_factors[META_WAYLAND_DMA_BUF_MAX_FDS];
|
|
||||||
uint8_t vertical_factors[META_WAYLAND_DMA_BUF_MAX_FDS];
|
|
||||||
uint8_t plane_indices[META_WAYLAND_DMA_BUF_MAX_FDS];
|
|
||||||
int n_planes, i;
|
int n_planes, i;
|
||||||
|
const MetaMultiTextureFormatInfo *mt_format_info;
|
||||||
|
|
||||||
n_planes = meta_multi_texture_format_get_n_planes (multi_format);
|
mt_format_info = meta_multi_texture_format_get_info (multi_format);
|
||||||
|
n_planes = mt_format_info->n_planes;
|
||||||
|
|
||||||
/* Each EGLImage is a plane in the final CoglMultiPlaneTexture */
|
/* Each EGLImage is a plane in the final CoglMultiPlaneTexture */
|
||||||
planes = g_ptr_array_new_full (n_planes, g_object_unref);
|
planes = g_ptr_array_new_full (n_planes, g_object_unref);
|
||||||
meta_multi_texture_format_get_subformats (multi_format, subformats);
|
|
||||||
meta_multi_texture_format_get_plane_indices (multi_format, plane_indices);
|
|
||||||
meta_multi_texture_format_get_subsampling_factors (multi_format,
|
|
||||||
horizontal_factors,
|
|
||||||
vertical_factors);
|
|
||||||
|
|
||||||
for (i = 0; i < n_planes; i++)
|
for (i = 0; i < n_planes; i++)
|
||||||
{
|
{
|
||||||
@ -459,21 +452,22 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer,
|
|||||||
CoglEglImageFlags flags;
|
CoglEglImageFlags flags;
|
||||||
CoglTexture *cogl_texture;
|
CoglTexture *cogl_texture;
|
||||||
uint32_t drm_format = 0;
|
uint32_t drm_format = 0;
|
||||||
int plane_index;
|
|
||||||
const MetaFormatInfo *format_info;
|
const MetaFormatInfo *format_info;
|
||||||
|
int plane_index = mt_format_info->plane_indices[i];
|
||||||
|
CoglPixelFormat subformat = mt_format_info->subformats[i];
|
||||||
|
int horizontal_factor = mt_format_info->hsub[i];
|
||||||
|
int vertical_factor = mt_format_info->vsub[i];
|
||||||
|
|
||||||
format_info = meta_format_info_from_cogl_format (subformats[i]);
|
format_info = meta_format_info_from_cogl_format (subformat);
|
||||||
g_return_val_if_fail (format_info != NULL, FALSE);
|
g_return_val_if_fail (format_info != NULL, FALSE);
|
||||||
drm_format = format_info->drm_format;
|
drm_format = format_info->drm_format;
|
||||||
|
|
||||||
plane_index = plane_indices[i];
|
|
||||||
|
|
||||||
egl_image = meta_egl_create_dmabuf_image (egl,
|
egl_image = meta_egl_create_dmabuf_image (egl,
|
||||||
egl_display,
|
egl_display,
|
||||||
dma_buf->width /
|
dma_buf->width /
|
||||||
horizontal_factors[i],
|
horizontal_factor,
|
||||||
dma_buf->height /
|
dma_buf->height /
|
||||||
vertical_factors[i],
|
vertical_factor,
|
||||||
drm_format,
|
drm_format,
|
||||||
1,
|
1,
|
||||||
&dma_buf->fds[plane_index],
|
&dma_buf->fds[plane_index],
|
||||||
@ -488,7 +482,7 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer,
|
|||||||
cogl_texture = cogl_egl_texture_2d_new_from_image (cogl_context,
|
cogl_texture = cogl_egl_texture_2d_new_from_image (cogl_context,
|
||||||
dma_buf->width,
|
dma_buf->width,
|
||||||
dma_buf->height,
|
dma_buf->height,
|
||||||
subformats[i],
|
subformat,
|
||||||
egl_image,
|
egl_image,
|
||||||
flags,
|
flags,
|
||||||
error);
|
error);
|
||||||
|
Loading…
Reference in New Issue
Block a user